фильтр

This commit is contained in:
2026-02-19 20:10:39 +05:00
parent 4c9298c573
commit 2df88ad168
3 changed files with 211 additions and 145 deletions

View File

@@ -90,6 +90,21 @@
</select>
</div>
<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>
<select id="creator-filter" onchange="loadTasks()">
<option value="">Все заказчики</option>
@@ -113,6 +128,11 @@
<label for="search-tasks"><i class="fas fa-search"></i> Поиск:</label>
<input type="text" id="search-tasks" placeholder="Поиск по названию и описанию..." oninput="loadTasks()">
</div>
<div class="filter-actions">
<button type="button" class="btn-reset" onclick="resetAllFilters()">
<i class="fas fa-undo"></i> Сбросить фильтры
</button>
</div>
</div>
<label class="show-deleted-label" style="display: none;">
<input type="checkbox" id="show-deleted" onchange="loadTasks()">

View File

@@ -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');