mirror of https://github.com/OCA/web.git
[FIX] web_timeline: order group_by field
Fix bug #2266: before this fix, the lines of the timeline view were always sorted by alphabetical order, ignoring the native order of the model on which the group_by field points to. Fix duplicate entries in the 'fields' argument when the 'colors' parameters uses the same field in multiple conditions.pull/2268/head
parent
cc88147229
commit
3dfcbcffb9
|
@ -66,6 +66,7 @@ odoo.define("web_timeline.TimelineController", function (require) {
|
||||||
kwargs: {
|
kwargs: {
|
||||||
fields: fields,
|
fields: fields,
|
||||||
domain: domains,
|
domain: domains,
|
||||||
|
order: [{name: this.renderer.arch.attrs.default_group_by}],
|
||||||
},
|
},
|
||||||
context: this.getSession().user_context,
|
context: this.getSession().user_context,
|
||||||
}).then((data) =>
|
}).then((data) =>
|
||||||
|
|
|
@ -11,6 +11,7 @@ odoo.define("web_timeline.TimelineModel", function (require) {
|
||||||
load: function (params) {
|
load: function (params) {
|
||||||
this.modelName = params.modelName;
|
this.modelName = params.modelName;
|
||||||
this.fieldNames = params.fieldNames;
|
this.fieldNames = params.fieldNames;
|
||||||
|
this.default_group_by = params.default_group_by;
|
||||||
if (!this.preload_def) {
|
if (!this.preload_def) {
|
||||||
this.preload_def = $.Deferred();
|
this.preload_def = $.Deferred();
|
||||||
$.when(
|
$.when(
|
||||||
|
@ -55,9 +56,12 @@ odoo.define("web_timeline.TimelineModel", function (require) {
|
||||||
return this._rpc({
|
return this._rpc({
|
||||||
model: this.modelName,
|
model: this.modelName,
|
||||||
method: "search_read",
|
method: "search_read",
|
||||||
context: this.data.context,
|
kwargs: {
|
||||||
fields: this.fieldNames,
|
fields: this.fieldNames,
|
||||||
domain: this.data.domain,
|
domain: this.data.domain,
|
||||||
|
order: [{name: this.default_group_by}],
|
||||||
|
context: this.data.context,
|
||||||
|
},
|
||||||
}).then((events) => {
|
}).then((events) => {
|
||||||
this.data.data = events;
|
this.data.data = events;
|
||||||
this.data.rights = {
|
this.data.rights = {
|
||||||
|
|
|
@ -35,6 +35,7 @@ odoo.define("web_timeline.TimelineRenderer", function (require) {
|
||||||
this.date_delay = params.date_delay;
|
this.date_delay = params.date_delay;
|
||||||
this.colors = params.colors;
|
this.colors = params.colors;
|
||||||
this.fieldNames = params.fieldNames;
|
this.fieldNames = params.fieldNames;
|
||||||
|
this.default_group_by = params.default_group_by;
|
||||||
this.dependency_arrow = params.dependency_arrow;
|
this.dependency_arrow = params.dependency_arrow;
|
||||||
this.modelClass = params.view.model;
|
this.modelClass = params.view.model;
|
||||||
this.fields = params.fields;
|
this.fields = params.fields;
|
||||||
|
@ -376,7 +377,8 @@ odoo.define("web_timeline.TimelineRenderer", function (require) {
|
||||||
return events;
|
return events;
|
||||||
}
|
}
|
||||||
const groups = [];
|
const groups = [];
|
||||||
groups.push({id: -1, content: _t("<b>UNASSIGNED</b>")});
|
groups.push({id: -1, content: _t("<b>UNASSIGNED</b>"), order: -1});
|
||||||
|
var seq = 1;
|
||||||
for (const evt of events) {
|
for (const evt of events) {
|
||||||
const group_name = evt[_.first(group_bys)];
|
const group_name = evt[_.first(group_bys)];
|
||||||
if (group_name) {
|
if (group_name) {
|
||||||
|
@ -389,7 +391,9 @@ odoo.define("web_timeline.TimelineRenderer", function (require) {
|
||||||
groups.push({
|
groups.push({
|
||||||
id: group_name[0],
|
id: group_name[0],
|
||||||
content: group_name[1],
|
content: group_name[1],
|
||||||
|
order: seq,
|
||||||
});
|
});
|
||||||
|
seq += 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -470,6 +474,7 @@ odoo.define("web_timeline.TimelineRenderer", function (require) {
|
||||||
start: date_start,
|
start: date_start,
|
||||||
content: content,
|
content: content,
|
||||||
id: evt.id,
|
id: evt.id,
|
||||||
|
order: evt.order,
|
||||||
group: group,
|
group: group,
|
||||||
evt: evt,
|
evt: evt,
|
||||||
style: `background-color: ${this.color};`,
|
style: `background-color: ${this.color};`,
|
||||||
|
|
|
@ -72,7 +72,9 @@ odoo.define("web_timeline.TimelineView", function (require) {
|
||||||
|
|
||||||
const colors = this.parse_colors();
|
const colors = this.parse_colors();
|
||||||
for (const color of colors) {
|
for (const color of colors) {
|
||||||
fieldNames.push(color.field);
|
if (!fieldNames.includes(color.field)) {
|
||||||
|
fieldNames.push(color.field);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dependency_arrow) {
|
if (dependency_arrow) {
|
||||||
|
@ -106,11 +108,13 @@ odoo.define("web_timeline.TimelineView", function (require) {
|
||||||
this.rendererParams.date_delay = date_delay;
|
this.rendererParams.date_delay = date_delay;
|
||||||
this.rendererParams.colors = colors;
|
this.rendererParams.colors = colors;
|
||||||
this.rendererParams.fieldNames = fieldNames;
|
this.rendererParams.fieldNames = fieldNames;
|
||||||
|
this.rendererParams.default_group_by = attrs.default_group_by;
|
||||||
this.rendererParams.min_height = min_height;
|
this.rendererParams.min_height = min_height;
|
||||||
this.rendererParams.dependency_arrow = dependency_arrow;
|
this.rendererParams.dependency_arrow = dependency_arrow;
|
||||||
this.rendererParams.fields = fields;
|
this.rendererParams.fields = fields;
|
||||||
this.loadParams.modelName = this.modelName;
|
this.loadParams.modelName = this.modelName;
|
||||||
this.loadParams.fieldNames = fieldNames;
|
this.loadParams.fieldNames = fieldNames;
|
||||||
|
this.loadParams.default_group_by = attrs.default_group_by;
|
||||||
this.controllerParams.open_popup_action = open_popup_action;
|
this.controllerParams.open_popup_action = open_popup_action;
|
||||||
this.controllerParams.date_start = date_start;
|
this.controllerParams.date_start = date_start;
|
||||||
this.controllerParams.date_stop = date_stop;
|
this.controllerParams.date_stop = date_stop;
|
||||||
|
@ -121,7 +125,7 @@ odoo.define("web_timeline.TimelineView", function (require) {
|
||||||
|
|
||||||
_preapre_vis_timeline_options: function (attrs) {
|
_preapre_vis_timeline_options: function (attrs) {
|
||||||
return {
|
return {
|
||||||
groupOrder: this.group_order,
|
groupOrder: "order",
|
||||||
orientation: "both",
|
orientation: "both",
|
||||||
selectable: true,
|
selectable: true,
|
||||||
multiselect: true,
|
multiselect: true,
|
||||||
|
@ -134,24 +138,6 @@ odoo.define("web_timeline.TimelineView", function (require) {
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
|
||||||
* Order function for groups.
|
|
||||||
* @param {Object} grp1
|
|
||||||
* @param {Object} grp2
|
|
||||||
* @returns {Integer}
|
|
||||||
*/
|
|
||||||
group_order: function (grp1, grp2) {
|
|
||||||
// Display non grouped elements first
|
|
||||||
if (grp1.id === -1) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
if (grp2.id === -1) {
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return grp1.content.localeCompare(grp2.content);
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parse the colors attribute.
|
* Parse the colors attribute.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in New Issue