[IMP] adds support for multiple measures in graph view (addon web_graph)
bzr revid: ged@openerp.com-20131128082754-4l7nx8ooye1pmc53
This commit is contained in:
parent
0d47d906fd
commit
51e4b240f8
|
@ -31,6 +31,13 @@ instance.web_graph.GraphView = instance.web.View.extend({
|
|||
this.display_data();
|
||||
},
|
||||
|
||||
'click .graph_measure_selection li' : function (event) {
|
||||
event.preventDefault();
|
||||
var measure = event.target.attributes['data-choice'].nodeValue;
|
||||
this.pivot_table.set_measure(measure)
|
||||
.then(this.proxy('display_data'));
|
||||
},
|
||||
|
||||
'click .graph_expand_selection li' : function (event) {
|
||||
event.preventDefault();
|
||||
switch (event.target.attributes['data-choice'].nodeValue) {
|
||||
|
@ -92,23 +99,35 @@ instance.web_graph.GraphView = instance.web.View.extend({
|
|||
this.pivot_table = null;
|
||||
this.heat_map_mode = false;
|
||||
this.mode = 'pivot';
|
||||
this.measure_list = [];
|
||||
this.important_fields = [];
|
||||
},
|
||||
|
||||
start: function () {
|
||||
this.table = $('<table></table>');
|
||||
this.$('.graph_main_content').append(this.table);
|
||||
instance.web.bus.on('click', this, function (ev) {
|
||||
if (this.dropdown) {
|
||||
this.dropdown.remove();
|
||||
this.dropdown = null;
|
||||
}
|
||||
});
|
||||
|
||||
return this.load_view();
|
||||
},
|
||||
|
||||
view_loading: function (fields_view_get) {
|
||||
var self = this,
|
||||
model = new instance.web.Model(fields_view_get.model, {group_by_no_leaf: true}),
|
||||
domain = [],
|
||||
measure = null,
|
||||
fields,
|
||||
important_fields = [],
|
||||
row_groupby = [];
|
||||
|
||||
|
||||
// get the default groupbys and measure defined in the field view
|
||||
_.each(fields_view_get.arch.children, function (field) {
|
||||
if ('name' in field.attrs) {
|
||||
if ('operator' in field.attrs) {
|
||||
measure = field.attrs.name;
|
||||
self.measure_list.push(field.attrs.name);
|
||||
} else {
|
||||
row_groupby.push(field.attrs.name);
|
||||
}
|
||||
|
@ -130,7 +149,7 @@ instance.web_graph.GraphView = instance.web.View.extend({
|
|||
_.each(g.children, function (g) {
|
||||
if (g.attrs.context) {
|
||||
var field_id = py.eval(g.attrs.context).group_by;
|
||||
important_fields.push(field_id);
|
||||
self.important_fields.push(field_id);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
@ -146,27 +165,21 @@ instance.web_graph.GraphView = instance.web.View.extend({
|
|||
model: model,
|
||||
domain: domain,
|
||||
fields: fields,
|
||||
important_fields: important_fields,
|
||||
measure: measure,
|
||||
measure_label: fields[measure].string,
|
||||
measure: self.measure_list[0],
|
||||
measure_label: fields[self.measure_list[0]].string,
|
||||
col_groupby: [],
|
||||
row_groupby: row_groupby,
|
||||
groups: [],
|
||||
total: null,
|
||||
};
|
||||
});
|
||||
},
|
||||
var measure_selection = self.$('.graph_measure_selection');
|
||||
_.each(self.measure_list, function (measure) {
|
||||
var choice = $('<a></a>').attr('data-choice', measure)
|
||||
.attr('href', '#')
|
||||
.append(fields[measure].string);
|
||||
measure_selection.append($('<li></li>').append(choice));
|
||||
|
||||
start: function () {
|
||||
this.table = $('<table></table>');
|
||||
this.$('.graph_main_content').append(this.table);
|
||||
instance.web.bus.on('click', this, function (ev) {
|
||||
if (this.dropdown) {
|
||||
this.dropdown.remove();
|
||||
this.dropdown = null;
|
||||
}
|
||||
});
|
||||
return this.load_view();
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
do_search: function (domain, context, group_by) {
|
||||
|
@ -233,7 +246,7 @@ instance.web_graph.GraphView = instance.web.View.extend({
|
|||
var self = this,
|
||||
pivot = this.pivot_table,
|
||||
already_grouped = pivot.rows.groupby.concat(pivot.cols.groupby),
|
||||
possible_groups = _.difference(self.data.important_fields, already_grouped),
|
||||
possible_groups = _.difference(self.important_fields, already_grouped),
|
||||
dropdown_options = {
|
||||
header_id: options.id,
|
||||
fields: _.map(possible_groups, function (field) {
|
||||
|
|
|
@ -28,7 +28,11 @@ openerp.web_graph.PivotTable = openerp.web.Class.extend({
|
|||
},
|
||||
|
||||
visible_fields: function () {
|
||||
return this.rows.groupby.concat(this.cols.groupby, this.measure);
|
||||
var result = this.rows.groupby.concat(this.cols.groupby);
|
||||
if (this.measure) {
|
||||
result = result.concat(this.measure);
|
||||
}
|
||||
return result;
|
||||
},
|
||||
|
||||
set_value: function (id1, id2, value) {
|
||||
|
@ -53,6 +57,11 @@ openerp.web_graph.PivotTable = openerp.web.Class.extend({
|
|||
return (cell === undefined) ? undefined : cell.value;
|
||||
},
|
||||
|
||||
set_measure: function (measure) {
|
||||
this.measure = (measure === '__count') ? null : measure;
|
||||
return this.update_values();
|
||||
},
|
||||
|
||||
get_header: function (id) {
|
||||
return _.find(this.rows.headers.concat(this.cols.headers), function (header) {
|
||||
return header.id == id;
|
||||
|
@ -101,7 +110,11 @@ openerp.web_graph.PivotTable = openerp.web.Class.extend({
|
|||
}
|
||||
});
|
||||
if (other) {
|
||||
self.set_value(new_header_id, other.id, data.attributes.aggregates[self.measure]);
|
||||
if (self.measure) {
|
||||
self.set_value(new_header_id, other.id, data.attributes.aggregates[self.measure]);
|
||||
} else {
|
||||
self.set_value(new_header_id, other.id, data.attributes.length);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
@ -333,14 +346,17 @@ openerp.web_graph.PivotTable = openerp.web.Class.extend({
|
|||
function make_headers (data, depth) {
|
||||
var main = {
|
||||
id: self.generate_id(),
|
||||
count: total.attributes.length,
|
||||
total: total.attributes.aggregates[self.measure],
|
||||
path: [],
|
||||
parent: null,
|
||||
children: [],
|
||||
title: '',
|
||||
domain: self.domain,
|
||||
};
|
||||
if (self.measure) {
|
||||
main.total = total.attributes.aggregates[self.measure];
|
||||
} else {
|
||||
main.total = total.attributes.length;
|
||||
}
|
||||
|
||||
if (depth > 0) {
|
||||
main.children = _.map(data, function (data_pt) {
|
||||
|
@ -361,7 +377,6 @@ openerp.web_graph.PivotTable = openerp.web.Class.extend({
|
|||
function make_tree_headers (data_pt, parent, max_depth) {
|
||||
var node = {
|
||||
id: self.generate_id(),
|
||||
count: data_pt.attributes.length,
|
||||
total: data_pt.attributes.aggregates[self.measure],
|
||||
path: parent.path.concat(data_pt.attributes.value[1]),
|
||||
title: data_pt.attributes.value[1],
|
||||
|
@ -369,6 +384,12 @@ openerp.web_graph.PivotTable = openerp.web.Class.extend({
|
|||
parent: parent,
|
||||
children: [],
|
||||
};
|
||||
if (self.measure) {
|
||||
node.total = data_pt.attributes.aggregates[self.measure];
|
||||
} else {
|
||||
node.total = data_pt.attributes.length;
|
||||
}
|
||||
|
||||
if (node.path.length < max_depth) {
|
||||
node.children = _.map(data_pt.subgroups_data, function (child) {
|
||||
return make_tree_headers (child, node, max_depth);
|
||||
|
@ -381,7 +402,13 @@ openerp.web_graph.PivotTable = openerp.web.Class.extend({
|
|||
_.each(data, function (group) {
|
||||
var attr = group.attributes,
|
||||
path = current_path,
|
||||
value;
|
||||
|
||||
if (self.measure) {
|
||||
value = attr.aggregates[self.measure];
|
||||
} else {
|
||||
value = attr.length;
|
||||
}
|
||||
|
||||
if (attr.grouped_on !== undefined) {
|
||||
path = path.concat(attr.value[1]);
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
Measure <span class="caret"></span>
|
||||
</label>
|
||||
<ul class="dropdown-menu graph_measure_selection" role="menu">
|
||||
<li><a data-choice="count" href="#">Count</a></li>
|
||||
<li><a data-choice="__count" href="#">Count</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="btn-group">
|
||||
|
|
Loading…
Reference in New Issue