[IMP] web: sort measures in graph view and pivot view
This commit is contained in:
@@ -88,7 +88,7 @@ var GraphController = AbstractController.extend(GroupByMenuInterfaceMixin,{
|
||||
renderButtons: function ($node) {
|
||||
if ($node) {
|
||||
var context = {
|
||||
measures: _.pairs(_.omit(this.measures, '__count__')),
|
||||
measures: _.sortBy(_.pairs(_.omit(this.measures, '__count__')), function (x) { return x[0]; }),
|
||||
};
|
||||
this.$buttons = $(qweb.render('GraphView.buttons', context));
|
||||
this.$measureList = this.$buttons.find('.o_graph_measures_list');
|
||||
|
||||
@@ -102,7 +102,7 @@ var PivotController = AbstractController.extend({
|
||||
*/
|
||||
renderButtons: function ($node) {
|
||||
if ($node) {
|
||||
var context = {measures: _.pairs(_.omit(this.measures, '__count'))};
|
||||
var context = {measures: _.sortBy(_.pairs(_.omit(this.measures, '__count')), function(x) { return x[0]; })};
|
||||
this.$buttons = $(QWeb.render('PivotView.buttons', context));
|
||||
this.$buttons.click(this._onButtonClick.bind(this));
|
||||
this.$buttons.find('button').tooltip();
|
||||
|
||||
@@ -119,5 +119,3 @@ var PivotView = AbstractView.extend({
|
||||
return PivotView;
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
||||
@@ -622,6 +622,30 @@ QUnit.module('Views', {
|
||||
assert.ok(true,"should not generate any error");
|
||||
graph.destroy();
|
||||
});
|
||||
|
||||
QUnit.test('graph measures should be alphabetically sorted', function (assert) {
|
||||
assert.expect(2);
|
||||
|
||||
var data = this.data;
|
||||
data.foo.fields.bouh = {string: "bouh", type: "integer"};
|
||||
|
||||
var graph = createView({
|
||||
View: GraphView,
|
||||
model: "foo",
|
||||
data: data,
|
||||
arch: '<graph string="Partners">' +
|
||||
'<field name="foo" type="measure"/>' +
|
||||
'<field name="bouh" type="measure"/>' +
|
||||
'</graph>',
|
||||
})
|
||||
|
||||
assert.strictEqual(graph.$buttons.find('.o_graph_measures_list li:first').data('field'), 'bouh',
|
||||
"Bouh should be the first measure");
|
||||
assert.strictEqual(graph.$buttons.find('.o_graph_measures_list li:last').data('field'), '__count__',
|
||||
"Count should be the last measure");
|
||||
|
||||
graph.destroy();
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
@@ -1178,4 +1178,28 @@ QUnit.module('Views', {
|
||||
"should have 6 rows");
|
||||
pivot.destroy();
|
||||
});
|
||||
|
||||
QUnit.test('pivot measures should be alphabetically sorted', function (assert) {
|
||||
assert.expect(2);
|
||||
|
||||
var data = this.data;
|
||||
data.partner.fields.bouh = {string: "bouh", type: "integer"};
|
||||
|
||||
var pivot = createView({
|
||||
View: PivotView,
|
||||
model: "partner",
|
||||
data: data,
|
||||
arch: '<pivot>' +
|
||||
'<field name="foo" type="measure"/>' +
|
||||
'<field name="bouh" type="measure"/>' +
|
||||
'</pivot>',
|
||||
})
|
||||
|
||||
assert.strictEqual(pivot.$buttons.find('.o_pivot_measures_list li:first').data('field'), 'bouh',
|
||||
"Bouh should be the first measure");
|
||||
assert.strictEqual(pivot.$buttons.find('.o_pivot_measures_list li:last').data('field'), '__count',
|
||||
"Count should be the last measure");
|
||||
|
||||
pivot.destroy();
|
||||
});
|
||||
});});
|
||||
|
||||
Reference in New Issue
Block a user