From 37c6905d46429166d35f8fb819fca065718aae55 Mon Sep 17 00:00:00 2001 From: Jachym Cepicky Date: Sun, 16 Jun 2019 10:25:29 +0200 Subject: [PATCH 1/4] cleaning time_spent formating --- helpdesk/lib.py | 15 ++++++++++++ helpdesk/models.py | 23 +++++++++++++++++++ helpdesk/serializers.py | 3 ++- helpdesk/templates/helpdesk/ticket.html | 2 +- .../templates/helpdesk/ticket_desc_table.html | 2 +- .../templates/helpdesk/ticket_list_table.html | 2 +- helpdesk/views/staff.py | 10 ++++---- 7 files changed, 49 insertions(+), 8 deletions(-) diff --git a/helpdesk/lib.py b/helpdesk/lib.py index b44e4109..99e6ef0b 100644 --- a/helpdesk/lib.py +++ b/helpdesk/lib.py @@ -291,3 +291,18 @@ def query_tickets_by_args(objects, order_by, **kwargs): 'total': total, 'draw': draw } + + +def format_time_spent(time_spent): + """Format time_spent attribute to "[H]HHh:MMm" text string to be allign in + all graphical outputs + """ + + if time_spent: + time_spent = "{0:02d}h:{0:02d}m".format( + int(time_spent.total_seconds() // 3600), + int((time_spent.total_seconds() % 3600) / 60) + ) + else: + time_spent = "" + return time_spent diff --git a/helpdesk/models.py b/helpdesk/models.py index 6264cf84..0cf8711a 100644 --- a/helpdesk/models.py +++ b/helpdesk/models.py @@ -31,6 +31,17 @@ import uuid from .templated_email import send_templated_mail +def format_time_spent(time_spent): + if time_spent: + time_spent = "{0:02d}h:{0:02d}m".format( + int(time_spent.total_seconds() // (3600)), + int((time_spent.total_seconds() % 3600) / 60) + ) + else: + time_spent = "" + return time_spent + + class EscapeHtml(Extension): def extendMarkdown(self, md, md_globals): del md.preprocessors['html_block'] @@ -346,6 +357,10 @@ class Queue(models.Model): total = total + val.time_spent return total + @property + def time_spent_formated(self): + return format_time_spent(self.time_spent) + def prepare_permission_name(self): """Prepare internally the codename for the permission and store it in permission_name. :return: The codename that can be used to create a new Permission object. @@ -553,6 +568,10 @@ class Ticket(models.Model): total = total + val.time_spent return total + @property + def time_spent_formated(self): + return format_time_spent(self.time_spent) + def send(self, roles, dont_send_to=None, **kwargs): """ Send notifications to everyone interested in this ticket. @@ -861,6 +880,10 @@ class FollowUp(models.Model): def get_markdown(self): return get_markdown(self.comment) + @property + def time_spent_formated(self): + return format_time_spent(self.time_spent) + class TicketChange(models.Model): """ diff --git a/helpdesk/serializers.py b/helpdesk/serializers.py index bacd96cc..bb7fca5d 100644 --- a/helpdesk/serializers.py +++ b/helpdesk/serializers.py @@ -1,6 +1,7 @@ from rest_framework import serializers from .models import Ticket +from .lib import format_time_spent from django.contrib.humanize.templatetags import humanize @@ -53,7 +54,7 @@ class TicketSerializer(serializers.ModelSerializer): return ("None") def get_time_spent(self, obj): - return str(obj.time_spent) + return format_time_spent(obj.time_spent) def get_row_class(self, obj): return (obj.get_priority_css_class) diff --git a/helpdesk/templates/helpdesk/ticket.html b/helpdesk/templates/helpdesk/ticket.html index 2b6eda2d..2e6b2dbb 100644 --- a/helpdesk/templates/helpdesk/ticket.html +++ b/helpdesk/templates/helpdesk/ticket.html @@ -49,7 +49,7 @@

{{ followup.get_markdown|urlizetrunc:50|num_to_link|linebreaksbr }}

{% endif %} {% if followup.time_spent %} - {% trans "Time spent" %}: {{ followup.time_spent }}

+ {% trans "Time spent" %}: {{ followup.time_spent_formated }}

{% endif %} {% for change in followup.ticketchange_set.all %} {% if forloop.first %}
diff --git a/helpdesk/templates/helpdesk/ticket.html b/helpdesk/templates/helpdesk/ticket.html index 2e6b2dbb..84a78b16 100644 --- a/helpdesk/templates/helpdesk/ticket.html +++ b/helpdesk/templates/helpdesk/ticket.html @@ -42,24 +42,21 @@
{{ followup.title }}
-   +  

{% if followup.comment %}

{{ followup.get_markdown|urlizetrunc:50|num_to_link|linebreaksbr }}

{% endif %} - {% if followup.time_spent %} - {% trans "Time spent" %}: {{ followup.time_spent_formated }}

- {% endif %} {% for change in followup.ticketchange_set.all %} {% if forloop.first %}
    {% endif %}
  • {% blocktrans with change.field as field and change.old_value as old_value and change.new_value as new_value %}Changed {{ field }} from {{ old_value }} to {{ new_value }}.{% endblocktrans %}
  • {% if forloop.last %}
{% endif %} {% endfor %} - {% for attachment in followup.followupattachment_set.all %}{% if forloop.first %}
    {% endif %} + {% for attachment in followup.followupattachment_set.all %}{% if forloop.first %}{% trans "Attachments" %}:
    {% endif %} @@ -71,11 +68,11 @@ {% if helpdesk_settings.HELPDESK_SHOW_EDIT_BUTTON_FOLLOW_UP %} {% if followup.user and request.user == followup.user and not followup.ticketchange_set.all %} - + {% endif %} {% endif %} {% if user.is_superuser and helpdesk_settings.HELPDESK_SHOW_DELETE_BUTTON_SUPERUSER_FOLLOW_UP %} - + {% endif %} {% endif %}{% endwith %} @@ -208,7 +205,7 @@ - + {% csrf_token %} diff --git a/helpdesk/templates/helpdesk/ticket_desc_table.html b/helpdesk/templates/helpdesk/ticket_desc_table.html index 86b965b4..409ad521 100644 --- a/helpdesk/templates/helpdesk/ticket_desc_table.html +++ b/helpdesk/templates/helpdesk/ticket_desc_table.html @@ -2,31 +2,90 @@ {% load static from staticfiles %}
    -
    - {% trans "Ticket Summary" %} -
    +
    - - -

    {{ ticket.queue.slug }}-{{ ticket.id }}. {{ ticket.title }} [{{ ticket.get_status }}]

    + + + - + {% for customfield in ticket.ticketcustomfieldvalue_set.all %} - + {% endfor %} - + + + + - + + + + + + + + + + + + + + + + + + + + + + + + {% if ticket.resolution %} @@ -35,82 +94,9 @@ {% endif %} - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

    {{ ticket.queue.slug }}-{{ ticket.id }}. {{ ticket.title }} [{{ ticket.get_status }}]

    + {% blocktrans with ticket.queue as queue %}Queue: {{ queue }}{% endblocktrans %} + | {% if ticket.on_hold %} | {% else %} | {% endif %} -
    {% blocktrans with ticket.queue as queue %}Queue: {{ queue }}{% endblocktrans %}
    {{ customfield.field.label }}{{ customfield.field.label }} {% ifequal customfield.field.data_type "url" %}{{ customfield.value }}{% else %}{{ customfield.value }}{% endifequal %}
    {% trans "Description" %}{% trans "Due Date" %}{{ ticket.due_date|date:"d. E Y" }} {% if ticket.due_date %}({{ ticket.due_date|naturaltime }}){% endif %} + {% trans "Submitted On" %}{{ ticket.created|date:"d. E Y" }} ({{ ticket.created|naturaltime }})
    {{ ticket.get_markdown|urlizetrunc:50|num_to_link|linebreaksbr }}{% trans "Assigned To" %}{{ ticket.get_assigned_to }}{% ifequal ticket.get_assigned_to _('Unassigned') %} + + {% endifequal %} + {% trans "Submitter E-Mail" %}{{ ticket.submitter_email }} + {% if user.is_superuser %} {% if submitter_userprofile_url %}{% endif %} + + {% endif %} +
    {% trans "Priority" %}{{ ticket.get_priority_display }} + {% trans "Copies To" %}{{ ticketcc_string }} {% if SHOW_SUBSCRIBE %}, {% endif %}
    {% trans "Dependencies" %} + + {% for dep in ticket.ticketdependency.all %} + {% if forloop.first %}

    {% trans "This ticket cannot be resolved until the following ticket(s) are resolved" %}

    {% endif %} + {% empty %} + {% trans "This ticket has no dependencies." %} + {% endfor %} +
    {% trans "Total time spent" %}{{ ticket.time_spent_formated }}
    {% trans "Attachments" %} +
      + {% for followup in ticket.followup_set.all %} + {% for attachment in followup.followupattachment_set.all %} +
    • {{ attachment.filename }} ({{ attachment.mime_type }}, {{ attachment.size|filesizeformat }}) + {% if followup.user and request.user == followup.user %} + + {% endif %} +
    • + {% endfor %} + {% endfor %} +
    +
    +

    {% trans "Description" %}

    + {{ ticket.get_markdown|urlizetrunc:50|num_to_link|linebreaksbr }}
    {{ ticket.get_resolution_markdown|urlizetrunc:50|linebreaksbr }}
    {% trans "Due Date" %}{{ ticket.due_date|date:"r" }} ({{ ticket.due_date|naturaltime }}) - - - -
    {% trans "Submitted On" %}{{ ticket.created|date:"r" }} ({{ ticket.created|naturaltime }})
    {% trans "Assigned To" %}{{ ticket.get_assigned_to }}{% ifequal ticket.get_assigned_to _('Unassigned') %} - - {% endifequal %} - - - -
    {% trans "Submitter E-Mail" %}{{ ticket.submitter_email }} - {% if user.is_superuser %} {% if submitter_userprofile_url %}{% endif %} - {% endif %} -
    {% trans "Priority" %}{{ ticket.get_priority_display }} - - - -
    {% trans "Copies To" %}{{ ticketcc_string }} {% if SHOW_SUBSCRIBE %}, {% endif %}
    {% trans "Dependencies" %}{% for dep in ticket.ticketdependency.all %} - {% if forloop.first %}

    {% trans "This ticket cannot be resolved until the following ticket(s) are resolved" %}

    {% endif %} - {% empty %} -

    {% trans "This ticket has no dependencies." %}

    - {% endfor %} -

    -
    {% trans "Total time spent" %}{{ ticket.time_spent_formated }}
    {% trans "Attachments" %} -
      - {% for followup in ticket.followup_set.all %} - {% for attachment in followup.followupattachment_set.all %} -
    • {{ attachment.filename }} ({{ attachment.mime_type }}, {{ attachment.size|filesizeformat }}) - {% if followup.user and request.user == followup.user %} - - {% endif %} -
    • - {% endfor %} - {% endfor %} -
    -
    + From e7465ab2fdad6620daf5273183c04e9818ae46b7 Mon Sep 17 00:00:00 2001 From: Jachym Cepicky Date: Sat, 6 Jul 2019 22:24:08 +0200 Subject: [PATCH 4/4] more redminenish ticket filters --- helpdesk/static/helpdesk/filter.js | 21 +++ helpdesk/static/helpdesk/helpdesk-extend.css | 7 +- helpdesk/templates/helpdesk/filters/date.html | 20 +++ .../templates/helpdesk/filters/keywords.html | 13 ++ .../templates/helpdesk/filters/owner.html | 21 +++ .../templates/helpdesk/filters/queue.html | 20 +++ .../templates/helpdesk/filters/sorting.html | 39 +++++ .../templates/helpdesk/filters/status.html | 15 ++ helpdesk/templates/helpdesk/ticket_list.html | 148 ++++++++---------- 9 files changed, 219 insertions(+), 85 deletions(-) create mode 100644 helpdesk/templates/helpdesk/filters/date.html create mode 100644 helpdesk/templates/helpdesk/filters/keywords.html create mode 100644 helpdesk/templates/helpdesk/filters/owner.html create mode 100644 helpdesk/templates/helpdesk/filters/queue.html create mode 100644 helpdesk/templates/helpdesk/filters/sorting.html create mode 100644 helpdesk/templates/helpdesk/filters/status.html diff --git a/helpdesk/static/helpdesk/filter.js b/helpdesk/static/helpdesk/filter.js index 7052f5f0..7b8165ff 100644 --- a/helpdesk/static/helpdesk/filter.js +++ b/helpdesk/static/helpdesk/filter.js @@ -16,6 +16,27 @@ $(document).ready(function() { $(boxName).children("select").each(function() { this.selectedIndex = -1; }); + + var selectId = $(this).parents(".filterBox").attr('id'); + var attr = selectId.replace("filterBox", ""); + $("#filterBuilderSelect-" + attr)[0].disabled = ""; + return false; }); }); + +/** + * Called, when filterBuilderSelect input changed - will make input div appear + * to the user. Also disable this option in the Add filter menu + * + * @param {string} val name of selected filter value + */ +var onFilterChange = function(val) { + if (val) { + var boxName = "#filterBox" + val; + $(boxName).slideDown(); + $(boxName)[0].style.display="block"; + + $("#filterBuilderSelect-" + val)[0].disabled = "disabled"; + } +}; diff --git a/helpdesk/static/helpdesk/helpdesk-extend.css b/helpdesk/static/helpdesk/helpdesk-extend.css index 8b2e5c69..8f5fa1e3 100644 --- a/helpdesk/static/helpdesk/helpdesk-extend.css +++ b/helpdesk/static/helpdesk/helpdesk-extend.css @@ -24,7 +24,6 @@ Bootstrap overrides } .thumbnail.filterBox { - display: none; float: left; border: solid #ccc 1px; padding: 10px; @@ -33,10 +32,14 @@ Bootstrap overrides min-height: 200px; } -.thumbnail.filterBoxShow { +.filterBox { + display: none; +} +.filterBoxShow { display: block; } + .filterBox label { clear: both; display: block; diff --git a/helpdesk/templates/helpdesk/filters/date.html b/helpdesk/templates/helpdesk/filters/date.html new file mode 100644 index 00000000..fee486c3 --- /dev/null +++ b/helpdesk/templates/helpdesk/filters/date.html @@ -0,0 +1,20 @@ +{% load i18n humanize %} +
    +
    + +
    +
    + +
    +
    + +
    +
    + +
    +
    + +
    + +

    {% trans "Use YYYY-MM-DD date format, eg 2018-01-30" %}

    +
    diff --git a/helpdesk/templates/helpdesk/filters/keywords.html b/helpdesk/templates/helpdesk/filters/keywords.html new file mode 100644 index 00000000..e46a17ab --- /dev/null +++ b/helpdesk/templates/helpdesk/filters/keywords.html @@ -0,0 +1,13 @@ +{% load i18n humanize %} +
    +
    + +
    +
    + +
    +
    + +
    +

    {% trans "Keywords are case-insensitive, and will be looked for in the title, body and submitter fields." %}

    +
    diff --git a/helpdesk/templates/helpdesk/filters/owner.html b/helpdesk/templates/helpdesk/filters/owner.html new file mode 100644 index 00000000..a047495d --- /dev/null +++ b/helpdesk/templates/helpdesk/filters/owner.html @@ -0,0 +1,21 @@ +{% load i18n humanize %} +{% load static from staticfiles %} +{% load in_list %} +
    +
    + +
    +
    + +
    +
    + +
    +
    {% trans "Ctrl-Click to select multiple options" %}
    +
    diff --git a/helpdesk/templates/helpdesk/filters/queue.html b/helpdesk/templates/helpdesk/filters/queue.html new file mode 100644 index 00000000..90caf4be --- /dev/null +++ b/helpdesk/templates/helpdesk/filters/queue.html @@ -0,0 +1,20 @@ +{% load i18n humanize %} +{% load static from staticfiles %} +{% load in_list %} +
    +
    + +
    +
    + +
    +
    + +
    +
    {% trans "Ctrl-click to select multiple options" %}
    +
    + diff --git a/helpdesk/templates/helpdesk/filters/sorting.html b/helpdesk/templates/helpdesk/filters/sorting.html new file mode 100644 index 00000000..e9e08772 --- /dev/null +++ b/helpdesk/templates/helpdesk/filters/sorting.html @@ -0,0 +1,39 @@ +{% load i18n humanize %} +{% load static from staticfiles %} +
    +
    + +
    +
    + +
    +
    + +
    +
    + +
    +
    + +
    +
    {% trans "Ordering applied to tickets" %}
    +
    diff --git a/helpdesk/templates/helpdesk/filters/status.html b/helpdesk/templates/helpdesk/filters/status.html new file mode 100644 index 00000000..edbc127a --- /dev/null +++ b/helpdesk/templates/helpdesk/filters/status.html @@ -0,0 +1,15 @@ +{% load i18n humanize %} +{% load static from staticfiles %} +{% load in_list %} +
    +
    + +
    +
    + +
    +
    + +
    +
    {% trans "Ctrl-click to select multiple options" %}
    +
    diff --git a/helpdesk/templates/helpdesk/ticket_list.html b/helpdesk/templates/helpdesk/ticket_list.html index 2398e6c9..0da85099 100644 --- a/helpdesk/templates/helpdesk/ticket_list.html +++ b/helpdesk/templates/helpdesk/ticket_list.html @@ -42,8 +42,8 @@
    @@ -51,90 +51,44 @@
    -
    - - + + + + + + + - {% trans "Add another filter to list of filers for finer selection of displayed tickets" %} - - {% csrf_token %} + {% csrf_token %} +
    -
    -
    - - - - -

    {% trans "Ordering applied to tickets" %}

    - -
    +
      +
    • + {% include './filters/sorting.html' %} +
    • +
    • + {% include './filters/owner.html' %} +
    • +
    • + {% include './filters/queue.html' %} +
    • +
    • + {% include './filters/status.html' %} +
    • +
    • + {% include './filters/date.html' %} +
    • +
    • + {% include './filters/keywords.html' %} +
    • +
    -
    - - -

    {% trans "Ctrl-Click to select multiple options" %}

    - -
    - -
    - -

    {% trans "Ctrl-click to select multiple options" %}

    - -
    - -
    - -

    {% trans "Ctrl-click to select multiple options" %}

    - -
    - -
    - - -

    {% trans "Use YYYY-MM-DD date format, eg 2018-01-30" %}

    - -
    - -
    - -

    {% trans "Keywords are case-insensitive, and will be looked for in the title, body and submitter fields." %}

    - -
    -
    -
    {% if from_saved_query and saved_query.user == user %}

    {% blocktrans with saved_query.title as query_name %}You are currently viewing saved query "{{ query_name }}".{% endblocktrans %} {% trans "Delete Saved Query" %}

    @@ -153,7 +107,7 @@
    @@ -184,7 +138,7 @@
    @@ -380,6 +334,34 @@ }); }); }) + + /** + * 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 %} + {% endblock %}