Merge lp:~gmb/launchpad/ajaxify-branch-linking into lp:launchpad/db-devel

Proposed by Graham Binns
Status: Merged
Approved by: Eleanor Berger
Approved revision: no longer in the source branch.
Merged at revision: not available
Proposed branch: lp:~gmb/launchpad/ajaxify-branch-linking
Merge into: lp:launchpad/db-devel
Diff against target: 172 lines
3 files modified
lib/canonical/launchpad/javascript/bugs/bugtask-index.js (+89/-7)
lib/lp/bugs/browser/bug.py (+1/-4)
lib/lp/bugs/stories/bugs/xx-link-bug-to-branch.txt (+0/-11)
To merge this branch: bzr merge lp:~gmb/launchpad/ajaxify-branch-linking
Reviewer Review Type Date Requested Status
Canonical Launchpad Engineering Pending
Review via email: mp+12514@code.launchpad.net

Commit message

It's now possible to link a branch to a bug inline.

To post a comment you must log in.
Revision history for this message
Graham Binns (gmb) wrote :

This branch ajaxifies the "Link a related branch" action on the bug page.

Note that this branch does *not* update the list of linked branches; that's a subsequent branch that's currently in progress but needs more work.

Revision history for this message
Graham Binns (gmb) wrote :
Download full text (3.9 KiB)

Here's the actual diff:

=== modified file 'lib/canonical/launchpad/javascript/bugs/bugtask-index.js'
--- lib/canonical/launchpad/javascript/bugs/bugtask-index.js 2009-09-22 11:46:49 +0000
+++ lib/canonical/launchpad/javascript/bugs/bugtask-index.js 2009-09-28 10:35:09 +0000
@@ -37,6 +37,7 @@
     'class="lazr-neg lazr-btn" >Cancel</button>';
 var privacy_link;
 var privacy_spinner;
+var link_branch_link;

 /*
  * An object representing the bugtask subscribers portlet.
@@ -210,9 +211,11 @@
             });
             privacy_link.addClass('js-action');
         }
+
         create_error_overlay();
         setup_inline_commenting();
         setup_add_attachment();
+ setup_link_branch_picker();
     }, window);
 };

@@ -627,6 +630,101 @@
     }
 }

+/**
+ * Set up the link-a-related-branch picker.
+ */
+function setup_link_branch_picker() {
+ if (lp_client === undefined || bug_repr === undefined) {
+ setup_client_and_bug();
+ }
+
+ var error_handler = new LP.client.ErrorHandler();
+
+ error_handler.clearProgressUI = function () {
+ link_branch_link.toggleClass('update-in-progress-message');
+ };
+ error_handler.showError = function(error_msg) {
+ display_error(Y.get('.menu-link-addsubscriber'), error_msg);
+ };
+
+ function get_branch_and_link_to_bug(data) {
+ var branch_url = data['api_uri'];
+ config = {
+ on: {
+ success: link_branch_to_bug,
+ failure: error_handler.getFailureHandler()
+ }
+ };
+
+ // Start the spinner and then grab the branch.
+ link_branch_link.toggleClass('update-in-progress-message');
+ lp_client.get(branch_url, config);
+ }
+
+ // Set up the picker itself.
+ link_branch_link = Y.get('.menu-link-addbranch');
+ if (Y.Lang.isValue(link_branch_link)) {
+ var config = {
+ header: 'Link a related branch',
+ step_title: 'Search'
+ };
+
+ var picker = Y.lp.picker.create(
+ 'Branch', get_branch_and_link_to_bug, config);
+
+ // Clear results and search terms on cancel or save.
+ picker.on('save', clear_picker, picker);
+ picker.on('cancel', clear_picker, picker);
+
+ link_branch_link.on('click', function(e) {
+ e.halt();
+ picker.show();
+ });
+ link_branch_link.addClass('js-action');
+ }
+}
+
+/**
+ * Link a branch to the current bug.
+ * @param branch {Object} The branch to link to the bug, as returned by
+ * the Launchpad API.
+ */
+function link_branch_to_bug(branch) {
+ var error_handler = new LP.client.ErrorHandler();
+ error_handler.clearProgressUI = function () {
+ link_branch_link.toggleClass('update-in-progress-message');
+ };
+ error_handler.showError = function(error_msg) {
+ display_error(Y.get('.menu-link-addsubscriber'), error_msg);
+ };
+
+ // Call linkBranch() on the bug and flash the 'add a branch' link
+ // accordingly.
+ config = {
+ on: {
+ success: function(client) {
+ // Show the green flash anim to say the action
+ // ...

Read more...

Revision history for this message
Graham Binns (gmb) wrote :

Incremental diff of changes:

=== modified file 'lib/canonical/launchpad/javascript/bugs/bugtask-index.js'
--- lib/canonical/launchpad/javascript/bugs/bugtask-index.js 2009-09-28 10:02:35 +0000
+++ lib/canonical/launchpad/javascript/bugs/bugtask-index.js 2009-09-28 11:01:30 +0000
@@ -634,14 +634,8 @@
  * Set up the link-a-related-branch picker.
  */
 function setup_link_branch_picker() {
- if (lp_client === undefined) {
- lp_client = new LP.client.Launchpad();
- }
-
- if (lp_bug_entry === undefined) {
- var bug_repr = LP.client.cache.bug;
- lp_bug_entry = new LP.client.Entry(
- lp_client, bug_repr, bug_repr.self_link);
+ if (lp_client === undefined || bug_repr === undefined) {
+ setup_client_and_bug();
     }

     var error_handler = new LP.client.ErrorHandler();
@@ -704,21 +698,13 @@
         display_error(Y.get('.menu-link-addsubscriber'), error_msg);
     };

- // Call linkBranch() on the bug and flash the 'add a branch' link
- // accordingly.
+ // Call linkBranch() on the bug.
     config = {
         on: {
             success: function(client) {
- // Show the green flash anim to say the action
- // has completed.
- var anim = Y.lazr.anim.green_flash(
- {node: link_branch_link});
- anim.on('end', function(e) {
- link_branch_link.toggleClass(
- 'update-in-progress-message');
- });
+ link_branch_link.toggleClass(
+ 'update-in-progress-message');
                 anim.run();
- link_branch_link.set('innerHTML', 'Link another branch');
             },
             failure: error_handler.getFailureHandler()
         },

=== modified file 'lib/lp/bugs/browser/bug.py'
--- lib/lp/bugs/browser/bug.py 2009-09-18 22:46:33 +0000
+++ lib/lp/bugs/browser/bug.py 2009-09-28 11:01:30 +0000
@@ -239,10 +239,7 @@

     def addbranch(self):
         """Return the 'Add branch' Link."""
- if self.context.bug.linked_branches.count() > 0:
- text = 'Link another branch'
- else:
- text = 'Link a related branch'
+ text = 'Link a related branch'
         return Link('+addbranch', text, icon='add')

     def linktocve(self):

=== modified file 'lib/lp/bugs/stories/bugs/xx-link-bug-to-branch.txt'
--- lib/lp/bugs/stories/bugs/xx-link-bug-to-branch.txt 2009-09-18 22:46:33 +0000
+++ lib/lp/bugs/stories/bugs/xx-link-bug-to-branch.txt 2009-09-28 11:01:30 +0000
@@ -36,17 +36,6 @@
     lp://dev/~name12/firefox/main (Development)
     ...

-The text "Link a related branch" has now changed to "Link another branch".
-
- >>> user_browser.getLink('Link a related branch')
- Traceback (most recent call last):
- ...
- LinkNotFoundError
-
- >>> user_browser.getLink('Link another branch')
- <Link text='Link another branch'
- url='http://bugs.launchpad.dev/firefox/+bug/1/+addbranch'>
-
 We can delete existing links between a bug and a branch.

     >>> delete_branch_link_url = (

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/canonical/launchpad/javascript/bugs/bugtask-index.js'
2--- lib/canonical/launchpad/javascript/bugs/bugtask-index.js 2009-10-09 20:29:23 +0000
3+++ lib/canonical/launchpad/javascript/bugs/bugtask-index.js 2009-10-16 08:32:15 +0000
4@@ -37,6 +37,7 @@
5 'class="lazr-neg lazr-btn" >Cancel</button>';
6 var privacy_link;
7 var privacy_spinner;
8+var link_branch_link;
9
10 /*
11 * An object representing the bugtask subscribers portlet.
12@@ -125,9 +126,7 @@
13 return;
14 }
15
16- if (lp_client === undefined || bug_repr === undefined) {
17- setup_client_and_bug();
18- }
19+ setup_client_and_bug();
20
21 // First look for 'Mark as duplicate' links.
22 var update_dupe_links = Y.all('.menu-link-mark-dupe');
23@@ -211,6 +210,7 @@
24 privacy_link.addClass('js-action');
25 }
26 setup_add_attachment();
27+ setup_link_branch_picker();
28 }, window);
29 };
30
31@@ -268,10 +268,7 @@
32 return;
33 }
34
35- if (lp_client === undefined || bug_repr === undefined) {
36- setup_client_and_bug();
37- }
38-
39+ setup_client_and_bug();
40 var subscription = new Y.lp.Subscription({
41 link: Y.get('.menu-link-subscription'),
42 spinner: Y.get('#sub-unsub-spinner'),
43@@ -567,6 +564,91 @@
44 };
45
46
47+/**
48+ * Set up the link-a-related-branch picker.
49+ */
50+function setup_link_branch_picker() {
51+ setup_client_and_bug();
52+
53+ var error_handler = new LP.client.ErrorHandler();
54+
55+ error_handler.clearProgressUI = function () {
56+ link_branch_link.toggleClass('update-in-progress-message');
57+ };
58+ error_handler.showError = function(error_msg) {
59+ display_error(Y.get('.menu-link-addsubscriber'), error_msg);
60+ };
61+
62+ function get_branch_and_link_to_bug(data) {
63+ var branch_url = data['api_uri'];
64+ config = {
65+ on: {
66+ success: link_branch_to_bug,
67+ failure: error_handler.getFailureHandler()
68+ }
69+ };
70+
71+ // Start the spinner and then grab the branch.
72+ link_branch_link.toggleClass('update-in-progress-message');
73+ lp_client.get(branch_url, config);
74+ }
75+
76+ // Set up the picker itself.
77+ link_branch_link = Y.get('.menu-link-addbranch');
78+ if (Y.Lang.isValue(link_branch_link)) {
79+ var config = {
80+ header: 'Link a related branch',
81+ step_title: 'Search'
82+ };
83+
84+ var picker = Y.lp.picker.create(
85+ 'Branch', get_branch_and_link_to_bug, config);
86+
87+ // Clear results and search terms on cancel or save.
88+ picker.on('save', clear_picker, picker);
89+ picker.on('cancel', clear_picker, picker);
90+
91+ link_branch_link.on('click', function(e) {
92+ e.halt();
93+ picker.show();
94+ });
95+ link_branch_link.addClass('js-action');
96+ }
97+}
98+
99+/**
100+ * Link a branch to the current bug.
101+ * @param branch {Object} The branch to link to the bug, as returned by
102+ * the Launchpad API.
103+ */
104+function link_branch_to_bug(branch) {
105+ var error_handler = new LP.client.ErrorHandler();
106+ error_handler.clearProgressUI = function () {
107+ link_branch_link.toggleClass('update-in-progress-message');
108+ };
109+ error_handler.showError = function(error_msg) {
110+ display_error(Y.get('.menu-link-addsubscriber'), error_msg);
111+ };
112+
113+ // Call linkBranch() on the bug.
114+ config = {
115+ on: {
116+ success: function(client) {
117+ link_branch_link.toggleClass(
118+ 'update-in-progress-message');
119+ anim.run();
120+ },
121+ failure: error_handler.getFailureHandler()
122+ },
123+ parameters: {
124+ branch: branch.get('self_link')
125+ }
126+ };
127+
128+ lp_client.named_post(
129+ lp_bug_entry.get('self_link'), 'linkBranch', config);
130+}
131+
132 /*
133 * Traverse the DOM of a given remove icon to find
134 * the user's link. Returns a URI of the form "/~username".
135
136=== modified file 'lib/lp/bugs/browser/bug.py'
137--- lib/lp/bugs/browser/bug.py 2009-09-18 22:46:33 +0000
138+++ lib/lp/bugs/browser/bug.py 2009-10-16 08:32:15 +0000
139@@ -239,10 +239,7 @@
140
141 def addbranch(self):
142 """Return the 'Add branch' Link."""
143- if self.context.bug.linked_branches.count() > 0:
144- text = 'Link another branch'
145- else:
146- text = 'Link a related branch'
147+ text = 'Link a related branch'
148 return Link('+addbranch', text, icon='add')
149
150 def linktocve(self):
151
152=== modified file 'lib/lp/bugs/stories/bugs/xx-link-bug-to-branch.txt'
153--- lib/lp/bugs/stories/bugs/xx-link-bug-to-branch.txt 2009-09-18 22:46:33 +0000
154+++ lib/lp/bugs/stories/bugs/xx-link-bug-to-branch.txt 2009-10-16 08:32:15 +0000
155@@ -36,17 +36,6 @@
156 lp://dev/~name12/firefox/main (Development)
157 ...
158
159-The text "Link a related branch" has now changed to "Link another branch".
160-
161- >>> user_browser.getLink('Link a related branch')
162- Traceback (most recent call last):
163- ...
164- LinkNotFoundError
165-
166- >>> user_browser.getLink('Link another branch')
167- <Link text='Link another branch'
168- url='http://bugs.launchpad.dev/firefox/+bug/1/+addbranch'>
169-
170 We can delete existing links between a bug and a branch.
171
172 >>> delete_branch_link_url = (

Subscribers

People subscribed via source and target branches

to status/vote changes: