фильтр
This commit is contained in:
@@ -90,6 +90,21 @@
|
|||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
<div class="filter-group">
|
<div class="filter-group">
|
||||||
|
<label for="type-filter"><i class="fas fa-tag"></i> Тип:</label>
|
||||||
|
<select id="type-filter" onchange="loadTasks()">
|
||||||
|
<option value="">Все типы</option>
|
||||||
|
<option value="regular">Обычная задача</option>
|
||||||
|
<option value="document">Согласование документа</option>
|
||||||
|
<option value="it">ИТ отдел</option>
|
||||||
|
<option value="ahch">АХЧ</option>
|
||||||
|
<option value="psychologist">Психолог</option>
|
||||||
|
<option value="speech_therapist">Логопед</option>
|
||||||
|
<option value="hr">Диспетчер расписания</option>
|
||||||
|
<option value="certificate">Справка</option>
|
||||||
|
<option value="e_journal">Эл. журнал</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<div class="filter-group">
|
||||||
<label for="creator-filter"><i class="fas fa-user-tie"></i> Заказчик:</label>
|
<label for="creator-filter"><i class="fas fa-user-tie"></i> Заказчик:</label>
|
||||||
<select id="creator-filter" onchange="loadTasks()">
|
<select id="creator-filter" onchange="loadTasks()">
|
||||||
<option value="">Все заказчики</option>
|
<option value="">Все заказчики</option>
|
||||||
@@ -113,6 +128,11 @@
|
|||||||
<label for="search-tasks"><i class="fas fa-search"></i> Поиск:</label>
|
<label for="search-tasks"><i class="fas fa-search"></i> Поиск:</label>
|
||||||
<input type="text" id="search-tasks" placeholder="Поиск по названию и описанию..." oninput="loadTasks()">
|
<input type="text" id="search-tasks" placeholder="Поиск по названию и описанию..." oninput="loadTasks()">
|
||||||
</div>
|
</div>
|
||||||
|
<div class="filter-actions">
|
||||||
|
<button type="button" class="btn-reset" onclick="resetAllFilters()">
|
||||||
|
<i class="fas fa-undo"></i> Сбросить фильтры
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<label class="show-deleted-label" style="display: none;">
|
<label class="show-deleted-label" style="display: none;">
|
||||||
<input type="checkbox" id="show-deleted" onchange="loadTasks()">
|
<input type="checkbox" id="show-deleted" onchange="loadTasks()">
|
||||||
|
|||||||
@@ -5,47 +5,75 @@ let showingTasksWithoutDate = false;
|
|||||||
|
|
||||||
async function loadTasks() {
|
async function loadTasks() {
|
||||||
try {
|
try {
|
||||||
showingTasksWithoutDate = false;
|
// Получаем значения фильтров
|
||||||
const btn = document.getElementById('tasks-no-date-btn');
|
|
||||||
if (btn) btn.classList.remove('active');
|
|
||||||
|
|
||||||
const search = document.getElementById('search-tasks')?.value || '';
|
|
||||||
const statusFilter = document.getElementById('status-filter')?.value || 'active,in_progress,assigned,overdue,rework';
|
const statusFilter = document.getElementById('status-filter')?.value || 'active,in_progress,assigned,overdue,rework';
|
||||||
const creatorFilter = document.getElementById('creator-filter')?.value || '';
|
const creatorFilter = document.getElementById('creator-filter')?.value || '';
|
||||||
const assigneeFilter = document.getElementById('assignee-filter')?.value || '';
|
const assigneeFilter = document.getElementById('assignee-filter')?.value || '';
|
||||||
const deadlineFilter = document.getElementById('deadline-filter')?.value || '';
|
const deadlineFilter = document.getElementById('deadline-filter')?.value || '';
|
||||||
const showDeleted = document.getElementById('show-deleted')?.checked || false;
|
const searchQuery = document.getElementById('search-tasks')?.value || '';
|
||||||
|
const typeFilter = document.getElementById('type-filter')?.value || '';
|
||||||
|
|
||||||
|
// Формируем URL с параметрами
|
||||||
let url = '/api/tasks?';
|
let url = '/api/tasks?';
|
||||||
if (search) url += `search=${encodeURIComponent(search)}&`;
|
const params = [];
|
||||||
if (statusFilter) url += `status=${encodeURIComponent(statusFilter)}&`;
|
|
||||||
if (creatorFilter) url += `creator=${encodeURIComponent(creatorFilter)}&`;
|
if (statusFilter !== 'all') {
|
||||||
if (assigneeFilter) url += `assignee=${encodeURIComponent(assigneeFilter)}&`;
|
params.push(`status=${encodeURIComponent(statusFilter)}`);
|
||||||
if (deadlineFilter) url += `deadline=${encodeURIComponent(deadlineFilter)}&`;
|
}
|
||||||
if (showDeleted) url += `showDeleted=true&`;
|
|
||||||
|
if (creatorFilter) {
|
||||||
|
params.push(`creator=${encodeURIComponent(creatorFilter)}`); // было creator_id, теперь creator
|
||||||
|
}
|
||||||
|
|
||||||
|
if (assigneeFilter) {
|
||||||
|
params.push(`assignee=${encodeURIComponent(assigneeFilter)}`); // было assignee_id, теперь assignee
|
||||||
|
}
|
||||||
|
|
||||||
|
if (deadlineFilter) {
|
||||||
|
params.push(`deadline=${encodeURIComponent(deadlineFilter)}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (searchQuery) {
|
||||||
|
params.push(`search=${encodeURIComponent(searchQuery)}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeFilter) {
|
||||||
|
params.push(`task_type=${encodeURIComponent(typeFilter)}`); // было type, теперь task_type
|
||||||
|
}
|
||||||
|
|
||||||
|
url += params.join('&');
|
||||||
|
|
||||||
|
console.log('Загрузка задач с фильтрами:', url);
|
||||||
|
|
||||||
const response = await fetch(url);
|
const response = await fetch(url);
|
||||||
|
if (!response.ok) {
|
||||||
|
throw new Error(`HTTP error! status: ${response.status}`);
|
||||||
|
}
|
||||||
|
|
||||||
tasks = await response.json();
|
tasks = await response.json();
|
||||||
|
console.log(`Загружено ${tasks.length} задач`);
|
||||||
|
|
||||||
// Загружаем файлы для всех задач
|
// Обновляем отображение
|
||||||
await Promise.all(tasks.map(async (task) => {
|
const activeSection = document.querySelector('.section.active');
|
||||||
try {
|
if (activeSection) {
|
||||||
const filesResponse = await fetch(`/api/tasks/${task.id}/files`);
|
const sectionId = activeSection.id;
|
||||||
if (filesResponse.ok) {
|
if (sectionId === 'mytasks-section') {
|
||||||
task.files = await filesResponse.json();
|
filterMyTasks();
|
||||||
} else {
|
} else if (sectionId === 'runtasks-section') {
|
||||||
task.files = [];
|
filterRunTasks();
|
||||||
}
|
} else {
|
||||||
} catch (error) {
|
renderTasks();
|
||||||
console.error(`Ошибка загрузки файлов для задачи ${task.id}:`, error);
|
|
||||||
task.files = [];
|
|
||||||
}
|
}
|
||||||
}));
|
} else {
|
||||||
|
renderTasks();
|
||||||
renderTasks();
|
}
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Ошибка загрузки задач:', error);
|
console.error('Ошибка загрузки задач:', error);
|
||||||
|
const container = document.getElementById('tasks-list');
|
||||||
|
if (container) {
|
||||||
|
container.innerHTML = '<div class="error">Ошибка загрузки задач</div>';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -55,7 +83,15 @@ function showTasksWithoutDate() {
|
|||||||
if (btn) btn.classList.add('active');
|
if (btn) btn.classList.add('active');
|
||||||
loadTasksWithoutDate();
|
loadTasksWithoutDate();
|
||||||
}
|
}
|
||||||
|
function resetAllFilters() {
|
||||||
|
document.getElementById('status-filter').value = 'active,in_progress,assigned,overdue,rework';
|
||||||
|
document.getElementById('creator-filter').value = '';
|
||||||
|
document.getElementById('assignee-filter').value = '';
|
||||||
|
document.getElementById('deadline-filter').value = '';
|
||||||
|
document.getElementById('type-filter').value = '';
|
||||||
|
document.getElementById('search-tasks').value = '';
|
||||||
|
loadTasks();
|
||||||
|
}
|
||||||
async function loadTasksWithoutDate() {
|
async function loadTasksWithoutDate() {
|
||||||
try {
|
try {
|
||||||
const response = await fetch('/api/tasks');
|
const response = await fetch('/api/tasks');
|
||||||
|
|||||||
@@ -72,143 +72,153 @@ function setupTaskEndpoints(app, db, upload) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// API для задач
|
// API для задач
|
||||||
app.get('/api/tasks', requireAuth, (req, res) => {
|
app.get('/api/tasks', requireAuth, (req, res) => {
|
||||||
const userId = req.session.user.id;
|
const userId = req.session.user.id;
|
||||||
const showDeleted = req.session.user.role === 'admin' && req.query.showDeleted === 'true';
|
const showDeleted = req.session.user.role === 'admin' && req.query.showDeleted === 'true';
|
||||||
const search = req.query.search || '';
|
const search = req.query.search || '';
|
||||||
const statusFilter = req.query.status || 'active,in_progress,assigned,overdue,rework';
|
const statusFilter = req.query.status || 'active,in_progress,assigned,overdue,rework';
|
||||||
const creatorFilter = req.query.creator || '';
|
const creatorFilter = req.query.creator || '';
|
||||||
const assigneeFilter = req.query.assignee || '';
|
const assigneeFilter = req.query.assignee || '';
|
||||||
const deadlineFilter = req.query.deadline || '';
|
const deadlineFilter = req.query.deadline || '';
|
||||||
|
const taskType = req.query.task_type || ''; // Новый параметр для фильтрации по типу задачи
|
||||||
|
|
||||||
let query = `
|
let query = `
|
||||||
SELECT DISTINCT
|
SELECT DISTINCT
|
||||||
t.*,
|
t.*,
|
||||||
u.name as creator_name,
|
u.name as creator_name,
|
||||||
u.login as creator_login,
|
u.login as creator_login,
|
||||||
ot.title as original_task_title,
|
ot.title as original_task_title,
|
||||||
ou.name as original_creator_name,
|
ou.name as original_creator_name,
|
||||||
GROUP_CONCAT(DISTINCT ta.user_id) as assigned_user_ids,
|
GROUP_CONCAT(DISTINCT ta.user_id) as assigned_user_ids,
|
||||||
GROUP_CONCAT(DISTINCT u2.name) as assigned_user_names
|
GROUP_CONCAT(DISTINCT u2.name) as assigned_user_names
|
||||||
FROM tasks t
|
FROM tasks t
|
||||||
LEFT JOIN users u ON t.created_by = u.id
|
LEFT JOIN users u ON t.created_by = u.id
|
||||||
LEFT JOIN tasks ot ON t.original_task_id = ot.id
|
LEFT JOIN tasks ot ON t.original_task_id = ot.id
|
||||||
LEFT JOIN users ou ON ot.created_by = ou.id
|
LEFT JOIN users ou ON ot.created_by = ou.id
|
||||||
LEFT JOIN task_assignments ta ON t.id = ta.task_id
|
LEFT JOIN task_assignments ta ON t.id = ta.task_id
|
||||||
LEFT JOIN users u2 ON ta.user_id = u2.id
|
LEFT JOIN users u2 ON ta.user_id = u2.id
|
||||||
WHERE 1=1
|
WHERE 1=1
|
||||||
`;
|
`;
|
||||||
|
|
||||||
const params = [];
|
const params = [];
|
||||||
|
|
||||||
if (req.session.user.role !== 'admin') {
|
// ===== ДОБАВЛЯЕМ ФИЛЬТР ПО ТИПУ ЗАДАЧИ =====
|
||||||
query += ` AND (t.created_by = ? OR ta.user_id = ?)`;
|
if (taskType) {
|
||||||
params.push(userId, userId);
|
query += ` AND t.task_type = ?`;
|
||||||
}
|
params.push(taskType);
|
||||||
|
}
|
||||||
|
|
||||||
if (!showDeleted) {
|
if (req.session.user.role !== 'admin') {
|
||||||
query += " AND t.status = 'active'";
|
query += ` AND (t.created_by = ? OR ta.user_id = ?)`;
|
||||||
}
|
params.push(userId, userId);
|
||||||
|
}
|
||||||
|
|
||||||
if (statusFilter && statusFilter !== 'all') {
|
if (!showDeleted) {
|
||||||
const statuses = statusFilter.split(',');
|
query += " AND t.status = 'active'";
|
||||||
|
}
|
||||||
|
|
||||||
if (statuses.includes('closed')) {
|
if (statusFilter && statusFilter !== 'all') {
|
||||||
if (req.session.user.role !== 'admin') {
|
const statuses = statusFilter.split(',');
|
||||||
query += ` AND (t.closed_at IS NOT NULL AND t.created_by = ?)`;
|
|
||||||
params.push(userId);
|
if (statuses.includes('closed')) {
|
||||||
} else {
|
if (req.session.user.role !== 'admin') {
|
||||||
query += ` AND t.closed_at IS NOT NULL`;
|
query += ` AND (t.closed_at IS NOT NULL AND t.created_by = ?)`;
|
||||||
}
|
params.push(userId);
|
||||||
} else {
|
} else {
|
||||||
query += ` AND t.closed_at IS NULL`;
|
query += ` AND t.closed_at IS NOT NULL`;
|
||||||
|
|
||||||
if (statuses.length > 0 && !statuses.includes('all')) {
|
|
||||||
query += ` AND EXISTS (
|
|
||||||
SELECT 1 FROM task_assignments ta2
|
|
||||||
WHERE ta2.task_id = t.id AND ta2.status IN (${statuses.map(() => '?').join(',')})
|
|
||||||
)`;
|
|
||||||
statuses.forEach(status => params.push(status));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (req.session.user.role !== 'admin') {
|
query += ` AND t.closed_at IS NULL`;
|
||||||
query += ` AND (t.closed_at IS NULL OR t.created_by = ?)`;
|
|
||||||
params.push(userId);
|
if (statuses.length > 0 && !statuses.includes('all')) {
|
||||||
|
query += ` AND EXISTS (
|
||||||
|
SELECT 1 FROM task_assignments ta2
|
||||||
|
WHERE ta2.task_id = t.id AND ta2.status IN (${statuses.map(() => '?').join(',')})
|
||||||
|
)`;
|
||||||
|
statuses.forEach(status => params.push(status));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
if (req.session.user.role !== 'admin') {
|
||||||
|
query += ` AND (t.closed_at IS NULL OR t.created_by = ?)`;
|
||||||
|
params.push(userId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (creatorFilter) {
|
if (creatorFilter) {
|
||||||
query += ` AND t.created_by = ?`;
|
query += ` AND t.created_by = ?`;
|
||||||
params.push(creatorFilter);
|
params.push(creatorFilter);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (assigneeFilter) {
|
||||||
|
query += ` AND ta.user_id = ?`;
|
||||||
|
params.push(assigneeFilter);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (deadlineFilter) {
|
||||||
|
const now = new Date();
|
||||||
|
let hours = 48;
|
||||||
|
if (deadlineFilter === '24h') hours = 24;
|
||||||
|
|
||||||
|
const deadlineTime = new Date(now.getTime() + hours * 60 * 60 * 1000);
|
||||||
|
const deadlineISO = deadlineTime.toISOString();
|
||||||
|
const nowISO = now.toISOString();
|
||||||
|
|
||||||
|
query += ` AND ta.due_date IS NOT NULL
|
||||||
|
AND ta.due_date > ?
|
||||||
|
AND ta.due_date <= ?
|
||||||
|
AND ta.status NOT IN ('completed', 'overdue')`;
|
||||||
|
params.push(nowISO, deadlineISO);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (search) {
|
||||||
|
query += ` AND (t.title LIKE ? OR t.description LIKE ?)`;
|
||||||
|
const searchPattern = `%${search}%`;
|
||||||
|
params.push(searchPattern, searchPattern);
|
||||||
|
}
|
||||||
|
|
||||||
|
query += " GROUP BY t.id ORDER BY t.created_at DESC";
|
||||||
|
|
||||||
|
console.log('SQL Query:', query);
|
||||||
|
console.log('Params:', params);
|
||||||
|
|
||||||
|
db.all(query, params, (err, tasks) => {
|
||||||
|
if (err) {
|
||||||
|
res.status(500).json({ error: err.message });
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (assigneeFilter) {
|
const taskPromises = tasks.map(task => {
|
||||||
query += ` AND ta.user_id = ?`;
|
return new Promise((resolve) => {
|
||||||
params.push(assigneeFilter);
|
db.all(`
|
||||||
}
|
SELECT ta.*, u.name as user_name, u.login as user_login
|
||||||
|
FROM task_assignments ta
|
||||||
if (deadlineFilter) {
|
LEFT JOIN users u ON ta.user_id = u.id
|
||||||
const now = new Date();
|
WHERE ta.task_id = ?
|
||||||
let hours = 48;
|
`, [task.id], (err, assignments) => {
|
||||||
if (deadlineFilter === '24h') hours = 24;
|
if (err) {
|
||||||
|
task.assignments = [];
|
||||||
const deadlineTime = new Date(now.getTime() + hours * 60 * 60 * 1000);
|
|
||||||
const deadlineISO = deadlineTime.toISOString();
|
|
||||||
const nowISO = now.toISOString();
|
|
||||||
|
|
||||||
query += ` AND ta.due_date IS NOT NULL
|
|
||||||
AND ta.due_date > ?
|
|
||||||
AND ta.due_date <= ?
|
|
||||||
AND ta.status NOT IN ('completed', 'overdue')`;
|
|
||||||
params.push(nowISO, deadlineISO);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (search) {
|
|
||||||
query += ` AND (t.title LIKE ? OR t.description LIKE ?)`;
|
|
||||||
const searchPattern = `%${search}%`;
|
|
||||||
params.push(searchPattern, searchPattern);
|
|
||||||
}
|
|
||||||
|
|
||||||
query += " GROUP BY t.id ORDER BY t.created_at DESC";
|
|
||||||
|
|
||||||
db.all(query, params, (err, tasks) => {
|
|
||||||
if (err) {
|
|
||||||
res.status(500).json({ error: err.message });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const taskPromises = tasks.map(task => {
|
|
||||||
return new Promise((resolve) => {
|
|
||||||
db.all(`
|
|
||||||
SELECT ta.*, u.name as user_name, u.login as user_login
|
|
||||||
FROM task_assignments ta
|
|
||||||
LEFT JOIN users u ON ta.user_id = u.id
|
|
||||||
WHERE ta.task_id = ?
|
|
||||||
`, [task.id], (err, assignments) => {
|
|
||||||
if (err) {
|
|
||||||
task.assignments = [];
|
|
||||||
resolve(task);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
assignments.forEach(assignment => {
|
|
||||||
if (checkIfOverdue(assignment.due_date, assignment.status) && assignment.status !== 'completed') {
|
|
||||||
assignment.status = 'overdue';
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
task.assignments = assignments || [];
|
|
||||||
resolve(task);
|
resolve(task);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
assignments.forEach(assignment => {
|
||||||
|
if (checkIfOverdue(assignment.due_date, assignment.status) && assignment.status !== 'completed') {
|
||||||
|
assignment.status = 'overdue';
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
task.assignments = assignments || [];
|
||||||
|
resolve(task);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
|
||||||
Promise.all(taskPromises).then(completedTasks => {
|
Promise.all(taskPromises).then(completedTasks => {
|
||||||
res.json(completedTasks);
|
res.json(completedTasks);
|
||||||
});
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
});
|
||||||
// API для задач по типу
|
// API для задач по типу
|
||||||
app.get('/api/tasks_by_type', requireAuth, (req, res) => {
|
app.get('/api/tasks_by_type', requireAuth, (req, res) => {
|
||||||
const userId = req.session.user.id;
|
const userId = req.session.user.id;
|
||||||
|
|||||||
Reference in New Issue
Block a user