[IMP] work in progress. goal is to allow expansion of rows/cols in pivottable (addon web_graph)

bzr revid: ged@openerp.com-20131113154731-lmhcyajqcf2k4bxt
This commit is contained in:
Gery Debongnie 2013-11-13 16:47:31 +01:00
parent cecac9a32a
commit 26e6a496be
1 changed files with 75 additions and 22 deletions

View File

@ -41,29 +41,62 @@ instance.web_graph.GraphView = instance.web.View.extend({
view_loading: function (fields_view_get) {
var self = this;
var model = new instance.web.Model(fields_view_get.model, {group_by_no_leaf: true});
var measure = null;
this.groupbys = [];
var options = {};
options.domain = [];
options.col_groupby = [];
// get the default groupbys and measure defined in the field view
options.measure = null;
options.row_groupby = [];
_.each(fields_view_get.arch.children, function (field) {
if ('name' in field.attrs) {
if ('operator' in field.attrs) {
measure = field.attrs.name;
options.measure = field.attrs.name;
} else {
self.groupbys.push(field.attrs.name);
options.row_groupby.push(field.attrs.name);
}
}
});
return model.call('fields_get', []).then(function (fields) {
self.pivot_table = new PivotTable(model, fields, [], self.groupbys, [], measure);
self.chart_view = new ChartView(model, fields, [], self.groupbys, [], measure);
return self.pivot_table.appendTo('.graph_main_content');
}).then(function() {
return self.chart_view.appendTo('.graph_main_content');
// get the most important fields (of the model) by looking at the
// groupby filters defined in the search view
options.important_fields = []
var load_view = instance.web.fields_view_get({
model: model,
view_type: 'search',
});
var important_fields_def = $.when(load_view).then(function (search_view) {
var groups = _.select(search_view.arch.children, function (c) {
return (c.tag == 'group') && (c.attrs.string != 'Display');
});
_.each(groups, function(g) {
_.each(g.children, function (g) {
if (g.attrs.context) {
var field_id = py.eval(g.attrs.context).group_by;
options.important_fields.push(field_id);
}
});
});
}).then
// get the fields descriptions from the model
var field_descr_def = model.call('fields_get', [])
.then(function (fields) { options.fields = fields; });
return $.when(important_fields_def, field_descr_def)
.then(function () {
self.pivot_table = new PivotTable(model, options);
self.chart_view = new ChartView(model, options);
})
.then(function () {
return self.pivot_table.appendTo('.graph_main_content')
})
.then(function() {
return self.chart_view.appendTo('.graph_main_content');
});
},
display_data : function () {
@ -107,16 +140,17 @@ var BasicDataView = instance.web.Widget.extend({
// col_groupby: idem, but on col
// measure: quantity to display. either a field from the model, or
// null, in which case we use the "count" measure
init: function (model, fields, domain, row_groupby, col_groupby, measure) {
init: function (model, options) {
this.model = model;
this.fields = fields;
this.domain = domain;
this.row_groupby = row_groupby;
this.col_groupby = col_groupby;
this.measure = measure;
this.measure_label = measure ? fields[measure].string : 'Quantity';
this.fields = options.fields;
this.domain = options.domain;
this.row_groupby = options.row_groupby;
this.col_groupby = options.col_groupby;
this.measure = options.measure;
this.measure_label = options.measure ? options.fields[options.measure].string : 'Quantity';
this.data = [];
this.need_redraw = true;
this.important_fields = options.important_fields;
},
set_domain: function (domain) {
@ -169,6 +203,20 @@ var PivotTable = BasicDataView.extend({
template: 'pivot_table',
rows: null,
cols: null,
current_row_id : 0,
events: {
'click .graph_border a' : function (event) {
event.preventDefault();
var row_id = event.target.attributes['data-row-id'].nodeValue;
console.log("clickclick on row ", row_id);
},
},
generate_id: function () {
this.current_row_id += 1;
return this.current_row_id - 1;
},
draw: function () {
this.get_data(this.row_groupby)
@ -196,19 +244,24 @@ var PivotTable = BasicDataView.extend({
}];
this.rows = _.map(data, function (datapt) {
var row = $('<tr></tr>');
row.html(make_cell(datapt.attributes.value[1], true));
row.append(make_cell(datapt.attributes.aggregates[self.measure]));
var jquery_row = $('<tr></tr>');
var header = $(make_cell(datapt.attributes.value[1], true));
var row_id = self.generate_id();
return {
header.prepend('<a data-row-id="'+ row_id + '" href="#">+ </a>');
jquery_row.html(header);
jquery_row.append(make_cell(datapt.attributes.aggregates[self.measure]));
var row = {
path: [datapt.attributes.grouped_on],
value: datapt.attributes.value[1],
expanded: false,
parent: null,
children: [],
html_tr: row,
html_tr: jquery_row,
domain: datapt.model._domain
};
return row;
});
},