Skip to content

Commit

Permalink
fix: remove ticket counters
Browse files Browse the repository at this point in the history
  • Loading branch information
francesco-filicetti committed Oct 13, 2023
1 parent 391a7dc commit c88d9f5
Show file tree
Hide file tree
Showing 9 changed files with 59 additions and 67 deletions.
28 changes: 17 additions & 11 deletions uniticket/uni_ticket/views/management.py
Original file line number Diff line number Diff line change
Expand Up @@ -446,29 +446,35 @@ def tickets(request, structure_slug, structure, office_employee=None):
# if user is operator
if office_employee:
ticket_list = visible_tickets_to_user(
user=request.user, structure=structure, office_employee=office_employee
user=request.user,
structure=structure,
office_employee=office_employee
)
tickets = Ticket.objects.filter(code__in=ticket_list)

not_closed = tickets.filter(is_closed=False)
# unassigned = []
# opened = []
# my_opened = []
unassigned = 0
opened = 0
my_opened = 0
unassigned = False
opened = False
my_opened = False
for nc in not_closed:
if unassigned and opened and my_opened:
break
if nc.has_been_taken():
if opened and my_opened:
continue
# opened.append(nc)
opened += 1
opened = True
if nc.has_been_taken_by_user(structure=structure, user=request.user):
# my_opened.append(nc)
my_opened += 1
my_opened = True
else:
# unassigned.append(nc)
unassigned += 1
unassigned = True
# chiusi = Ticket.objects.filter(code__in=ticket_list, is_closed=True)
chiusi = tickets.filter(is_closed=True).count()
# chiusi = tickets.filter(is_closed=True).count()
ticket_codes = not_closed.values_list('ticket__code', flat=True)
# if user is manager
else:
Expand All @@ -479,9 +485,9 @@ def tickets(request, structure_slug, structure, office_employee=None):
).select_related('ticket')

# chiusi = assignments.filter(ticket__is_closed=True).values('ticket__code').annotate(total=Count('ticket__code')).count()
opened = assignments.filter(ticket__assigned_date__isnull=False, ticket__is_closed=False).values('ticket__code').annotate(total=Count('ticket__code')).count()
unassigned = assignments.filter(ticket__assigned_date__isnull=True, ticket__is_closed=False).values('ticket__code').annotate(total=Count('ticket__code')).count()
my_opened = assignments.filter(ticket__assigned_date__isnull=False, ticket__is_closed=False, taken_by=request.user).values('ticket__code').annotate(total=Count('ticket__code')).count()
opened = assignments.filter(ticket__assigned_date__isnull=False, ticket__is_closed=False).exists()
unassigned = assignments.filter(ticket__assigned_date__isnull=True, ticket__is_closed=False).exists()
my_opened = assignments.filter(ticket__assigned_date__isnull=False, ticket__is_closed=False, taken_by=request.user).exists()
ticket_codes = assignments.filter(ticket__is_closed=False).values_list('ticket__code', flat=True)

# unread messages
Expand Down
15 changes: 5 additions & 10 deletions uniticket/uni_ticket/views/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,32 +49,27 @@ def dashboard(request, structure_slug, structure):
"Gestisci le richieste per la struttura {}").format(structure)
template = "manager/dashboard.html"

# ta = TicketAssignment
# structure_tickets = ta.get_ticket_per_structure(structure=structure)
# tickets = Ticket.objects.filter(code__in=structure_tickets)

assignments = TicketAssignment.objects.filter(
office__organizational_structure=structure,
office__is_active=True,
follow=True
).select_related('ticket').values('ticket')

# chiusi = assignments.filter(ticket__is_closed=True).annotate(total=Count('ticket__code')).count()
opened = assignments.filter(ticket__assigned_date__isnull=False, ticket__is_closed=False).annotate(total=Count('ticket__code')).count()
unassigned = assignments.filter(ticket__assigned_date__isnull=True, ticket__is_closed=False).annotate(total=Count('ticket__code')).count()
my_opened = assignments.filter(ticket__assigned_date__isnull=False, ticket__is_closed=False, taken_by=request.user).annotate(total=Count('ticket__code')).count()
opened = assignments.filter(ticket__assigned_date__isnull=False, ticket__is_closed=False).exists()
unassigned = assignments.filter(ticket__assigned_date__isnull=True, ticket__is_closed=False).exists()
my_opened = assignments.filter(ticket__assigned_date__isnull=False, ticket__is_closed=False, taken_by=request.user).exists()

om = OrganizationalStructureOffice
offices = om.objects.filter(organizational_structure=structure)

cm = TicketCategory
categories = cm.objects.filter(organizational_structure=structure)\
.select_related('organizational_office')
# disabled_expired_items(categories)

# messages = TicketReply.get_unread_messages_count(tickets=tickets)
ticket_codes = assignments.filter(ticket__is_closed=False).values_list('ticket__code', flat=True).distinct()
messages = TicketReply.get_unread_messages_count(ticket_codes=ticket_codes)
# messages = 0

d = {
"categories": categories,
"offices": offices,
Expand Down
16 changes: 10 additions & 6 deletions uniticket/uni_ticket/views/operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,20 @@ def dashboard(request, structure_slug, structure, office_employee):
)
tickets = Ticket.objects.filter(code__in=user_tickets)
not_closed = tickets.filter(is_closed=False)
unassigned = 0
opened = 0
my_opened = 0
unassigned = False
opened = False
my_opened = False
for nc in not_closed:
if unassigned and opened and my_opened:
break
if nc.has_been_taken():
opened += 1
if opened and my_opened:
continue
opened = True
if nc.has_been_taken_by_user(structure=structure, user=request.user):
my_opened += 1
my_opened = True
else:
unassigned += 1
unassigned = True

# chiusi = tickets.filter(is_closed=True).count()
ticket_codes = not_closed.values_list('ticket__code', flat=True).distinct()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
{% load static %}

<a role="button"
class="btn btn-outline-secondary"
class="btn btn-outline-{% if ticket_aperti %}warning{% else %}secondary{% endif %}"
href="{% url 'uni_ticket:manage_unassigned_ticket_url' structure_slug=structure.slug %}">
<span class="badge badge-light">{{ ticket_non_gestiti }}</span> {% trans 'Aperte' %}
{% trans 'Aperte' %}
</a>
<a role="button" class="btn btn-outline-secondary" href="{% url 'uni_ticket:manage_opened_ticket_url' structure_slug=structure.slug %}">
<span class="badge badge-light">{{ ticket_aperti }}</span> {% trans 'Assegnate' %}
(<span class="badge badge-light">{{ ticket_assegnati_a_me }}</span> {% trans 'a me' %})
<a role="button" class="btn btn-outline-{% if ticket_aperti %}warning{% else %}secondary{% endif %}" href="{% url 'uni_ticket:manage_opened_ticket_url' structure_slug=structure.slug %}">
{% trans 'Assegnate' %}
{% if ticket_assegnati_a_me %}({% trans 'anche a me' %}){% endif %}
</a>
<a role="button" class="btn btn-outline-secondary" href="{% url 'uni_ticket:manage_closed_ticket_url' structure_slug=structure.slug %}">
{% trans 'Chiuse' %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,16 @@

<li>
<a href="{% url 'uni_ticket:manage_unassigned_ticket_url' structure_slug=structure.slug %}">
{% if ticket_non_gestiti > 0 %}
<div class="badge-wrapper"><span class="toolbar-badge badge-primary">{{ ticket_non_gestiti }}</span></div>
{% endif %}
<svg class="icon"><use xlink:href="{% static 'svg/sprite.svg' %}#it-warning-circle"></use></svg>
<svg class="icon {% if ticket_non_gestiti %}icon-warning{% endif %}"><use xlink:href="{% static 'svg/sprite.svg' %}#it-warning-circle"></use></svg>
<span class="toolbar-label">{% trans 'Aperte' %}</span></span>
</a>
</li>
<li>
<a href="{% url 'uni_ticket:manage_opened_ticket_url' structure_slug=structure.slug %}">
{% if ticket_aperti > 0 %}
<div class="badge-wrapper"><span class="toolbar-badge">{{ ticket_aperti }}</span></div>
{% endif %}
<svg class="icon"><use xlink:href="{% static 'svg/sprite.svg' %}#it-clock"></use></svg>
<svg class="icon {% if ticket_aperti %}icon-warning{% endif %}"><use xlink:href="{% static 'svg/sprite.svg' %}#it-clock"></use></svg>
<span class="toolbar-label">{% trans 'Assegnate' %}
{% if ticket_assegnati_a_me > 0 %}
<br>({{ ticket_assegnati_a_me }} {% trans 'a me' %})
{% if ticket_assegnati_a_me %}
<br>({% trans 'anche a me' %})
{% endif %}
</span>
</a>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,16 +242,15 @@ <h5 class="modal-title">
</div>

{% if ticket_taken %}
{% with ticket.get_messages_count.1 as unread_messages %}
<a role="button"
href="{% url 'uni_ticket:manage_ticket_message_url' structure_slug=structure.slug ticket_id=ticket.code %}"
class="btn btn-outline-secondary">
{% with ticket.get_messages_count.1 as unread_messages %}
<svg class="icon icon-xs {% if unread_messages > 0 %}icon-warning{% endif %}">
<use xlink:href="{% static 'svg/sprite.svg' %}#it-comment"></use>
</svg> {% trans "Messaggi" %}
{% endwith %}

class="btn btn-outline-{% if unread_messages > 0 %}warning{% else %}secondary{% endif %}">
<svg class="icon icon-xs">
<use xlink:href="{% static 'svg/sprite.svg' %}#it-comment"></use>
</svg> {% trans "Messaggi" %}
</a>
{% endwith %}
{% endif %}

{% if ticket_taken and ticket.is_closed and not ticket.is_notification %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<div class="pb-4 clearfix">
<div class="pull-left d-none d-md-block">
{% include 'management/ticket_cards.html' %}
<a role="button" class="btn btn-outline-{% if ticket_messages %}warning{% else %}secondary{% endif %}" href="{% url 'uni_ticket:manager_messages' structure_slug=structure.slug %}">
<a role="button" class="btn btn-outline-{% if ticket_aperti %}warning{% else %}secondary{% endif %}" href="{% url 'uni_ticket:manager_messages' structure_slug=structure.slug %}">
<svg class="icon icon-xs">
<use xlink:href="{% static 'svg/sprite.svg' %}#it-comment"></use>
</svg>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,17 @@

<div class="pb-4 clearfix">
<div class="pull-left d-none d-md-block">
<a role="button" class="btn btn-outline-secondary" href="{% url 'uni_ticket:user_unassigned_ticket' %}">
<span class="badge badge-light">{{ ticket_non_gestiti }}</span> {% trans 'Aperte' %}
<a role="button" class="btn btn-outline-{% if ticket_non_gestiti %}warning{% else %}secondary{% endif %}" href="{% url 'uni_ticket:user_unassigned_ticket' %}">
{% trans 'Aperte' %}
</a>
<a role="button" class="btn btn-outline-secondary" href="{% url 'uni_ticket:user_opened_ticket' %}">
<span class="badge badge-light">{{ ticket_aperti }}</span> {% trans 'Assegnate' %}
<a role="button" class="btn btn-outline-{% if ticket_aperti %}warning{% else %}secondary{% endif %}" href="{% url 'uni_ticket:user_opened_ticket' %}">
{% trans 'Assegnate' %}
</a>
<a role="button" class="btn btn-outline-secondary" href="{% url 'uni_ticket:user_closed_ticket' %}">
{% trans 'Chiuse' %}
</a>
<a role="button" class="btn btn-outline-secondary" href="{% url 'uni_ticket:messages' %}">
<svg class="icon icon-xs {% if ticket_messages > 0 %}icon-warning{% endif %}">
<a role="button" class="btn btn-outline-{% if ticket_messages %}warning{% else %}secondary{% endif %}" href="{% url 'uni_ticket:messages' %}">
<svg class="icon icon-xs">
<use xlink:href="{% static 'svg/sprite.svg' %}#it-comment"></use>
</svg>
{% trans 'Messaggi' %}
Expand All @@ -36,19 +36,13 @@
<ul>
<li>
<a href="{% url 'uni_ticket:user_unassigned_ticket' %}">
{% if ticket_non_gestiti > 0 %}
<div class="badge-wrapper"><span class="toolbar-badge badge-primary">{{ ticket_non_gestiti }}</span></div>
{% endif %}
<svg class="icon"><use xlink:href="{% static 'svg/sprite.svg' %}#it-warning-circle"></use></svg>
<svg class="icon {% if ticket_non_gestiti %}icon-warning{% endif %}"><use xlink:href="{% static 'svg/sprite.svg' %}#it-warning-circle"></use></svg>
<span class="toolbar-label">{% trans 'Aperte' %}</span></span>
</a>
</li>
<li>
<a href="{% url 'uni_ticket:user_opened_ticket' %}">
{% if ticket_aperti > 0 %}
<div class="badge-wrapper"><span class="toolbar-badge">{{ ticket_aperti }}</span></div>
{% endif %}
<svg class="icon"><use xlink:href="{% static 'svg/sprite.svg' %}#it-clock"></use></svg>
<svg class="icon {% if ticket_aperti %}icon-warning{% endif %}"><use xlink:href="{% static 'svg/sprite.svg' %}#it-clock"></use></svg>
<span class="toolbar-label">{% trans 'Assegnate' %}</span>
</a>
</li>
Expand All @@ -60,7 +54,7 @@
</li>
<li>
<a href="{% url 'uni_ticket:messages' %}">
<svg class="icon {% if ticket_messages > 0 %}icon-warning{% endif %}"><use xlink:href="{% static 'svg/sprite.svg' %}#it-comment"></use></svg>
<svg class="icon {% if ticket_messages %}icon-warning{% endif %}"><use xlink:href="{% static 'svg/sprite.svg' %}#it-comment"></use></svg>
<span class="toolbar-label">{% trans 'Messaggi' %}</span></span>
</a>
</li>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,9 @@ <h5 class="modal-title">

{% if ticket_taken %}
<a role="button" href="{% url 'uni_ticket:ticket_message' ticket_id=ticket.code %}"
class="btn btn-outline-secondary">
class="btn btn-outline-{% if unread_messages > 0 %}warning{% else %}secondary{% endif %}">
{% get_unread_messages ticket=ticket as unread_messages %}
<svg class="icon icon-xs {% if unread_messages > 0 %}icon-warning{% endif %}">
<svg class="icon icon-xs">
<use xlink:href="{% static 'svg/sprite.svg' %}#it-comment"></use>
</svg> {% trans "Messaggi" %}
</a>
Expand Down

0 comments on commit c88d9f5

Please sign in to comment.