From dc75248b89bcb6e839bcdf30830cdc5dbb9d80ec Mon Sep 17 00:00:00 2001 From: RomainLibert Date: Tue, 3 Jul 2018 15:34:32 +0200 Subject: [PATCH 1/3] [IMP] web: sort measures in graph view and pivot view --- .../src/js/views/graph/graph_controller.js | 2 +- .../src/js/views/pivot/pivot_controller.js | 2 +- .../static/src/js/views/pivot/pivot_view.js | 2 -- addons/web/static/tests/views/graph_tests.js | 24 +++++++++++++++++++ addons/web/static/tests/views/pivot_tests.js | 24 +++++++++++++++++++ 5 files changed, 50 insertions(+), 4 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 e9f933023b1..e7f25c23fdd 100644 --- a/addons/web/static/src/js/views/graph/graph_controller.js +++ b/addons/web/static/src/js/views/graph/graph_controller.js @@ -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'); diff --git a/addons/web/static/src/js/views/pivot/pivot_controller.js b/addons/web/static/src/js/views/pivot/pivot_controller.js index 5f31c7103c7..f0976c9a8b4 100644 --- a/addons/web/static/src/js/views/pivot/pivot_controller.js +++ b/addons/web/static/src/js/views/pivot/pivot_controller.js @@ -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(); diff --git a/addons/web/static/src/js/views/pivot/pivot_view.js b/addons/web/static/src/js/views/pivot/pivot_view.js index 251fa10200d..643ee68a498 100644 --- a/addons/web/static/src/js/views/pivot/pivot_view.js +++ b/addons/web/static/src/js/views/pivot/pivot_view.js @@ -119,5 +119,3 @@ var PivotView = AbstractView.extend({ return PivotView; }); - - diff --git a/addons/web/static/tests/views/graph_tests.js b/addons/web/static/tests/views/graph_tests.js index 5f7227815c1..60e6680993c 100644 --- a/addons/web/static/tests/views/graph_tests.js +++ b/addons/web/static/tests/views/graph_tests.js @@ -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: '' + + '' + + '' + + '', + }) + + 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(); + }); }); }); diff --git a/addons/web/static/tests/views/pivot_tests.js b/addons/web/static/tests/views/pivot_tests.js index 4d7358f2574..70eee5b3431 100644 --- a/addons/web/static/tests/views/pivot_tests.js +++ b/addons/web/static/tests/views/pivot_tests.js @@ -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: '' + + '' + + '' + + '', + }) + + 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(); + }); });}); From 950923807969057e1e982b195ca6ce3f33d2a95b Mon Sep 17 00:00:00 2001 From: RomainLibert Date: Thu, 5 Jul 2018 15:34:02 +0200 Subject: [PATCH 2/3] [DOC] split graph and pivot documentation Pivot view documentation was still inside the graph view documentation as it was previously only a mode of this graph view. As the pivot is now an entirely different view, it has the right to have it's own documentation. --- doc/reference/views.rst | 40 ++++++++++++++++++++++++++++++++++------ 1 file changed, 34 insertions(+), 6 deletions(-) diff --git a/doc/reference/views.rst b/doc/reference/views.rst index 9093bc314c6..2b5f0873e98 100644 --- a/doc/reference/views.rst +++ b/doc/reference/views.rst @@ -784,7 +784,7 @@ The only allowed element within a graph view is ``field`` which can have the following attributes: ``name`` (required) - the name of a field to use in a graph view. If used for grouping (rather + the name of a field to use in the view. If used for grouping (rather than aggregating) ``type`` @@ -793,10 +793,9 @@ following attributes: ``row`` (default) groups by the specified field. All graph types support at least one level - of grouping, some may support more. For pivot views, each group gets its - own row. + of grouping, some may support more. ``col`` - only used by pivot tables, creates column-wise groups + authorized in graph views but only used by pivot tables ``measure`` field to aggregate within a group @@ -810,8 +809,11 @@ following attributes: graph view aggregations are performed on database content, non-stored function fields can not be used in graph views + +.. _reference/views/pivot: + Pivots ------- +====== The pivot view is used to visualize aggregations as a `pivot table`_. Its root element is ```` which can take the following attributes: @@ -821,7 +823,33 @@ element is ```` which can take the following attributes: ``display_quantity`` Set to ``true`` to display the Quantity column by default. -The elements allowed within a pivot view are the same as for the graph view. +The only allowed element within a pivot view is ``field`` which can have the +following attributes: + +``name`` (required) + the name of a field to use in the view. If used for grouping (rather + than aggregating) + +``type`` + indicates whether the field should be used as a grouping criteria or as an + aggregated value within a group. Possible values are: + + ``row`` (default) + groups by the specified field, each group gets its own row. + ``col`` + creates column-wise groups + ``measure`` + field to aggregate within a group + ``interval`` + on date and datetime fields, groups by the specified interval (``day``, + ``week``, ``month``, ``quarter`` or ``year``) instead of grouping on the + specific datetime (fixed second resolution) or date (fixed day resolution). + +.. warning:: + + like the graph view, the pivot aggregates data on database content + which means that non-stored function fields can not be used in pivot views + .. _reference/views/kanban: From a1c422d2ded4a1606eeefa34948bc7fdb2649845 Mon Sep 17 00:00:00 2001 From: RomainLibert Date: Tue, 3 Jul 2018 15:35:18 +0200 Subject: [PATCH 3/3] [DOC] pivot,graph: add documentation on alphabetical sort As pivot and graph measures are now automatically alphabetically sorted, we need to update the documentation --- doc/reference/views.rst | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/doc/reference/views.rst b/doc/reference/views.rst index 2b5f0873e98..f8a87032a0e 100644 --- a/doc/reference/views.rst +++ b/doc/reference/views.rst @@ -804,6 +804,10 @@ following attributes: ``week``, ``month``, ``quarter`` or ``year``) instead of grouping on the specific datetime (fixed second resolution) or date (fixed day resolution). +The measures are automatically generated from the model fields; only the +aggregatable fields are used. Those measures are also alphabetically +sorted on the string of the field. + .. warning:: graph view aggregations are performed on database content, non-stored @@ -845,6 +849,10 @@ following attributes: ``week``, ``month``, ``quarter`` or ``year``) instead of grouping on the specific datetime (fixed second resolution) or date (fixed day resolution). +The measures are automatically generated from the model fields; only the +aggregatable fields are used. Those measures are also alphabetically +sorted on the string of the field. + .. warning:: like the graph view, the pivot aggregates data on database content