From 4a03e2a47f729c12e1b0493e1b803e923a95b35f Mon Sep 17 00:00:00 2001 From: Roberto Rosario Date: Fri, 17 May 2019 01:43:02 -0400 Subject: [PATCH] Statitics and chart updates Show last update date and time in list view and details view. Change color scheme to match rest of project. Increase size of data points. Improve responsive settings. Redirect to the current view after queueing. Signed-off-by: Roberto Rosario --- HISTORY.rst | 3 +++ docs/releases/3.2.rst | 3 +++ mayan/apps/mayan_statistics/apps.py | 9 ++++++-- mayan/apps/mayan_statistics/classes.py | 23 ++++++++++++++++--- mayan/apps/mayan_statistics/renderers.py | 21 ++++++----------- .../statistics/renderers/chartjs/line.html | 19 +++++++++++---- mayan/apps/mayan_statistics/views.py | 9 +------- 7 files changed, 56 insertions(+), 31 deletions(-) diff --git a/HISTORY.rst b/HISTORY.rst index 2dee2a7851..94a2d4808d 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -654,6 +654,9 @@ model. - Make icon classes file template based. - Add the current step and total steps of a wizard in the template context. +- Chart updates: Show last update date and time in list view and details view. + Change color scheme to match rest of project. Increase size of data points. + Improve responsive settings. Redirect to the current view after queueing. 3.0.3 (2018-08-17) ================== diff --git a/docs/releases/3.2.rst b/docs/releases/3.2.rst index 07b59c607f..32bef420f6 100644 --- a/docs/releases/3.2.rst +++ b/docs/releases/3.2.rst @@ -696,6 +696,9 @@ Other changes - Add task dotted path validation. - Increase dropzone upload file size limit to 2GB - Add cabinet created and edited events. +- Chart updates: Show last update date and time in list view and details view. + Change color scheme to match rest of project. Increase size of data points. + Improve responsive settings. Redirect to the current view after queueing. Removals diff --git a/mayan/apps/mayan_statistics/apps.py b/mayan/apps/mayan_statistics/apps.py index 78ebd94189..3c6880e3c0 100644 --- a/mayan/apps/mayan_statistics/apps.py +++ b/mayan/apps/mayan_statistics/apps.py @@ -26,11 +26,16 @@ class StatisticsApp(MayanAppConfig): super(StatisticsApp, self).ready() SourceColumn( - source=StatisticLineChart, + attribute='schedule', # Translators: Schedule here is a noun, the 'schedule' at # which the statistic will be updated label=_('Schedule'), - attribute='schedule', + source=StatisticLineChart, + ) + + SourceColumn( + attribute='get_last_update', label=_('Last update'), + source=StatisticLineChart, ) menu_object.bind_links( diff --git a/mayan/apps/mayan_statistics/classes.py b/mayan/apps/mayan_statistics/classes.py index 1ba7be3414..162dcfa8e8 100644 --- a/mayan/apps/mayan_statistics/classes.py +++ b/mayan/apps/mayan_statistics/classes.py @@ -2,6 +2,7 @@ from __future__ import unicode_literals from django.apps import apps from django.utils.encoding import force_text, python_2_unicode_compatible +from django.utils.translation import ugettext_lazy as _ from celery.schedules import crontab @@ -138,16 +139,32 @@ class Statistic(object): self.store_results(results=results) def get_chart_data(self): - return self.renderer(data=self.get_results()).get_chart_data() + return self.renderer(data=self.get_results_data()).get_chart_data() - def get_results(self): + def get_last_update(self): + results = self.get_results() + + if results: + return results.datetime + else: + return _('Never') + + def get_results(self, only=None): StatisticResult = apps.get_model( app_label='mayan_statistics', model_name='StatisticResult' ) try: - return StatisticResult.objects.get(slug=self.slug).get_data() + return StatisticResult.objects.get(slug=self.slug) except StatisticResult.DoesNotExist: + return StatisticResult.objects.none() + + def get_results_data(self): + results = self.get_results() + + if results: + return results.get_data() + else: return {'series': {}} def get_task_name(self): diff --git a/mayan/apps/mayan_statistics/renderers.py b/mayan/apps/mayan_statistics/renderers.py index 91b75779bf..4aab284a76 100644 --- a/mayan/apps/mayan_statistics/renderers.py +++ b/mayan/apps/mayan_statistics/renderers.py @@ -16,20 +16,13 @@ class ChartJSLine(ChartRenderer): dataset_palette = ( { - 'fillColor': "rgba(220,220,220,0.2)", - 'strokeColor': "rgba(220,220,220,1)", - 'pointColor': "rgba(220,220,220,1)", - 'pointStrokeColor': "#fff", - 'pointHighlightFill': "#fff", - 'pointHighlightStroke': "rgba(220,220,220,1)", - }, - { - 'fillColor': "rgba(151,187,205,0.2)", - 'strokeColor': "rgba(151,187,205,1)", - 'pointColor': "rgba(151,187,205,1)", - 'pointStrokeColor': "#fff", - 'pointHighlightFill': "#fff", - 'pointHighlightStroke': "rgba(151,187,205,1)", + 'backgroundColor': 'rgba(24, 188, 156, 0.1)', + 'borderColor': '#18bc9c', + 'pointBorderWidth': 3, + 'pointHitRadius': 6, + 'pointHoverRadius': 7, + 'pointRadius': 6, + }, ) diff --git a/mayan/apps/mayan_statistics/templates/statistics/renderers/chartjs/line.html b/mayan/apps/mayan_statistics/templates/statistics/renderers/chartjs/line.html index f554e5ee25..0a9531feb5 100644 --- a/mayan/apps/mayan_statistics/templates/statistics/renderers/chartjs/line.html +++ b/mayan/apps/mayan_statistics/templates/statistics/renderers/chartjs/line.html @@ -11,7 +11,9 @@
{% if no_data %} - {% trans 'No data available yet' %} + {% trans 'No data available.' %} + {% else %} + {% blocktrans with object.get_results.datetime as datetime %}Last update: {{ datetime }}{% endblocktrans %} {% endif %}
@@ -28,15 +30,24 @@ type: 'line', data: data, options: { + animation: { + duration: 0, + }, + aspectRatio: 2.5, + hover: { + animationDuration: 0, + }, layout: { padding: { left: 0, right: 0, top: 2, bottom: 0 - } - } - } + }, + }, + responsive: true, + responsiveAnimationDuration: 0, + } }); }); diff --git a/mayan/apps/mayan_statistics/views.py b/mayan/apps/mayan_statistics/views.py index b5846a913d..b99ca2430f 100644 --- a/mayan/apps/mayan_statistics/views.py +++ b/mayan/apps/mayan_statistics/views.py @@ -51,7 +51,7 @@ class StatisticDetailView(SimpleView): 'chart_data': obj.get_chart_data(), 'namespace': obj.namespace, 'navigation_object_list': ('namespace', 'object'), - 'no_data': not obj.get_results()['series'], + 'no_data': not obj.get_results_data()['series'], 'object': obj, 'title': _('Results for: %s') % obj, } @@ -88,13 +88,6 @@ class StatisticQueueView(ConfirmView): except KeyError: raise Http404(_('Statistic "%s" not found.') % self.kwargs['slug']) - def get_post_action_redirect(self): - return reverse( - viewname='statistics:statistic_detail', kwargs={ - 'slug': self.get_object().slug - } - ) - def view_action(self): task_execute_statistic.delay(slug=self.get_object().slug) messages.success(