Merge pull request #830 from Bukowskaii/feature/dashboard_pagination

Feature/dashboard pagination
This commit is contained in:
Garret Wassermann 2020-06-02 00:44:05 -04:00 committed by GitHub
commit bc74237e6f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 81 additions and 3 deletions

View File

@ -16,18 +16,21 @@
{% if all_tickets_reported_by_current_user %} {% if all_tickets_reported_by_current_user %}
{% trans "All Tickets submitted by you" as ticket_list_caption %} {% trans "All Tickets submitted by you" as ticket_list_caption %}
{% include 'helpdesk/include/tickets.html' with ticket_list=all_tickets_reported_by_current_user ticket_list_empty_message="" %} {% trans "atrbcu_page" as page_var %}
{% include 'helpdesk/include/tickets.html' with ticket_list=all_tickets_reported_by_current_user ticket_list_empty_message="" page_var=page_var %}
{% endif %} {% endif %}
{% trans "Open Tickets assigned to you (you are working on this ticket)" as ticket_list_caption %} {% trans "Open Tickets assigned to you (you are working on this ticket)" as ticket_list_caption %}
{% trans "You have no tickets assigned to you." as no_assigned_tickets %} {% trans "You have no tickets assigned to you." as no_assigned_tickets %}
{% include 'helpdesk/include/tickets.html' with ticket_list=user_tickets ticket_list_empty_message=no_assigned_tickets %} {% trans "ut_page" as page_var %}
{% include 'helpdesk/include/tickets.html' with ticket_list=user_tickets ticket_list_empty_message=no_assigned_tickets page_var=page_var %}
{% include 'helpdesk/include/unassigned.html' %} {% include 'helpdesk/include/unassigned.html' %}
{% if user_tickets_closed_resolved %} {% if user_tickets_closed_resolved %}
{% trans "Closed & resolved Tickets you used to work on" as ticket_list_caption %} {% trans "Closed & resolved Tickets you used to work on" as ticket_list_caption %}
{% include 'helpdesk/include/tickets.html' with ticket_list=user_tickets_closed_resolved ticket_list_empty_message="" %} {% trans "utcr_page" as page_var %}
{% include 'helpdesk/include/tickets.html' with ticket_list=user_tickets_closed_resolved ticket_list_empty_message="" page_var=page_var %}
{% endif %} {% endif %}
{% endblock %} {% endblock %}

View File

@ -37,6 +37,36 @@
</table> </table>
</div> </div>
<!-- /.table-responsive --> <!-- /.table-responsive -->
{% if ticket_list.has_other_pages %}
<ul class="pagination">
<!-- if we aren't on page one, go back to start and go back one controls -->
{% if ticket_list.has_previous %}
<li><a href="?{{ page_var }}=1">&laquo;&laquo;</a></li>
<li><a href="?{{ page_var }}={{ ticket_list.previous_page_number }}">&laquo;</a></li>
{% else %}
<li class="disabled"><span>&laquo;&laquo;</span></li>
<li class="disabled"><span>&laquo;</span></li>
{% endif %}
<!-- other pages, set thresh to the number to show before and after active -->
{% with 5 as thresh %}
{% for i in ticket_list.paginator.page_range %}
{% if ticket_list.number == i %}
<li class="active"><span>{{ i }} <span class="sr-only">(current)</span></span></li>
{% elif i <= ticket_list.number|add:5 and i >= ticket_list.number|add:-5 %}
<li><a href="?{{ page_var }}={{ i }}">{{ i }}</a></li>
{% endif %}
{% endfor %}
{% endwith %}
<!-- if we aren't on the last page, go forward one and go to end controls -->
{% if ticket_list.has_next %}
<li><a href="?{{ page_var }}={{ ticket_list.next_page_number }}">&raquo;</a></li>
<li><a href="?{{ page_var }}={{ ticket_list.paginator.num_pages }}">&raquo;&raquo;</a></li>
{% else %}
<li class="disabled"><span>&raquo;</span></li>
<li class="disabled"><span>&raquo;&raquo;</span></li>
{% endif %}
</ul>
{% endif %}
</div> </div>
<!-- /.panel-body --> <!-- /.panel-body -->
</div> </div>

View File

@ -15,6 +15,7 @@ from django.conf import settings
from django.contrib.auth import get_user_model from django.contrib.auth import get_user_model
from django.urls import reverse from django.urls import reverse
from django.core.exceptions import ValidationError, PermissionDenied from django.core.exceptions import ValidationError, PermissionDenied
from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
from django.db.models import Q from django.db.models import Q
from django.http import HttpResponseRedirect, Http404, HttpResponse from django.http import HttpResponseRedirect, Http404, HttpResponse
from django.shortcuts import render, get_object_or_404 from django.shortcuts import render, get_object_or_404
@ -91,6 +92,15 @@ def dashboard(request):
showing ticket counts by queue/status, and a list of unassigned tickets showing ticket counts by queue/status, and a list of unassigned tickets
with options for them to 'Take' ownership of said tickets. with options for them to 'Take' ownership of said tickets.
""" """
# user settings num tickets per page
tickets_per_page = request.user.usersettings_helpdesk.settings.get('tickets_per_page') or 25
# page vars for the three ticket tables
user_tickets_page = request.GET.get('ut_page', 1)
user_tickets_closed_resolved_page = request.GET.get('utcr_page', 1)
all_tickets_reported_by_current_user_page = request.GET.get('atrbcu_page', 1)
# open & reopened tickets, assigned to current user # open & reopened tickets, assigned to current user
tickets = Ticket.objects.select_related('queue').filter( tickets = Ticket.objects.select_related('queue').filter(
assigned_to=request.user, assigned_to=request.user,
@ -141,6 +151,41 @@ def dashboard(request):
else: else:
where_clause = """WHERE q.id = t.queue_id""" where_clause = """WHERE q.id = t.queue_id"""
# get user assigned tickets page
paginator = Paginator(
tickets, tickets_per_page)
try:
tickets = paginator.page(user_tickets_page)
except PageNotAnInteger:
tickets = paginator.page(1)
except EmptyPage:
tickets = paginator.page(
paginator.num_pages)
# get user completed tickets page
paginator = Paginator(
tickets_closed_resolved, tickets_per_page)
try:
tickets_closed_resolved = paginator.page(
user_tickets_closed_resolved_page)
except PageNotAnInteger:
tickets_closed_resolved = paginator.page(1)
except EmptyPage:
tickets_closed_resolved = paginator.page(
paginator.num_pages)
# get user submitted tickets page
paginator = Paginator(
all_tickets_reported_by_current_user, tickets_per_page)
try:
all_tickets_reported_by_current_user = paginator.page(
all_tickets_reported_by_current_user_page)
except PageNotAnInteger:
all_tickets_reported_by_current_user = paginator.page(1)
except EmptyPage:
all_tickets_reported_by_current_user = paginator.page(
paginator.num_pages)
return render(request, 'helpdesk/dashboard.html', { return render(request, 'helpdesk/dashboard.html', {
'user_tickets': tickets, 'user_tickets': tickets,
'user_tickets_closed_resolved': tickets_closed_resolved, 'user_tickets_closed_resolved': tickets_closed_resolved,