From ae58fd5bd31cd02b287d5c64758eb52a0536a000 Mon Sep 17 00:00:00 2001 From: RomainLibert Date: Fri, 12 Jan 2018 14:37:09 +0100 Subject: [PATCH] [IMP] WEB: Progressbar Subgroup count in Sumfield The idea is that when we click on either the green, orange or red part of the progressbar the count on it's right changes to whatever the value of filtered records should be. --- .../views/kanban/kanban_column_progressbar.js | 26 +++++++++++++++- addons/web/static/tests/views/kanban_tests.js | 30 +++++++++++++++++++ 2 files changed, 55 insertions(+), 1 deletion(-) diff --git a/addons/web/static/src/js/views/kanban/kanban_column_progressbar.js b/addons/web/static/src/js/views/kanban/kanban_column_progressbar.js index 7e4f2cd96a8..fad822efdb9 100644 --- a/addons/web/static/src/js/views/kanban/kanban_column_progressbar.js +++ b/addons/web/static/src/js/views/kanban/kanban_column_progressbar.js @@ -30,6 +30,7 @@ var KanbanColumnProgressBar = Widget.extend({ this.fieldName = columnState.progressBarValues.field; this.colors = columnState.progressBarValues.colors; this.sumField = columnState.progressBarValues.sum_field; + this.progressBarHelp = columnState.progressBarValues.help; // Previous progressBar state var state = options.progressBarStates[this.columnID]; @@ -130,6 +131,14 @@ var KanbanColumnProgressBar = Widget.extend({ } }, }); + if (this.progressBarHelp && _.every(this.subgroupCounts, function (val) { return val === 0; })) { + this.$el.tooltip({ + delay: '0', + trigger:'hover', + placement: 'top', + title: this.progressBarHelp, + }); + } // Display and animate the progress bars _.each(self.colors, function (val, key) { @@ -165,9 +174,24 @@ var KanbanColumnProgressBar = Widget.extend({ // Display and animate the counter number var start = this.prevTotalCounterValue; var end = this.totalCounterValue; + + if (this.activeFilter) { + if (this.sumField) { + end = 0; + _.each(self.columnState.data, function (record) { + var recordData = record.data; + if (self.activeFilter === recordData[self.fieldName]) { + end += parseFloat(recordData[self.sumField]); + } + }); + } else { + end = this.subgroupCounts[this.activeFilter]; + } + } + this.prevTotalCounterValue = end; var animationClass = start > 999 ? 'o_kanban_grow' : 'o_kanban_grow_huge'; - if (start !== undefined && end > start && this.ANIMATE) { + if (start !== undefined && (end > start || this.activeFilter) && this.ANIMATE) { $({currentValue: start}).animate({currentValue: end}, { duration: 1000, start: function () { diff --git a/addons/web/static/tests/views/kanban_tests.js b/addons/web/static/tests/views/kanban_tests.js index 8092cd4d47f..eed80410e7f 100644 --- a/addons/web/static/tests/views/kanban_tests.js +++ b/addons/web/static/tests/views/kanban_tests.js @@ -2272,6 +2272,36 @@ QUnit.module('Views', { kanban.destroy(); }); + QUnit.test('progress bar subgroup count recompute', function(assert) { + assert.expect(2); + + var kanban = createView({ + View: KanbanView, + model: 'partner', + data: this.data, + arch: + '' + + '' + + '' + + '
' + + '' + + '
' + + '
' + + '
', + groupBy: ['bar'], + }); + + var initialCount = parseInt(kanban.$('.o_kanban_counter_side').eq(1).text()); + assert.strictEqual(initialCount, 3, + "Initial count should be Three"); + kanban.$('.bg-success-full').click(); + var lastCount = parseInt(kanban.$('.o_kanban_counter_side').eq(1).text()); + assert.strictEqual(lastCount, 0, + "kanban counters should vary according to what subgroup is selected"); + + kanban.destroy(); + }); + QUnit.test('keep adding quickcreate in first column after a record from this column was moved', function (assert) { assert.expect(2);