[FIX] web: Kanban: load more records in column
The method `load_more` has been wrongly removed from the Kanban model.
This commit is contained in:
@@ -32,6 +32,7 @@ odoo.define('web.BasicModel', function (require) {
|
||||
* groupedBy: {string[]},
|
||||
* id: {integer},
|
||||
* isOpen: {boolean},
|
||||
* loadMoreOffset: {integer},
|
||||
* limit: {integer},
|
||||
* model: {string,
|
||||
* offset: {integer},
|
||||
@@ -618,6 +619,12 @@ var BasicModel = AbstractModel.extend({
|
||||
if (options.offset !== undefined) {
|
||||
this._setOffset(element.id, options.offset);
|
||||
}
|
||||
if (options.loadMoreOffset !== undefined) {
|
||||
element.loadMoreOffset = options.loadMoreOffset;
|
||||
} else {
|
||||
// reset if not specified
|
||||
element.loadMoreOffset = 0;
|
||||
}
|
||||
if (options.currentId !== undefined) {
|
||||
element.res_id = options.currentId;
|
||||
}
|
||||
@@ -2086,6 +2093,7 @@ var BasicModel = AbstractModel.extend({
|
||||
id: _.uniqueId(params.modelName + '_'),
|
||||
isOpen: params.isOpen,
|
||||
limit: type === 'record' ? 1 : params.limit,
|
||||
loadMoreOffset: 0,
|
||||
model: params.modelName,
|
||||
offset: params.offset || (type === 'record' ? _.indexOf(res_ids, res_id) : 0),
|
||||
openGroupByDefault: params.openGroupByDefault,
|
||||
@@ -2636,11 +2644,12 @@ var BasicModel = AbstractModel.extend({
|
||||
context: list.context,
|
||||
domain: list.domain || [],
|
||||
limit: list.limit,
|
||||
offset: list.offset,
|
||||
offset: list.loadMoreOffset + list.offset,
|
||||
orderBy: list.orderedBy,
|
||||
})
|
||||
.then(function (result) {
|
||||
list.count = result.length;
|
||||
var ids = _.pluck(result.records, 'id');
|
||||
var data = _.map(result.records, function (record) {
|
||||
var dataPoint = self._makeDataPoint({
|
||||
data: record,
|
||||
@@ -2655,8 +2664,13 @@ var BasicModel = AbstractModel.extend({
|
||||
self._parseServerData(fieldNames, dataPoint.fields, dataPoint.data);
|
||||
return dataPoint.id;
|
||||
});
|
||||
list.data = data;
|
||||
list.res_ids = _.pluck(result.records, 'id');
|
||||
if (list.loadMoreOffset) {
|
||||
list.data = list.data.concat(data);
|
||||
list.res_ids = list.res_ids.concat(ids);
|
||||
} else {
|
||||
list.data = data;
|
||||
list.res_ids = ids;
|
||||
}
|
||||
return list;
|
||||
});
|
||||
},
|
||||
|
||||
@@ -97,7 +97,7 @@ var KanbanController = BasicController.extend({
|
||||
* The column quick create should be displayed in kanban iff grouped by an
|
||||
* m2o field and group_create action enabled.
|
||||
*
|
||||
* @returns {Boolean}
|
||||
* @returns {boolean}
|
||||
*/
|
||||
_isCreateColumnEnabled: function () {
|
||||
var groupCreate = this.is_action_enabled('group_create');
|
||||
@@ -131,10 +131,10 @@ var KanbanController = BasicController.extend({
|
||||
_updateButtons: function () {
|
||||
if (this.$buttons) {
|
||||
var data = this.model.get(this.handle, {raw: true});
|
||||
var create_muted = data.count === 0 && this.createColumnEnabled;
|
||||
var createMuted = data.count === 0 && this.createColumnEnabled;
|
||||
this.$buttons.find('.o-kanban-button-new')
|
||||
.toggleClass('btn-primary', !create_muted)
|
||||
.toggleClass('btn-default', create_muted);
|
||||
.toggleClass('btn-primary', !createMuted)
|
||||
.toggleClass('btn-default', createMuted);
|
||||
}
|
||||
},
|
||||
/**
|
||||
@@ -236,7 +236,7 @@ var KanbanController = BasicController.extend({
|
||||
_onLoadMore: function (event) {
|
||||
var self = this;
|
||||
var column = event.target;
|
||||
this.model.load_more(column.db_id).then(function (db_id) {
|
||||
this.model.loadMore(column.db_id).then(function (db_id) {
|
||||
var data = self.model.get(db_id);
|
||||
self.renderer.updateColumn(db_id, data);
|
||||
});
|
||||
|
||||
@@ -89,6 +89,19 @@ var KanbanModel = BasicModel.extend({
|
||||
params.groupedBy = (params.groupedBy && params.groupedBy.length) ? params.groupedBy : this.defaultGroupedBy;
|
||||
return this._super(params);
|
||||
},
|
||||
/**
|
||||
* Load more records in a group.
|
||||
*
|
||||
* @param {string} groupID localID of the group
|
||||
* @returns {Deferred<string>} resolves to the localID of the group
|
||||
*/
|
||||
loadMore: function (groupID) {
|
||||
var group = this.localData[groupID];
|
||||
var offset = group.loadMoreOffset + group.limit;
|
||||
return this.reload(group.id, {
|
||||
loadMoreOffset: offset,
|
||||
});
|
||||
},
|
||||
/**
|
||||
* Moves a record from a group to another.
|
||||
*
|
||||
|
||||
@@ -1270,7 +1270,109 @@ QUnit.module('Views', {
|
||||
"there should not be partners anymore");
|
||||
|
||||
kanban.destroy();
|
||||
});
|
||||
|
||||
QUnit.test('load more records in column', function (assert) {
|
||||
assert.expect(9);
|
||||
|
||||
var kanban = createView({
|
||||
View: KanbanView,
|
||||
model: 'partner',
|
||||
data: this.data,
|
||||
arch: '<kanban>' +
|
||||
'<templates><t t-name="kanban-box">' +
|
||||
'<div><field name="foo"/></div>' +
|
||||
'</t></templates>' +
|
||||
'</kanban>',
|
||||
groupBy: ['bar'],
|
||||
viewOptions: {
|
||||
limit: 2,
|
||||
},
|
||||
mockRPC: function (route, args) {
|
||||
if (route === '/web/dataset/search_read') {
|
||||
assert.step([args.limit, args.offset]);
|
||||
}
|
||||
return this._super.apply(this, arguments);
|
||||
},
|
||||
});
|
||||
|
||||
assert.strictEqual(kanban.$('.o_kanban_group:eq(1) .o_kanban_record').length, 2,
|
||||
"there should be 2 records in the column");
|
||||
|
||||
// load more
|
||||
kanban.$('.o_kanban_group:eq(1)').find('.o_kanban_load_more').click();
|
||||
|
||||
assert.strictEqual(kanban.$('.o_kanban_group:eq(1) .o_kanban_record').length, 3,
|
||||
"there should now be 3 records in the column");
|
||||
|
||||
assert.verifySteps([[2, undefined], [2, undefined], [2, 2]],
|
||||
"the records should be correctly fetched");
|
||||
|
||||
kanban.reload();
|
||||
assert.strictEqual(kanban.$('.o_kanban_group:eq(1) .o_kanban_record').length, 2,
|
||||
"there should be 2 records in the column after reload");
|
||||
|
||||
kanban.destroy();
|
||||
});
|
||||
|
||||
QUnit.test('load more records in column with x2many', function (assert) {
|
||||
assert.expect(10);
|
||||
|
||||
this.data.partner.records[0].category_ids = [7];
|
||||
this.data.partner.records[1].category_ids = [];
|
||||
this.data.partner.records[2].category_ids = [6];
|
||||
this.data.partner.records[3].category_ids = [];
|
||||
|
||||
// record [2] will be loaded after
|
||||
|
||||
var kanban = createView({
|
||||
View: KanbanView,
|
||||
model: 'partner',
|
||||
data: this.data,
|
||||
arch: '<kanban>' +
|
||||
'<templates><t t-name="kanban-box">' +
|
||||
'<div>' +
|
||||
'<field name="category_ids"/>' +
|
||||
'<field name="foo"/>' +
|
||||
'</div>' +
|
||||
'</t></templates>' +
|
||||
'</kanban>',
|
||||
groupBy: ['bar'],
|
||||
viewOptions: {
|
||||
limit: 2,
|
||||
},
|
||||
mockRPC: function (route, args) {
|
||||
if (args.model === 'category' && args.method === 'read') {
|
||||
assert.step(args.args[0]);
|
||||
}
|
||||
if (route === '/web/dataset/search_read') {
|
||||
if (args.limit) {
|
||||
assert.strictEqual(args.limit, 2,
|
||||
"the limit should be correctly set");
|
||||
}
|
||||
if (args.offset) {
|
||||
assert.strictEqual(args.offset, 2,
|
||||
"the offset should be correctly set at load more");
|
||||
}
|
||||
}
|
||||
return this._super.apply(this, arguments);
|
||||
},
|
||||
});
|
||||
|
||||
assert.strictEqual(kanban.$('.o_kanban_group:eq(1) .o_kanban_record').length, 2,
|
||||
"there should be 2 records in the column");
|
||||
|
||||
assert.verifySteps([[7]], "only the appearing category should be fetched");
|
||||
|
||||
// load more
|
||||
kanban.$('.o_kanban_group:eq(1)').find('.o_kanban_load_more').click();
|
||||
|
||||
assert.strictEqual(kanban.$('.o_kanban_group:eq(1) .o_kanban_record').length, 3,
|
||||
"there should now be 3 records in the column");
|
||||
|
||||
assert.verifySteps([[7], [6]], "the other categories should not be fetched");
|
||||
|
||||
kanban.destroy();
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user