diff options
| author | Aaron Bohy <aab@odoo.com> | 2017-06-01 09:57:16 +0200 |
|---|---|---|
| committer | Aaron Bohy <aab@odoo.com> | 2017-06-01 12:02:17 +0200 |
| commit | 033aec082669d6fb8126d6740b8aa7d09a2831d3 (patch) | |
| tree | 044773d7547cf8614f360e8664b209fcc4f4af85 | |
| parent | 2a4a011256f9f0d44546c6082ec1ccf4450bff52 (diff) | |
[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.
| -rw-r--r-- | addons/web/static/src/js/views/graph/graph_controller.js | 16 | ||||
| -rw-r--r-- | addons/web/static/tests/views/graph_tests.js | 53 |
2 files changed, 69 insertions, 0 deletions
diff --git a/addons/web/static/src/js/views/graph/graph_controller.js b/addons/web/static/src/js/views/graph/graph_controller.js index 388d390701c..d68808bac1d 100644 --- a/addons/web/static/src/js/views/graph/graph_controller.js +++ b/addons/web/static/src/js/views/graph/graph_controller.js @@ -40,6 +40,22 @@ var GraphController = AbstractController.extend({ //-------------------------------------------------------------------------- /** + * 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. * Set this.$buttons with the produced jQuery element diff --git a/addons/web/static/tests/views/graph_tests.js b/addons/web/static/tests/views/graph_tests.js index faab8420fbb..df6e500d181 100644 --- a/addons/web/static/tests/views/graph_tests.js +++ b/addons/web/static/tests/views/graph_tests.js @@ -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(); + }); + }); }); }); |
