From afb19c59ee523c5150802a7591e7d92b8343cc3d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A9ry=20Debongnie?= Date: Fri, 25 Jul 2014 14:35:42 +0200 Subject: [IMP] improve graph view layout and groupbys * add a 'total' foldable button to allow the user to control the column in pivot table view * in the dropdown menu, add all fields from the model instead of only those from the search view groupbys --- addons/web_graph/static/src/css/graph.css | 39 ++++++++++++++++++++++++ addons/web_graph/static/src/js/graph_widget.js | 42 ++++++++++++++++++-------- addons/web_graph/static/src/xml/web_graph.xml | 37 ++++++++--------------- 3 files changed, 81 insertions(+), 37 deletions(-) (limited to 'addons/web_graph/static/src') diff --git a/addons/web_graph/static/src/css/graph.css b/addons/web_graph/static/src/css/graph.css index 6bc628f2eb7..415a2148d73 100644 --- a/addons/web_graph/static/src/css/graph.css +++ b/addons/web_graph/static/src/css/graph.css @@ -113,6 +113,7 @@ span.field-selection { border-radius: 3px; } + .graph_widget .dropdown-menu li a, .graph_widget .dropdown-menu li a:hover, .graph_widget .dropdown-menu li a:focus { color: black; text-decoration: none; @@ -124,3 +125,41 @@ th.measure_row { padding:0px 5px 0px 5px ; margin:0; } + + +.dropdown-submenu { + position: relative; +} + +.dropdown-submenu>.dropdown-menu { + top: 0; + left: 100%; + margin-top: -6px; + margin-left: -1px; + -webkit-border-radius: 0 6px 6px 6px; + -moz-border-radius: 0 6px 6px; + border-radius: 0 6px 6px 6px; +} + +.dropdown-submenu:hover>.dropdown-menu { + display: block; +} + +.dropdown-submenu>a:after { + display: block; + content: " "; + float: right; + width: 0; + height: 0; + border-color: transparent; + border-style: solid; + border-width: 5px 0 5px 5px; + border-left-color: #ccc; + margin-top: 5px; + margin-right: -10px; +} + +.dropdown-submenu:hover>a:after { + border-left-color: #fff; +} + diff --git a/addons/web_graph/static/src/js/graph_widget.js b/addons/web_graph/static/src/js/graph_widget.js index 59f0af95882..db33e567b42 100644 --- a/addons/web_graph/static/src/js/graph_widget.js +++ b/addons/web_graph/static/src/js/graph_widget.js @@ -57,7 +57,7 @@ openerp.web_graph.Graph = openerp.web.Widget.extend({ return this.model.call('fields_get', []).then(function (f) { self.fields = f; self.fields.__count = {field:'__count', type: 'integer', string:_t('Quantity')}; - self.important_fields = self.get_search_fields(); + self.groupby_fields = self.get_groupby_fields(); self.measure_list = self.get_measures(); self.add_measures_to_options(); self.pivot_options.row_groupby = self.create_field_values(self.pivot_options.row_groupby || []); @@ -81,6 +81,25 @@ openerp.web_graph.Graph = openerp.web.Widget.extend({ }); }, + get_groupby_fields: function () { + var search_fields = this.get_search_fields(), + search_field_names = _.pluck(search_fields, 'field'), + other_fields = [], + groupable_types = ['many2one', 'char', 'boolean', 'selection', 'date', 'datetime']; + + _.each(this.fields, function (val, key) { + if (!_.contains(search_field_names, key) && + _.contains(groupable_types, val.type) && + val.store === true) { + other_fields.push({ + field: key, + string: val.string, + }); + } + }); + return search_fields.concat(other_fields); + }, + // this method gets the fields that appear in the search view, under the // 'Groupby' heading get_search_fields: function () { @@ -196,7 +215,7 @@ openerp.web_graph.Graph = openerp.web.Widget.extend({ create_field_value: function (f) { var field = (_.contains(f, ':')) ? f.split(':')[0] : f, - groupby_field = _.findWhere(this.important_fields, {field:field}), + groupby_field = _.findWhere(this.groupby_fields, {field:field}), string = groupby_field ? groupby_field.string : this.fields[field].string, result = {field: f, string: string, type: this.fields[field].type }; @@ -309,11 +328,11 @@ openerp.web_graph.Graph = openerp.web.Widget.extend({ this.expand(id); return; } - if (!this.important_fields.length) { + if (!this.groupby_fields.length) { return; } - var fields = _.map(this.important_fields, function (field) { + var fields = _.map(this.groupby_fields, function (field) { return {id: field.field, value: field.string, type:self.fields[field.field.split(':')[0]].type}; }); if (this.dropdown) { @@ -324,7 +343,7 @@ openerp.web_graph.Graph = openerp.web.Widget.extend({ this.dropdown.css({position:'absolute', left:event.originalEvent.layerX, top:event.originalEvent.layerY}); - this.$('.field-selection').next('.dropdown-menu').toggle(); + this.$('.field-selection').next('.dropdown-menu').first().toggle(); }, @@ -423,23 +442,22 @@ openerp.web_graph.Graph = openerp.web.Widget.extend({ build_headers: function () { var pivot = this.pivot, nbr_measures = pivot.measures.length, - height = _.max(_.map(pivot.cols.headers, function(g) {return g.path.length;})), + height = _.max(_.map(pivot.cols.headers, function(g) {return g.path.length;})) + 1, rows = []; _.each(pivot.cols.headers, function (col) { - if (col.path.length === 0) { return;} var cell_width = nbr_measures * (col.expanded ? pivot.get_ancestor_leaves(col).length : 1), - cell_height = col.expanded ? 1 : height - col.path.length + 1, + cell_height = col.expanded ? 1 : height - col.path.length, cell = {width: cell_width, height: cell_height, title: col.title, id: col.id, expanded: col.expanded}; - if (rows[col.path.length - 1]) { - rows[col.path.length - 1].push(cell); + if (rows[col.path.length]) { + rows[col.path.length].push(cell); } else { - rows[col.path.length - 1] = [cell]; + rows[col.path.length] = [cell]; } }); if (pivot.get_cols_leaves().length > 1) { - rows[0].push({width: nbr_measures, height: height, title: _t('Total'), id: pivot.main_col().id }); + rows[0].push({width: nbr_measures, height: height, title: ' ', id: pivot.main_col().id }); } if (pivot.cols.headers.length === 1) { rows = [[{width: nbr_measures, height: 1, title: _t('Total'), id: pivot.main_col().id, expanded: false}]]; diff --git a/addons/web_graph/static/src/xml/web_graph.xml b/addons/web_graph/static/src/xml/web_graph.xml index 81804e5a9b1..6a2032b0f8f 100644 --- a/addons/web_graph/static/src/xml/web_graph.xml +++ b/addons/web_graph/static/src/xml/web_graph.xml @@ -57,35 +57,22 @@
-
+