Merge lp:~rockstar/launchpad/fix-launchpad-dev into lp:launchpad

Proposed by Paul Hummer
Status: Merged
Merged at revision: not available
Proposed branch: lp:~rockstar/launchpad/fix-launchpad-dev
Merge into: lp:launchpad
Diff against target: None lines
To merge this branch: bzr merge lp:~rockstar/launchpad/fix-launchpad-dev
Reviewer Review Type Date Requested Status
Deryck Hodge (community) Approve
Review via email: mp+9387@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Paul Hummer (rockstar) wrote :

This branch fixes bug #403839 - There was a launchpad.dev link being generated
by the javascript.

I could've just fixed the HTML being generated, but I thought I'd rather
experiment with dealing with entire page fragments. The UI is exactly the same
as before (sans the bugfix), but this way, I'm not duplicating HTML.

The way that I do this is subject to change, as I have two more branches to
play around with this idea. I've chatted with a few people about this, and
each fragment implementation has different pros/cons, and I'd like to find the
easiest to follow, and metal macros are not the easiest.

To test, run the windmill tests in lp/code/windmill/test_branch_links.py

 reviewer deryck

Cheers,
Paul

Revision history for this message
Deryck Hodge (deryck) wrote :

Hi, Paul.

As we discussed on IRC, I think you need better error handling
here that just an alert since you have two-levels of XHR success
callbacks. I think you should make use of LP.client.ErrorHandler.
Our style guide also calls for JSDoc comments, so the comments need
updating throughout.

I'm marking this "Approve" based on these things being done, and since
otherwise, this code looks really nice. I like the approach you've
taken here! I do like the way you can build HTML in TAL. It makes
for more readable JS code, certainly.

Cheers,
deryck

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'lib/canonical/launchpad/javascript/code/branchlinks.js'
--- lib/canonical/launchpad/javascript/code/branchlinks.js 2009-07-14 06:10:05 +0000
+++ lib/canonical/launchpad/javascript/code/branchlinks.js 2009-07-28 18:25:15 +0000
@@ -14,6 +14,9 @@
1414
15var link_bug_overlay;15var link_bug_overlay;
1616
17/*
18 * Connect the links to the javascript events.
19 */
17Y.branchlinks.connect_branchlinks = function() {20Y.branchlinks.connect_branchlinks = function() {
1821
19 link_bug_overlay = new Y.lazr.FormOverlay({22 link_bug_overlay = new Y.lazr.FormOverlay({
@@ -53,6 +56,10 @@
5356
54};57};
5558
59/*
60 * Connect the remove links of each bug link to the javascript functions to
61 * remove the links.
62 */
56function connect_remove_links() {63function connect_remove_links() {
57 var linked_bugs = Y.all('.delete-buglink');64 var linked_bugs = Y.all('.delete-buglink');
58 if (Y.Lang.isValue(linked_bugs)) {65 if (Y.Lang.isValue(linked_bugs)) {
@@ -64,6 +71,9 @@
64 }71 }
65}72}
6673
74/*
75 * Link a specified bug to the branch.
76 */
67function link_bug_to_branch(data) {77function link_bug_to_branch(data) {
68 link_bug_overlay.hide();78 link_bug_overlay.hide();
6979
@@ -88,7 +98,7 @@
88 var config = {98 var config = {
89 on: {99 on: {
90 success: function(bugtasks) {100 success: function(bugtasks) {
91 add_html_bug(bug, bugtasks);101 update_bug_links(bug);
92 }102 }
93 }103 }
94 };104 };
@@ -109,6 +119,39 @@
109 });119 });
110}120}
111121
122/*
123 * Update the list of bug links.
124 */
125function update_bug_links(bug) {
126
127 BUG_LINK_SNIPPET = '++bug-links';
128 Y.io(BUG_LINK_SNIPPET, {
129 on: {
130 success: function(id, response) {
131 destroy_temporary_spinner();
132 Y.get('#linkbug').set(
133 'innerHTML', 'Link to another bug report');
134 Y.get('#buglink-list').set('innerHTML', response.responseText);
135 var new_buglink = Y.get('#buglink-' + bug.get('id'));
136 var anim = Y.lazr.anim.green_flash({node: new_buglink});
137 anim.on('end', connect_remove_links);
138 anim.run();
139 },
140 failure: function(id, response) {
141 // At least remove the "Linking..." text
142 destroy_temporary_spinner();
143
144 alert('Unable to update bug links.');
145 Y.log(response);
146 }
147 }
148 });
149
150}
151
152/*
153 * Unlink a bug from the branch.
154 */
112function unlink_bug_from_branch(bugnumber) {155function unlink_bug_from_branch(bugnumber) {
113 link_bug_overlay.hide();156 link_bug_overlay.hide();
114157
@@ -191,52 +234,6 @@
191 }234 }
192}235}
193236
194
195function add_html_bug(bug, bugtasks) {
196
197 var bugnumber = parseInt(bug.get('id'), 10);
198 var bugtitle = bug.get('title').replace('<', '&lt;').replace('>', '&gt;');
199 var bugimportance = bugtasks.entries[0].importance;
200 var bugstatus = bugtasks.entries[0].status;
201
202 var text = [
203 '<div id="buglink-' + bugnumber + '">',
204 '<div class="bug-branch-summary">',
205 '<a href="https://bugs.launchpad.dev/bug/' + bugnumber + '"',
206 'class="sprite bug-' + bugimportance.toLowerCase() + '">',
207 'Bug #' + bugnumber + ': ' + bugtitle,
208 '</a> ',
209 '(<span class="importance' + bugimportance.toUpperCase() + '">',
210 bugimportance + '</span> &ndash;',
211 '<span class="status' + bugstatus.toUpperCase(),
212 '">' + bugstatus + '</span>)',
213 '<a title="Remove link" class="delete-buglink" href="+bug/',
214 bugnumber + '/+delete"',
215 'id="delete-buglink-' + bugnumber + '">',
216 '<img src="/@@/remove" />',
217 '</a>',
218 '</div>',
219 '</div>'].join('');
220 var new_buglink = Y.Node.create(text);
221
222 var buglinks = Y.get('#buglinks');
223 var last = Y.get('#linkbug').get('parentNode');
224 if (last) {
225 buglinks.insertBefore(new_buglink, last);
226 }
227
228 var temp_spinner = Y.get('#temp-spinner');
229 var spinner_parent = temp_spinner.get('parentNode');
230 spinner_parent.removeChild(temp_spinner);
231
232 anim = Y.lazr.anim.green_flash({node: new_buglink});
233 anim.run();
234 connect_remove_links();
235 Y.get("[id='field.bug']").set('value', '');
236 Y.get('#linkbug').set('innerHTML', 'Link to another bug');
237}
238
239
240/*237/*
241 * Show the temporary "Linking..." text238 * Show the temporary "Linking..." text
242 */239 */
@@ -252,5 +249,15 @@
252 }249 }
253}250}
254251
252/*
253 * Destroy the temporary "Linking..." text
254 */
255function destroy_temporary_spinner() {
256
257 var temp_spinner = Y.get('#temp-spinner');
258 var spinner_parent = temp_spinner.get('parentNode');
259 spinner_parent.removeChild(temp_spinner);
260
261}
255262
256}, '0.1', {requires: ['base', 'lazr.anim', 'lazr.formoverlay']});263}, '0.1', {requires: ['base', 'lazr.anim', 'lazr.formoverlay']});
257264
=== modified file 'lib/canonical/launchpad/pagetitles.py'
--- lib/canonical/launchpad/pagetitles.py 2009-07-17 00:26:05 +0000
+++ lib/canonical/launchpad/pagetitles.py 2009-07-28 16:36:26 +0000
@@ -170,6 +170,8 @@
170branch_associations = ContextDisplayName(smartquote(170branch_associations = ContextDisplayName(smartquote(
171 '"%s" branch associations'))171 '"%s" branch associations'))
172172
173branch_bug_links = ContextDisplayName(smartquote('Bug links for %s'))
174
173branch_delete = ContextDisplayName(smartquote('Delete branch "%s"'))175branch_delete = ContextDisplayName(smartquote('Delete branch "%s"'))
174176
175branch_edit = ContextDisplayName(smartquote('Change "%s" branch details'))177branch_edit = ContextDisplayName(smartquote('Change "%s" branch details'))
176178
=== modified file 'lib/lp/code/browser/configure.zcml'
--- lib/lp/code/browser/configure.zcml 2009-07-17 00:26:05 +0000
+++ lib/lp/code/browser/configure.zcml 2009-07-28 16:36:26 +0000
@@ -347,6 +347,9 @@
347 <browser:page347 <browser:page
348 name="+merges"348 name="+merges"
349 template="../templates/branch-merges.pt"/>349 template="../templates/branch-merges.pt"/>
350 <browser:page
351 name="++bug-links"
352 template="../templates/branch-bug-links.pt"/>
350 </browser:pages>353 </browser:pages>
351 <browser:pages354 <browser:pages
352 for="lp.code.interfaces.branch.IBranch"355 for="lp.code.interfaces.branch.IBranch"
353356
=== added file 'lib/lp/code/templates/branch-bug-links.pt'
--- lib/lp/code/templates/branch-bug-links.pt 1970-01-01 00:00:00 +0000
+++ lib/lp/code/templates/branch-bug-links.pt 2009-07-28 16:36:26 +0000
@@ -0,0 +1,11 @@
1<div
2 xmlns:tal="http://xml.zope.org/namespaces/tal"
3 xmlns:metal="http://xml.zope.org/namespaces/metal"
4 xmlns:i18n="http://xml.zope.org/namespaces/i18n">
5
6 <tal:bugs tal:define="branch context;
7 show_edit python:True;">
8 <metal:bug-branch-links use-macro="context/@@+macros/bug-branch-links"/>
9 </tal:bugs>
10
11</div>
012
=== modified file 'lib/lp/code/templates/branch-index.pt'
--- lib/lp/code/templates/branch-index.pt 2009-07-17 17:59:07 +0000
+++ lib/lp/code/templates/branch-index.pt 2009-07-28 18:25:15 +0000
@@ -398,10 +398,12 @@
398 <div id="related-bugs-and-blueprints">398 <div id="related-bugs-and-blueprints">
399 <h2>Linked bug reports and blueprints</h2>399 <h2>Linked bug reports and blueprints</h2>
400 <div id="buglinks" class="actions">400 <div id="buglinks" class="actions">
401 <tal:bugs tal:define="branch context;401 <div id="buglink-list">
402 show_edit python:True;">402 <tal:bugs tal:define="branch context;
403 <metal:bug-branch-links use-macro="context/@@+macros/bug-branch-links"/>403 show_edit python:True;">
404 </tal:bugs>404 <metal:bug-branch-links use-macro="context/@@+macros/bug-branch-links"/>
405 </tal:bugs>
406 </div>
405407
406 <div408 <div
407 tal:define="link context_menu/link_bug"409 tal:define="link context_menu/link_bug"