diff options
| author | Mathieu Duckerts-Antoine <dam@odoo.com> | 2020-05-25 18:11:02 +0000 |
|---|---|---|
| committer | Mathieu Duckerts-Antoine <dam@odoo.com> | 2020-06-04 19:32:42 +0000 |
| commit | be5a51a345b8986da0e19627260f64f984e11ae9 (patch) | |
| tree | 4a0b1e5b0bfdad3124718ccf8e67164b5bbe07dd /addons/web/static/src/js/control_panel/time_range_menu.js | |
| parent | 884ef9f7ee345ab1e940dbf88f4432b7e10f36e3 (diff) | |
[IMP] web: Comparison menu
This commit replaces the "time range menu" in the control panel by a new
component: the "comparison menu".
Its purpose is roughly the same: compare a period of data in a reporting
view with the previous period or the previous year.
Its implementation is a bit simpler: it will only appear if at least one
date filter is selected in the search view, and will suggest to compare
each selected date option with the previous period or the previous year.
Task ID: 2245719
Co-authored-by: Mathieu Duckerts-Antoine <dam@odoo.com>
Co-authored-by: Julien Mougenot <jum@odoo.com>
Diffstat (limited to 'addons/web/static/src/js/control_panel/time_range_menu.js')
| -rw-r--r-- | addons/web/static/src/js/control_panel/time_range_menu.js | 109 |
1 files changed, 0 insertions, 109 deletions
diff --git a/addons/web/static/src/js/control_panel/time_range_menu.js b/addons/web/static/src/js/control_panel/time_range_menu.js deleted file mode 100644 index b18b376d40b..00000000000 --- a/addons/web/static/src/js/control_panel/time_range_menu.js +++ /dev/null @@ -1,109 +0,0 @@ -odoo.define('web.TimeRangeMenu', function (require) { - "use strict"; - - const { COMPARISON_TIME_RANGE_OPTIONS, DEFAULT_PERIOD, TIME_RANGE_OPTIONS } = require('web.searchUtils'); - const DropdownMenu = require('web.DropdownMenu'); - const { useModel } = require('web.model'); - - // Used to provide unique ids to its template elements. - let timeRangeMenuId = 0; - - /** - * 'Time ranges' menu - * - * Component used to create a time range from a field, a given range and optionally - * another field to make a comparison. - * - * The component template overrides the dropdownmenu to keep the basic behaviours - * (opening/closing, layout). The template itself iis a set of labels/inputs - * used to select the field and range. There is also a checkbox used to determine - * whether to render the comparison range field selection (input). - * @extends DropdownMenu - */ - class TimeRangeMenu extends DropdownMenu { - constructor() { - super(...arguments); - this.model = useModel('controlPanelModel'); - - this.domId = timeRangeMenuId++; - this.fields = Object.values(this.props.fields) - .filter(field => this._validateField(field)); - this.periodOptions = TIME_RANGE_OPTIONS; - this.comparisonTimeRangeOptions = COMPARISON_TIME_RANGE_OPTIONS; - this.periodGroups = Object.values(this.periodOptions).reduce((acc, o) => { - if (!acc.includes(o.groupNumber)) { - acc.push(o.groupNumber); - } - return acc; - }, []); - const activeTimeRange = this.model.getFiltersOfType('timeRange').find( - timeRange => timeRange.isActive - ); - Object.assign(this.state, { - fieldName: this.fields[0] && this.fields[0].name, - rangeId: DEFAULT_PERIOD, - }, activeTimeRange); - } - - //--------------------------------------------------------------------- - // Getters - //--------------------------------------------------------------------- - - /** - * @override - */ - get title() { - return this.env._t("Time Ranges"); - } - - //--------------------------------------------------------------------- - // Private - //--------------------------------------------------------------------- - - /** - * @private - * @param {Object} field - * @returns {boolean} - */ - _validateField(field) { - return field.sortable && - ['date', 'datetime'].includes(field.type); - } - - //--------------------------------------------------------------------- - // Handlers - //--------------------------------------------------------------------- - - /** - * @private - */ - _onApply() { - this.model.dispatch('activateTimeRange', - this.state.fieldName, - this.state.rangeId, - this.state.comparisonRangeId - ); - } - - /** - * @private - */ - _onCheckboxClick() { - if (!this.state.comparisonRangeId) { - this.state.comparisonRangeId = 'previous_period'; // default - } else { - delete this.state.comparisonRangeId; - } - } - } - - TimeRangeMenu.defaultProps = Object.assign({}, DropdownMenu.defaultProps, { - icon: 'fa fa-calendar', - }); - TimeRangeMenu.props = Object.assign({}, DropdownMenu.props, { - fields: Object, - }); - TimeRangeMenu.template = 'web.TimeRangeMenu'; - - return TimeRangeMenu; -}); |
