summaryrefslogtreecommitdiff
path: root/addons/web/static/src/js/views/graph/graph_view.js
diff options
context:
space:
mode:
authorMathieu Duckerts-Antoine <dam@odoo.com>2018-06-11 15:45:30 +0200
committerGéry Debongnie <ged@odoo.com>2018-06-12 09:22:20 +0200
commite1aac71769c8d07a358b2d8717efa28248e18a34 (patch)
treeba63c14ad7aee42fc1e5fbd9b9b25f31ef1e69cc /addons/web/static/src/js/views/graph/graph_view.js
parent7bf5dd687be3919f6add10b1ac59a9cdee824632 (diff)
[IMP] web: add support for interval selection in groupbys
In this commit, we extend the search view to allow the selection of some intervals for date or datetime fields in groupby menu. The valid intervals are day, week, month, quarter, and year. It is also possible to add a button 'Group By' in the control panel owned by a graph view in case it is declared 'embedded' (e.g. in a dashboard view). Note that have three new generic reusable widgets have been introduced in this commit: DropdownMenu, GroupByMenu, and FiltersMenu.
Diffstat (limited to 'addons/web/static/src/js/views/graph/graph_view.js')
-rw-r--r--addons/web/static/src/js/views/graph/graph_view.js24
1 files changed, 18 insertions, 6 deletions
diff --git a/addons/web/static/src/js/views/graph/graph_view.js b/addons/web/static/src/js/views/graph/graph_view.js
index 54ff6642b15..07c486cf5b7 100644
--- a/addons/web/static/src/js/views/graph/graph_view.js
+++ b/addons/web/static/src/js/views/graph/graph_view.js
@@ -16,6 +16,9 @@ var GraphRenderer = require('web.GraphRenderer');
var _t = core._t;
var _lt = core._lt;
+var GROUPABLE_TYPES =
+ ['many2one', 'char', 'boolean', 'selection', 'date', 'datetime'];
+
var GraphView = AbstractView.extend({
display_name: _lt('Graph'),
icon: 'fa-bar-chart',
@@ -43,18 +46,22 @@ var GraphView = AbstractView.extend({
var measure;
var groupBys = [];
var measures = {__count__: {string: _t("Count"), type: "integer"}};
+ var groupableFields = {};
+ var intervalMapping = {};
this.fields.__count__ = {string: _t("Count"), type: "integer"};
this.arch.children.forEach(function (field) {
- var name = field.attrs.name;
- if (field.attrs.interval) {
- name += ':' + field.attrs.interval;
+ var fieldName = field.attrs.name;
+ var interval = field.attrs.interval;
+ if (interval) {
+ intervalMapping[fieldName] = interval;
+ fieldName = fieldName + ':' + interval;
}
if (field.attrs.type === 'measure') {
- measure = name;
- measures[name] = self.fields[name];
+ measure = fieldName;
+ measures[fieldName] = self.fields[fieldName];
} else {
- groupBys.push(name);
+ groupBys.push(fieldName);
}
});
@@ -64,15 +71,20 @@ var GraphView = AbstractView.extend({
_.contains(params.additionalMeasures, name)) {
measures[name] = field;
}
+ if (_.contains(GROUPABLE_TYPES, field.type)) {
+ groupableFields[name] = field;
+ }
}
});
this.controllerParams.measures = measures;
+ this.controllerParams.groupableFields = groupableFields;
this.rendererParams.stacked = this.arch.attrs.stacked !== "False";
this.loadParams.mode = this.arch.attrs.type || 'bar';
this.loadParams.measure = measure || '__count__';
this.loadParams.groupBys = groupBys || [];
+ this.loadParams.intervalMapping = intervalMapping;
this.loadParams.fields = this.fields;
},
});