фильтр
This commit is contained in:
@@ -5,47 +5,75 @@ let showingTasksWithoutDate = false;
|
||||
|
||||
async function loadTasks() {
|
||||
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 creatorFilter = document.getElementById('creator-filter')?.value || '';
|
||||
const assigneeFilter = document.getElementById('assignee-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?';
|
||||
if (search) url += `search=${encodeURIComponent(search)}&`;
|
||||
if (statusFilter) url += `status=${encodeURIComponent(statusFilter)}&`;
|
||||
if (creatorFilter) url += `creator=${encodeURIComponent(creatorFilter)}&`;
|
||||
if (assigneeFilter) url += `assignee=${encodeURIComponent(assigneeFilter)}&`;
|
||||
if (deadlineFilter) url += `deadline=${encodeURIComponent(deadlineFilter)}&`;
|
||||
if (showDeleted) url += `showDeleted=true&`;
|
||||
const params = [];
|
||||
|
||||
if (statusFilter !== 'all') {
|
||||
params.push(`status=${encodeURIComponent(statusFilter)}`);
|
||||
}
|
||||
|
||||
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);
|
||||
if (!response.ok) {
|
||||
throw new Error(`HTTP error! status: ${response.status}`);
|
||||
}
|
||||
|
||||
tasks = await response.json();
|
||||
console.log(`Загружено ${tasks.length} задач`);
|
||||
|
||||
// Загружаем файлы для всех задач
|
||||
await Promise.all(tasks.map(async (task) => {
|
||||
try {
|
||||
const filesResponse = await fetch(`/api/tasks/${task.id}/files`);
|
||||
if (filesResponse.ok) {
|
||||
task.files = await filesResponse.json();
|
||||
} else {
|
||||
task.files = [];
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(`Ошибка загрузки файлов для задачи ${task.id}:`, error);
|
||||
task.files = [];
|
||||
// Обновляем отображение
|
||||
const activeSection = document.querySelector('.section.active');
|
||||
if (activeSection) {
|
||||
const sectionId = activeSection.id;
|
||||
if (sectionId === 'mytasks-section') {
|
||||
filterMyTasks();
|
||||
} else if (sectionId === 'runtasks-section') {
|
||||
filterRunTasks();
|
||||
} else {
|
||||
renderTasks();
|
||||
}
|
||||
}));
|
||||
|
||||
renderTasks();
|
||||
} else {
|
||||
renderTasks();
|
||||
}
|
||||
|
||||
} catch (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');
|
||||
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() {
|
||||
try {
|
||||
const response = await fetch('/api/tasks');
|
||||
|
||||
Reference in New Issue
Block a user