diff --git a/backend/api/v1/requests_app/serializers.py b/backend/api/v1/requests_app/serializers.py index 7496ae4f..e23f7463 100644 --- a/backend/api/v1/requests_app/serializers.py +++ b/backend/api/v1/requests_app/serializers.py @@ -87,6 +87,8 @@ class RequestReadSerializer(serializers.ModelSerializer): recipient_count = serializers.SerializerMethodField() cc_count = serializers.SerializerMethodField() is_recipient = serializers.SerializerMethodField() + # Используем аннотированное поле из queryset + comments_count = serializers.IntegerField(read_only=True) class Meta: model = Request @@ -116,6 +118,7 @@ class RequestReadSerializer(serializers.ModelSerializer): "recipient_count", "cc_count", "is_recipient", + "comments_count", ) read_only_fields = ( "employee", @@ -132,6 +135,7 @@ class RequestReadSerializer(serializers.ModelSerializer): "recipient_count", "cc_count", "is_recipient", + "comments_count", ) def get_recipient_count(self, obj): diff --git a/backend/api/v1/requests_app/views.py b/backend/api/v1/requests_app/views.py index 24b7ba11..1800e917 100644 --- a/backend/api/v1/requests_app/views.py +++ b/backend/api/v1/requests_app/views.py @@ -2,7 +2,7 @@ from __future__ import annotations from typing import Any, List, Optional # было: Any, Dict, List, Type -from django.db.models import Q, QuerySet +from django.db.models import Q, QuerySet, Count from django.shortcuts import get_object_or_404 # раскомментируйте импорт from employees.models import EmployeeDepartment, Department # добавлен Department from requests_app.models import Request as EmployeeRequest @@ -59,7 +59,9 @@ class RequestViewSet(viewsets.ModelViewSet): queryset = EmployeeRequest.objects.select_related( "employee", "approver", "department" - ).all() + ).annotate( + comments_count=Count('comments') + ).order_by('-created_at') parser_classes = (MultiPartParser, FormParser, JSONParser) # Используем глобальную пагинацию из settings (PageNumberPagination, PAGE_SIZE=20) diff --git a/backend/static/js/components/requestCommentsHandler.js b/backend/static/js/components/requestCommentsHandler.js index 0b27add0..b9d98e81 100644 --- a/backend/static/js/components/requestCommentsHandler.js +++ b/backend/static/js/components/requestCommentsHandler.js @@ -153,8 +153,11 @@ export function initRequestCommentsHandler(options) { async function handleCommentSubmit(e) { const form = e.target; - // Проверяем, что это форма комментария внутри блока заявки - if (!form.matches(`${collapseSelector} form[data-role=form]`)) return; + // Проверяем, что это форма комментария + if (!form.matches('form[data-role=form]')) return; + + // Проверяем, что форма находится внутри блока заявки + if (!form.closest(collapseSelector)) return; e.preventDefault(); e.stopPropagation(); diff --git a/backend/static/js/components/requestListHandler.js b/backend/static/js/components/requestListHandler.js index e4472c75..c7c2d5f0 100644 --- a/backend/static/js/components/requestListHandler.js +++ b/backend/static/js/components/requestListHandler.js @@ -22,11 +22,11 @@ export function initRequestListHandler(options) { headers = {} } = options; - const listElement = document.getElementById('reqList'); + const listElement = document.getElementById('reqListContent'); const searchInput = document.getElementById('reqFilter'); if (!listElement) { - console.warn('initRequestListHandler: #reqList not found'); + console.warn('initRequestListHandler: #reqListContent not found'); return { load: () => {}, destroy: () => {} }; } @@ -158,6 +158,11 @@ export function initRequestListHandler(options) { if (spinner) { spinner.remove(); } + // Удаляем начальный спиннер из шаблона + const initialSpinner = document.getElementById('reqListLoading'); + if (initialSpinner) { + initialSpinner.remove(); + } } /** diff --git a/backend/templates/requests_app/request_list_full.html b/backend/templates/requests_app/request_list_full.html index febdc4ae..914d9432 100644 --- a/backend/templates/requests_app/request_list_full.html +++ b/backend/templates/requests_app/request_list_full.html @@ -49,10 +49,13 @@ - {# Список загружается через JavaScript из requestListHandler.js #} -
-
- Загрузка... + {# Контейнер для данных заявлений #} +
+ {# Список загружается через JavaScript из requestListHandler.js #} +
+
+ Загрузка... +