diff options
| author | Mathieu Duckerts-Antoine <dam@odoo.com> | 2019-08-07 12:40:14 +0000 |
|---|---|---|
| committer | Mathieu Duckerts-Antoine <dam@odoo.com> | 2019-08-08 09:27:23 +0000 |
| commit | d925a4557a270e3601947b748eca037e8690cc8e (patch) | |
| tree | bd8e844f9dd9a371e5aec7ced026af35a08c157b /addons/web/static/src | |
| parent | f337496eba58841d9fe2e94367f0450eaf0fa240 (diff) | |
[IMP] web: default groupbys can be given a rank
Consider an action with a search view defined by the arch
<search>
<filter name="gb_foo" context="{'group_by':'foo'}"/>
<filter name="gb_bar" context="{'group_by':'bar'}"/>
</search>
If the action context is
{
search_defaults_gb_foo: true,
search_defaults_gb_bar: true,
}
the two groupbys will be activated at start but not necessarily in a suitable
order.
This commit allows to specify the order in which the default groupbys should be
activated by giving them a rank. For example
{
search_defaults_gb_foo: 2,
search_defaults_gb_bar: 1,
}
leads to group first by bar then by foo.
The rank number should be chosen between 1 and 99.
closes odoo/odoo#35538
Signed-off-by: Géry Debongnie (ged) <ged@openerp.com>
Diffstat (limited to 'addons/web/static/src')
| -rw-r--r-- | addons/web/static/src/js/views/control_panel/control_panel_model.js | 17 | ||||
| -rw-r--r-- | addons/web/static/src/js/views/control_panel/control_panel_view.js | 10 |
2 files changed, 18 insertions, 9 deletions
diff --git a/addons/web/static/src/js/views/control_panel/control_panel_model.js b/addons/web/static/src/js/views/control_panel/control_panel_model.js index 1cc5adceb0e..045052b4a64 100644 --- a/addons/web/static/src/js/views/control_panel/control_panel_model.js +++ b/addons/web/static/src/js/views/control_panel/control_panel_model.js @@ -457,17 +457,16 @@ var ControlPanelModel = mvc.Model.extend({ * @private */ _activateDefaultFilters: function () { - var self = this; - Object.keys(this.filters).forEach(function (filterId) { - var filter = self.filters[filterId]; - // if we are here, this means there is no favorite with isDefault set to true - if (filter.isDefault && filter.type !== 'favorite') { - if (filter.hasOptions) { - self.toggleFilterWithOptions(filter.id); + Object.values(this.filters) + .filter(f => f.isDefault && f.type !== 'favorite') + .sort((f1, f2) => (f1.defaultRank || 100) - (f2.defaultRank || 100)) + .forEach(f => { + if (f.hasOptions) { + this.toggleFilterWithOptions(f.id); } else { - self.toggleFilter(filter.id); + this.toggleFilter(f.id); } - }}); + }); }, /** * If defaultTimeRanges param is provided, activate the filter of type diff --git a/addons/web/static/src/js/views/control_panel/control_panel_view.js b/addons/web/static/src/js/views/control_panel/control_panel_view.js index bd7c4110a26..49d01f5523b 100644 --- a/addons/web/static/src/js/views/control_panel/control_panel_view.js +++ b/addons/web/static/src/js/views/control_panel/control_panel_view.js @@ -157,6 +157,9 @@ var ControlPanelView = Factory.extend({ attrs.domain || 'Ω'; if (filter.type === 'filter') { + if (filter.isDefault) { + filter.defaultRank = -5; + } filter.domain = attrs.domain; filter.context = pyUtils.eval('context', attrs.context); if (attrs.date) { @@ -174,6 +177,10 @@ var ControlPanelView = Factory.extend({ filter.invisible = true; } } else if (filter.type === 'groupBy') { + if (filter.isDefault) { + const val = this.searchDefaults[attrs.name]; + filter.defaultRank = typeof val === 'number' ? val : 100; + } filter.fieldName = attrs.fieldName; filter.fieldType = this.fields[attrs.fieldName].type; if (_.contains(['date', 'datetime'], filter.fieldType)) { @@ -184,6 +191,9 @@ var ControlPanelView = Factory.extend({ filter.currentOptionId = false; } } else if (filter.type === 'field') { + if (filter.isDefault) { + filter.defaultRank = -10; + } var field = this.fields[attrs.name]; filter.attrs = attrs; filter.autoCompleteValues = []; |
