Merge lp:~gmb/launchpad/new-subscriptions-widget-bug-616653 into lp:launchpad

Proposed by Graham Binns
Status: Merged
Approved by: Brad Crittenden
Approved revision: no longer in the source branch.
Merged at revision: 11413
Proposed branch: lp:~gmb/launchpad/new-subscriptions-widget-bug-616653
Merge into: lp:launchpad
Diff against target: 210 lines (+196/-0)
3 files modified
lib/lp/bugs/javascript/bug_subscription_widget.js (+85/-0)
lib/lp/bugs/javascript/tests/test_bug_subscription_widget.html (+41/-0)
lib/lp/bugs/javascript/tests/test_bug_subscription_widget.js (+70/-0)
To merge this branch: bzr merge lp:~gmb/launchpad/new-subscriptions-widget-bug-616653
Reviewer Review Type Date Requested Status
Brad Crittenden (community) code Approve
Review via email: mp+33215@code.launchpad.net

Commit message

The first stage of a new subscription widget has been added to the lp.bugs Javascript.

Description of the change

This branch adds the beginnings of a new subscription widget. It isn't actually hooked up to anything yet.

The widget will first be used for bug subscriptions before being converted to work for both individual bugs *and* structural subscriptions. It will eventually be used for subscriptions-to-searches, too.

The widget isn't, as I said, hooked up to anything; this branch is about giving us a good base to work from for the rest of the development work.

I've added a simple test to check that the values used for the bug notification level radio buttons are valid, but tests will become more thorough as more development work is carried out, since we'll be able to add Windmill tests, too.

To post a comment you must log in.
Revision history for this message
Brad Crittenden (bac) wrote :

Hi Graham,

Thanks for the preliminary work on this widget. As we discussed on IRC s/2009/2010 and s/2008/2010/

Also follow young Matthew's advice on the wording of the troublesome option.

review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added file 'lib/lp/bugs/javascript/bug_subscription_widget.js'
2--- lib/lp/bugs/javascript/bug_subscription_widget.js 1970-01-01 00:00:00 +0000
3+++ lib/lp/bugs/javascript/bug_subscription_widget.js 2010-08-23 09:19:43 +0000
4@@ -0,0 +1,85 @@
5+/* Copyright 2010 Canonical Ltd. This software is licensed under the
6+ * GNU Affero General Public License version 3 (see the file LICENSE).
7+ *
8+ * Handling of the bug subscription form overlay widget.
9+ *
10+ * @module bugs
11+ * @submodule bug_subscription_widget
12+ */
13+YUI.add('lp.bugs.bug_subscription_widget', function(Y) {
14+
15+var namespace = Y.namespace('lp.bugs.bug_subscription_widget');
16+
17+var submit_button_html =
18+ '<button type="submit" name="field.actions.subscribe" ' +
19+ 'value="Subscribe"' +
20+ 'class="lazr-pos lazr-btn" >OK</button>';
21+var cancel_button_html =
22+ '<button type="button" name="field.actions.cancel" ' +
23+ 'class="lazr-neg lazr-btn" >Cancel</button>';
24+
25+namespace.create_subscription_overlay = function() {
26+ // Construct the form. This is a bit hackish but it saves us from
27+ // having to try to get information from TAL into JavaScript and all
28+ // the horror that entails.
29+ var subscribe_form_body =
30+ '<div>' +
31+ ' <p>Tell me when</p>' +
32+ ' <table>' +
33+ ' <tr>' +
34+ ' <td>' +
35+ ' <input type="radio" name="field.bug_notification_level" ' +
36+ ' id="bug-notification-level-comments"' +
37+ ' value="Discussion"' +
38+ ' class="bug-notification-level" />' +
39+ ' </td>' +
40+ ' <td>' +
41+ ' <label for="bug-notification-level-comments">' +
42+ ' A change is made or a comment is added to this bug' +
43+ ' </label>' +
44+ ' </td>' +
45+ ' </tr>' +
46+ ' <tr>' +
47+ ' <td>' +
48+ ' <input type="radio" name="field.bug_notification_level" ' +
49+ ' id="bug-notification-level-metadata" value="Details"' +
50+ ' class="bug-notification-level" />' +
51+ ' </td>' +
52+ ' <td>' +
53+ ' <label for="bug-notification-level-metadata">' +
54+ ' A change is made to the bug; do not notify me about ' +
55+ ' new comments.' +
56+ ' </label>' +
57+ ' </td>' +
58+ ' </tr>' +
59+ ' <tr>' +
60+ ' <td>' +
61+ ' <input type="radio" name="field.bug_notification_level" ' +
62+ ' id="bug-notification-level-lifecycle" value="Lifecycle"' +
63+ ' class="bug-notification-level" />' +
64+ ' </td>' +
65+ ' <td>' +
66+ ' <label for="bug-notification-level-lifecycle">' +
67+ ' Changes are made to the bug\'s status.' +
68+ ' </label>' +
69+ ' </td>' +
70+ ' </tr>' +
71+ ' </table>' +
72+ '</div>';
73+
74+ // Create the do-you-want-to-subscribe FormOverlay.
75+ var subscribe_form_overlay = new Y.lazr.FormOverlay({
76+ headerContent: '<h2>Subscribe to this bug</h2>',
77+ form_content: subscribe_form_body,
78+ form_submit_button: Y.Node.create(submit_button_html),
79+ form_cancel_button: Y.Node.create(cancel_button_html),
80+ centered: true,
81+ visible: false
82+ });
83+ subscribe_form_overlay.render('#subscribe-overlay');
84+
85+ return subscribe_form_overlay;
86+};
87+
88+}, "0.1", {"requires": [
89+ "base", "io", "oop", "node", "event", "lazr.formoverlay", "lazr.effects"]});
90
91=== added file 'lib/lp/bugs/javascript/tests/test_bug_subscription_widget.html'
92--- lib/lp/bugs/javascript/tests/test_bug_subscription_widget.html 1970-01-01 00:00:00 +0000
93+++ lib/lp/bugs/javascript/tests/test_bug_subscription_widget.html 2010-08-23 09:19:43 +0000
94@@ -0,0 +1,41 @@
95+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
96+<html>
97+ <head>
98+ <title>Bug Subscription Widget</title>
99+
100+ <!-- YUI 3.0 Setup -->
101+ <script type="text/javascript" src="../../../../canonical/launchpad/icing/yui/yui/yui.js"></script>
102+ <link rel="stylesheet" href="../../../../canonical/launchpad/icing/yui/cssreset/reset.css"/>
103+ <link rel="stylesheet" href="../../../../canonical/launchpad/icing/yui/cssfonts/fonts.css"/>
104+ <link rel="stylesheet" href="../../../../canonical/launchpad/icing/yui/cssbase/base.css"/>
105+
106+ <!-- Dependency -->
107+ <script type="text/javascript"
108+ src="../../../../canonical/launchpad/icing/lazr/build/lazr.js"></script>
109+ <script type="text/javascript"
110+ src="../../../../canonical/launchpad/icing/lazr/build/overlay/overlay.js">
111+ </script>
112+ <script type="text/javascript"
113+ src="../../../../canonical/launchpad/icing/lazr/build/choiceedit/choiceedit.js">
114+ </script>
115+ <script type="text/javascript"
116+ src="../../../../canonical/launchpad/javascript/client/client.js"></script>
117+
118+ <!-- The module under test -->
119+ <script type="text/javascript" src="../bug_subscription_widget.js"></script>
120+
121+ <!-- The test suite -->
122+ <script type="text/javascript" src="test_bug_subscription_widget.js"></script>
123+
124+ <!-- Test layout -->
125+ <link rel="stylesheet"
126+ href="../../../../canonical/launchpad/javascript/test.css" />
127+ <style type="text/css">
128+ /* CSS classes specific to this test */
129+ .unseen { display: none; }
130+ </style>
131+</head>
132+<body class="yui-skin-sam">
133+ <div id="log"></div>
134+</body>
135+</html>
136
137=== added file 'lib/lp/bugs/javascript/tests/test_bug_subscription_widget.js'
138--- lib/lp/bugs/javascript/tests/test_bug_subscription_widget.js 1970-01-01 00:00:00 +0000
139+++ lib/lp/bugs/javascript/tests/test_bug_subscription_widget.js 2010-08-23 09:19:43 +0000
140@@ -0,0 +1,70 @@
141+/* Copyright (c) 2010, Canonical Ltd. All rights reserved. */
142+
143+YUI({
144+ base: '../../../../canonical/launchpad/icing/yui/',
145+ filter: 'raw',
146+ combine: false
147+ }).use(
148+ 'event', 'lp.bugs.bug_subscription_widget', 'node', 'test',
149+ 'widget-stack', 'console', function(Y) {
150+
151+// Local aliases
152+var Assert = Y.Assert,
153+ ArrayAssert = Y.ArrayAssert;
154+
155+var suite = new Y.Test.Suite("Bug subscription widget tests");
156+
157+suite.add(new Y.Test.Case({
158+
159+ name: 'bug_subscription_widget_basics',
160+
161+ setUp: function() {
162+ // Monkeypatch LP.client to avoid network traffic and to make
163+ // some things work as expected.
164+ LP.client.Launchpad.prototype.named_post =
165+ function(url, func, config) {
166+ config.on.success();
167+ };
168+ LP.client.cache.bug = {
169+ self_link: "http://bugs.example.com/bugs/1234"
170+ };
171+ this.subscribe_overlay =
172+ Y.lp.bugs.bug_subscription_widget.create_subscription_overlay();
173+ this.subscribe_overlay.show();
174+ },
175+
176+ test_bug_notification_level_values: function() {
177+ // The bug_notification_level field will have a value that's one
178+ // of [Discussion, Details, Lifecycle].
179+ var form_node = this.subscribe_overlay.form_node;
180+ var notification_level_radio_buttons = form_node.queryAll(
181+ 'input[name=field.bug_notification_level]');
182+ Y.each(notification_level_radio_buttons, function(obj) {
183+ var value = obj.getAttribute('value');
184+ Assert.isTrue(
185+ value == 'Discussion' ||
186+ value == 'Details' ||
187+ value == 'Lifecycle');
188+ });
189+ }
190+
191+}));
192+
193+var handle_complete = function(data) {
194+ status_node = Y.Node.create(
195+ '<p id="complete">Test status: complete</p>');
196+ Y.get('body').appendChild(status_node);
197+ };
198+Y.Test.Runner.on('complete', handle_complete);
199+Y.Test.Runner.add(suite);
200+
201+var yconsole = new Y.Console({
202+ newestOnTop: false
203+});
204+yconsole.render('#log');
205+
206+Y.on('domready', function() {
207+ Y.Test.Runner.run();
208+});
209+
210+});