diff options
| author | Géry Debongnie <ged@odoo.com> | 2014-07-25 14:35:42 +0200 |
|---|---|---|
| committer | Olivier Dony <odo@openerp.com> | 2014-07-30 15:11:21 +0200 |
| commit | afb19c59ee523c5150802a7591e7d92b8343cc3d (patch) | |
| tree | 7d104d3191ffee971885b1ef12f0f1dde8400188 /addons/web_graph/static/src/js/graph_widget.js | |
| parent | 35d50f0390f20180dbfd94ddeed1bf269a12fba0 (diff) | |
[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
Diffstat (limited to 'addons/web_graph/static/src/js/graph_widget.js')
| -rw-r--r-- | addons/web_graph/static/src/js/graph_widget.js | 42 |
1 files changed, 30 insertions, 12 deletions
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}]]; |
