Remove "classic" code path and always use datatables for ticket lists

This commit is contained in:
Timothy Hobbs 2019-10-08 17:00:57 +02:00
parent f127b2c224
commit b862732512
5 changed files with 119 additions and 150 deletions

View File

@ -106,9 +106,6 @@ HELPDESK_REDIRECT_TO_LOGIN_BY_DEFAULT = False
LOGIN_URL = '/login/'
LOGIN_REDIRECT_URL = '/login/'
# Turn off server-side processing for this local demo
HELPDESK_USE_SERVERSIDE_PROCESSING = False
# Database
# - by default, we use SQLite3 for the demo, but you can also
# configure MySQL or PostgreSQL, see the docs for more:

View File

@ -90,11 +90,6 @@ These changes are visible throughout django-helpdesk
**Default:** ``HELPDESK_ANON_ACCESS_RAISES_404 = False``
- **HELPDESK_USE_SERVERSIDE_PROCESSING** If True, may improve performance by utilizing server-side processing of the full ticket list whenever performing queries on the ticket list. Set to False to restore the "classic" functionality using javascript.
**Default:** ``HELPDESK_USE_SERVERSIDE_PROCESSING = True``
Options shown on public pages
-----------------------------

View File

@ -151,7 +151,3 @@ HELPDESK_ENABLE_PER_QUEUE_STAFF_PERMISSION = getattr(
# use https in the email links
HELPDESK_USE_HTTPS_IN_EMAIL_LINK = getattr(settings, 'HELPDESK_USE_HTTPS_IN_EMAIL_LINK', False)
# Asynchronous Datatables - Optional
HELPDESK_USE_SERVERSIDE_PROCESSING = getattr(
settings, 'HELPDESK_USE_SERVERSIDE_PROCESSING', True)

View File

@ -185,9 +185,6 @@
<th>{% trans "Time Spent" %}</th>
</tr>
</thead>
{% if not server_side %}
{% include 'helpdesk/ticket_list_table.html' %}
{% endif %}
</table>
<p><label>{% trans "Select:" %} </label>
@ -229,135 +226,126 @@
{% block helpdesk_js %}
<script src='{% static "helpdesk/filter.js" %}'></script>
<script>
{% if not server_side %}
$('#ticketTable').DataTable({
"language": {
"emptyTable": "{% trans 'No Tickets Match Your Selection' %}"
},
"order": [],
responsive: true
});
{% else %}
function get_url(row)
{
return "{% url 'helpdesk:view' 1234 %}".replace(/1234/, row.id.toString());
}
$(document).ready(function()
{
//DataTables Initialization
let tasks_table = $('#ticketTable').DataTable({
"language": {
"emptyTable": "{% trans 'No Tickets Match Your Selection' %}"
},
"processing": true,
"serverSide": true,
"ajax": {
"url": "{% url 'helpdesk:datatables_ticket_list' %}",
"type": "GET",
},
createdRow: function( row, data, dataIndex )
{
$( row ).addClass(data.row_class);
},
function get_url(row)
{
return "{% url 'helpdesk:view' 1234 %}".replace(/1234/, row.id.toString());
}
$(document).ready(function()
{
//DataTables Initialization
let tasks_table = $('#ticketTable').DataTable({
"language": {
"emptyTable": "{% trans 'No Tickets Match Your Selection' %}"
},
"processing": true,
"serverSide": true,
"ajax": {
"url": "{% url 'helpdesk:datatables_ticket_list' %}",
"type": "GET",
},
createdRow: function( row, data, dataIndex )
{
$( row ).addClass(data.row_class);
},
"columns": [
{"data": "id",
"orderable": false,
"render": function(data, type, row, meta)
{
var pk = data;
if(type === 'display'){
data = "<input type='checkbox' name='ticket_id' value='"+pk+"'"+ "class='ticket_multi_select' />"
}
return data
}
},
{"data": "ticket",
"render": function (data, type, row, meta)
{
var id = data.split(" ")[0];
var name = data.split(" ")[1];
if (type === 'display')
{
data = '<div class="tickettitle"><a href="' + get_url(row) + '" >' +
row.id + '. ' +
row.title + '</a></div>';
}
return data
}
},
{"data": "priority",
"render": function (data, type, row, meta) {
var priority = "success";
if (data == 4 ) {
priority = "warning";
} else if (data == 5) {
priority = "danger";
}
return '<p class="text-'+priority+'">'+data+'</p>';
}
},
{"data": "queue",
"render": function(data, type, row, meta) {
return data.title;
}
},
{"data": "status"},
{"data": "created"},
{"data": "due_date"},
{"data": "assigned_to",
"render": function(data, type, row, meta) {
if (data != "None") {
return data;
}
else {
return "";
}
}
},
{"data": "time_spent"},
]
});
})
{% endif %}
$(document).ready(function()
{
$("#select_all_btn").click(function() {
$(".ticket_multi_select").prop('checked', true);
});
$("#select_none_btn").click(function() {
$(".ticket_multi_select").prop('checked', false);
});
$("#select_inverse_btn").click(function() {
$(".ticket_multi_select").each(function() {
$(this).prop('checked', !$(this).prop('checked'));
});
});
})
"columns": [
{"data": "id",
"orderable": false,
"render": function(data, type, row, meta)
{
var pk = data;
if(type === 'display'){
data = "<input type='checkbox' name='ticket_id' value='"+pk+"'"+ "class='ticket_multi_select' />"
}
return data
}
},
{"data": "ticket",
"render": function (data, type, row, meta)
{
var id = data.split(" ")[0];
var name = data.split(" ")[1];
if (type === 'display')
{
data = '<div class="tickettitle"><a href="' + get_url(row) + '" >' +
row.id + '. ' +
row.title + '</a></div>';
}
return data
}
},
{"data": "priority",
"render": function (data, type, row, meta) {
var priority = "success";
if (data == 4 ) {
priority = "warning";
} else if (data == 5) {
priority = "danger";
}
return '<p class="text-'+priority+'">'+data+'</p>';
}
},
{"data": "queue",
"render": function(data, type, row, meta) {
return data.title;
}
},
{"data": "status"},
{"data": "created"},
{"data": "due_date"},
{"data": "assigned_to",
"render": function(data, type, row, meta) {
if (data != "None") {
return data;
}
else {
return "";
}
}
},
{"data": "time_spent"},
]
});
})
/**
* Disable active filtering options in filter select menu
*/
$(document).ready(function() {
{% if query_params.sorting %}
$("#filterBuilderSelect-Sort")[0].disabled = "disabled";
{% endif %}
{% if query_params.filtering.assigned_to__id__in %}
$("#filterBuilderSelect-Owner")[0].disabled = "disabled";
{% endif %}
{% if query_params.filtering.queue__id__in %}
$("#filterBuilderSelect-Queue")[0].disabled = "disabled";
{% endif %}
{% if query_params.filtering.status__in %}
$("#filterBuilderSelect-Status")[0].disabled = "disabled";
{% endif %}
{% if query_params.filtering.created__gte or query_params.filtering.created__lte %}
$("#filterBuilderSelect-Dates")[0].disabled = "disabled";
{% endif %}
{% if query %}
$("#filterBuilderSelect-Keywords")[0].disabled = "disabled";
{% endif %}
});
$(document).ready(function()
{
$("#select_all_btn").click(function() {
$(".ticket_multi_select").prop('checked', true);
});
$("#select_none_btn").click(function() {
$(".ticket_multi_select").prop('checked', false);
});
$("#select_inverse_btn").click(function() {
$(".ticket_multi_select").each(function() {
$(this).prop('checked', !$(this).prop('checked'));
});
});
})
/**
* Disable active filtering options in filter select menu
*/
$(document).ready(function() {
{% if query_params.sorting %}
$("#filterBuilderSelect-Sort")[0].disabled = "disabled";
{% endif %}
{% if query_params.filtering.assigned_to__id__in %}
$("#filterBuilderSelect-Owner")[0].disabled = "disabled";
{% endif %}
{% if query_params.filtering.queue__id__in %}
$("#filterBuilderSelect-Queue")[0].disabled = "disabled";
{% endif %}
{% if query_params.filtering.status__in %}
$("#filterBuilderSelect-Status")[0].disabled = "disabled";
{% endif %}
{% if query_params.filtering.created__gte or query_params.filtering.created__lte %}
$("#filterBuilderSelect-Dates")[0].disabled = "disabled";
{% endif %}
{% if query %}
$("#filterBuilderSelect-Keywords")[0].disabled = "disabled";
{% endif %}
});
{% for f in query_params.filtering %}
{% endfor %}

View File

@ -24,7 +24,6 @@ from django.utils.html import escape
from django import forms
from django.utils import timezone
from django.views.generic.edit import FormView, UpdateView
# For datatables serverside
from django.core.cache import cache
from helpdesk.lib import query_tickets_by_args
@ -972,13 +971,7 @@ def ticket_list(request):
user_saved_queries = SavedSearch.objects.filter(Q(user=request.user) | Q(shared__exact=True))
# Serverside processing on datatables is optional. Set
# HELPDESK_USE_SERVERSIDE_PROCESSING to False in settings.py to disable
if helpdesk_settings.HELPDESK_USE_SERVERSIDE_PROCESSING:
cache.set('ticket_qs', ticket_qs)
context['server_side'] = True
else:
context['server_side'] = False
cache.set('ticket_qs', ticket_qs)
return render(request, 'helpdesk/ticket_list.html', dict(
context,