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
=== modified file 'lib/canonical/launchpad/javascript/bugs/bugtask-index.js'
--- lib/canonical/launchpad/javascript/bugs/bugtask-index.js 2009-10-09 20:29:23 +0000
+++ lib/canonical/launchpad/javascript/bugs/bugtask-index.js 2009-10-16 08:32:15 +0000
@@ -37,6 +37,7 @@
37 'class="lazr-neg lazr-btn" >Cancel</button>';37 'class="lazr-neg lazr-btn" >Cancel</button>';
38var privacy_link;38var privacy_link;
39var privacy_spinner;39var privacy_spinner;
40var link_branch_link;
4041
41/*42/*
42 * An object representing the bugtask subscribers portlet.43 * An object representing the bugtask subscribers portlet.
@@ -125,9 +126,7 @@
125 return;126 return;
126 }127 }
127128
128 if (lp_client === undefined || bug_repr === undefined) {129 setup_client_and_bug();
129 setup_client_and_bug();
130 }
131130
132 // First look for 'Mark as duplicate' links.131 // First look for 'Mark as duplicate' links.
133 var update_dupe_links = Y.all('.menu-link-mark-dupe');132 var update_dupe_links = Y.all('.menu-link-mark-dupe');
@@ -211,6 +210,7 @@
211 privacy_link.addClass('js-action');210 privacy_link.addClass('js-action');
212 }211 }
213 setup_add_attachment();212 setup_add_attachment();
213 setup_link_branch_picker();
214 }, window);214 }, window);
215};215};
216216
@@ -268,10 +268,7 @@
268 return;268 return;
269 }269 }
270270
271 if (lp_client === undefined || bug_repr === undefined) {271 setup_client_and_bug();
272 setup_client_and_bug();
273 }
274
275 var subscription = new Y.lp.Subscription({272 var subscription = new Y.lp.Subscription({
276 link: Y.get('.menu-link-subscription'),273 link: Y.get('.menu-link-subscription'),
277 spinner: Y.get('#sub-unsub-spinner'),274 spinner: Y.get('#sub-unsub-spinner'),
@@ -567,6 +564,91 @@
567};564};
568565
569566
567/**
568 * Set up the link-a-related-branch picker.
569 */
570function setup_link_branch_picker() {
571 setup_client_and_bug();
572
573 var error_handler = new LP.client.ErrorHandler();
574
575 error_handler.clearProgressUI = function () {
576 link_branch_link.toggleClass('update-in-progress-message');
577 };
578 error_handler.showError = function(error_msg) {
579 display_error(Y.get('.menu-link-addsubscriber'), error_msg);
580 };
581
582 function get_branch_and_link_to_bug(data) {
583 var branch_url = data['api_uri'];
584 config = {
585 on: {
586 success: link_branch_to_bug,
587 failure: error_handler.getFailureHandler()
588 }
589 };
590
591 // Start the spinner and then grab the branch.
592 link_branch_link.toggleClass('update-in-progress-message');
593 lp_client.get(branch_url, config);
594 }
595
596 // Set up the picker itself.
597 link_branch_link = Y.get('.menu-link-addbranch');
598 if (Y.Lang.isValue(link_branch_link)) {
599 var config = {
600 header: 'Link a related branch',
601 step_title: 'Search'
602 };
603
604 var picker = Y.lp.picker.create(
605 'Branch', get_branch_and_link_to_bug, config);
606
607 // Clear results and search terms on cancel or save.
608 picker.on('save', clear_picker, picker);
609 picker.on('cancel', clear_picker, picker);
610
611 link_branch_link.on('click', function(e) {
612 e.halt();
613 picker.show();
614 });
615 link_branch_link.addClass('js-action');
616 }
617}
618
619/**
620 * Link a branch to the current bug.
621 * @param branch {Object} The branch to link to the bug, as returned by
622 * the Launchpad API.
623 */
624function link_branch_to_bug(branch) {
625 var error_handler = new LP.client.ErrorHandler();
626 error_handler.clearProgressUI = function () {
627 link_branch_link.toggleClass('update-in-progress-message');
628 };
629 error_handler.showError = function(error_msg) {
630 display_error(Y.get('.menu-link-addsubscriber'), error_msg);
631 };
632
633 // Call linkBranch() on the bug.
634 config = {
635 on: {
636 success: function(client) {
637 link_branch_link.toggleClass(
638 'update-in-progress-message');
639 anim.run();
640 },
641 failure: error_handler.getFailureHandler()
642 },
643 parameters: {
644 branch: branch.get('self_link')
645 }
646 };
647
648 lp_client.named_post(
649 lp_bug_entry.get('self_link'), 'linkBranch', config);
650}
651
570/*652/*
571 * Traverse the DOM of a given remove icon to find653 * Traverse the DOM of a given remove icon to find
572 * the user's link. Returns a URI of the form "/~username".654 * the user's link. Returns a URI of the form "/~username".
573655
=== 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-10-16 08:32:15 +0000
@@ -239,10 +239,7 @@
239239
240 def addbranch(self):240 def addbranch(self):
241 """Return the 'Add branch' Link."""241 """Return the 'Add branch' Link."""
242 if self.context.bug.linked_branches.count() > 0:242 text = 'Link a related branch'
243 text = 'Link another branch'
244 else:
245 text = 'Link a related branch'
246 return Link('+addbranch', text, icon='add')243 return Link('+addbranch', text, icon='add')
247244
248 def linktocve(self):245 def linktocve(self):
249246
=== 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-10-16 08:32:15 +0000
@@ -36,17 +36,6 @@
36 lp://dev/~name12/firefox/main (Development)36 lp://dev/~name12/firefox/main (Development)
37 ...37 ...
3838
39The text "Link a related branch" has now changed to "Link another branch".
40
41 >>> user_browser.getLink('Link a related branch')
42 Traceback (most recent call last):
43 ...
44 LinkNotFoundError
45
46 >>> user_browser.getLink('Link another branch')
47 <Link text='Link another branch'
48 url='http://bugs.launchpad.dev/firefox/+bug/1/+addbranch'>
49
50We can delete existing links between a bug and a branch.39We can delete existing links between a bug and a branch.
5140
52 >>> delete_branch_link_url = (41 >>> delete_branch_link_url = (

Subscribers

People subscribed via source and target branches

to status/vote changes: