[IMP] Graph views: show always measure + filters record measures in context
This commit is contained in:
parent
4c6dcd7fcb
commit
8307a5f6ed
|
@ -26,7 +26,8 @@ instance.web_graph.GraphView = instance.web.View.extend({
|
|||
this.model = new instance.web.Model(dataset.model, {group_by_no_leaf: true});
|
||||
this.search_view = parent.searchview;
|
||||
this.col_search_field = {
|
||||
get_context: function() { return { col_group_by: self.graph_widget.get_col_groupbys()};},
|
||||
get_context: function() { return { col_group_by: self.graph_widget.get_col_groupbys(),
|
||||
measures: self.graph_widget.get_current_measures()};},
|
||||
get_domain: function () {},
|
||||
get_groupby: function () {},
|
||||
};
|
||||
|
@ -83,7 +84,8 @@ instance.web_graph.GraphView = instance.web.View.extend({
|
|||
}
|
||||
var self = this,
|
||||
groupbys = this.get_groupbys_from_searchview(),
|
||||
col_group_by = groupbys.col_group_by;
|
||||
col_group_by = groupbys.col_group_by,
|
||||
measures = groupbys.measures;
|
||||
|
||||
if (!this.graph_widget) {
|
||||
if (group_by.length) {
|
||||
|
@ -92,22 +94,25 @@ instance.web_graph.GraphView = instance.web.View.extend({
|
|||
if (col_group_by.length) {
|
||||
this.widget_config.col_groupby = col_group_by;
|
||||
}
|
||||
if (measures.length) {
|
||||
this.widget_config.measures = measures;
|
||||
}
|
||||
this.graph_widget = new openerp.web_graph.Graph(this, this.model, domain, this.widget_config);
|
||||
this.graph_widget.appendTo(this.$el);
|
||||
this.ViewManager.on('switch_mode', this, function (e) {
|
||||
if (e === 'graph') {
|
||||
var group_bys = self.get_groupbys_from_searchview();
|
||||
this.graph_widget.set(domain, group_bys.group_by, group_bys.col_group_by);
|
||||
this.graph_widget.set(domain, group_bys.group_by, group_bys.col_group_by, group_bys.measures);
|
||||
}
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
this.graph_widget.set(domain, group_by, col_group_by);
|
||||
this.graph_widget.set(domain, group_by, col_group_by, measures);
|
||||
},
|
||||
|
||||
get_groupbys_from_searchview: function () {
|
||||
var result = { group_by: [], col_group_by: []},
|
||||
var result = { group_by: [], col_group_by: [], measures: []},
|
||||
searchdata = this.search_view.build_search_data();
|
||||
|
||||
_.each(searchdata.groupbys, function (data) {
|
||||
|
@ -116,6 +121,9 @@ instance.web_graph.GraphView = instance.web.View.extend({
|
|||
if (data.col_group_by) {
|
||||
result.col_group_by = result.col_group_by.concat(data.col_group_by);
|
||||
}
|
||||
if (data.measures) {
|
||||
result.measures = result.measures.concat(data.measures);
|
||||
}
|
||||
});
|
||||
|
||||
if (result.col_group_by.length) {
|
||||
|
@ -125,6 +133,9 @@ instance.web_graph.GraphView = instance.web.View.extend({
|
|||
if (context.col_group_by) {
|
||||
result.col_group_by = result.col_group_by.concat(context.col_group_by);
|
||||
}
|
||||
if (context.measures) {
|
||||
result.measures = result.measures.concat(context.measures);
|
||||
}
|
||||
});
|
||||
return result;
|
||||
},
|
||||
|
@ -144,9 +155,10 @@ instance.web_graph.GraphView = instance.web.View.extend({
|
|||
groupbys = this.get_groupbys_from_searchview(),
|
||||
search_row_groupby = groupbys.group_by,
|
||||
search_col_groupby = groupbys.col_group_by,
|
||||
search_measures = groupbys.measures,
|
||||
row_gb_changed = !_.isEqual(_.pluck(row_groupby, 'field'), search_row_groupby),
|
||||
col_gb_changed = !_.isEqual(_.pluck(col_groupby, 'field'), search_col_groupby);
|
||||
|
||||
col_gb_changed = !_.isEqual(_.pluck(col_groupby, 'field'), search_col_groupby),
|
||||
measures_gb_changed = !_.isEqual(_.pluck(col_groupby, 'field'), search_col_groupby);
|
||||
if (!_.has(this.search_view, '_s_groupby')) { return; }
|
||||
|
||||
if (!row_gb_changed && !col_gb_changed) {
|
||||
|
@ -226,11 +238,3 @@ instance.web_graph.GraphView = instance.web.View.extend({
|
|||
},
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -153,41 +153,49 @@ openerp.web_graph.Graph = openerp.web.Widget.extend({
|
|||
// ----------------------------------------------------------------------
|
||||
// Configuration methods
|
||||
// ----------------------------------------------------------------------
|
||||
set: function (domain, row_groupby, col_groupby) {
|
||||
set: function (domain, row_groupby, col_groupby, measures_groupby) {
|
||||
if (!this.pivot) {
|
||||
this.pivot_options.domain = domain;
|
||||
this.pivot_options.row_groupby = row_groupby;
|
||||
this.pivot_options.col_groupby = col_groupby;
|
||||
this.pivot_options.measures_groupby = measures_groupby;
|
||||
return;
|
||||
}
|
||||
var row_gbs = this.create_field_values(row_groupby),
|
||||
col_gbs = this.create_field_values(col_groupby),
|
||||
measures_gbs = this.create_field_values(measures_groupby),
|
||||
dom_changed = !_.isEqual(this.pivot.domain, domain),
|
||||
row_gb_changed = !_.isEqual(row_gbs, this.pivot.rows.groupby),
|
||||
col_gb_changed = !_.isEqual(col_gbs, this.pivot.cols.groupby),
|
||||
measures_gb_changed = !_.isEqual(measures_gbs, this.pivot.measures),
|
||||
row_reduced = is_strict_beginning_of(row_gbs, this.pivot.rows.groupby),
|
||||
col_reduced = is_strict_beginning_of(col_gbs, this.pivot.cols.groupby);
|
||||
col_reduced = is_strict_beginning_of(col_gbs, this.pivot.cols.groupby),
|
||||
measures_reduced = is_strict_beginning_of(measures_gbs, this.pivot.measures);
|
||||
|
||||
if (!dom_changed && row_reduced && !col_gb_changed) {
|
||||
if (!dom_changed && row_reduced && !col_gb_changed && !measures_gb_changed) {
|
||||
this.pivot.fold_with_depth(this.pivot.rows, row_gbs.length);
|
||||
this.display_data();
|
||||
return;
|
||||
}
|
||||
if (!dom_changed && col_reduced && !row_gb_changed) {
|
||||
if (!dom_changed && col_reduced && !row_gb_changed && !measures_gb_changed) {
|
||||
this.pivot.fold_with_depth(this.pivot.cols, col_gbs.length);
|
||||
this.display_data();
|
||||
return;
|
||||
}
|
||||
|
||||
if (!dom_changed && col_reduced && row_reduced) {
|
||||
if (!dom_changed && col_reduced && row_reduced && !measures_gb_changed) {
|
||||
this.pivot.fold_with_depth(this.pivot.rows, row_gbs.length);
|
||||
this.pivot.fold_with_depth(this.pivot.cols, col_gbs.length);
|
||||
this.display_data();
|
||||
return;
|
||||
}
|
||||
|
||||
if (dom_changed || row_gb_changed || col_gb_changed) {
|
||||
this.pivot.set(domain, row_gbs, col_gbs).then(this.proxy('display_data'));
|
||||
if (dom_changed || row_gb_changed || col_gb_changed || measures_gb_changed) {
|
||||
this.pivot.set(domain, row_gbs, col_gbs, measures_gbs).then(this.proxy('display_data'));
|
||||
}
|
||||
|
||||
if (measures_gb_changed) {
|
||||
this.put_measure_checkmarks();
|
||||
}
|
||||
},
|
||||
|
||||
|
@ -235,6 +243,10 @@ openerp.web_graph.Graph = openerp.web.Widget.extend({
|
|||
return _.pluck(this.pivot.cols.groupby, 'field');
|
||||
},
|
||||
|
||||
get_current_measures: function () {
|
||||
return _.pluck(this.pivot.measures, 'field');
|
||||
},
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// UI code
|
||||
// ----------------------------------------------------------------------
|
||||
|
@ -627,7 +639,6 @@ openerp.web_graph.Graph = openerp.web.Widget.extend({
|
|||
},
|
||||
|
||||
draw_measure_row: function (measure_row) {
|
||||
if (this.pivot.measures.length === 1) { return; }
|
||||
var $row = $('<tr>').append('<th>');
|
||||
_.each(measure_row, function (cell) {
|
||||
var $cell = $('<th>').addClass('measure_row').text(cell.text);
|
||||
|
|
|
@ -55,23 +55,27 @@ openerp.web_graph.PivotTable = openerp.web.Class.extend({
|
|||
}
|
||||
},
|
||||
|
||||
set: function (domain, row_groupby, col_groupby) {
|
||||
set: function (domain, row_groupby, col_groupby, measures_groupby) {
|
||||
var self = this;
|
||||
if (this.updating) {
|
||||
return this.updating.then(function () {
|
||||
self.updating = false;
|
||||
return self.set(domain, row_groupby,col_groupby);
|
||||
return self.set(domain, row_groupby, col_groupby, measures_groupby);
|
||||
});
|
||||
}
|
||||
var row_gb_changed = !_.isEqual(row_groupby, this.rows.groupby),
|
||||
col_gb_changed = !_.isEqual(col_groupby, this.cols.groupby);
|
||||
col_gb_changed = !_.isEqual(col_groupby, this.cols.groupby),
|
||||
measures_gb_changed = !_.isEqual(measures_groupby, this.measures);
|
||||
|
||||
this.domain = domain;
|
||||
this.rows.groupby = row_groupby;
|
||||
this.cols.groupby = col_groupby;
|
||||
|
||||
if (measures_groupby.length) { this.measures = measures_groupby; }
|
||||
|
||||
if (row_gb_changed) { this.rows.headers = null; }
|
||||
if (col_gb_changed) { this.cols.headers = null; }
|
||||
if (measures_gb_changed && measures_groupby.length) { this.set_measures(measures_groupby); }
|
||||
|
||||
return this.update_data();
|
||||
},
|
||||
|
@ -460,5 +464,3 @@ openerp.web_graph.PivotTable = openerp.web.Class.extend({
|
|||
});
|
||||
|
||||
})();
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue