From 3751379f1e9a4c215fb6eb898b4ccc67659b9ace Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Tue, 10 May 2022 21:51:50 +0700 Subject: initial commit 2 --- addons/web/static/src/js/widgets/pie_chart.js | 102 ++++++++++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 addons/web/static/src/js/widgets/pie_chart.js (limited to 'addons/web/static/src/js/widgets/pie_chart.js') diff --git a/addons/web/static/src/js/widgets/pie_chart.js b/addons/web/static/src/js/widgets/pie_chart.js new file mode 100644 index 00000000..f4254ff3 --- /dev/null +++ b/addons/web/static/src/js/widgets/pie_chart.js @@ -0,0 +1,102 @@ +odoo.define('web.PieChart', function (require) { +"use strict"; + +/** + * This widget render a Pie Chart. It is used in the dashboard view. + */ + +var core = require('web.core'); +var Domain = require('web.Domain'); +var viewRegistry = require('web.view_registry'); +var Widget = require('web.Widget'); +var widgetRegistry = require('web.widget_registry'); + +var qweb = core.qweb; + +var PieChart = Widget.extend({ + className: 'o_pie_chart', + xmlDependencies: ['/web/static/src/xml/chart.xml'], + + /** + * @override + * @param {Widget} parent + * @param {Object} record + * @param {Object} node node from arch + */ + init: function (parent, record, node) { + this._super.apply(this, arguments); + + var modifiers = node.attrs.modifiers; + var domain = record.domain.concat( + Domain.prototype.stringToArray(modifiers.domain || '[]')); + var arch = qweb.render('web.PieChart', { + modifiers: modifiers, + title: node.attrs.title || modifiers.title || modifiers.measure, + }); + + var pieChartContext = JSON.parse(JSON.stringify(record.context)); + delete pieChartContext.graph_mode; + delete pieChartContext.graph_measure; + delete pieChartContext.graph_groupbys; + + this.subViewParams = { + modelName: record.model, + withButtons: false, + withControlPanel: false, + withSearchPanel: false, + isEmbedded: true, + useSampleModel: record.isSample, + mode: 'pie', + }; + this.subViewParams.searchQuery = { + context: pieChartContext, + domain: domain, + groupBy: [], + timeRanges: {}, + }; + + this.viewInfo = { + arch: arch, + fields: record.fields, + viewFields: record.fieldsInfo.dashboard, + }; + }, + /** + * Instantiates the pie chart view and starts the graph controller. + * + * @override + */ + willStart: function () { + var self = this; + var def1 = this._super.apply(this, arguments); + + var SubView = viewRegistry.get('graph'); + var subView = new SubView(this.viewInfo, this.subViewParams); + var def2 = subView.getController(this).then(function (controller) { + self.controller = controller; + return self.controller.appendTo(document.createDocumentFragment()); + }); + return Promise.all([def1, def2]); + }, + /** + * @override + */ + start: function () { + this.$el.append(this.controller.$el); + return this._super.apply(this, arguments); + }, + /** + * Call `on_attach_callback` for each subview + * + * @override + */ + on_attach_callback: function () { + this.controller.on_attach_callback(); + }, +}); + +widgetRegistry.add('pie_chart', PieChart); + +return PieChart; + +}); -- cgit v1.2.3