summaryrefslogtreecommitdiff
path: root/addons/web_graph/static
diff options
context:
space:
mode:
authorChristophe Simonis <chs@odoo.com>2014-09-05 15:28:22 +0200
committerChristophe Simonis <chs@odoo.com>2014-09-05 15:28:22 +0200
commit31bf30d2d0eb78baaa36360b99fe58bf7cd4c9e7 (patch)
treed7be61ecd6bb4c8b5552e39b03e2a64eebbbf323 /addons/web_graph/static
parentafba9e8817c458640ae446ac7aaaab79be4fe1e9 (diff)
parented1c173971968eaa96693cb4e1547efa6e6c34e0 (diff)
[MERGE] forward port of branch 8.0 up to ed1c173
Diffstat (limited to 'addons/web_graph/static')
-rw-r--r--addons/web_graph/static/src/js/graph_view.js61
-rw-r--r--addons/web_graph/static/src/js/graph_widget.js38
-rw-r--r--addons/web_graph/static/src/js/pivot_table.js41
3 files changed, 79 insertions, 61 deletions
diff --git a/addons/web_graph/static/src/js/graph_view.js b/addons/web_graph/static/src/js/graph_view.js
index e4e074b2e7f..953de133ef9 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 () {},
};
@@ -51,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) {
@@ -83,7 +81,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 +91,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 +118,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 +130,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 +152,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 +235,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..f0e07e06e6a 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
// ----------------------------------------------------------------------
@@ -340,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) {
@@ -627,7 +638,6 @@ openerp.web_graph.Graph = openerp.web.Widget.extend({
},
draw_measure_row: function (measure_row) {
- if (this.pivot.measures.length === 1) { return; }
var $row = $('<tr>').append('<th>');
_.each(measure_row, function (cell) {
var $cell = $('<th>').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 48ae9ec3830..b66bc41e98c 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) {
@@ -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();
},
@@ -80,7 +84,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 +107,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 +154,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 +185,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 +259,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 +293,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;
}
@@ -423,10 +427,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 (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];
});
@@ -445,8 +454,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;
@@ -455,5 +464,3 @@ openerp.web_graph.PivotTable = openerp.web.Class.extend({
});
})();
-
-