Merge lp:~rharding/launchpad/1024866_buglink into lp:launchpad

Proposed by Richard Harding
Status: Merged
Approved by: Richard Harding
Approved revision: no longer in the source branch.
Merged at revision: 15632
Proposed branch: lp:~rharding/launchpad/1024866_buglink
Merge into: lp:launchpad
Diff against target: 127 lines (+43/-11)
5 files modified
lib/lp/app/javascript/listing_navigator.js (+18/-2)
lib/lp/app/javascript/tests/test_listing_navigator.js (+20/-6)
lib/lp/bugs/javascript/buglisting.js (+1/-1)
lib/lp/bugs/javascript/tests/test_buglisting.js (+3/-1)
lib/lp/registry/javascript/sharing/shareetable.js (+1/-1)
To merge this branch: bzr merge lp:~rharding/launchpad/1024866_buglink
Reviewer Review Type Date Requested Status
Benji York (community) code Approve
Review via email: mp+115117@code.launchpad.net

Commit message

Fixes 1024866 to limit listing navigator selector scope.

Description of the change

= Summary =

There was an update to the portlet html that the bug listing code ended up
grabbing html from the portlet and trying to turn it into nex/prev links. This
corrects that.

== Implementation Notes ==

This adds helpers to the listing navigator to add a parent node to limit work
within replacing usage of Y.one/all with it's own version.

== Tests ==

test_listing_navigator.js

== LoC Qualification ==

I've got a small credit from recent YUI 3.5 work see branch:

https://code.launchpad.net/~rharding/launchpad/soyuz_yui35

To post a comment you must log in.
Revision history for this message
Benji York (benji) wrote :

Looks good.

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/app/javascript/listing_navigator.js'
2--- lib/lp/app/javascript/listing_navigator.js 2012-06-27 14:09:43 +0000
3+++ lib/lp/app/javascript/listing_navigator.js 2012-07-16 18:00:36 +0000
4@@ -28,6 +28,22 @@
5 return url.substr(0, cut_at - 1);
6 }
7
8+
9+/**
10+ * Generate selector helpers so that we only find nodes within our own
11+ * UI.
12+ */
13+module.one = function (parent, selector) {
14+ var updated_selector = parent + " " + selector;
15+ return Y.one(updated_selector);
16+};
17+
18+module.all = function (parent, selector) {
19+ var updated_selector = parent + " " + selector;
20+ return Y.all(updated_selector);
21+};
22+
23+
24 /**
25 * Constructor.
26 *
27@@ -520,9 +536,9 @@
28 * Rewrite all nodes with navigation classes so that they are hyperlinks.
29 * Content is retained.
30 */
31-module.linkify_navigation = function() {
32+module.linkify_navigation = function(parent_selector) {
33 Y.each(['previous', 'next', 'first', 'last'], function(class_name) {
34- Y.all('.' + class_name).each(function(node) {
35+ module.all(parent_selector, '.' + class_name).each(function(node) {
36 new_node = Y.Node.create('<a href="#"></a>');
37 new_node.addClass(class_name);
38 new_node.setContent(node.getContent());
39
40=== modified file 'lib/lp/app/javascript/tests/test_listing_navigator.js'
41--- lib/lp/app/javascript/tests/test_listing_navigator.js 2012-06-27 20:04:57 +0000
42+++ lib/lp/app/javascript/tests/test_listing_navigator.js 2012-07-16 18:00:36 +0000
43@@ -181,22 +181,36 @@
44 */
45 test_linkify_navigation: function() {
46 Y.one('#fixture').setContent(
47+ '<span id="notme" class="first"></span>' +
48+ '<div id="bugs-table-listing">' +
49 '<span class="previous">PreVious</span>' +
50 '<span class="next">NeXt</span>' +
51 '<span class="first">FiRST</span>' +
52- '<span class="last">lAst</span>');
53- module.linkify_navigation();
54+ '<span class="last">lAst</span>' +
55+ '</div>');
56+ module.linkify_navigation('#bugs-table-listing');
57 function checkNav(selector, content) {
58- var node = Y.one(selector);
59- Y.Assert.areEqual('a', node.get('tagName').toLowerCase());
60- Y.Assert.areEqual(content, node.getContent());
61- Y.Assert.areEqual('#', node.get('href').substr(-1, 1));
62+ var nodelist = Y.all(selector);
63+ nodelist.each(function (node) {
64+ if (node.get('id') != 'notme') {
65+ Y.Assert.areEqual('a',
66+ node.get('tagName').toLowerCase());
67+ Y.Assert.areEqual(content, node.getContent());
68+ Y.Assert.areEqual('#',
69+ node.get('href').substr(-1, 1));
70+ } else {
71+ Y.Assert.areEqual('span',
72+ node.get('tagName').toLowerCase(),
73+ 'Ignore nodes outside of the bug listing table');
74+ }
75+ });
76 }
77 checkNav('.previous', 'PreVious');
78 checkNav('.next', 'NeXt');
79 checkNav('.first', 'FiRST');
80 checkNav('.last', 'lAst');
81 },
82+
83 /**
84 * Render should update the navigation_indices with the result info.
85 */
86
87=== modified file 'lib/lp/bugs/javascript/buglisting.js'
88--- lib/lp/bugs/javascript/buglisting.js 2012-03-22 19:08:39 +0000
89+++ lib/lp/bugs/javascript/buglisting.js 2012-07-16 18:00:36 +0000
90@@ -176,7 +176,7 @@
91 var navigation_indices = Y.all('.batch-navigation-index');
92 var pre_fetch = Y.lp.app.listing_navigator.get_feature_flag(
93 'bugs.dynamic_bug_listings.pre_fetch');
94- Y.lp.app.listing_navigator.linkify_navigation();
95+ Y.lp.app.listing_navigator.linkify_navigation('#bugs-table-listing');
96 var navigator = new module.BugListingNavigator({
97 current_url: window.location,
98 cache: LP.cache,
99
100=== modified file 'lib/lp/bugs/javascript/tests/test_buglisting.js'
101--- lib/lp/bugs/javascript/tests/test_buglisting.js 2012-06-28 13:18:14 +0000
102+++ lib/lp/bugs/javascript/tests/test_buglisting.js 2012-07-16 18:00:36 +0000
103@@ -103,8 +103,10 @@
104 },
105 test_from_page_with_client: function() {
106 Y.one('#fixture').setContent(
107+ '<div id="bugs-table-listing">' +
108 '<a class="previous" href="http://example.org/">PreVious</span>' +
109- '<div id="client-listing"></div>');
110+ '<div id="client-listing"></div>' +
111+ '</div>');
112 Y.Assert.areSame('http://example.org/', this.getPreviousLink());
113 module.BugListingNavigator.from_page();
114 Y.Assert.areNotSame('http://example.org/', this.getPreviousLink());
115
116=== modified file 'lib/lp/registry/javascript/sharing/shareetable.js'
117--- lib/lp/registry/javascript/sharing/shareetable.js 2012-07-07 14:00:30 +0000
118+++ lib/lp/registry/javascript/sharing/shareetable.js 2012-07-16 18:00:36 +0000
119@@ -100,7 +100,7 @@
120
121 make_navigator: function() {
122 var navigation_indices = Y.all('.batch-navigation-index');
123- Y.lp.app.listing_navigator.linkify_navigation();
124+ Y.lp.app.listing_navigator.linkify_navigation('#sharee-table-listing');
125 var ns = Y.lp.registry.sharing.shareelisting_navigator;
126 var cache = LP.cache;
127 cache.total = this.get('sharees').length;