[IMP] web: limit number of open columns in kanban view
With this commit, we limit the kanban view to 10 open groups at the start. This is useful to prevent the web client to make too many requests at once. This limit is set in the constant 'OPEN_GROUP_LIMIT'. Note: - columns already set as folded by default aren't take into account. - the user can still open any folded column, as usual. Task #1878113 (1/2)
This commit is contained in:
@@ -134,6 +134,9 @@ var x2ManyCommands = {
|
||||
};
|
||||
|
||||
var BasicModel = AbstractModel.extend({
|
||||
// constants
|
||||
OPEN_GROUP_LIMIT: 10, // after this limit, groups are automatically folded
|
||||
|
||||
// list of models for which the DataManager's cache should be cleared on
|
||||
// create, update and delete operations
|
||||
noCacheModels: [
|
||||
@@ -3991,6 +3994,7 @@ var BasicModel = AbstractModel.extend({
|
||||
list.data = [];
|
||||
list.count = 0;
|
||||
var defs = [];
|
||||
var openGroupCount = 0;
|
||||
|
||||
_.each(groups, function (group) {
|
||||
var aggregateValues = {};
|
||||
@@ -4046,7 +4050,7 @@ var BasicModel = AbstractModel.extend({
|
||||
oldGroup.limit = oldGroup.limit + oldGroup.loadMoreOffset;
|
||||
_.extend(oldGroup, updatedProps);
|
||||
newGroup = oldGroup;
|
||||
} else if (!newGroup.openGroupByDefault) {
|
||||
} else if (!newGroup.openGroupByDefault || openGroupCount >= self.OPEN_GROUP_LIMIT) {
|
||||
newGroup.isOpen = false;
|
||||
} else {
|
||||
newGroup.isOpen = '__fold' in group ? !group.__fold : true;
|
||||
@@ -4054,6 +4058,7 @@ var BasicModel = AbstractModel.extend({
|
||||
list.data.push(newGroup.id);
|
||||
list.count += newGroup.count;
|
||||
if (newGroup.isOpen && newGroup.count > 0) {
|
||||
openGroupCount++;
|
||||
defs.push(self._load(newGroup, options));
|
||||
}
|
||||
});
|
||||
|
||||
@@ -2162,6 +2162,72 @@ QUnit.module('Views', {
|
||||
kanban.destroy();
|
||||
});
|
||||
|
||||
QUnit.test('auto fold group when reach the limit', function (assert) {
|
||||
assert.expect(7);
|
||||
|
||||
var data = this.data;
|
||||
for (var i = 0; i < 12; i++) {
|
||||
data.product.records.push({
|
||||
id: (8 + i),
|
||||
name: ("column"),
|
||||
});
|
||||
data.partner.records.push({
|
||||
id: (20 + i),
|
||||
foo: ("dumb entry"),
|
||||
product_id: (8 + i),
|
||||
});
|
||||
}
|
||||
|
||||
var kanban = createView({
|
||||
View: KanbanView,
|
||||
model: 'partner',
|
||||
data: data,
|
||||
arch: '<kanban class="o_kanban_test">' +
|
||||
'<field name="product_id"/>' +
|
||||
'<templates><t t-name="kanban-box">' +
|
||||
'<div><field name="foo"/></div>' +
|
||||
'</t></templates>' +
|
||||
'</kanban>',
|
||||
groupBy: ['product_id'],
|
||||
mockRPC: function (route, args) {
|
||||
if (args.method === 'read_group') {
|
||||
return this._super.apply(this, arguments).then(function (result) {
|
||||
result[2].__fold = true;
|
||||
result[8].__fold = true;
|
||||
return result;
|
||||
});
|
||||
}
|
||||
return this._super(route, args);
|
||||
},
|
||||
});
|
||||
|
||||
// we look if column are fold/unfold according what is expected
|
||||
assert.notOk(kanban.$('.o_kanban_group:nth-child(2)').hasClass('o_column_folded'),
|
||||
'second column must be unfolded by default');
|
||||
assert.notOk(kanban.$('.o_kanban_group:nth-child(4)').hasClass('o_column_folded'),
|
||||
'fourth column must be unfolded by default');
|
||||
assert.notOk(kanban.$('.o_kanban_group:nth-child(10)').hasClass('o_column_folded'),
|
||||
'tenth column must be unfolded by default');
|
||||
assert.ok(
|
||||
kanban.$('.o_kanban_group:nth-child(3)').hasClass('o_column_folded')
|
||||
&& kanban.$('.o_kanban_group:nth-child(9)').hasClass('o_column_folded'),
|
||||
'third and ninth columns must be folded by default');
|
||||
// we look if columns are actually fold after we reached the limit
|
||||
assert.ok(
|
||||
kanban.$('.o_kanban_group:nth-child(13)').hasClass('o_column_folded')
|
||||
&& kanban.$('.o_kanban_group:nth-child(14)').hasClass('o_column_folded'),
|
||||
'thirteenth and fourtheenth columns must be folded because we reached the limit');
|
||||
// we look if we have the right count of folded/unfolded column
|
||||
assert.strictEqual(
|
||||
kanban.$('.o_kanban_group:not(.o_column_folded)').length,
|
||||
10, 'must have ten opened columns');
|
||||
assert.strictEqual(
|
||||
kanban.$('.o_kanban_group.o_column_folded').length,
|
||||
4, 'must have four folded columns');
|
||||
|
||||
kanban.destroy();
|
||||
});
|
||||
|
||||
QUnit.test('hide and display help message (ESC) in kanban quick create', function (assert) {
|
||||
assert.expect(2);
|
||||
|
||||
|
||||
@@ -983,6 +983,10 @@ non-editable :ref:`form view <reference/views/form>`. Records may be grouped
|
||||
in columns for use in workflow visualisation or manipulation (e.g. tasks or
|
||||
work-progress management), or ungrouped (used simply to visualize records).
|
||||
|
||||
.. note:: The kanban view will load and display a maximum of ten columns.
|
||||
Any column after that will be closed (but can still be opened by
|
||||
the user).
|
||||
|
||||
The root element of the Kanban view is ``<kanban>``, it can use the following
|
||||
attributes:
|
||||
|
||||
|
||||
Reference in New Issue
Block a user