Merge lp:~openerp-dev/openerp-web/saas-4-graphview-fixes-ged into lp:~openerp/openerp-web/saas-4

Proposed by Géry Debongnie
Status: Merged
Merged at revision: 3982
Proposed branch: lp:~openerp-dev/openerp-web/saas-4-graphview-fixes-ged
Merge into: lp:~openerp/openerp-web/saas-4
Diff against target: 211 lines (+38/-28)
3 files modified
addons/web/static/src/js/search.js (+17/-10)
addons/web_graph/static/src/js/graph_view.js (+2/-2)
addons/web_graph/static/src/js/graph_widget.js (+19/-16)
To merge this branch: bzr merge lp:~openerp-dev/openerp-web/saas-4-graphview-fixes-ged
Reviewer Review Type Date Requested Status
Olivier Dony (Odoo) Pending
Review via email: mp+216747@code.launchpad.net

Description of the change

Lots of small (but very useful) bug fixes (for the graph view), including:
* correct labels in line charts
* no more scaling problem in the y-axis in bar charts with 1 row groupby
* the view does not scroll back up when folding/unfolding in pivot table

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'addons/web/static/src/js/search.js'
2--- addons/web/static/src/js/search.js 2014-03-26 17:08:18 +0000
3+++ addons/web/static/src/js/search.js 2014-04-22 15:12:47 +0000
4@@ -29,8 +29,8 @@
5 B.Model.prototype.initialize.apply(this, arguments);
6
7 this.values = new my.FacetValues(values || []);
8- this.values.on('add remove change reset', function () {
9- this.trigger('change', this);
10+ this.values.on('add remove change reset', function (_, options) {
11+ this.trigger('change', this, options);
12 }, this);
13 },
14 get: function (key) {
15@@ -399,7 +399,8 @@
16 this.setup_global_completion();
17 this.query = new my.SearchQuery()
18 .on('add change reset remove', this.proxy('do_search'))
19- .on('add change reset remove', this.proxy('renderFacets'));
20+ .on('change', this.proxy('renderChangedFacets'))
21+ .on('add reset remove', this.proxy('renderFacets'));
22
23 if (this.options.hidden) {
24 this.$el.hide();
25@@ -578,14 +579,20 @@
26 .trigger('blur');
27 },
28 /**
29- *
30- * @param {openerp.web.search.SearchQuery | openerp.web.search.Facet} _1
31- * @param {openerp.web.search.Facet} [_2]
32+ * Call the renderFacets method with the correct arguments.
33+ * This is due to the fact that change events are called with two arguments
34+ * (model, options) while add, reset and remove events are called with
35+ * (collection, model, options) as arguments
36+ */
37+ renderChangedFacets: function (model, options) {
38+ this.renderFacets(undefined, model, options);
39+ },
40+ /**
41+ * @param {openerp.web.search.SearchQuery | undefined} Undefined if event is change
42+ * @param {openerp.web.search.Facet}
43 * @param {Object} [options]
44 */
45- renderFacets: function (_1, _2, options) {
46- // _1: model if event=change, otherwise collection
47- // _2: undefined if event=change, otherwise model
48+ renderFacets: function (collection, model, options) {
49 var self = this;
50 var started = [];
51 var $e = this.$('div.oe_searchview_facets');
52@@ -610,6 +617,7 @@
53 });
54
55 $.when.apply(null, started).then(function () {
56+ if (options && options.focus_input === false) return;
57 var input_to_focus;
58 // options.at: facet inserted at given index, focus next input
59 // otherwise just focus last input
60@@ -618,7 +626,6 @@
61 } else {
62 input_to_focus = self.input_subviews[(options.at + 1) * 2];
63 }
64-
65 input_to_focus.$el.focus();
66 });
67 },
68
69=== modified file 'addons/web_graph/static/src/js/graph_view.js'
70--- addons/web_graph/static/src/js/graph_view.js 2014-03-11 13:22:00 +0000
71+++ addons/web_graph/static/src/js/graph_view.js 2014-04-22 15:12:47 +0000
72@@ -167,7 +167,7 @@
73 row_search_facet = query.findWhere({category:'GroupBy'});
74
75 if (row_search_facet) {
76- row_search_facet.values.reset(row_facet.values);
77+ row_search_facet.values.reset(row_facet.values, {focus_input:false});
78 } else {
79 if (row_groupby.length) {
80 query.add(row_facet);
81@@ -181,7 +181,7 @@
82 col_search_facet = query.findWhere({category:'ColGroupBy'});
83
84 if (col_search_facet) {
85- col_search_facet.values.reset(col_facet.values);
86+ col_search_facet.values.reset(col_facet.values, {focus_input:false});
87 } else {
88 if (col_groupby.length) {
89 query.add(col_facet);
90
91=== modified file 'addons/web_graph/static/src/js/graph_widget.js'
92--- addons/web_graph/static/src/js/graph_widget.js 2014-04-09 09:39:20 +0000
93+++ addons/web_graph/static/src/js/graph_widget.js 2014-04-22 15:12:47 +0000
94@@ -44,7 +44,7 @@
95 }
96
97 openerp.session.rpc('/web_graph/check_xlwt').then(function (result) {
98- self.$('.graph_options_selection label').toggle(result);
99+ self.$('.graph_options_selection label').last().toggle(result);
100 });
101
102 return this.model.call('fields_get', []).then(function (f) {
103@@ -305,11 +305,11 @@
104 if (header.expanded) {
105 this.fold(header);
106 return;
107- }
108+ }
109 if (header.path.length < header.root.groupby.length) {
110 this.expand(id);
111 return;
112- }
113+ }
114 if (!this.important_fields.length) {
115 return;
116 }
117@@ -498,10 +498,12 @@
118 // Main display method
119 // ----------------------------------------------------------------------
120 display_data: function () {
121+ var scroll = $(window).scrollTop();
122 this.$('.graph_main_content svg').remove();
123 this.$('.graph_main_content div').remove();
124 this.table.empty();
125 this.table.toggleClass('heatmap', this.heatmap_mode !== 'none');
126+ this.$('.graph_options_selection label').last().toggleClass('disabled', this.pivot.no_data);
127 this.width = this.$el.width();
128 this.height = Math.min(Math.max(document.documentElement.clientHeight - 116 - 60, 250), Math.round(0.8*this.$el.width()));
129
130@@ -511,6 +513,7 @@
131 } else {
132 if (this.mode === 'pivot') {
133 this.draw_table();
134+ $(window).scrollTop(scroll);
135 } else {
136 this.$('.graph_main_content').append($('<div><svg>'));
137 this.svg = this.$('.graph_main_content svg')[0];
138@@ -608,7 +611,7 @@
139 if ((dim_x === 0) && (dim_y === 0)) {
140 data = [{key: _t('Total'), values:[{
141 x: _t('Total'),
142- y: this.pivot.get_total(),
143+ y: this.pivot.get_total()[0],
144 }]}];
145 // Only column groupbys
146 } else if ((dim_x === 0) && (dim_y >= 1)){
147@@ -621,7 +624,7 @@
148 // Just 1 row groupby
149 } else if ((dim_x === 1) && (dim_y === 0)) {
150 data = _.map(this.pivot.main_row().children, function (pt) {
151- var value = self.pivot.get_total(pt),
152+ var value = self.pivot.get_total(pt)[0],
153 title = (pt.title !== undefined) ? pt.title : _t('Undefined');
154 return {x: title, y: value};
155 });
156@@ -658,8 +661,6 @@
157
158 nv.addGraph(function () {
159 var chart = nv.models.multiBarChart()
160- .width(self.width)
161- .height(self.height)
162 .reduceXTicks(false)
163 .stacked(self.bar_ui === 'stack')
164 .showControls(show_controls);
165@@ -687,9 +688,12 @@
166 dim_x = this.pivot.rows.groupby.length,
167 dim_y = this.pivot.cols.groupby.length;
168
169+ var rows = this.pivot.get_rows_with_depth(dim_x),
170+ labels = _.pluck(rows, 'title');
171+
172 var data = _.map(this.pivot.get_cols_leaves(), function (col) {
173- var values = _.map(self.pivot.get_rows_with_depth(dim_x), function (row) {
174- return {x: row.title, y: self.pivot.get_values(row.id,col.id)[0] || 0};
175+ var values = _.map(rows, function (row, index) {
176+ return {x: index, y: self.pivot.get_values(row.id,col.id)[0] || 0};
177 });
178 var title = _.map(col.path, function (p) {
179 return p || _t('Undefined');
180@@ -702,10 +706,9 @@
181
182 nv.addGraph(function () {
183 var chart = nv.models.lineChart()
184- .x(function (d,u) { return u; })
185- .width(self.width)
186- .height(self.height)
187- .margin({top: 30, right: 20, bottom: 20, left: 60});
188+ .x(function (d,u) { return u; });
189+
190+ chart.xAxis.tickFormat(function (d,u) {return labels[d];});
191
192 d3.select(self.svg)
193 .attr('width', self.width)
194@@ -727,14 +730,14 @@
195 if (dim_x === 0) {
196 title = self.measure_label;
197 }
198- return {x: title, y: self.pivot.get_total(row)};
199+ return {x: title, y: self.pivot.get_total(row)[0]};
200 });
201
202 nv.addGraph(function () {
203 var chart = nv.models.pieChart()
204- .color(d3.scale.category10().range())
205 .width(self.width)
206- .height(self.height);
207+ .height(self.height)
208+ .color(d3.scale.category10().range());
209
210 d3.select(self.svg)
211 .datum(data)

Subscribers

People subscribed via source and target branches