diff --git a/apps/home/urls.py b/apps/home/urls.py index 8d52334..11f21dc 100644 --- a/apps/home/urls.py +++ b/apps/home/urls.py @@ -16,6 +16,7 @@ urlpatterns = [ path('get/', include([ path('one/', views.get_ticket, name="ticket-getone"), path('many/', views.get_tickets, name="ticket-getmany"), + path("filtercounts/", views.get_filter_counts, name="ticket-getfiltercounts"), ])), ])), diff --git a/apps/home/views.py b/apps/home/views.py index abd9bbd..0e6c761 100644 --- a/apps/home/views.py +++ b/apps/home/views.py @@ -57,6 +57,33 @@ def get_tickets(request): return JsonResponse(data) +@login_required +@require_POST +def get_filter_counts(request): + + priorities = TicketPriority.objects.all() + tags = TicketTag.objects.all() + departments = Department.objects.all() + + tickets = Ticket.objects.all() + + data = { + "priority_counts": {}, + "tag_counts": {}, + "department_counts": {}, + "ticket_count": tickets.count() + } + + for priority in priorities: + data["priority_counts"][str(priority.id)] = tickets.filter(priority=priority).count() + + for tag in tags: + data["tag_counts"][str(tag.id)] = tickets.filter(tags__in=[tag]).count() + + for department in departments: + data["department_counts"][str(department.id)] = tickets.filter(author__department=department).count() + + return JsonResponse(data) @login_required() @require_POST diff --git a/apps/templates/home/tickets.html b/apps/templates/home/tickets.html index 61853ff..e0d65a7 100644 --- a/apps/templates/home/tickets.html +++ b/apps/templates/home/tickets.html @@ -21,138 +21,86 @@