mirror of
https://github.com/django-helpdesk/django-helpdesk.git
synced 2024-12-13 18:31:10 +01:00
Merge pull request #830 from Bukowskaii/feature/dashboard_pagination
Feature/dashboard pagination
This commit is contained in:
commit
bc74237e6f
@ -16,18 +16,21 @@
|
||||
|
||||
{% if all_tickets_reported_by_current_user %}
|
||||
{% 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 %}
|
||||
|
||||
{% 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 %}
|
||||
{% 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' %}
|
||||
|
||||
{% if user_tickets_closed_resolved %}
|
||||
{% 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 %}
|
||||
|
||||
{% endblock %}
|
||||
|
@ -37,6 +37,36 @@
|
||||
</table>
|
||||
</div>
|
||||
<!-- /.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">««</a></li>
|
||||
<li><a href="?{{ page_var }}={{ ticket_list.previous_page_number }}">«</a></li>
|
||||
{% else %}
|
||||
<li class="disabled"><span>««</span></li>
|
||||
<li class="disabled"><span>«</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 }}">»</a></li>
|
||||
<li><a href="?{{ page_var }}={{ ticket_list.paginator.num_pages }}">»»</a></li>
|
||||
{% else %}
|
||||
<li class="disabled"><span>»</span></li>
|
||||
<li class="disabled"><span>»»</span></li>
|
||||
{% endif %}
|
||||
</ul>
|
||||
{% endif %}
|
||||
</div>
|
||||
<!-- /.panel-body -->
|
||||
</div>
|
||||
|
@ -15,6 +15,7 @@ from django.conf import settings
|
||||
from django.contrib.auth import get_user_model
|
||||
from django.urls import reverse
|
||||
from django.core.exceptions import ValidationError, PermissionDenied
|
||||
from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
|
||||
from django.db.models import Q
|
||||
from django.http import HttpResponseRedirect, Http404, HttpResponse
|
||||
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
|
||||
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
|
||||
tickets = Ticket.objects.select_related('queue').filter(
|
||||
assigned_to=request.user,
|
||||
@ -141,6 +151,41 @@ def dashboard(request):
|
||||
else:
|
||||
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', {
|
||||
'user_tickets': tickets,
|
||||
'user_tickets_closed_resolved': tickets_closed_resolved,
|
||||
|
Loading…
Reference in New Issue
Block a user