[FIX] web: Graph: correctly return graph's context
allowing to properly save the current state (mode, measure, groupbys) of the view in the Favorites or add it to the dashboard.
This commit is contained in:
@@ -39,6 +39,22 @@ var GraphController = AbstractController.extend({
|
||||
// Public
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Returns the current mode, measure and groupbys, so we can restore the
|
||||
* view when we save the current state in the search view, or when we add it
|
||||
* to the dashboard.
|
||||
*
|
||||
* @override
|
||||
* @returns {Object}
|
||||
*/
|
||||
getContext: function () {
|
||||
var state = this.model.get();
|
||||
return {
|
||||
graph_measure: state.measure,
|
||||
graph_mode: state.mode,
|
||||
graph_groupbys: state.groupedBy,
|
||||
};
|
||||
},
|
||||
/**
|
||||
* Render the buttons according to the GraphView.buttons and
|
||||
* add listeners on it.
|
||||
|
||||
@@ -251,6 +251,59 @@ QUnit.module('Views', {
|
||||
});
|
||||
});
|
||||
|
||||
QUnit.test('getContext correctly returns mode, measure and groupbys', function (assert) {
|
||||
var done = assert.async();
|
||||
assert.expect(4);
|
||||
|
||||
var graph = createView({
|
||||
View: GraphView,
|
||||
model: "foo",
|
||||
data: this.data,
|
||||
arch: '<graph string="Gloups">' +
|
||||
'<field name="product_id"/>' +
|
||||
'</graph>',
|
||||
});
|
||||
return concurrency.delay(0).then(function () {
|
||||
assert.deepEqual(graph.getContext(), {
|
||||
graph_mode: 'bar',
|
||||
graph_measure: '__count__',
|
||||
graph_groupbys: ['product_id'],
|
||||
}, "context should be correct");
|
||||
|
||||
graph.$buttons.find('li[data-field="foo"] a').click(); // change measure
|
||||
|
||||
return concurrency.delay(0);
|
||||
}).then(function () {
|
||||
assert.deepEqual(graph.getContext(), {
|
||||
graph_mode: 'bar',
|
||||
graph_measure: 'foo',
|
||||
graph_groupbys: ['product_id'],
|
||||
}, "context should be correct");
|
||||
|
||||
graph.$buttons.find('button[data-mode="line"]').click(); // change mode
|
||||
|
||||
return concurrency.delay(0);
|
||||
}).then(function () {
|
||||
assert.deepEqual(graph.getContext(), {
|
||||
graph_mode: 'line',
|
||||
graph_measure: 'foo',
|
||||
graph_groupbys: ['product_id'],
|
||||
}, "context should be correct");
|
||||
|
||||
graph.update({groupBy: ['product_id', 'color_id']}); // change groupbys
|
||||
|
||||
return concurrency.delay(0);
|
||||
}).then(function () {
|
||||
assert.deepEqual(graph.getContext(), {
|
||||
graph_mode: 'line',
|
||||
graph_measure: 'foo',
|
||||
graph_groupbys: ['product_id', 'color_id'],
|
||||
}, "context should be correct");
|
||||
|
||||
graph.destroy();
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user