[IMP] preliminary work on supporting col expansion in pivottable widget (addon web_graph)

bzr revid: ged@openerp.com-20131119132024-k67wlje2h14p5ptu
This commit is contained in:
Gery Debongnie 2013-11-19 14:20:24 +01:00
parent 40ededd540
commit 3ce4ec44d9
3 changed files with 90 additions and 11 deletions

View File

@ -16,13 +16,13 @@ span.field-selection {
}
span.web_graph_indent {
padding-left: 50px;
padding-left: 30px;
}
span.web_graph_indent:first-child {
/*span.web_graph_indent:first-child {
padding-left: 25px;
}
*/
.web_graph_click:hover {
cursor: pointer;
}

View File

@ -279,11 +279,11 @@ var PivotTable = instance.web.Widget.extend({
var self = this;
var col_id = this.generate_id();
var col_header = this.make_cell(this.data.measure_label,
{is_border:true, foldable: true, col_id:col_id});
var header = $('<tr></tr>');
header.append(this.make_cell(' ', {is_border:true}));
header.append(this.make_cell(this.data.measure_label,
{is_border:true, foldable: true, col_id:col_id}));
header.append(col_header);
this.headers = [header];
this.cols= [{
@ -295,6 +295,7 @@ var PivotTable = instance.web.Widget.extend({
children: [],
cells: [], // a cell is {td:<jquery td>, row_id:<some id>}
domain: this.data.domain,
header: col_header
}];
var main_row = this.make_row(this.data.total[0]);
@ -324,7 +325,7 @@ var PivotTable = instance.web.Widget.extend({
if (has_parent) {
parent = this.get_row(parent_id);
path = parent.path.concat(group.attributes.grouped_on);
path = parent.path.concat(group.attributes.value[1]);
value = group.attributes.value[1];
expanded = false;
parent.children.push(row_id);
@ -418,9 +419,9 @@ var PivotTable = instance.web.Widget.extend({
var visible_fields = this.data.row_groupby.concat(this.data.col_groupby, this.data.measure);
query_groups(this.data.model, visible_fields, row.domain, [field_id])
.then(function (data) {
_.each(data.reverse(), function (datapt) {
var new_row = self.make_row(datapt, row_id);
.then(function (groups) {
_.each(groups.reverse(), function (group) {
var new_row = self.make_row(group, row_id);
row.html.after(new_row.html);
});
});
@ -428,7 +429,69 @@ var PivotTable = instance.web.Widget.extend({
},
expand_col: function (col_id, field_id) {
console.log("expandidng col",col_id, field_id);
var self = this;
var col = this.get_col(col_id);
console.log("expanding col",col);
if (col.path.length == this.data.col_groupby.length) {
this.data.col_groupby.push(field_id);
}
col.expanded = true;
col.header.find('.icon-plus-sign')
.removeClass('icon-plus-sign')
.addClass('icon-minus-sign');
var visible_fields = this.data.row_groupby.concat(this.data.col_groupby, this.data.measure);
query_groups_data(this.data.model, visible_fields, col.domain, this.data.row_groupby, field_id)
.then(function (groups) {
console.log("inserting groups",groups);
console.log("this.rows",self.rows);
console.log("this.cols",self.cols);
_.each(groups, function (group) {
var new_col = {
id: self.generate_id(),
path: col.path.concat(field_id),
value: group[0].attributes.value[1],
expanded: false,
parent: col_id,
children: [],
cells: [], // a cell is {td:<jquery td>, row_id:<some id>}
domain: group[0].model._domain,
// header: col_header
};
col.header.css('display','none');
col.children.push(new_col.id);
self.cols.push(new_col);
_.each(col.cells, function (cell) {
var col_path = self.get_row(cell.row_id).path;
var datapt = _.find(group, function (g) {
return _.isEqual(g.path.slice(1), col_path);
});
var value;
if (datapt === undefined) {
value = '';
} else {
value = datapt.attributes.aggregates[self.data.measure];
}
console.log("value", value);
// make new cell
var new_cell = {
row_id: cell.row_id,
td: self.make_cell(value)
};
// add cell to new_col cells ({row_id, td})
new_col.cells.push(new_cell);
// insert new cell (td) after cell.td
cell.td.after(new_cell.td);
cell.td.css('display','none');
});
});
});
},
fold_row: function (row_id) {

View File

@ -36,3 +36,19 @@ function query_groups (model, fields, domain, groupbys) {
});
}
function query_groups_data(model, fields, domain, row_groupbys, col_groupby) {
return query_groups(model, fields, domain, [col_groupby].concat(row_groupbys)).then(function (groups) {
return _.map(groups, function (group) {
return format_group(group, []);
});
});
}
function format_group (group, path) {
group.path = path.concat(group.attributes.value[1]);
result = [group];
_.each(group.subgroups_data, function (subgroup) {
result = result.concat(format_group (subgroup, group.path));
});
return result;
}