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
1=== modified file 'lib/canonical/launchpad/javascript/code/branchlinks.js'
2--- lib/canonical/launchpad/javascript/code/branchlinks.js 2009-07-14 06:10:05 +0000
3+++ lib/canonical/launchpad/javascript/code/branchlinks.js 2009-07-28 18:25:15 +0000
4@@ -14,6 +14,9 @@
5
6 var link_bug_overlay;
7
8+/*
9+ * Connect the links to the javascript events.
10+ */
11 Y.branchlinks.connect_branchlinks = function() {
12
13 link_bug_overlay = new Y.lazr.FormOverlay({
14@@ -53,6 +56,10 @@
15
16 };
17
18+/*
19+ * Connect the remove links of each bug link to the javascript functions to
20+ * remove the links.
21+ */
22 function connect_remove_links() {
23 var linked_bugs = Y.all('.delete-buglink');
24 if (Y.Lang.isValue(linked_bugs)) {
25@@ -64,6 +71,9 @@
26 }
27 }
28
29+/*
30+ * Link a specified bug to the branch.
31+ */
32 function link_bug_to_branch(data) {
33 link_bug_overlay.hide();
34
35@@ -88,7 +98,7 @@
36 var config = {
37 on: {
38 success: function(bugtasks) {
39- add_html_bug(bug, bugtasks);
40+ update_bug_links(bug);
41 }
42 }
43 };
44@@ -109,6 +119,39 @@
45 });
46 }
47
48+/*
49+ * Update the list of bug links.
50+ */
51+function update_bug_links(bug) {
52+
53+ BUG_LINK_SNIPPET = '++bug-links';
54+ Y.io(BUG_LINK_SNIPPET, {
55+ on: {
56+ success: function(id, response) {
57+ destroy_temporary_spinner();
58+ Y.get('#linkbug').set(
59+ 'innerHTML', 'Link to another bug report');
60+ Y.get('#buglink-list').set('innerHTML', response.responseText);
61+ var new_buglink = Y.get('#buglink-' + bug.get('id'));
62+ var anim = Y.lazr.anim.green_flash({node: new_buglink});
63+ anim.on('end', connect_remove_links);
64+ anim.run();
65+ },
66+ failure: function(id, response) {
67+ // At least remove the "Linking..." text
68+ destroy_temporary_spinner();
69+
70+ alert('Unable to update bug links.');
71+ Y.log(response);
72+ }
73+ }
74+ });
75+
76+}
77+
78+/*
79+ * Unlink a bug from the branch.
80+ */
81 function unlink_bug_from_branch(bugnumber) {
82 link_bug_overlay.hide();
83
84@@ -191,52 +234,6 @@
85 }
86 }
87
88-
89-function add_html_bug(bug, bugtasks) {
90-
91- var bugnumber = parseInt(bug.get('id'), 10);
92- var bugtitle = bug.get('title').replace('<', '&lt;').replace('>', '&gt;');
93- var bugimportance = bugtasks.entries[0].importance;
94- var bugstatus = bugtasks.entries[0].status;
95-
96- var text = [
97- '<div id="buglink-' + bugnumber + '">',
98- '<div class="bug-branch-summary">',
99- '<a href="https://bugs.launchpad.dev/bug/' + bugnumber + '"',
100- 'class="sprite bug-' + bugimportance.toLowerCase() + '">',
101- 'Bug #' + bugnumber + ': ' + bugtitle,
102- '</a> ',
103- '(<span class="importance' + bugimportance.toUpperCase() + '">',
104- bugimportance + '</span> &ndash;',
105- '<span class="status' + bugstatus.toUpperCase(),
106- '">' + bugstatus + '</span>)',
107- '<a title="Remove link" class="delete-buglink" href="+bug/',
108- bugnumber + '/+delete"',
109- 'id="delete-buglink-' + bugnumber + '">',
110- '<img src="/@@/remove" />',
111- '</a>',
112- '</div>',
113- '</div>'].join('');
114- var new_buglink = Y.Node.create(text);
115-
116- var buglinks = Y.get('#buglinks');
117- var last = Y.get('#linkbug').get('parentNode');
118- if (last) {
119- buglinks.insertBefore(new_buglink, last);
120- }
121-
122- var temp_spinner = Y.get('#temp-spinner');
123- var spinner_parent = temp_spinner.get('parentNode');
124- spinner_parent.removeChild(temp_spinner);
125-
126- anim = Y.lazr.anim.green_flash({node: new_buglink});
127- anim.run();
128- connect_remove_links();
129- Y.get("[id='field.bug']").set('value', '');
130- Y.get('#linkbug').set('innerHTML', 'Link to another bug');
131-}
132-
133-
134 /*
135 * Show the temporary "Linking..." text
136 */
137@@ -252,5 +249,15 @@
138 }
139 }
140
141+/*
142+ * Destroy the temporary "Linking..." text
143+ */
144+function destroy_temporary_spinner() {
145+
146+ var temp_spinner = Y.get('#temp-spinner');
147+ var spinner_parent = temp_spinner.get('parentNode');
148+ spinner_parent.removeChild(temp_spinner);
149+
150+}
151
152 }, '0.1', {requires: ['base', 'lazr.anim', 'lazr.formoverlay']});
153
154=== modified file 'lib/canonical/launchpad/pagetitles.py'
155--- lib/canonical/launchpad/pagetitles.py 2009-07-17 00:26:05 +0000
156+++ lib/canonical/launchpad/pagetitles.py 2009-07-28 16:36:26 +0000
157@@ -170,6 +170,8 @@
158 branch_associations = ContextDisplayName(smartquote(
159 '"%s" branch associations'))
160
161+branch_bug_links = ContextDisplayName(smartquote('Bug links for %s'))
162+
163 branch_delete = ContextDisplayName(smartquote('Delete branch "%s"'))
164
165 branch_edit = ContextDisplayName(smartquote('Change "%s" branch details'))
166
167=== modified file 'lib/lp/code/browser/configure.zcml'
168--- lib/lp/code/browser/configure.zcml 2009-07-17 00:26:05 +0000
169+++ lib/lp/code/browser/configure.zcml 2009-07-28 16:36:26 +0000
170@@ -347,6 +347,9 @@
171 <browser:page
172 name="+merges"
173 template="../templates/branch-merges.pt"/>
174+ <browser:page
175+ name="++bug-links"
176+ template="../templates/branch-bug-links.pt"/>
177 </browser:pages>
178 <browser:pages
179 for="lp.code.interfaces.branch.IBranch"
180
181=== added file 'lib/lp/code/templates/branch-bug-links.pt'
182--- lib/lp/code/templates/branch-bug-links.pt 1970-01-01 00:00:00 +0000
183+++ lib/lp/code/templates/branch-bug-links.pt 2009-07-28 16:36:26 +0000
184@@ -0,0 +1,11 @@
185+<div
186+ xmlns:tal="http://xml.zope.org/namespaces/tal"
187+ xmlns:metal="http://xml.zope.org/namespaces/metal"
188+ xmlns:i18n="http://xml.zope.org/namespaces/i18n">
189+
190+ <tal:bugs tal:define="branch context;
191+ show_edit python:True;">
192+ <metal:bug-branch-links use-macro="context/@@+macros/bug-branch-links"/>
193+ </tal:bugs>
194+
195+</div>
196
197=== modified file 'lib/lp/code/templates/branch-index.pt'
198--- lib/lp/code/templates/branch-index.pt 2009-07-17 17:59:07 +0000
199+++ lib/lp/code/templates/branch-index.pt 2009-07-28 18:25:15 +0000
200@@ -398,10 +398,12 @@
201 <div id="related-bugs-and-blueprints">
202 <h2>Linked bug reports and blueprints</h2>
203 <div id="buglinks" class="actions">
204- <tal:bugs tal:define="branch context;
205- show_edit python:True;">
206- <metal:bug-branch-links use-macro="context/@@+macros/bug-branch-links"/>
207- </tal:bugs>
208+ <div id="buglink-list">
209+ <tal:bugs tal:define="branch context;
210+ show_edit python:True;">
211+ <metal:bug-branch-links use-macro="context/@@+macros/bug-branch-links"/>
212+ </tal:bugs>
213+ </div>
214
215 <div
216 tal:define="link context_menu/link_bug"