[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.
This commit is contained in:
RomainLibert
2018-01-15 10:23:13 +01:00
parent e5330857b7
commit ae58fd5bd3
2 changed files with 55 additions and 1 deletions
@@ -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 () {
@@ -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:
'<kanban>' +
'<progressbar field="foo" colors=\'{"yop": "success", "gnap": "warning", "blip": "danger"}\'/>' +
'<templates><t t-name="kanban-box">' +
'<div>' +
'<field name="foo"/>' +
'</div>' +
'</t></templates>' +
'</kanban>',
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);