[IMP] adds some rudimentary support to the integration of search bar groupby into the graph view (addon web_graph)
bzr revid: ged@openerp.com-20131128130146-33i0ydw9gbjqgc0v
This commit is contained in:
parent
2ff2fc4c9e
commit
d41ca29475
|
@ -180,7 +180,11 @@ instance.web_graph.GraphView = instance.web.View.extend({
|
|||
|
||||
do_search: function (domain, context, group_by) {
|
||||
this.pivot_table.domain = domain;
|
||||
this.pivot_table.update_values().done(this.proxy('display_data'));
|
||||
if (group_by.length > 0) {
|
||||
this.pivot_table.set_row_groupby(group_by).done(this.proxy('display_data'));
|
||||
} else {
|
||||
this.pivot_table.update_values().done(this.proxy('display_data'));
|
||||
}
|
||||
},
|
||||
|
||||
do_show: function () {
|
||||
|
|
|
@ -182,6 +182,31 @@ openerp.web_graph.PivotTable = openerp.web.Class.extend({
|
|||
});
|
||||
},
|
||||
|
||||
set_row_groupby: function (groupby) {
|
||||
var self = this;
|
||||
this.rows.groupby = groupby;
|
||||
return this.query_all_values().then(function (result) {
|
||||
if (result) {
|
||||
self.no_data = false;
|
||||
self.rows.headers = result.row_headers;
|
||||
self.cols.headers = self.update_headers(self.cols.headers, result.col_headers);
|
||||
self.cells = result.cells;
|
||||
self.cols.main = self.cols.headers[0];
|
||||
self.rows.main = self.rows.headers[0];
|
||||
_.each(self.rows.headers, function (row) {
|
||||
row.root = self.rows;
|
||||
row.is_expanded = (row.children.length > 0);
|
||||
});
|
||||
_.each(self.cols.headers, function (col) {
|
||||
col.root = self.cols;
|
||||
});
|
||||
|
||||
} else {
|
||||
self.no_data = true;
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
get_total: function (header) {
|
||||
if (header) {
|
||||
var main = (header.root === this.rows) ? this.cols.main : this.rows.main;
|
||||
|
@ -191,6 +216,7 @@ openerp.web_graph.PivotTable = openerp.web.Class.extend({
|
|||
}
|
||||
},
|
||||
|
||||
|
||||
update_values: function () {
|
||||
if (!this.rows.headers) {
|
||||
return this.expand_all();
|
||||
|
@ -201,39 +227,11 @@ openerp.web_graph.PivotTable = openerp.web.Class.extend({
|
|||
return undefined;
|
||||
}
|
||||
self.no_data = false;
|
||||
self.cols.headers = update_headers(self.cols.headers, result.col_headers);
|
||||
self.rows.headers = update_headers(self.rows.headers, result.row_headers);
|
||||
self.cols.headers = self.update_headers(self.cols.headers, result.col_headers);
|
||||
self.rows.headers = self.update_headers(self.rows.headers, result.row_headers);
|
||||
self.cols.main = self.cols.headers[0];
|
||||
self.rows.main = self.rows.headers[0];
|
||||
|
||||
|
||||
function update_headers (old_headers, new_headers) {
|
||||
_.each(old_headers, function (header) {
|
||||
var corresponding_header = _.find(new_headers, function (h) {
|
||||
return _.isEqual(h.path, header.path);
|
||||
});
|
||||
if (corresponding_header && (header.is_expanded)) {
|
||||
corresponding_header.is_expanded = true;
|
||||
_.each(corresponding_header.children, function (c) {
|
||||
c.is_expanded = false;
|
||||
});
|
||||
}
|
||||
if (corresponding_header && (!header.is_expanded)) {
|
||||
corresponding_header.is_expanded = false;
|
||||
}
|
||||
});
|
||||
var updated_headers = _.filter(new_headers, function (header) {
|
||||
return (header.is_expanded !== undefined);
|
||||
});
|
||||
_.each(updated_headers, function (hdr) {
|
||||
if (!hdr.is_expanded) {
|
||||
hdr.children = [];
|
||||
}
|
||||
});
|
||||
|
||||
return updated_headers;
|
||||
}
|
||||
|
||||
_.each(self.rows.headers, function (row) {
|
||||
row.root = self.rows;
|
||||
});
|
||||
|
@ -244,6 +242,32 @@ openerp.web_graph.PivotTable = openerp.web.Class.extend({
|
|||
});
|
||||
},
|
||||
|
||||
update_headers: function (old_headers, new_headers) {
|
||||
_.each(old_headers, function (header) {
|
||||
var corresponding_header = _.find(new_headers, function (h) {
|
||||
return _.isEqual(h.path, header.path);
|
||||
});
|
||||
if (corresponding_header && (header.is_expanded)) {
|
||||
corresponding_header.is_expanded = true;
|
||||
_.each(corresponding_header.children, function (c) {
|
||||
c.is_expanded = false;
|
||||
});
|
||||
}
|
||||
if (corresponding_header && (!header.is_expanded)) {
|
||||
corresponding_header.is_expanded = false;
|
||||
}
|
||||
});
|
||||
var updated_headers = _.filter(new_headers, function (header) {
|
||||
return (header.is_expanded !== undefined);
|
||||
});
|
||||
_.each(updated_headers, function (hdr) {
|
||||
if (!hdr.is_expanded) {
|
||||
hdr.children = [];
|
||||
}
|
||||
});
|
||||
return updated_headers;
|
||||
},
|
||||
|
||||
// this method is a little tricky. In order to obtain all the values
|
||||
// required to draw the full table, we have to do at least
|
||||
// 2 + min(row.groupby.length, col.groupby.length)
|
||||
|
|
Loading…
Reference in New Issue