From 007a2f2a24869ec5bc803f2ac35d220d95853380 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9rome=20Maes?= Date: Thu, 7 Aug 2014 16:00:19 +0200 Subject: [FIX] web_graph : display the correct label for Selection fields in view graph --- addons/web_graph/static/src/js/pivot_table.js | 28 +++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) (limited to 'addons/web_graph/static/src/js') diff --git a/addons/web_graph/static/src/js/pivot_table.js b/addons/web_graph/static/src/js/pivot_table.js index 48ae9ec3830..086e7205990 100644 --- a/addons/web_graph/static/src/js/pivot_table.js +++ b/addons/web_graph/static/src/js/pivot_table.js @@ -28,7 +28,7 @@ openerp.web_graph.PivotTable = openerp.web.Class.extend({ // ---------------------------------------------------------------------- // this.measures: list of measure [measure], measure = {field: _, string: _, type: _} // this.rows.groupby, this.cols.groupby : list of groupbys used for describing rows (...), - // a groupby is also {field:_, string:_, type:_} + // a groupby is also {field:_, string:_, type:_} // If its type is date/datetime, field can have the corresponding interval in its description, // for example 'create_date:week'. set_measures: function (measures) { @@ -65,7 +65,7 @@ openerp.web_graph.PivotTable = openerp.web.Class.extend({ } var row_gb_changed = !_.isEqual(row_groupby, this.rows.groupby), col_gb_changed = !_.isEqual(col_groupby, this.cols.groupby); - + this.domain = domain; this.rows.groupby = row_groupby; this.cols.groupby = col_groupby; @@ -80,7 +80,7 @@ openerp.web_graph.PivotTable = openerp.web.Class.extend({ // Cells manipulation methods // ---------------------------------------------------------------------- // cells are objects {x:_, y:_, values:_} where x < y and values is an array - // of values (one for each measure). The condition x < y might look + // of values (one for each measure). The condition x < y might look // unnecessary, but it makes the rest of the code simpler: headers // don't krow if they are rows or cols, they just know their id, so // it is useful that a call get_values(id1, id2) is the same as get_values(id2, id1) @@ -103,9 +103,9 @@ openerp.web_graph.PivotTable = openerp.web.Class.extend({ // ---------------------------------------------------------------------- // Headers/Rows/Cols manipulation methods // ---------------------------------------------------------------------- - // this.rows.headers, this.cols.headers = [header] describe the tree structure + // this.rows.headers, this.cols.headers = [header] describe the tree structure // of rows/cols. Headers are objects - // { + // { // id:_, (unique id obviously) // path: [...], (array of all parents title, with its own title at the end) // title:_, (name of the row/col) @@ -150,12 +150,12 @@ openerp.web_graph.PivotTable = openerp.web.Class.extend({ get_rows_leaves: function () { return _.where(this.rows.headers, {expanded:false}); }, - + // return all non expanded cols get_cols_leaves: function () { return _.where(this.cols.headers, {expanded:false}); }, - + get_ancestors: function (header) { var self = this; if (!header.children) return []; @@ -181,7 +181,7 @@ openerp.web_graph.PivotTable = openerp.web.Class.extend({ }, main_row: function () { return this.rows.headers[0]; }, - + main_col: function () { return this.cols.headers[0]; }, // ---------------------------------------------------------------------- @@ -255,7 +255,7 @@ openerp.web_graph.PivotTable = openerp.web.Class.extend({ // Data updating methods // ---------------------------------------------------------------------- // update_data will try to preserve the expand/not expanded status of each - // column/row. If you want to expand all, then set this.cols.headers/this.rows.headers + // column/row. If you want to expand all, then set this.cols.headers/this.rows.headers // to null before calling update_data. update_data: function () { var self = this; @@ -289,7 +289,7 @@ openerp.web_graph.PivotTable = openerp.web.Class.extend({ data_pts.forEach(function (data_pt) { var row_value = (prefix || []).concat(data_pt.attributes.value.slice(0,index)); var col_value = data_pt.attributes.value.slice(index); - + if (expand && !_.find(col_headers, function (hdr) {return self.isEqual(col_value, hdr.path);})) { return; } @@ -427,6 +427,10 @@ openerp.web_graph.PivotTable = openerp.web.Class.extend({ return _t('Undefined'); } else if (attrs.value[i] instanceof Array) { return attrs.value[i][1]; + }else if (grouped_on && self.fields[grouped_on].type === 'selection'){ + var selection = self.fields[grouped_on].selection; + var value_lookup = _.where(selection, {0:attrs.value[i]}); + return value_lookup ? value_lookup[0][1] : _t('Undefined'); } return attrs.value[i]; }); @@ -445,8 +449,8 @@ openerp.web_graph.PivotTable = openerp.web.Class.extend({ isEqual: function (path1, path2) { if (path1.length !== path2.length) { return false; } for (var i = 0; i < path1.length; i++) { - if (path1[i] !== path2[i]) { - return false; + if (path1[i] !== path2[i]) { + return false; } } return true; -- cgit v1.2.3 From ff0ab6426a116bb504188764f76b63e4387279b7 Mon Sep 17 00:00:00 2001 From: Christophe Simonis Date: Wed, 13 Aug 2014 11:12:20 +0200 Subject: [FIX] web_graph : display the corresponding label for selection fields in graph view --- addons/web_graph/static/src/js/pivot_table.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'addons/web_graph/static/src/js') diff --git a/addons/web_graph/static/src/js/pivot_table.js b/addons/web_graph/static/src/js/pivot_table.js index 086e7205990..b842b00f00d 100644 --- a/addons/web_graph/static/src/js/pivot_table.js +++ b/addons/web_graph/static/src/js/pivot_table.js @@ -423,14 +423,15 @@ openerp.web_graph.PivotTable = openerp.web.Class.extend({ attrs.value = [attrs.value]; } attrs.value = _.range(grouped_on.length).map(function (i) { + var grp = grouped_on[i], + field = self.fields[grp]; if (attrs.value[i] === false) { return _t('Undefined'); } else if (attrs.value[i] instanceof Array) { return attrs.value[i][1]; - }else if (grouped_on && self.fields[grouped_on].type === 'selection'){ - var selection = self.fields[grouped_on].selection; - var value_lookup = _.where(selection, {0:attrs.value[i]}); - return value_lookup ? value_lookup[0][1] : _t('Undefined'); + } else if (field && field.type === 'selection') { + var selected = _.where(field.selection, {0: attrs.value[i]})[0]; + return selected ? selected[1] : attrs.value[i]; } return attrs.value[i]; }); -- cgit v1.2.3 From 8307a5f6ed54bd69ada4250e0c3170552bf210de Mon Sep 17 00:00:00 2001 From: qdc Date: Thu, 21 Aug 2014 09:03:12 +0200 Subject: [IMP] Graph views: show always measure + filters record measures in context --- addons/web_graph/static/src/js/graph_view.js | 34 ++++++++++++++------------ addons/web_graph/static/src/js/graph_widget.js | 27 ++++++++++++++------ addons/web_graph/static/src/js/pivot_table.js | 12 +++++---- 3 files changed, 45 insertions(+), 28 deletions(-) (limited to 'addons/web_graph/static/src/js') diff --git a/addons/web_graph/static/src/js/graph_view.js b/addons/web_graph/static/src/js/graph_view.js index e4e074b2e7f..4a81ceaa98c 100644 --- a/addons/web_graph/static/src/js/graph_view.js +++ b/addons/web_graph/static/src/js/graph_view.js @@ -26,7 +26,8 @@ instance.web_graph.GraphView = instance.web.View.extend({ this.model = new instance.web.Model(dataset.model, {group_by_no_leaf: true}); this.search_view = parent.searchview; this.col_search_field = { - get_context: function() { return { col_group_by: self.graph_widget.get_col_groupbys()};}, + get_context: function() { return { col_group_by: self.graph_widget.get_col_groupbys(), + measures: self.graph_widget.get_current_measures()};}, get_domain: function () {}, get_groupby: function () {}, }; @@ -83,7 +84,8 @@ instance.web_graph.GraphView = instance.web.View.extend({ } var self = this, groupbys = this.get_groupbys_from_searchview(), - col_group_by = groupbys.col_group_by; + col_group_by = groupbys.col_group_by, + measures = groupbys.measures; if (!this.graph_widget) { if (group_by.length) { @@ -92,22 +94,25 @@ instance.web_graph.GraphView = instance.web.View.extend({ if (col_group_by.length) { this.widget_config.col_groupby = col_group_by; } + if (measures.length) { + this.widget_config.measures = measures; + } this.graph_widget = new openerp.web_graph.Graph(this, this.model, domain, this.widget_config); this.graph_widget.appendTo(this.$el); this.ViewManager.on('switch_mode', this, function (e) { if (e === 'graph') { var group_bys = self.get_groupbys_from_searchview(); - this.graph_widget.set(domain, group_bys.group_by, group_bys.col_group_by); + this.graph_widget.set(domain, group_bys.group_by, group_bys.col_group_by, group_bys.measures); } }); return; } - this.graph_widget.set(domain, group_by, col_group_by); + this.graph_widget.set(domain, group_by, col_group_by, measures); }, get_groupbys_from_searchview: function () { - var result = { group_by: [], col_group_by: []}, + var result = { group_by: [], col_group_by: [], measures: []}, searchdata = this.search_view.build_search_data(); _.each(searchdata.groupbys, function (data) { @@ -116,6 +121,9 @@ instance.web_graph.GraphView = instance.web.View.extend({ if (data.col_group_by) { result.col_group_by = result.col_group_by.concat(data.col_group_by); } + if (data.measures) { + result.measures = result.measures.concat(data.measures); + } }); if (result.col_group_by.length) { @@ -125,6 +133,9 @@ instance.web_graph.GraphView = instance.web.View.extend({ if (context.col_group_by) { result.col_group_by = result.col_group_by.concat(context.col_group_by); } + if (context.measures) { + result.measures = result.measures.concat(context.measures); + } }); return result; }, @@ -144,9 +155,10 @@ instance.web_graph.GraphView = instance.web.View.extend({ groupbys = this.get_groupbys_from_searchview(), search_row_groupby = groupbys.group_by, search_col_groupby = groupbys.col_group_by, + search_measures = groupbys.measures, row_gb_changed = !_.isEqual(_.pluck(row_groupby, 'field'), search_row_groupby), - col_gb_changed = !_.isEqual(_.pluck(col_groupby, 'field'), search_col_groupby); - + col_gb_changed = !_.isEqual(_.pluck(col_groupby, 'field'), search_col_groupby), + measures_gb_changed = !_.isEqual(_.pluck(col_groupby, 'field'), search_col_groupby); if (!_.has(this.search_view, '_s_groupby')) { return; } if (!row_gb_changed && !col_gb_changed) { @@ -226,11 +238,3 @@ instance.web_graph.GraphView = instance.web.View.extend({ }, }); }; - - - - - - - - diff --git a/addons/web_graph/static/src/js/graph_widget.js b/addons/web_graph/static/src/js/graph_widget.js index db33e567b42..483c2199747 100644 --- a/addons/web_graph/static/src/js/graph_widget.js +++ b/addons/web_graph/static/src/js/graph_widget.js @@ -153,41 +153,49 @@ openerp.web_graph.Graph = openerp.web.Widget.extend({ // ---------------------------------------------------------------------- // Configuration methods // ---------------------------------------------------------------------- - set: function (domain, row_groupby, col_groupby) { + set: function (domain, row_groupby, col_groupby, measures_groupby) { if (!this.pivot) { this.pivot_options.domain = domain; this.pivot_options.row_groupby = row_groupby; this.pivot_options.col_groupby = col_groupby; + this.pivot_options.measures_groupby = measures_groupby; return; } var row_gbs = this.create_field_values(row_groupby), col_gbs = this.create_field_values(col_groupby), + measures_gbs = this.create_field_values(measures_groupby), dom_changed = !_.isEqual(this.pivot.domain, domain), row_gb_changed = !_.isEqual(row_gbs, this.pivot.rows.groupby), col_gb_changed = !_.isEqual(col_gbs, this.pivot.cols.groupby), + measures_gb_changed = !_.isEqual(measures_gbs, this.pivot.measures), row_reduced = is_strict_beginning_of(row_gbs, this.pivot.rows.groupby), - col_reduced = is_strict_beginning_of(col_gbs, this.pivot.cols.groupby); + col_reduced = is_strict_beginning_of(col_gbs, this.pivot.cols.groupby), + measures_reduced = is_strict_beginning_of(measures_gbs, this.pivot.measures); - if (!dom_changed && row_reduced && !col_gb_changed) { + if (!dom_changed && row_reduced && !col_gb_changed && !measures_gb_changed) { this.pivot.fold_with_depth(this.pivot.rows, row_gbs.length); this.display_data(); return; } - if (!dom_changed && col_reduced && !row_gb_changed) { + if (!dom_changed && col_reduced && !row_gb_changed && !measures_gb_changed) { this.pivot.fold_with_depth(this.pivot.cols, col_gbs.length); this.display_data(); return; } - if (!dom_changed && col_reduced && row_reduced) { + if (!dom_changed && col_reduced && row_reduced && !measures_gb_changed) { this.pivot.fold_with_depth(this.pivot.rows, row_gbs.length); this.pivot.fold_with_depth(this.pivot.cols, col_gbs.length); this.display_data(); return; } - if (dom_changed || row_gb_changed || col_gb_changed) { - this.pivot.set(domain, row_gbs, col_gbs).then(this.proxy('display_data')); + if (dom_changed || row_gb_changed || col_gb_changed || measures_gb_changed) { + this.pivot.set(domain, row_gbs, col_gbs, measures_gbs).then(this.proxy('display_data')); + } + + if (measures_gb_changed) { + this.put_measure_checkmarks(); } }, @@ -235,6 +243,10 @@ openerp.web_graph.Graph = openerp.web.Widget.extend({ return _.pluck(this.pivot.cols.groupby, 'field'); }, + get_current_measures: function () { + return _.pluck(this.pivot.measures, 'field'); + }, + // ---------------------------------------------------------------------- // UI code // ---------------------------------------------------------------------- @@ -627,7 +639,6 @@ openerp.web_graph.Graph = openerp.web.Widget.extend({ }, draw_measure_row: function (measure_row) { - if (this.pivot.measures.length === 1) { return; } var $row = $('').append(''); _.each(measure_row, function (cell) { var $cell = $('').addClass('measure_row').text(cell.text); diff --git a/addons/web_graph/static/src/js/pivot_table.js b/addons/web_graph/static/src/js/pivot_table.js index b842b00f00d..b66bc41e98c 100644 --- a/addons/web_graph/static/src/js/pivot_table.js +++ b/addons/web_graph/static/src/js/pivot_table.js @@ -55,23 +55,27 @@ openerp.web_graph.PivotTable = openerp.web.Class.extend({ } }, - set: function (domain, row_groupby, col_groupby) { + set: function (domain, row_groupby, col_groupby, measures_groupby) { var self = this; if (this.updating) { return this.updating.then(function () { self.updating = false; - return self.set(domain, row_groupby,col_groupby); + return self.set(domain, row_groupby, col_groupby, measures_groupby); }); } var row_gb_changed = !_.isEqual(row_groupby, this.rows.groupby), - col_gb_changed = !_.isEqual(col_groupby, this.cols.groupby); + col_gb_changed = !_.isEqual(col_groupby, this.cols.groupby), + measures_gb_changed = !_.isEqual(measures_groupby, this.measures); this.domain = domain; this.rows.groupby = row_groupby; this.cols.groupby = col_groupby; + if (measures_groupby.length) { this.measures = measures_groupby; } + if (row_gb_changed) { this.rows.headers = null; } if (col_gb_changed) { this.cols.headers = null; } + if (measures_gb_changed && measures_groupby.length) { this.set_measures(measures_groupby); } return this.update_data(); }, @@ -460,5 +464,3 @@ openerp.web_graph.PivotTable = openerp.web.Class.extend({ }); })(); - - -- cgit v1.2.3 From 10be95407a96e2bc7457b790213e42f9b0009a07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A9ry=20Debongnie?= Date: Fri, 22 Aug 2014 12:52:58 +0200 Subject: [FIX] css fix in graph view The field selection menu was not positioned correctly when there was a long list. (was not displayed at the position clicked) --- addons/web_graph/static/src/js/graph_widget.js | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'addons/web_graph/static/src/js') diff --git a/addons/web_graph/static/src/js/graph_widget.js b/addons/web_graph/static/src/js/graph_widget.js index 483c2199747..f0e07e06e6a 100644 --- a/addons/web_graph/static/src/js/graph_widget.js +++ b/addons/web_graph/static/src/js/graph_widget.js @@ -352,12 +352,11 @@ openerp.web_graph.Graph = openerp.web.Widget.extend({ } this.dropdown = $(QWeb.render('field_selection', {fields:fields, header_id:id})); $(event.target).after(this.dropdown); - this.dropdown.css({position:'absolute', - left:event.originalEvent.layerX, - top:event.originalEvent.layerY}); - this.$('.field-selection').next('.dropdown-menu').first().toggle(); - - + this.dropdown.css({ + position:'absolute', + left:event.originalEvent.layerX, + }); + this.$('.field-selection').next('.dropdown-menu').first().toggle(); }, field_selection: function (event) { -- cgit v1.2.3 From 2ad092b5e54fa39a906b38d9240e08b9800ea0da Mon Sep 17 00:00:00 2001 From: Raphael Collet Date: Fri, 22 Aug 2014 17:51:20 +0200 Subject: [ADD] doc: new documentation, with training tutorials, and new scaffolding --- addons/web_graph/static/src/js/graph_view.js | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) (limited to 'addons/web_graph/static/src/js') diff --git a/addons/web_graph/static/src/js/graph_view.js b/addons/web_graph/static/src/js/graph_view.js index 4a81ceaa98c..953de133ef9 100644 --- a/addons/web_graph/static/src/js/graph_view.js +++ b/addons/web_graph/static/src/js/graph_view.js @@ -52,24 +52,21 @@ instance.web_graph.GraphView = instance.web.View.extend({ if (_.has(field.attrs, 'interval')) { field_name = field.attrs.name + ':' + field.attrs.interval; } - if (_.has(field.attrs, 'type')) { - switch (field.attrs.type) { - case 'row': - self.widget_config.row_groupby.push(field_name); - break; - case 'col': - self.widget_config.col_groupby.push(field_name); - break; - case 'measure': - self.widget_config.measures.push(field_name); - break; - } - } else { // old style, kept for backward compatibility + //noinspection FallThroughInSwitchStatementJS + switch (field.attrs.type) { + case 'measure': + self.widget_config.measures.push(field_name); + break; + case 'col': + self.widget_config.col_groupby.push(field_name); + break; + default: if ('operator' in field.attrs) { self.widget_config.measures.push(field_name); - } else { - self.widget_config.row_groupby.push(field_name); + break; } + case 'row': + self.widget_config.row_groupby.push(field_name); } }); if (self.widget_config.measures.length === 0) { -- cgit v1.2.3