diff options
| author | Julien Mougenot <jum@odoo.com> | 2020-03-11 09:38:28 +0000 |
|---|---|---|
| committer | Julien Mougenot <jum@odoo.com> | 2020-03-13 14:08:33 +0000 |
| commit | 18e5416636b19b0953b1e6e26bfaeab1ebecce4c (patch) | |
| tree | 5be75af26f1707a5b8b2184545719f3628d2980f /addons/web/static/src/js/views/pivot | |
| parent | fbf347498f1cc7b74ef373179b7bcae201715c24 (diff) | |
[REF] web: Adapt views/actions to new control panel
Some web actions/controllers/viewsl have been adapted to properly instantiate the
newly refactored control panel and update it accordingly. We needed to adapt the
starting mechanism of actions and controllers to ensure that the control panel
instantiation did not delay the loading of any widget.
Part of task 2196029
Co-authored-by: Mathieu Duckerts-Antoine <dam@odoo.com>
Diffstat (limited to 'addons/web/static/src/js/views/pivot')
| -rw-r--r-- | addons/web/static/src/js/views/pivot/pivot_controller.js | 67 | ||||
| -rw-r--r-- | addons/web/static/src/js/views/pivot/pivot_model.js | 87 | ||||
| -rw-r--r-- | addons/web/static/src/js/views/pivot/pivot_view.js | 6 |
3 files changed, 60 insertions, 100 deletions
diff --git a/addons/web/static/src/js/views/pivot/pivot_controller.js b/addons/web/static/src/js/views/pivot/pivot_controller.js index c54c6affedc..ee37aba3ce5 100644 --- a/addons/web/static/src/js/views/pivot/pivot_controller.js +++ b/addons/web/static/src/js/views/pivot/pivot_controller.js @@ -85,25 +85,44 @@ odoo.define('web.PivotController', function (require) { * add listeners on it. * Set this.$buttons with the produced jQuery element * + * @override * @param {jQuery} [$node] a jQuery node where the rendered buttons should * be inserted. $node may be undefined, in which case the PivotView * does nothing */ renderButtons: function ($node) { + const context = { + measures: Object.entries(this.measures) + .filter(x => x[0] !== '__count') + .sort((a, b) => a[1].string.toLowerCase() > b[1].string.toLowerCase() ? 1 : -1), + }; + this.$buttons = $(QWeb.render('PivotView.buttons', context)); + this.$buttons.click(this._onButtonClick.bind(this)); + this.$buttons.find('button').tooltip(); if ($node) { - const context = { - measures: Object.entries(this.measures) - .filter(x => x[0] !== '__count') - .sort((a, b) => a[1].string.toLowerCase() > b[1].string.toLowerCase() ? 1 : -1), - }; - this.$buttons = $(QWeb.render('PivotView.buttons', context)); - this.$buttons.click(this._onButtonClick.bind(this)); - this.$buttons.find('button').tooltip(); - this.$buttons.appendTo($node); - this._updateButtons(); } }, + /** + * @override + */ + updateButtons: function () { + if (!this.$buttons) { + return; + } + const state = this.model.get({ raw: true }); + Object.entries(this.measures).forEach(elt => { + const name = elt[0]; + const isSelected = state.measures.includes(name); + this.$buttons.find('.dropdown-item[data-field="' + name + '"]') + .toggleClass('selected', isSelected); + + }); + const noDataDisplayed = !state.hasData || !state.measures.length; + this.$buttons.find('.o_pivot_flip_button').prop('disabled', noDataDisplayed); + this.$buttons.find('.o_pivot_expand_button').prop('disabled', noDataDisplayed); + this.$buttons.find('.o_pivot_download').prop('disabled', noDataDisplayed); + }, //-------------------------------------------------------------------------- // Private @@ -131,34 +150,6 @@ odoo.define('web.PivotController', function (require) { error: (error) => this.call('crash_manager', 'rpc_error', error), }); }, - /** - * @override - * @private - */ - _update: function () { - this._updateButtons(); - return this._super.apply(this, arguments); - }, - /** - * @private - */ - _updateButtons: function () { - if (!this.$buttons) { - return; - } - const state = this.model.get({ raw: true }); - Object.entries(this.measures).forEach(elt => { - const name = elt[0]; - const isSelected = state.measures.includes(name); - this.$buttons.find('.dropdown-item[data-field="' + name + '"]') - .toggleClass('selected', isSelected); - - }); - const noDataDisplayed = !state.hasData || !state.measures.length; - this.$buttons.find('.o_pivot_flip_button').prop('disabled', noDataDisplayed); - this.$buttons.find('.o_pivot_expand_button').prop('disabled', noDataDisplayed); - this.$buttons.find('.o_pivot_download').prop('disabled', noDataDisplayed); - }, //-------------------------------------------------------------------------- // Handlers diff --git a/addons/web/static/src/js/views/pivot/pivot_model.js b/addons/web/static/src/js/views/pivot/pivot_model.js index 67122ceb40d..8e4f92a4d75 100644 --- a/addons/web/static/src/js/views/pivot/pivot_model.js +++ b/addons/web/static/src/js/views/pivot/pivot_model.js @@ -530,18 +530,15 @@ var PivotModel = AbstractModel.extend({ * @param {boolean} [params.compare=false] * @param {Object} params.context * @param {Object} params.fields - * @param {Array[]} [params.comparisonTimeRange=[]] * @param {string[]} [params.groupedBy] - * @param {Array[]} [params.timeRange=[]] * @param {string[]} params.colGroupBys * @param {Array[]} params.domain * @param {string[]} params.measures * @param {string[]} params.rowGroupBys - * @param {string} [params.comparisonTimeRangeDescription=""] * @param {string} [params.default_order] - * @param {string} [params.timeRangeDescription=""] * @param {string} params.modelName * @param {Object[]} params.groupableFields + * @param {Object} params.timeRanges * @returns {Promise} */ load: function (params) { @@ -556,19 +553,14 @@ var PivotModel = AbstractModel.extend({ expandedRowGroupBys: [], expandedColGroupBys: [], domain: this.initialDomain, - timeRange: params.timeRange || [], - timeRangeDescription: params.timeRangeDescription || "", - comparisonTimeRange: params.comparisonTimeRange || [], - comparisonTimeRangeDescription: params.comparisonTimeRangeDescription || "", - compare: params.compare || false, context: _.extend({}, session.user_context, params.context), groupedBy: params.context.pivot_row_groupby || params.groupedBy, colGroupBys: params.context.pivot_column_groupby || params.colGroupBys, measures: this._processMeasures(params.context.pivot_measures) || params.measures, + timeRanges: params.timeRanges, }; + this._computeDerivedParams(); - this.data.domains = this._getDomains(); - this.data.origins = this._getOrigins(); this.data.rowGroupBys = !_.isEmpty(this.data.groupedBy) ? this.data.groupedBy : this.initialRowGroupBys; var defaultOrder = params.default_order && params.default_order.split(' '); @@ -588,14 +580,11 @@ var PivotModel = AbstractModel.extend({ * @param {Object} params * @param {boolean} [params.compare=false] * @param {Object} params.context - * @param {Array[]} [params.comparisonTimeRange=[]] * @param {string[]} [params.groupedBy] - * @param {Array[]} [params.timeRange=[]] * @param {Array[]} params.domain * @param {string[]} params.groupBy * @param {string[]} params.measures - * @param {string} [params.comparisonTimeRangeDescription=""] - * @param {string} [params.timeRangeDescription=""] + * @param {Object} [params.timeRanges] * @returns {Promise} */ reload: function (handle, params) { @@ -608,21 +597,6 @@ var PivotModel = AbstractModel.extend({ this.data.groupedBy = params.context.pivot_row_groupby || this.data.groupedBy; this.data.measures = this._processMeasures(params.context.pivot_measures) || this.data.measures; this.defaultGroupedBy = this.data.groupedBy.length ? this.data.groupedBy : this.defaultGroupedBy; - var timeRangeMenuData = params.context.timeRangeMenuData; - if (timeRangeMenuData) { - this.data.timeRange = timeRangeMenuData.timeRange || []; - this.data.timeRangeDescription = timeRangeMenuData.timeRangeDescription || ""; - this.data.comparisonTimeRange = timeRangeMenuData.comparisonTimeRange || []; - this.data.comparisonTimeRangeDescription = timeRangeMenuData.comparisonTimeRangeDescription || ""; - this.data.compare = this.data.comparisonTimeRange.length > 0; - } else { - this.data.timeRange = []; - this.data.timeRangeDescription = ""; - this.data.comparisonTimeRange = []; - this.data.comparisonTimeRangeDescription = ""; - this.data.compare = false; - this.data.context = _.omit(this.data.context, 'timeRangeMenuData'); - } } if ('domain' in params) { this.data.domain = params.domain; @@ -633,9 +607,11 @@ var PivotModel = AbstractModel.extend({ if ('groupBy' in params) { this.data.groupedBy = params.groupBy.length ? params.groupBy : this.defaultGroupedBy; } + if ('timeRanges' in params) { + this.data.timeRanges = params.timeRanges; + } + this._computeDerivedParams(); - this.data.domains = this._getDomains(); - this.data.origins = this._getOrigins(); this.data.rowGroupBys = !_.isEmpty(this.data.groupedBy) ? this.data.groupedBy : this.initialRowGroupBys; if (!_.isEqual(oldRowGroupBys, self.data.rowGroupBys)) { @@ -792,20 +768,6 @@ var PivotModel = AbstractModel.extend({ } }, /** - * Returns the principal domains used by the pivot model to fetch data. - * The domains represent two main groups of records. - * - * @private - * @returns {Array[][]} - */ - _getDomains: function () { - var domains = [this.data.domain.concat(this.data.timeRange)]; - if (this.data.compare) { - domains.push(this.data.domain.concat(this.data.comparisonTimeRange)); - } - return domains; - }, - /** * Returns the rowGroupBys and colGroupBys arrays that * are actually used by the pivot view internally * (for read_group or other purpose) @@ -1083,19 +1045,6 @@ var PivotModel = AbstractModel.extend({ return originRow; }, - /** - * Create an array with the origin descriptions. - * - * @private - * @returns {string[]} - */ - _getOrigins: function () { - var origins = [this.data.timeRangeDescription || ""]; - if (this.data.compare) { - origins.push(this.data.comparisonTimeRangeDescription); - } - return origins; - }, /** * Get the selection needed to display the group by dropdown @@ -1438,6 +1387,26 @@ var PivotModel = AbstractModel.extend({ } }, /** + * Determine this.data.domains and this.data.origins from + * this.data.domain and this.data.timeRanges; + * + * @private + */ + _computeDerivedParams: function () { + const { range, rangeDescription, comparisonRange, comparisonRangeDescription } = this.data.timeRanges; + if (range) { + this.data.domains = [this.data.domain.concat(range)]; + this.data.origins = [rangeDescription]; + if (comparisonRange) { + this.data.domains.push(this.data.domain.concat(comparisonRange)); + this.data.origins.push(comparisonRangeDescription); + } + } else { + this.data.domains = [this.data.domain]; + this.data.origins = [""]; + } + }, + /** * Make any group in tree a leaf if it was a leaf in oldTree. * * @private diff --git a/addons/web/static/src/js/views/pivot/pivot_view.js b/addons/web/static/src/js/views/pivot/pivot_view.js index bd259d9d0aa..1fca1e14487 100644 --- a/addons/web/static/src/js/views/pivot/pivot_view.js +++ b/addons/web/static/src/js/views/pivot/pivot_view.js @@ -18,8 +18,8 @@ odoo.define('web.PivotView', function (require) { const _t = core._t; const _lt = core._lt; - const controlPanelViewParameters = require('web.controlPanelViewParameters'); - const GROUPABLE_TYPES = controlPanelViewParameters.GROUPABLE_TYPES; + const searchUtils = require('web.searchUtils'); + const GROUPABLE_TYPES = searchUtils.GROUPABLE_TYPES; const PivotView = AbstractView.extend({ display_name: _lt('Pivot'), @@ -141,7 +141,7 @@ odoo.define('web.PivotView', function (require) { */ getRenderer(parent, state) { state = Object.assign(state || {}, this.rendererParams); - return new RendererWrapper(null, this.config.Renderer, state); + return new RendererWrapper(parent, this.config.Renderer, state); }, }); |
