summaryrefslogtreecommitdiff
path: root/addons/web_graph/static/src
diff options
context:
space:
mode:
authorGery Debongnie <ged@openerp.com>2014-04-10 16:24:19 +0200
committerGery Debongnie <ged@openerp.com>2014-04-10 16:24:19 +0200
commit60f74ff3f4c7bb1e5208b0f4be3ef2577a5645f4 (patch)
tree9b20283e49f31331284eb452995b65827a5ecf84 /addons/web_graph/static/src
parentd67e63150e5f6652b457201e7933164719f2c03f (diff)
parente52841aab3be99887ea28827bf35a9ea5298dcff (diff)
[MERGE] this commit contains a fix for a crash when the graph view does not have any data (wrong check for 0 data) and a quite good optimization of the javascript code in graph view when loading large tables. (addon graph view)
bzr revid: ged@openerp.com-20140410142419-vphlbb2diw21jih3
Diffstat (limited to 'addons/web_graph/static/src')
-rw-r--r--addons/web_graph/static/src/js/graph_widget.js17
-rw-r--r--addons/web_graph/static/src/js/pivot_table.js35
2 files changed, 41 insertions, 11 deletions
diff --git a/addons/web_graph/static/src/js/graph_widget.js b/addons/web_graph/static/src/js/graph_widget.js
index 3d8d8fa2d98..317ea6cbfb9 100644
--- a/addons/web_graph/static/src/js/graph_widget.js
+++ b/addons/web_graph/static/src/js/graph_widget.js
@@ -453,12 +453,25 @@ openerp.web_graph.Graph = openerp.web.Widget.extend({
build_rows: function (raw) {
var self = this,
pivot = this.pivot,
- m, cell;
+ m, i, cell;
return _.map(pivot.rows.headers, function (row) {
var cells = [];
+ var pivot_cells = [];
+ for (i = 0; i < pivot.cells.length; i++) {
+ if (pivot.cells[i].x == row.id || pivot.cells[i].y == row.id) {
+ pivot_cells.push(pivot.cells[i]);
+ }
+ }
_.each(pivot.get_cols_leaves(), function (col) {
- var values = pivot.get_values(row.id,col.id);
+ var values;
+ for (i = 0; i < pivot_cells.length; i++) {
+ if (pivot_cells[i].x == col.id || pivot_cells[i].y == col.id) {
+ values = pivot_cells[i].values;
+ break;
+ }
+ }
+ if (!values) { values = new Array(pivot.measures.length);}
for (m = 0; m < pivot.measures.length; m++) {
cells.push(self.make_cell(row,col,values[m], m, raw));
}
diff --git a/addons/web_graph/static/src/js/pivot_table.js b/addons/web_graph/static/src/js/pivot_table.js
index d0867ca6d1a..6b12829982e 100644
--- a/addons/web_graph/static/src/js/pivot_table.js
+++ b/addons/web_graph/static/src/js/pivot_table.js
@@ -81,10 +81,15 @@ openerp.web_graph.PivotTable = openerp.web.Class.extend({
},
get_values: function (id1, id2, default_values) {
- var cell = _.findWhere(this.cells, {x: Math.min(id1, id2), y: Math.max(id1, id2)});
- return (cell !== undefined) ?
- cell.values :
- (default_values || new Array(this.measures.length));
+ var cells = this.cells,
+ x = Math.min(id1, id2),
+ y = Math.max(id1, id2);
+ for (var i = 0; i < cells.length; i++) {
+ if (cells[i].x == x && cells[i].y == y) {
+ return cells[i].values;
+ }
+ }
+ return (default_values || new Array(this.measures.length));
},
// ----------------------------------------------------------------------
@@ -248,7 +253,7 @@ openerp.web_graph.PivotTable = openerp.web.Class.extend({
var self = this;
return this.perform_requests().then (function () {
var data = Array.prototype.slice.call(arguments);
- self.no_data = !data[0][0].attributes.length;
+ self.no_data = !data[0].length;
if (self.no_data) {
return;
}
@@ -276,7 +281,7 @@ openerp.web_graph.PivotTable = openerp.web.Class.extend({
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 _.isEqual(col_value, hdr.path);})) {
+ if (expand && !_.find(col_headers, function (hdr) {return self.isEqual(col_value, hdr.path);})) {
return;
}
var row = self.find_or_create_header(row_headers, row_value, data_pt);
@@ -306,8 +311,9 @@ openerp.web_graph.PivotTable = openerp.web.Class.extend({
},
find_or_create_header: function (headers, path, data_pt) {
+ var self = this;
var hdr = _.find(headers, function (header) {
- return _.isEqual(path, header.path);
+ return self.isEqual(path, header.path);
});
if (hdr) {
return hdr;
@@ -323,7 +329,7 @@ openerp.web_graph.PivotTable = openerp.web.Class.extend({
title: _t(_.last(path))
});
var parent = _.find(headers, function (header) {
- return _.isEqual(header.path, _.initial(path, 1));
+ return self.isEqual(header.path, _.initial(path, 1));
});
var previous = parent.children.length ? _.last(parent.children) : parent;
@@ -355,10 +361,11 @@ openerp.web_graph.PivotTable = openerp.web.Class.extend({
// set the 'expanded' status of new_headers more or less like root.headers, with root as root
set_headers: function(new_headers, root) {
+ var self = this;
if (root.headers) {
_.each(root.headers, function (header) {
var corresponding_header = _.find(new_headers, function (h) {
- return _.isEqual(h.path, header.path);
+ return self.isEqual(h.path, header.path);
});
if (corresponding_header && header.expanded) {
corresponding_header.expanded = true;
@@ -426,6 +433,16 @@ openerp.web_graph.PivotTable = openerp.web.Class.extend({
return field.split(':')[0];
},
+ 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;
+ }
+ }
+ return true;
+ },
+
});
})();