From ae610d0e205da921111b5a320dec833d84b05056 Mon Sep 17 00:00:00 2001 From: Dhruv Patel Date: Mon, 16 Mar 2020 04:55:53 +0000 Subject: [IMP] web: graph: drill down to records in bar/pie charts After this commit, in the graph view, when the user clicks on parts of the bar and pie charts, it opens the list view of the concerned records (like what was already done in the pivot view). This is the default behavior, but it can be deactivated by setting the attribute 'disable_linking' to true in the view. Task 2198461 closes odoo/odoo#47796 Signed-off-by: Aaron Bohy (aab) Co-authored-by: Aaron Bohy --- .../static/src/js/views/graph/graph_controller.js | 30 ++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'addons/web/static/src/js/views/graph/graph_controller.js') diff --git a/addons/web/static/src/js/views/graph/graph_controller.js b/addons/web/static/src/js/views/graph/graph_controller.js index f47bfaeb5bb..eb5fd107081 100644 --- a/addons/web/static/src/js/views/graph/graph_controller.js +++ b/addons/web/static/src/js/views/graph/graph_controller.js @@ -23,6 +23,7 @@ class CarretDropdownMenu extends DropdownMenu { var GraphController = AbstractController.extend({ custom_events: _.extend({}, AbstractController.prototype.custom_events, { item_selected: '_onItemSelected', + open_view: '_onOpenView', }), /** @@ -42,6 +43,9 @@ var GraphController = AbstractController.extend({ // button in the control panel owned by the graph view. this.isEmbedded = params.isEmbedded; this.withButtons = params.withButtons; + // views to use in the action triggered when the graph is clicked + this.views = params.views; + this.title = params.title; // this parameter determines what is the list of fields // that may be used within the groupby menu available when @@ -296,6 +300,32 @@ var GraphController = AbstractController.extend({ this.measureMenu.update({ items: this.measures }); } }, + + /** + * @private + * @param {OdooEvent} ev + * @param {Array[]} ev.data.domain + */ + _onOpenView(ev) { + ev.stopPropagation(); + const state = this.model.get(); + const context = Object.assign({}, state.context); + Object.keys(context).forEach(x => { + if (x === 'group_by' || x.startsWith('search_default_')) { + delete context[x]; + } + }); + this.do_action({ + context: context, + domain: ev.data.domain, + name: this.title, + res_model: this.modelName, + target: 'current', + type: 'ir.actions.act_window', + view_mode: 'list', + views: this.views, + }); + }, }); return GraphController; -- cgit v1.2.3