Skip to content

Commit

Permalink
Fix bug with useless rerendering of Dashboard chart.
Browse files Browse the repository at this point in the history
Changes:

* add rerendering of chart (or some of its lines) only when it needed.

Closes #242

See merge request polemarch/ce!184
  • Loading branch information
onegreyonewhite committed Jan 10, 2020
2 parents f9c3d97 + 6f8fe49 commit 8c1c888
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 18 deletions.
2 changes: 1 addition & 1 deletion polemarch/main/models/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ def _get_history_stats_by(self, qs, grouped_by='day') -> List:
sum_by_date[hist_stat[grouped_by]] = (
sum_by_date.get(hist_stat[grouped_by], 0) + hist_stat['sum']
)
for hist_stat in qs.order_by(grouped_by):
for hist_stat in qs.order_by(grouped_by, 'status'):
hist_stat.update({'all': sum_by_date[hist_stat[grouped_by]]})
values.append(hist_stat)
return values
Expand Down
24 changes: 12 additions & 12 deletions polemarch/static/js/pmDashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,10 @@ guiWidgets.history_chart = class HistoryChart extends guiWidgets.line_chart {
color: guiCustomizer.skin.settings.chart_axes_lines_color,
}
}]
}
},
tooltips: {
mode: 'index',
},
};
}
});
Expand Down Expand Up @@ -570,12 +573,6 @@ customRoutesComponentsTemplates.home = { /* globals customRoutesComponentsTempla
this.setLoadingError(error);
});
},
/**
* Redefinition of 'getAutoUpdateInterval' method of view_with_autoupdate_mixin.
*/
getAutoUpdateInterval() {
return 15000;
},
/**
* Redefinition of 'updateData' method of view_with_autoupdate_mixin.
*/
Expand Down Expand Up @@ -640,13 +637,16 @@ customRoutesComponentsTemplates.home = { /* globals customRoutesComponentsTempla
let exclude_stats = ['jobs'];

for(let key in response.data) {
if (response.data.hasOwnProperty(key)) {
if (exclude_stats.includes(key)) {
w_data.pmwChartWidget = response.data[key];
}
if (!response.data.hasOwnProperty(key)) {
continue;
}

w_data['pmw' + capitalizeString(key) + 'Counter'] = response.data[key];
if (exclude_stats.includes(key)) {
w_data.pmwChartWidget = response.data[key];
continue;
}

w_data['pmw' + capitalizeString(key) + 'Counter'] = response.data[key];
}

return w_data;
Expand Down
4 changes: 2 additions & 2 deletions polemarch/static/js/pmItems.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ vst_vue_components.widgets.w_history_chart = Vue.component('w_history_chart', {
};
},
watch: {
'customizer.skin.name': function(value) { /* jshint unused: false */ /* TODO ask about args*/
this.generateChart();
'customizer.skin.name': function(value) { /* jshint unused: false */
this.updateChartData();
}
},
computed: {
Expand Down
14 changes: 13 additions & 1 deletion polemarch/static/templates/pmItems.html
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,19 @@ <h5 class="text-center" style="margin-top:25px;">{{ $t('statistic') | capitalize
<div class="progress-group">
{{ $t(line.name) }}
<span class="float-right">
<b> {{ progressBarsData[line.name].sum }} </b>/ {{ progressBarsData[line.name].all }}
<span>
<transition name="slide-fade" mode="out-in">
<span :key="progressBarsData[line.name].sum">
<b> {{ progressBarsData[line.name].sum }} </b>
</span>
</transition>
</span>
<span>/</span>
<span>
<span>
{{ progressBarsData[line.name].all }}
</span>
</span>
</span>
<div class="progress progress-sm">
<div class="progress-bar"
Expand Down
1 change: 1 addition & 0 deletions polemarch/translations/en.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@
'groups counter': 'groups | group | groups',
'hosts counter': 'hosts | host | hosts',
'users counter': 'users | user | users',
'all_tasks': 'all tasks',
}
2 changes: 1 addition & 1 deletion requirements-doc.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# Docs
vstutils[doc]~=2.15.1
vstutils[doc]~=2.15.2
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Main
vstutils[rpc,ldap,doc,prod]~=2.15.1
vstutils[rpc,ldap,doc,prod]~=2.15.2
docutils==0.15.2
markdown2==2.3.8

Expand Down

0 comments on commit 8c1c888

Please sign in to comment.