diff --git a/uniticket/api_rest/urls.py b/uniticket/api_rest/urls.py index 3e06efa9..a6c31367 100644 --- a/uniticket/api_rest/urls.py +++ b/uniticket/api_rest/urls.py @@ -31,7 +31,10 @@ path('api/ticket/close//', user.TicketAPIClose.as_view(), name='api-ticket-close'), # manager - path(f'api/{slugify(MANAGEMENT_URL_PREFIX["manager"])}//tickets/count/', manager.TicketAPICounter.as_view(), name='api-manager-tickets-count'), + path(f'api/{slugify(MANAGEMENT_URL_PREFIX["manager"])}//tickets/unassigned/count/', manager.TicketAPIUnassignedCounter.as_view(), name='api-manager-tickets-unassigned-count'), + path(f'api/{slugify(MANAGEMENT_URL_PREFIX["manager"])}//tickets/open/count/', manager.TicketAPIOpenCounter.as_view(), name='api-manager-tickets-open-count'), + path(f'api/{slugify(MANAGEMENT_URL_PREFIX["manager"])}//tickets/my-open/count/', manager.TicketAPIMyOpenCounter.as_view(), name='api-manager-tickets-my-open-count'), + path(f'api/{slugify(MANAGEMENT_URL_PREFIX["manager"])}//tickets/messages/count/', manager.TicketAPIMessagesCounter.as_view(), name='api-manager-tickets-messages-count'), # operator path(f'api/{slugify(MANAGEMENT_URL_PREFIX["operator"])}//tickets/count/', operator.TicketAPICounter.as_view(), name='api-operator-tickets-count'),] diff --git a/uniticket/api_rest/views/manager.py b/uniticket/api_rest/views/manager.py index 9992f3d7..8798adaf 100644 --- a/uniticket/api_rest/views/manager.py +++ b/uniticket/api_rest/views/manager.py @@ -24,7 +24,7 @@ logger = logging.getLogger(__name__) -class TicketAPICounter(TicketAPIBaseView): +class TicketAPIUnassignedCounter(TicketAPIBaseView): def get(self, request, structure_slug, *args, **kwargs): structure = get_object_or_404(OrganizationalStructure, slug=structure_slug) if not user_is_manager(request.user, structure): raise PermissionDenied @@ -33,14 +33,38 @@ def get(self, request, structure_slug, *args, **kwargs): closed=False, taken=False) + return Response({'count': unassigned_tickets.count()}) + + +class TicketAPIOpenCounter(TicketAPIBaseView): + def get(self, request, structure_slug, *args, **kwargs): + structure = get_object_or_404(OrganizationalStructure, slug=structure_slug) + if not user_is_manager(request.user, structure): raise PermissionDenied + open_tickets = TicketAssignment.get_ticket_per_structure(structure=structure, closed=False, taken=True) + return Response({'count': open_tickets.count()}) + + +class TicketAPIMyOpenCounter(TicketAPIBaseView): + def get(self, request, structure_slug, *args, **kwargs): + structure = get_object_or_404(OrganizationalStructure, slug=structure_slug) + if not user_is_manager(request.user, structure): raise PermissionDenied + my_open_tickets = TicketAssignment.get_ticket_per_structure(structure=structure, closed=False, taken=True, taken_by=request.user) + return Response({'count': my_open_tickets.count()}) + + +class TicketAPIMessagesCounter(TicketAPIBaseView): + def get(self, request, structure_slug, *args, **kwargs): + structure = get_object_or_404(OrganizationalStructure, slug=structure_slug) + if not user_is_manager(request.user, structure): raise PermissionDenied + ticket_ids = TicketAssignment.objects.filter( office__organizational_structure=structure, office__is_active=True, @@ -49,7 +73,4 @@ def get(self, request, structure_slug, *args, **kwargs): ).values_list('ticket__pk', flat=True).distinct() messages = TicketReply.get_unread_messages_count(ticket_ids=ticket_ids) - return Response({'unassigned': unassigned_tickets.count(), - 'open': open_tickets.count(), - 'my_open': my_open_tickets.count(), - 'new_messages': messages}) + return Response({'count': messages}) diff --git a/uniticket/uni_ticket_bootstrap_italia_template/templates/manager/counters.html b/uniticket/uni_ticket_bootstrap_italia_template/templates/manager/counters.html index 4c6823f5..e23ad815 100644 --- a/uniticket/uni_ticket_bootstrap_italia_template/templates/manager/counters.html +++ b/uniticket/uni_ticket_bootstrap_italia_template/templates/manager/counters.html @@ -106,18 +106,42 @@ clearInterval(this.interval) }, mounted () { - this.getCounters() + this.getUnassigned() + this.getOpen() + this.getMyOpen() + this.getMessages() }, methods: { - getCounters() { - api_url = '{% url "api_rest:api-manager-tickets-count" structure_slug=structure.slug %}' + getUnassigned() { + api_url = '{% url "api_rest:api-manager-tickets-unassigned-count" structure_slug=structure.slug %}' axios .get(api_url) .then(response => { - this.unassigned = response.data.unassigned - this.open = response.data.open - this.my_open = response.data.my_open - this.new_messages = response.data.new_messages + this.unassigned = response.data.count + }) + }, + getOpen() { + api_url = '{% url "api_rest:api-manager-tickets-open-count" structure_slug=structure.slug %}' + axios + .get(api_url) + .then(response => { + this.open = response.data.count + }) + }, + getMyOpen() { + api_url = '{% url "api_rest:api-manager-tickets-my-open-count" structure_slug=structure.slug %}' + axios + .get(api_url) + .then(response => { + this.my_open = response.data.count + }) + }, + getMessages() { + api_url = '{% url "api_rest:api-manager-tickets-messages-count" structure_slug=structure.slug %}' + axios + .get(api_url) + .then(response => { + this.new_messages = response.data.count }) } }