diff --git a/backend/requests_app/views.py b/backend/requests_app/views.py index a56d4001..3d2da97d 100644 --- a/backend/requests_app/views.py +++ b/backend/requests_app/views.py @@ -239,10 +239,20 @@ class RequestsView(LoginRequiredMixin, TemplateView): type_ = (request.GET.get("type") or "").strip() status_ = (request.GET.get("status") or "").strip() + employee_id = (request.GET.get("employee_id") or "").strip() + date_from = (request.GET.get("date_from") or "").strip() + date_to = (request.GET.get("date_to") or "").strip() + if type_: params["type"] = type_ if status_: params["status"] = status_ + if employee_id: + params["employee_id"] = employee_id + if date_from: + params["date_from"] = date_from + if date_to: + params["date_to"] = date_to # NB: в API сортировки нет — параметр `ordering` не прокидываем. @@ -254,6 +264,14 @@ class RequestsView(LoginRequiredMixin, TemplateView): data.get("detail") or f"Не удалось загрузить список заявлений (HTTP {status}).", ) + + # Загружаем список сотрудников для фильтра + employees = [] + ok_emp, data_emp, _ = _api_unpack(api.get("v1/employees/", params={"page_size": 1000})) + if ok_emp: + employees_results, _, _, _ = _parse_page_payload(data_emp) + employees = employees_results + ctx.update( { "requests": [], @@ -262,10 +280,14 @@ class RequestsView(LoginRequiredMixin, TemplateView): "count": None, "scope": scope, "can_process": _user_can_process_requests(request.user), + "employees": employees, "filters": { "type": type_, "status": status_, "view": scope, + "employee_id": employee_id, + "date_from": date_from, + "date_to": date_to, }, } ) @@ -273,6 +295,13 @@ class RequestsView(LoginRequiredMixin, TemplateView): results, next_url, prev_url, count = _parse_page_payload(data) + # Загружаем список сотрудников для фильтра + employees = [] + ok_emp, data_emp, _ = _api_unpack(api.get("v1/employees/", params={"page_size": 1000})) + if ok_emp: + employees_results, _, _, _ = _parse_page_payload(data_emp) + employees = employees_results + ctx.update( { "requests": results, @@ -281,10 +310,14 @@ class RequestsView(LoginRequiredMixin, TemplateView): "count": count, "scope": scope, "can_process": _user_can_process_requests(request.user), + "employees": employees, "filters": { "type": type_, "status": status_, "view": scope, + "employee_id": employee_id, + "date_from": date_from, + "date_to": date_to, }, } ) diff --git a/backend/static/js/components/requestListHandler.js b/backend/static/js/components/requestListHandler.js index 84661177..2372ae95 100644 --- a/backend/static/js/components/requestListHandler.js +++ b/backend/static/js/components/requestListHandler.js @@ -35,6 +35,9 @@ export function initRequestListHandler(options) { let currentView = urlParams.get("view") || ""; // 'mine' | 'addressed' | '' let currentType = urlParams.get("type") || ""; let currentStatus = urlParams.get("status") || ""; + let currentEmployeeId = urlParams.get("employee_id") || ""; + let currentDateFrom = urlParams.get("date_from") || ""; + let currentDateTo = urlParams.get("date_to") || ""; let searchQuery = ""; // Поисковый запрос let allRequests = []; // Все загруженные заявления let loading = false; @@ -48,7 +51,13 @@ export function initRequestListHandler(options) { "type =", currentType, "status =", - currentStatus + currentStatus, + "employee_id =", + currentEmployeeId, + "date_from =", + currentDateFrom, + "date_to =", + currentDateTo ); // Intersection Observer для бесконечной прокрутки @@ -114,6 +123,15 @@ export function initRequestListHandler(options) { if (currentStatus) { params.append("status", currentStatus); } + if (currentEmployeeId) { + params.append("employee_id", currentEmployeeId); + } + if (currentDateFrom) { + params.append("date_from", currentDateFrom); + } + if (currentDateTo) { + params.append("date_to", currentDateTo); + } url = `${apiListUrl}?${params}`; console.log("loadRequests: initial load", url); diff --git a/backend/templates/requests_app/_filters.html b/backend/templates/requests_app/_filters.html index d4d5ec99..d97c5fe1 100644 --- a/backend/templates/requests_app/_filters.html +++ b/backend/templates/requests_app/_filters.html @@ -5,7 +5,7 @@ {% endif %} -
+
-
+
-
-