summaryrefslogtreecommitdiff
path: root/addons/web/static/src/js/views/graph/graph_view.js
diff options
context:
space:
mode:
authorGéry Debongnie <ged@odoo.com>2017-03-05 10:05:56 +0100
committerAaron Bohy <aab@odoo.com>2017-04-11 19:44:38 +0200
commit905e01921f3c3ef43ace6fc537d1d8c0d280002c (patch)
tree265c43ab21c5401a5d9f0f3d64d86f1ac417451c /addons/web/static/src/js/views/graph/graph_view.js
parent54d4c73af4ad05c7640d28c1892247c9538b8017 (diff)
[REF] web, *: redesign all JS views
This commit introduce a full redesign of all JS views. We started basically from scratch. The goal was to unify all the various views under a common framework, to make them testable, to make then usable in different conditions (in studio, or in the frontend), and to make our lives easier. Some important points are: - we introduced new coding guidelines (camelCase, 80 chars width, ...) - we have a brand new testing framework (still QUnit based) - kanban view moved to the web addon - calendar view (formerly web_calender) moved to web as well - the tree view was removed - all new code should be documented We hope that this code is the start of a new era for the Odoo web client, we want to have a high quality codebase, well documented, well tested, well designed. Work done by the framework team: mostly aab, ged, chm, dmo, qsm
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.js69
1 files changed, 69 insertions, 0 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
new file mode 100644
index 00000000000..3422a0922d3
--- /dev/null
+++ b/addons/web/static/src/js/views/graph/graph_view.js
@@ -0,0 +1,69 @@
+odoo.define('web.GraphView', function (require) {
+"use strict";
+
+/**
+ * The Graph View is responsible to display a graphical (meaning: chart)
+ * representation of the current dataset. As of now, it is currently able to
+ * display data in three types of chart: bar chart, line chart and pie chart.
+ */
+
+var AbstractView = require('web.AbstractView');
+var core = require('web.core');
+var GraphModel = require('web.GraphModel');
+var Controller = require('web.GraphController');
+var GraphRenderer = require('web.GraphRenderer');
+
+var _t = core._t;
+var _lt = core._lt;
+
+var GraphView = AbstractView.extend({
+ display_name: _lt('Graph'),
+ icon: 'fa-bar-chart',
+ config: {
+ Model: GraphModel,
+ Controller: Controller,
+ Renderer: GraphRenderer,
+ },
+ /**
+ * @override
+ */
+ init: function (arch, fields) {
+ this._super.apply(this, arguments);
+
+ var initialMeasure = '__count__';
+ var initialGroupBys = [];
+ fields.__count__ = {string: _t("Count"), type: "integer"};
+ arch.children.forEach(function (field) {
+ var name = field.attrs.name;
+ if (field.attrs.interval) {
+ name += ':' + field.attrs.interval;
+ }
+ if (field.attrs.type === 'measure') {
+ initialMeasure = name;
+ } else {
+ initialGroupBys.push(name);
+ }
+ });
+
+ var measures = {__count__: {string: _t("Count"), type: "integer"}};
+ _.each(fields, function (field, name) {
+ if (name !== 'id' && field.store === true) {
+ if (field.type === 'integer' || field.type === 'float' || field.type === 'monetary') {
+ measures[name] = field;
+ }
+ }
+ });
+
+ this.controllerParams.measures = measures;
+ this.rendererParams.stacked = arch.attrs.stacked !== "False";
+
+ this.loadParams.initialMode = arch.attrs.type || 'bar';
+ this.loadParams.initialMeasure = initialMeasure;
+ this.loadParams.initialGroupBys = initialGroupBys;
+ this.loadParams.fields = fields;
+ },
+});
+
+return GraphView;
+
+});