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

Proposed by Géry Debongnie
Status: Merged
Merged at revision: 3957
Proposed branch: lp:~openerp-dev/openerp-web/saas-3-graphview-fixes-real-ged
Merge into: lp:~openerp/openerp-web/saas-3
Diff against target: 206 lines (+81/-39)
3 files modified
addons/web_graph/static/src/css/graph.css (+8/-0)
addons/web_graph/static/src/js/graph_view.js (+60/-38)
addons/web_graph/static/src/js/graph_widget.js (+13/-1)
To merge this branch: bzr merge lp:~openerp-dev/openerp-web/saas-3-graphview-fixes-real-ged
Reviewer Review Type Date Requested Status
Olivier Dony (Odoo) Pending
Review via email: mp+208378@code.launchpad.net

Description of the change

various fixes for the graph view. It mainly has to do with the search bar (group bys, filters, ...)

To post a comment you must log in.
3958. By Géry Debongnie

[IMP] this commit adds two css classes (graph_pivot_mode and graph_chart_mode) to better separate the ui from the code in graph view (addon web_graph)

3959. By Géry Debongnie

[FIX] adds a missing semicolon... :/ (addon web_graph)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'addons/web_graph/static/src/css/graph.css'
2--- addons/web_graph/static/src/css/graph.css 2014-01-28 15:11:13 +0000
3+++ addons/web_graph/static/src/css/graph.css 2014-02-26 14:40:51 +0000
4@@ -1,3 +1,11 @@
5+.graph_pivot_mode {
6+ position:initial;
7+}
8+
9+.graph_chart_mode {
10+ position:relative;
11+}
12+
13 .graph_main_content td {
14 font-size: 12px;
15 margin: 45px;
16
17=== modified file 'addons/web_graph/static/src/js/graph_view.js'
18--- addons/web_graph/static/src/js/graph_view.js 2014-02-10 15:32:21 +0000
19+++ addons/web_graph/static/src/js/graph_view.js 2014-02-26 14:40:51 +0000
20@@ -81,9 +81,9 @@
21 this.ignore_do_search = false;
22 return;
23 }
24-
25 var self = this,
26- col_group_by = self.get_groupbys_from_searchview('ColGroupBy', 'col_group_by');
27+ groupbys = this.get_groupbys_from_searchview(),
28+ col_group_by = groupbys.col_group_by;
29
30 if (!this.graph_widget) {
31 if (group_by.length) {
32@@ -95,10 +95,10 @@
33 this.graph_widget = new openerp.web_graph.Graph(this, this.model, domain, this.widget_config);
34 this.graph_widget.appendTo(this.$el);
35 this.ViewManager.on('switch_mode', this, function (e) {
36- var col_gb = self.get_groupbys_from_searchview('ColGroupBy', 'col_group_by'),
37- row_gb = self.get_groupbys_from_searchview('GroupBy', 'group_by');
38-
39- if (e === 'graph') this.graph_widget.set(domain, row_gb, col_gb);
40+ if (e === 'graph') {
41+ var group_bys = self.get_groupbys_from_searchview();
42+ this.graph_widget.set(domain, group_bys.group_by, group_bys.col_group_by);
43+ }
44 });
45 return;
46 }
47@@ -106,19 +106,27 @@
48 this.graph_widget.set(domain, group_by, col_group_by);
49 },
50
51- extract_groupby: function (cat_field, context) {
52- context = (_.isString(context)) ? py.eval(context) : context;
53- return context[cat_field];
54- },
55-
56- get_groupbys_from_searchview: function (cat_name, cat_field) {
57- var self=this,
58- facet = this.search_view.query.findWhere({category:cat_name}),
59- groupby_list = facet ? facet.values.models : [];
60- return _.map(groupby_list, function (g) {
61- var context = g.attributes.value.attrs.context;
62- return self.extract_groupby(cat_field, context);
63- });
64+ get_groupbys_from_searchview: function () {
65+ var result = { group_by: [], col_group_by: []},
66+ searchdata = this.search_view.build_search_data();
67+
68+ _.each(searchdata.groupbys, function (data) {
69+ data = (_.isString(data)) ? py.eval(data) : data;
70+ result.group_by = result.group_by.concat(data.group_by);
71+ if (data.col_group_by) {
72+ result.col_group_by = result.col_group_by.concat(data.col_group_by);
73+ }
74+ });
75+
76+ if (result.col_group_by.length) {
77+ return result;
78+ }
79+ _.each(searchdata.contexts, function (context) {
80+ if (context.col_group_by) {
81+ result.col_group_by = result.col_group_by.concat(context.col_group_by);
82+ }
83+ });
84+ return result;
85 },
86
87 do_show: function () {
88@@ -132,11 +140,20 @@
89
90 // add groupby to the search view
91 register_groupby: function(row_groupby, col_groupby) {
92- var query = this.search_view.query;
93+ var query = this.search_view.query,
94+ groupbys = this.get_groupbys_from_searchview(),
95+ search_row_groupby = groupbys.group_by,
96+ search_col_groupby = groupbys.col_group_by,
97+ row_gb_changed = !_.isEqual(_.pluck(row_groupby, 'field'), search_row_groupby),
98+ col_gb_changed = !_.isEqual(_.pluck(col_groupby, 'field'), search_col_groupby);
99
100 if (!_.has(this.search_view, '_s_groupby')) { return; }
101
102- if (row_groupby.length && col_groupby.length) {
103+ if (!row_gb_changed && !col_gb_changed) {
104+ return;
105+ }
106+
107+ if (row_gb_changed && col_gb_changed) {
108 // when two changes to the search view will be done, the method do_search
109 // will be called twice, once with the correct groupby and incorrect col_groupby,
110 // and once with correct informations. This flag is necessary to prevent the
111@@ -144,26 +161,31 @@
112 this.ignore_do_search = true;
113 }
114
115- // add row groupbys
116- var row_facet = this.make_row_groupby_facets(row_groupby),
117- row_search_facet = query.findWhere({category:'GroupBy'});
118+ if (row_gb_changed) {
119+ // add row groupbys
120+ var row_facet = this.make_row_groupby_facets(row_groupby),
121+ row_search_facet = query.findWhere({category:'GroupBy'});
122
123- if (row_search_facet) {
124- row_search_facet.values.reset(row_facet.values);
125- } else {
126- if (row_groupby.length) {
127- query.add(row_facet);
128+ if (row_search_facet) {
129+ row_search_facet.values.reset(row_facet.values);
130+ } else {
131+ if (row_groupby.length) {
132+ query.add(row_facet);
133+ }
134 }
135 }
136- // add col groupbys
137- var col_facet = this.make_col_groupby_facets(col_groupby),
138- col_search_facet = query.findWhere({category:'ColGroupBy'});
139-
140- if (col_search_facet) {
141- col_search_facet.values.reset(col_facet.values);
142- } else {
143- if (col_groupby.length) {
144- query.add(col_facet);
145+
146+ if (col_gb_changed) {
147+ // add col groupbys
148+ var col_facet = this.make_col_groupby_facets(col_groupby),
149+ col_search_facet = query.findWhere({category:'ColGroupBy'});
150+
151+ if (col_search_facet) {
152+ col_search_facet.values.reset(col_facet.values);
153+ } else {
154+ if (col_groupby.length) {
155+ query.add(col_facet);
156+ }
157 }
158 }
159 },
160
161=== modified file 'addons/web_graph/static/src/js/graph_widget.js'
162--- addons/web_graph/static/src/js/graph_widget.js 2014-02-10 09:17:16 +0000
163+++ addons/web_graph/static/src/js/graph_widget.js 2014-02-26 14:40:51 +0000
164@@ -37,6 +37,9 @@
165
166 if (this.mode !== 'pivot') {
167 this.$('.graph_heatmap label').addClass('disabled');
168+ this.$('.graph_main_content').addClass('graph_chart_mode');
169+ } else {
170+ this.$('.graph_main_content').addClass('graph_pivot_mode');
171 }
172
173 return this.model.call('fields_get', []).then(function (f) {
174@@ -149,6 +152,13 @@
175 return;
176 }
177
178+ if (!dom_changed && col_reduced && row_reduced) {
179+ this.pivot.fold_with_depth(this.pivot.rows, row_gbs.length);
180+ this.pivot.fold_with_depth(this.pivot.cols, col_gbs.length);
181+ this.display_data();
182+ return;
183+ }
184+
185 if (dom_changed || row_gb_changed || col_gb_changed) {
186 this.pivot.set(domain, row_gbs, col_gbs).then(this.proxy('display_data'));
187 }
188@@ -159,8 +169,10 @@
189
190 if (mode === 'pivot') {
191 this.$('.graph_heatmap label').removeClass('disabled');
192+ this.$('.graph_main_content').removeClass('graph_chart_mode').addClass('graph_pivot_mode');
193 } else {
194 this.$('.graph_heatmap label').addClass('disabled');
195+ this.$('.graph_main_content').removeClass('graph_pivot_mode').addClass('graph_chart_mode');
196 }
197 this.display_data();
198 },
199@@ -364,7 +376,7 @@
200 this.$('.graph_main_content svg').remove();
201 this.$('.graph_main_content div').remove();
202 this.table.empty();
203- this.table.toggleClass('heatmap', this.heatmap_mode !== 'none')
204+ this.table.toggleClass('heatmap', this.heatmap_mode !== 'none');
205 this.width = this.$el.width();
206 this.height = Math.min(Math.max(document.documentElement.clientHeight - 116 - 60, 250), Math.round(0.8*this.$el.width()));
207

Subscribers

People subscribed via source and target branches