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 <roberto.rosario.gonzalez@gmail.com>
This commit is contained in:
Roberto Rosario
2019-05-17 01:43:02 -04:00
parent c9809becba
commit 4a03e2a47f
7 changed files with 56 additions and 31 deletions

View File

@@ -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)
==================

View File

@@ -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

View File

@@ -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(

View File

@@ -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):

View File

@@ -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,
},
)

View File

@@ -11,7 +11,9 @@
<div class="row">
<div class="col-xs-12">
{% 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 %}
<canvas id="canvas-chart"></canvas>
</div>
@@ -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,
}
});
});
</script>

View File

@@ -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(