Merge lp:~rvb/launchpad/longpoll-stats-903586 into lp:launchpad

Proposed by Raphaël Badin on 2012-01-03
Status: Merged
Approved by: Raphaël Badin on 2012-01-03
Approved revision: no longer in the source branch.
Merged at revision: 14626
Proposed branch: lp:~rvb/launchpad/longpoll-stats-903586
Merge into: lp:launchpad
Diff against target: 344 lines (+161/-14)
8 files modified
lib/lp/code/browser/configure.zcml (+3/-0)
lib/lp/code/javascript/branchmergeproposal.reviewcomment.js (+3/-1)
lib/lp/code/javascript/branchmergeproposal.updater.js (+97/-4)
lib/lp/code/javascript/tests/test_branchmergeproposal.updater.html (+12/-0)
lib/lp/code/javascript/tests/test_branchmergeproposal.updater.js (+34/-5)
lib/lp/code/templates/branchmergeproposal-diff-stats.pt (+7/-0)
lib/lp/code/templates/branchmergeproposal-index.pt (+4/-1)
lib/lp/code/templates/branchmergeproposal-pagelet-summary.pt (+1/-3)
To merge this branch: bzr merge lp:~rvb/launchpad/longpoll-stats-903586
Reviewer Review Type Date Requested Status
Graham Binns (community) code 2012-01-03 Approve on 2012-01-03
Review via email: mp+87372@code.launchpad.net

Commit Message

[r=gmb][bug=903586] Update the stats on a MP page.

Description of the Change

This branch makes it so that ,on a merge proposal page, when a new diff is available the stats (number of lines changed, conflicts) are updated. This rely on the existing longpoll mechanism that already updates the diff itself when a new version is available.

= Implementation details =
This branch does 2 things:
- Extract the template bit that generates the stats and expose it mp/++diff-stats (it is done the same way for the diff itself: mp/++diff)
- Change the JavaScript code used by the MP page to update the diff stats when a new version of the diff is available.

= Tests =
firefox lib/lp/code/javascript/tests/test_branchmergeproposal.updater.html
(note that the change to the stats display is already tested in the code)

= QA =
Create a MP and then add a new revision to the branch, wait for the branches to be scanned and make sure that the stats are updated along with the diff itself when the longpoll event kicks in.

To post a comment you must log in.
Graham Binns (gmb) :
review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/code/browser/configure.zcml'
2--- lib/lp/code/browser/configure.zcml 2011-12-24 17:49:30 +0000
3+++ lib/lp/code/browser/configure.zcml 2012-01-03 15:53:28 +0000
4@@ -193,6 +193,9 @@
5 name="++diff"
6 template="../templates/branchmergeproposal-diff.pt"/>
7 <browser:page
8+ name="++diff-stats"
9+ template="../templates/branchmergeproposal-diff-stats.pt"/>
10+ <browser:page
11 name="+pagelet-summary"
12 template="../templates/branchmergeproposal-pagelet-summary.pt"/>
13 </browser:pages>
14
15=== modified file 'lib/lp/code/javascript/branchmergeproposal.reviewcomment.js'
16--- lib/lp/code/javascript/branchmergeproposal.reviewcomment.js 2011-09-20 15:27:04 +0000
17+++ lib/lp/code/javascript/branchmergeproposal.reviewcomment.js 2012-01-03 15:53:28 +0000
18@@ -71,6 +71,8 @@
19 });
20 }
21
22+namespace.link_scroller = link_scroller;
23+
24
25 /*
26 * Make the edit link a javascript link (green).
27@@ -245,7 +247,7 @@
28
29
30 var NumberToggle = function () {
31- NumberToggle.superclass.constructor.apply(this, arguments);
32+ NumberToggle.superclass.constructor.apply(this, arguments);
33 };
34
35
36
37=== modified file 'lib/lp/code/javascript/branchmergeproposal.updater.js'
38--- lib/lp/code/javascript/branchmergeproposal.updater.js 2011-09-30 09:15:21 +0000
39+++ lib/lp/code/javascript/branchmergeproposal.updater.js 2012-01-03 15:53:28 +0000
40@@ -32,6 +32,16 @@
41 },
42
43 /**
44+ * The summary node.
45+ *
46+ * @attribute summary_node
47+ */
48+ summary_node: {
49+ value: null,
50+ writeOnce: "initOnly"
51+ },
52+
53+ /**
54 * Whether or not this MP is still 'pending'.
55 *
56 * @attribute pending
57@@ -46,6 +56,30 @@
58 },
59
60 /**
61+ * The HTML code for the stats diff.
62+ *
63+ * @attribute diff_stats
64+ */
65+ diff_stats: {
66+ getter: function() {
67+ var summary_node = this.get('summary_node');
68+ if (!Y.Lang.isValue(summary_node) ||
69+ !Y.Lang.isValue(summary_node.one(
70+ '#summary-row-b-diff'))) {
71+ return null;
72+ }
73+ return summary_node.one(
74+ '#summary-row-b-diff').one('td').get('innerHTML');
75+ },
76+ setter: function(value) {
77+ this._setup_diff_stats_container();
78+ var container = this.get(
79+ 'summary_node').one('#summary-row-b-diff').one('td');
80+ container.set('innerHTML', value);
81+ }
82+ },
83+
84+ /**
85 * The HTML code for the diff.
86 *
87 * @attribute diff
88@@ -78,14 +112,14 @@
89 * @method initializer
90 * @protected
91 */
92- initializer: function(){
93+ initializer: function(cfg){
94 // If we have not been provided with a Launchpad Client, then
95 // create one now:
96 if (null === this.get("lp_client")){
97 // Create our own instance of the LP client.
98 this.set("lp_client", new Y.lp.client.Launchpad());
99 }
100- var self = this;
101+ this.set('summary_node', cfg.summary_node);
102 },
103
104 /*
105@@ -146,6 +180,25 @@
106 },
107
108 /*
109+ * Add a row in the page summary table to display the diff stats
110+ * if needed.
111+ *
112+ * @method _setup_diff_stats_container
113+ */
114+ _setup_diff_stats_container: function() {
115+ if (!Y.Lang.isValue(this.get('diff_stats'))) {
116+ var summary_node = this.get('summary_node');
117+ var diff_stats = Y.Node.create('<tr />')
118+ .set('id', 'summary-row-b-diff')
119+ .append(Y.Node.create('<th />')
120+ .set("text", "Diff against target:"))
121+ .append(Y.Node.create('<td />'));
122+ summary_node.one(
123+ '#summary-row-9-target-branch').insert(diff_stats, 'after');
124+ }
125+ },
126+
127+ /*
128 * Populate the widget with the required nodes to display the diff
129 * if needed.
130 *
131@@ -167,11 +220,50 @@
132 },
133
134 /*
135- * Update the diff content with the last version.
136+ * Update the page with the last version of the diff and update the
137+ * stats.
138 *
139 * @method update
140 */
141 update: function() {
142+ this.update_stats();
143+ this.update_diff();
144+ },
145+
146+ /*
147+ * Update the diff stats with the last version.
148+ *
149+ * @method update_stats
150+ */
151+ update_stats: function() {
152+ var self = this;
153+ var config = {
154+ on: {
155+ success: function(diff_stats) {
156+ self.set('diff_stats', diff_stats);
157+ // (re)connect the js scroller link.
158+ Y.lp.code.branchmergeproposal.reviewcomment.link_scroller(
159+ '#proposal-summary a.diff-link', '#review-diff');
160+ var node = self.get('summary_node');
161+ Y.lp.anim.green_flash({node: node}).run();
162+ },
163+ failure: function() {
164+ var node = self.get('summary_node');
165+ Y.lp.anim.red_flash({node: node}).run();
166+ }
167+ }
168+ };
169+ var mp_uri = LP.cache.context.web_link;
170+ this.get('lp_client').get(mp_uri + "/++diff-stats", config);
171+ },
172+
173+
174+ /*
175+ * Update the diff content with the last version.
176+ *
177+ * @method update_diff
178+ */
179+ update_diff: function() {
180 var self = this;
181 var config = {
182 on: {
183@@ -214,4 +306,5 @@
184 event_data.edited_fields.indexOf("preview_diff") >= 0);
185 };
186
187-}, '0.1', {requires: ['node', 'lp.client', 'lp.anim']});
188+}, '0.1', {requires: ['node', 'lp.client', 'lp.anim',
189+ 'lp.code.branchmergeproposal.reviewcomment']});
190
191=== modified file 'lib/lp/code/javascript/tests/test_branchmergeproposal.updater.html'
192--- lib/lp/code/javascript/tests/test_branchmergeproposal.updater.html 2011-09-20 15:30:37 +0000
193+++ lib/lp/code/javascript/tests/test_branchmergeproposal.updater.html 2012-01-03 15:53:28 +0000
194@@ -17,6 +17,9 @@
195 <script type="text/javascript" src="../../../app/javascript/anim/anim.js"></script>
196 <script type="text/javascript"
197 src="../../../app/javascript/extras/extras.js"></script>
198+ <script type="text/javascript"
199+ src="../branchmergeproposal.reviewcomment.js"></script>
200+
201
202 <!-- expected variable -->
203 <script type="text/javascript">
204@@ -38,6 +41,15 @@
205 </div>
206
207 <script type="text/x-template" id="pending-mp">
208+ <table id="proposal-summary">
209+ <tr id="summary-row-9-target-branch">
210+ <th>Merge into:</th>
211+ <td>
212+ <a href="/~me/project/branch"
213+ class="sprite branch">lp://dev/~me/project/branch</a>
214+ </td>
215+ </tr>
216+ </table>
217 <div id="diff-area">
218 <div class="pending-update" id="diff-pending-update">
219 <h3>Updating diff...</h3>
220
221=== modified file 'lib/lp/code/javascript/tests/test_branchmergeproposal.updater.js'
222--- lib/lp/code/javascript/tests/test_branchmergeproposal.updater.js 2011-09-30 09:14:49 +0000
223+++ lib/lp/code/javascript/tests/test_branchmergeproposal.updater.js 2012-01-03 15:53:28 +0000
224@@ -30,7 +30,9 @@
225 .empty()
226 .append(Y.Node.create(pending_mp));
227 var diff_area = Y.one('#diff-area');
228- this.updater = new UpdaterWidget({srcNode: diff_area});
229+ var summary_node = Y.one('#proposal-summary');
230+ this.updater = new UpdaterWidget(
231+ {srcNode: diff_area, summary_node: summary_node});
232
233 LP.cache.context = {
234 web_link: "https://code.launchpad.dev/~foo/bar/foobr/+merge/123"};
235@@ -61,6 +63,19 @@
236 'srcNode').one('.diff-content').get('text'));
237 },
238
239+ test__setup_diff_stats_container: function() {
240+ Y.Assert.isNull(this.updater.get('diff_stats'));
241+ this.updater._setup_diff_stats_container();
242+ Y.Assert.areEqual('', this.updater.get('diff_stats'));
243+ },
244+
245+ test_set_diff_stats: function() {
246+ this.updater.set('diff_stats', '13 lines (+4/-0) 1 file modified');
247+ Y.Assert.areEqual(
248+ '13 lines (+4/-0) 1 file modified',
249+ this.updater.get('diff_stats'));
250+ },
251+
252 test_set_status_updating: function() {
253 this.updater.set_status_updating();
254 Y.Assert.areEqual(
255@@ -107,13 +122,13 @@
256 Y.one('.diff-content').get('innerHTML'));
257 },
258
259- test_update_success: function() {
260+ test_update_diff_success: function() {
261 var mockio = new Y.lp.testing.mockio.MockIo();
262 this.updater.get('lp_client').io_provider = mockio;
263 Y.Assert.areEqual(
264 '',
265 this.updater.get('diff'));
266- this.updater.update();
267+ this.updater.update_diff();
268 mockio.success({
269 responseText: 'New <span>diff</span>',
270 responseHeaders: {'Content-Type': 'text/html'}});
271@@ -123,14 +138,28 @@
272 this.updater.get('diff'));
273 },
274
275- test_update_fires_event: function() {
276+ test_update_stats_success: function() {
277+ var mockio = new Y.lp.testing.mockio.MockIo();
278+ this.updater.get('lp_client').io_provider = mockio;
279+ Y.Assert.isNull(this.updater.get('diff_stats'));
280+ this.updater.update_stats();
281+ mockio.success({
282+ responseText: '13 lines (+4/-0) 1 file modified',
283+ responseHeaders: {'Content-Type': 'text/html'}});
284+
285+ Y.Assert.areEqual(
286+ '13 lines (+4/-0) 1 file modified',
287+ this.updater.get('diff_stats'));
288+ },
289+
290+ test_update_diff_fires_event: function() {
291 var fired = false;
292 var mockio = new Y.lp.testing.mockio.MockIo();
293 this.updater.get('lp_client').io_provider = mockio;
294 this.updater.on(this.updater.NAME + '.updated', function() {
295 fired = true;
296 });
297- this.updater.update();
298+ this.updater.update_diff();
299 mockio.success({
300 responseText: 'New <span>diff</span>',
301 responseHeaders: {'Content-Type': 'text/html'}});
302
303=== added file 'lib/lp/code/templates/branchmergeproposal-diff-stats.pt'
304--- lib/lp/code/templates/branchmergeproposal-diff-stats.pt 1970-01-01 00:00:00 +0000
305+++ lib/lp/code/templates/branchmergeproposal-diff-stats.pt 2012-01-03 15:53:28 +0000
306@@ -0,0 +1,7 @@
307+<tal:root
308+ xmlns:tal="http://xml.zope.org/namespaces/tal"
309+>
310+ <tal:diff replace="structure view/preview_diff/fmt:link"/>
311+ <pre tal:condition="view/preview_diff/has_conflicts"
312+ tal:content="view/preview_diff/conflicts"/>
313+</tal:root>
314
315=== modified file 'lib/lp/code/templates/branchmergeproposal-index.pt'
316--- lib/lp/code/templates/branchmergeproposal-index.pt 2011-12-08 12:40:18 +0000
317+++ lib/lp/code/templates/branchmergeproposal-index.pt 2012-01-03 15:53:28 +0000
318@@ -230,7 +230,10 @@
319
320 if (Y.Lang.isValue(LP.cache.merge_proposal_event_key)) {
321 var updater = new Y.lp.code.branchmergeproposal.updater.UpdaterWidget(
322- {srcNode: Y.one('#diff-area')});
323+ {
324+ srcNode: Y.one('#diff-area'),
325+ summary_node: Y.one('#proposal-summary')
326+ });
327 Y.on(LP.cache.merge_proposal_event_key, function(data) {
328 if (Y.lp.code.branchmergeproposal.updater.is_mp_diff_updated(data)) {
329 updater.update();
330
331=== modified file 'lib/lp/code/templates/branchmergeproposal-pagelet-summary.pt'
332--- lib/lp/code/templates/branchmergeproposal-pagelet-summary.pt 2010-12-30 19:37:29 +0000
333+++ lib/lp/code/templates/branchmergeproposal-pagelet-summary.pt 2012-01-03 15:53:28 +0000
334@@ -136,9 +136,7 @@
335 tal:condition="context/preview_diff">
336 <th>Diff against target:</th>
337 <td>
338- <tal:diff replace="structure context/preview_diff/fmt:link"/>
339- <pre tal:condition="context/preview_diff/has_conflicts"
340- tal:content="context/preview_diff/conflicts"/>
341+ <div tal:replace="structure context/@@++diff-stats" />
342 </td>
343 </tr>
344 <tr id="summary-row-merge-instruction">