summaryrefslogtreecommitdiff
path: root/addons/web_graph/static/src
diff options
context:
space:
mode:
authorGery Debongnie <ged@openerp.com>2013-11-13 16:47:31 +0100
committerGery Debongnie <ged@openerp.com>2013-11-13 16:47:31 +0100
commit26e6a496bebb3200c58e37b5e5bb7f167e0f3618 (patch)
treecdf77fa901e7e5e2221f93a87ee4ab94aad96fc9 /addons/web_graph/static/src
parentcecac9a32a786a4bdb5d0e0c8a4847738c7ffc00 (diff)
[IMP] work in progress. goal is to allow expansion of rows/cols in pivottable (addon web_graph)
bzr revid: ged@openerp.com-20131113154731-lmhcyajqcf2k4bxt
Diffstat (limited to 'addons/web_graph/static/src')
-rw-r--r--addons/web_graph/static/src/js/graph.js97
1 files changed, 75 insertions, 22 deletions
diff --git a/addons/web_graph/static/src/js/graph.js b/addons/web_graph/static/src/js/graph.js
index f400f76d459..bc1040e9df9 100644
--- a/addons/web_graph/static/src/js/graph.js
+++ b/addons/web_graph/static/src/js/graph.js
@@ -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();
+
+ header.prepend('<a data-row-id="'+ row_id + '" href="#">+ </a>');
+ jquery_row.html(header);
+ jquery_row.append(make_cell(datapt.attributes.aggregates[self.measure]));
- return {
+ 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;
});
},