diff --git a/uniticket/api_rest/urls.py b/uniticket/api_rest/urls.py index a6c31367..25a04520 100644 --- a/uniticket/api_rest/urls.py +++ b/uniticket/api_rest/urls.py @@ -23,10 +23,14 @@ re_path('^openapi/$', get_schema_view(**{}), name='openapi-schema'), re_path('^openapi.json/$', get_schema_view(renderer_classes = [JSONOpenAPIRenderer], **{}), name='openapi-schema-json'), - path('api///ticket/new/', user.TicketAPIView.as_view(), name='api-new-ticket'), - path('api/ticket//', user.TicketAPIDetail.as_view(), name='api-view-ticket'), + + # generic path('api/strutture/list/', generic.TicketAPIStruttureList.as_view(), name='api-strutture-list'), path('api/ticket/category/list/', generic.TicketAPITicketCategoryList.as_view(),name='api-ticket-category-list'), + + # user + path('api///ticket/new/', user.TicketAPIView.as_view(), name='api-new-ticket'), + path('api/ticket//', user.TicketAPIDetail.as_view(), name='api-view-ticket'), path('api/ticket/user/list/', user.TicketAPIListCreated.as_view(), name='api-ticket-user-list'), path('api/ticket/close//', user.TicketAPIClose.as_view(), name='api-ticket-close'), @@ -37,4 +41,7 @@ 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'),] + path(f'api/{slugify(MANAGEMENT_URL_PREFIX["operator"])}//tickets/unassigned/count/', operator.TicketAPIUnassignedCounter.as_view(), name='api-operator-tickets-unassigned-count'), + path(f'api/{slugify(MANAGEMENT_URL_PREFIX["operator"])}//tickets/open/count/', operator.TicketAPIOpenCounter.as_view(), name='api-operator-tickets-open-count'), + path(f'api/{slugify(MANAGEMENT_URL_PREFIX["operator"])}//tickets/my-open/count/', operator.TicketAPIMyOpenCounter.as_view(), name='api-operator-tickets-my-open-count'), + path(f'api/{slugify(MANAGEMENT_URL_PREFIX["operator"])}//tickets/messages/count/', operator.TicketAPIMessagesCounter.as_view(), name='api-operator-tickets-messages-count'), diff --git a/uniticket/api_rest/views/operator.py b/uniticket/api_rest/views/operator.py index 45b9b6ca..9cacb776 100644 --- a/uniticket/api_rest/views/operator.py +++ b/uniticket/api_rest/views/operator.py @@ -24,41 +24,56 @@ 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) oe = user_is_operator(request.user, structure) if not oe: raise PermissionDenied - unassigned_tickets = visible_tickets_to_user(user=request.user, structure=structure, office_employee=oe, 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) + oe = user_is_operator(request.user, structure) + if not oe: raise PermissionDenied open_tickets = visible_tickets_to_user(user=request.user, structure=structure, office_employee=oe, 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) + oe = user_is_operator(request.user, structure) + if not oe: raise PermissionDenied my_open_tickets = visible_tickets_to_user(user=request.user, structure=structure, office_employee=oe, 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) + oe = user_is_operator(request.user, structure) + if not oe: raise PermissionDenied ticket_ids = visible_tickets_to_user( user=request.user, structure=structure, office_employee=oe, closed=False ) - messages = TicketReply.get_unread_messages_count(ticket_ids=ticket_ids) - - return Response({'unassigned': len(unassigned_tickets), - 'open': len(open_tickets), - 'my_open': len(my_open_tickets), - '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 b00aaa1b..22f2ac37 100644 --- a/uniticket/uni_ticket_bootstrap_italia_template/templates/manager/counters.html +++ b/uniticket/uni_ticket_bootstrap_italia_template/templates/manager/counters.html @@ -79,7 +79,7 @@ - {% trans 'Messaggi' %} + {% trans 'Messaggi' %} diff --git a/uniticket/uni_ticket_bootstrap_italia_template/templates/operator/counters.html b/uniticket/uni_ticket_bootstrap_italia_template/templates/operator/counters.html index fd9b10b8..c4821d19 100644 --- a/uniticket/uni_ticket_bootstrap_italia_template/templates/operator/counters.html +++ b/uniticket/uni_ticket_bootstrap_italia_template/templates/operator/counters.html @@ -33,7 +33,7 @@ - {% trans "Nuovi" %}{% trans "Nuovi" %} + {% trans "Nuovi" %} {% trans 'Messaggi' %} @@ -80,7 +80,7 @@ - {% trans 'Messaggi' %} + {% trans 'Messaggi' %} @@ -100,24 +100,52 @@ }, created(){ this.interval = setInterval(() =>{ - this.getCounters(); + this.getUnassigned(); + this.getOpen(); + this.getMyOpen(); + this.getMessages(); }, 20000) }, destroyed(){ clearInterval(this.interval) }, mounted () { - this.getCounters() + this.getUnassigned() + this.getOpen() + this.getMyOpen() + this.getMessages() }, methods: { - getCounters() { - api_url = '{% url "api_rest:api-operator-tickets-count" structure_slug=structure.slug %}' + getUnassigned() { + api_url = '{% url "api_rest:api-operator-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.unassigned = response.data.count + }) + }, + getOpen() { + api_url = '{% url "api_rest:api-operator-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-operator-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-operator-tickets-messages-count" structure_slug=structure.slug %}' + axios + .get(api_url) + .then(response => { + this.new_messages = response.data.count }) } }