[FIX] web: fixes issues with custom filters and search view

The problem was that when the user manipulates the graph view (in pivot
table mode), the graph view resetted the group by facet in the search
view.  It was not a problem unless a custom filter with a groupby was
already there, in which case, the group bys were duplicated.

The search view is now smarter, it only resets the additional groupbys
(and col_groupbys).   Also, to prevent usability problems, the graph
view disable the '+/-' groupbys added by a custom filters.

Note that this fix is only temporary: a revamp of custom filters, facets,
search view is coming in the next months. (at least, that's the idea). Right
now, too much 'search logic' is in the graph view.

Another note: this fix is somewhat fragile: it makes some assumptions
about the search query (mainly that the custom filter is the first facet,
also, that no other filters add groupbys/col_groupbys)
This commit is contained in:
Géry Debongnie 2014-09-09 12:26:16 +02:00 committed by Martin Trigaux
parent ec0b770ed3
commit 22b1f5ce0c
3 changed files with 82 additions and 23 deletions

View File

@ -888,15 +888,9 @@
return new $.Deferred(function (d) {setTimeout(function () {
var result;
try {
var contexts = ([instance.session.user_context] || []).concat(source.contexts);
// see Session.eval_context in Python
result = {
context: instance.web.pyeval.eval('contexts', contexts),
domain: instance.web.pyeval.eval('domains', source.domains),
group_by: instance.web.pyeval.eval('groupbys', source.group_by_seq || [])
};
} catch (e) {
result = instance.web.pyeval.sync_eval_domains_and_contexts(source);
}
catch (e) {
result = { error: {
code: 400,
message: instance.web._t("Evaluation Error"),
@ -906,9 +900,18 @@
instance.web._t("Local evaluation failure\n%s\n\n%s"),
e.message, JSON.stringify(source))
}
}};
}};
}
d.resolve(result);
}, 0); });
};
instance.web.pyeval.sync_eval_domains_and_contexts = function (source) {
var contexts = ([instance.session.user_context] || []).concat(source.contexts);
// see Session.eval_context in Python
return {
context: instance.web.pyeval.eval('contexts', contexts),
domain: instance.web.pyeval.eval('domains', source.domains),
group_by: instance.web.pyeval.eval('groupbys', source.group_by_seq || [])
};
};
})();

View File

@ -162,6 +162,10 @@ instance.web_graph.GraphView = instance.web.View.extend({
return;
}
var custom_groups = this.get_custom_filter_groupbys();
row_groupby = row_groupby.slice(custom_groups.groupby.length);
col_groupby = col_groupby.slice(custom_groups.col_groupby.length);
if (row_gb_changed && col_gb_changed) {
// when two changes to the search view will be done, the method do_search
// will be called twice, once with the correct groupby and incorrect col_groupby,
@ -233,5 +237,46 @@ instance.web_graph.GraphView = instance.web.View.extend({
};
});
},
get_custom_filter_groupbys: function () {
var gb = [],
col_gb = [];
var facet = this.search_view.query.at(0);
if (facet) {
if (facet.get('category') !== 'GroupBy' && facet.get('category') !== 'ColGroupBy') {
gb = get_groupby(facet);
col_gb = get_col_groupby(facet);
}
}
return {
groupby: gb,
col_groupby: col_gb,
}
}
});
function get_groupby(facet) {
var field = facet.get('field'),
result = [];
if ('get_groupby' in field) {
result = instance.web.pyeval.sync_eval_domains_and_contexts({
group_by_seq: field.get_groupby(facet)
}).group_by;
}
return result;
}
function get_col_groupby(facet) {
var field = facet.get('field'),
result = [];
if ('get_context' in field) {
result = instance.web.pyeval.sync_eval_domains_and_contexts({
contexts: field.get_context(facet)
}).context.col_group_by || [];
}
return result;
}
};

View File

@ -594,41 +594,52 @@ openerp.web_graph.Graph = openerp.web.Widget.extend({
// Drawing the table
// ----------------------------------------------------------------------
draw_table: function () {
var custom_gbs = this.graph_view.get_custom_filter_groupbys(),
frozen_rows = custom_gbs.groupby.length,
frozen_cols = custom_gbs.col_groupby.length;
var table = this.build_table();
var doc_fragment = $(document.createDocumentFragment());
this.draw_headers(table.headers, doc_fragment);
this.draw_headers(table.headers, doc_fragment, frozen_cols);
this.draw_measure_row(table.measure_row, doc_fragment);
this.draw_rows(table.rows, doc_fragment);
this.draw_rows(table.rows, doc_fragment, frozen_rows);
this.table.append(doc_fragment);
},
make_header_cell: function (header) {
make_header_cell: function (header, frozen) {
var cell = (_.has(header, 'cells') ? $('<td>') : $('<th>'))
.addClass('graph_border')
.attr('rowspan', header.height)
.attr('colspan', header.width);
var $content = $('<span>').addClass('web_graph_click')
.attr('href','#')
var $content = $('<span>').attr('href','#')
.text(' ' + (header.title || _t('Undefined')))
.css('margin-left', header.indent*30 + 'px')
.attr('data-id', header.id);
if (_.has(header, 'expanded')) {
$content.addClass(header.expanded ? 'fa fa-minus-square' : 'fa fa-plus-square');
if (('indent' in header) && header.indent >= frozen) {
$content.addClass(header.expanded ? 'fa fa-minus-square' : 'fa fa-plus-square');
$content.addClass('web_graph_click');
}
if (!('indent' in header) && header.lvl >= frozen) {
$content.addClass(header.expanded ? 'fa fa-minus-square' : 'fa fa-plus-square');
$content.addClass('web_graph_click');
}
} else {
$content.css('font-weight', 'bold');
}
return cell.append($content);
},
draw_headers: function (headers, doc_fragment) {
draw_headers: function (headers, doc_fragment, frozen_cols) {
var make_cell = this.make_header_cell,
$empty_cell = $('<th>').attr('rowspan', headers.length),
$thead = $('<thead>');
_.each(headers, function (row) {
_.each(headers, function (row, lvl) {
var $row = $('<tr>');
_.each(row, function (header) {
$row.append(make_cell(header));
header.lvl = lvl;
$row.append(make_cell(header, frozen_cols));
});
$thead.append($row);
});
@ -647,10 +658,10 @@ openerp.web_graph.Graph = openerp.web.Widget.extend({
this.$thead.append($row);
},
draw_row: function (row) {
draw_row: function (row, frozen_rows) {
var $row = $('<tr>')
.attr('data-indent', row.indent)
.append(this.make_header_cell(row));
.append(this.make_header_cell(row, frozen_rows));
var cells_length = row.cells.length;
var cells_list = [];
@ -671,13 +682,13 @@ openerp.web_graph.Graph = openerp.web.Widget.extend({
return $row.append(cells_list.join(''));
},
draw_rows: function (rows, doc_fragment) {
draw_rows: function (rows, doc_fragment, frozen_rows) {
var rows_length = rows.length,
$tbody = $('<tbody>');
doc_fragment.append($tbody);
for (var i = 0; i < rows_length; i++) {
$tbody.append(this.draw_row(rows[i]));
$tbody.append(this.draw_row(rows[i], frozen_rows));
}
},