Merge lp:~danilo/launchpad/bug-772763-remove-unmute-dialog into lp:launchpad/db-devel

Proposed by Данило Шеган
Status: Merged
Merged at revision: 10583
Proposed branch: lp:~danilo/launchpad/bug-772763-remove-unmute-dialog
Merge into: lp:launchpad/db-devel
Prerequisite: lp:~danilo/launchpad/bug-772763-remove-unmute-dialog-part1
Diff against target: 393 lines (+111/-193)
2 files modified
lib/lp/bugs/javascript/bugtask_index_portlets.js (+110/-192)
lib/lp/bugs/javascript/subscriber.js (+1/-1)
To merge this branch: bzr merge lp:~danilo/launchpad/bug-772763-remove-unmute-dialog
Reviewer Review Type Date Requested Status
Brad Crittenden (community) code Needs Fixing
Данило Шеган (community) Abstain
Review via email: mp+61780@code.launchpad.net

Commit message

"Unmute bug mail" unmutes directly (and restores any previous subscription) without popping up a dialog.

Description of the change

= Bug 772763: remove unmute dialog =

As part of fixing 772763, we drop the pop-dialog when "unmute" is clicked and instead make it a direct action on click.

== Proposed fix ==

Turn "Unmute" link into a direct action (instead of popping up an "advanced overlay" with options to unmute and similar).

== Implementation details ==

This branch is entirely Gary's work. I am only shepherding it.

Basically, it's a very welcome refactoring of the entire mute handling for a single bug:

 - no use of JS Subscription class for muting/unmuting (it didn't really make sense since "mute" is not a subscription, but instead orthogonal to it)
 - no tests are provided because we plan to refactor this code further with our next bug (subscribers' list)

== Tests ==

Nada.

== Demo and Q/A ==

Go to https://bugs.launchpad.dev/debian/+source/mozilla-firefox/+bug/3 and play with muting/unmuting while having a subscription or not having one.

= Launchpad lint =

Checking for conflicts and issues in changed files.

Linting changed files:
  lib/lp/bugs/javascript/bugtask_index_portlets.js
  lib/lp/bugs/javascript/subscriber.js

To post a comment you must log in.
Revision history for this message
Данило Шеган (danilo) :
review: Abstain
Revision history for this message
Brad Crittenden (bac) wrote :

Hi Gary/Danilo,

The branch looks good with the exception that if I am muted and there are no other subscribers then "No subscribers" is correctly shown. However when unmuting, the person's name is added to the subscriber list but "No subscribers" is not removed. Looks like that action should happen around line 119 of the diff.

review: Needs Fixing (code)
Revision history for this message
Данило Шеган (danilo) wrote :

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/bugs/javascript/bugtask_index_portlets.js'
2--- lib/lp/bugs/javascript/bugtask_index_portlets.js 2011-05-18 18:34:19 +0000
3+++ lib/lp/bugs/javascript/bugtask_index_portlets.js 2011-05-20 15:07:33 +0000
4@@ -246,34 +246,6 @@
5 }, '.unsub-icon');
6 }
7
8-/*
9- * Set up and return a Subscription object for the mute link.
10- * @method get_mute_subscription
11- */
12-function get_mute_subscription() {
13- setup_client_and_bug();
14- var mute_link = Y.one('.menu-link-mute_subscription');
15- if (Y.Lang.isNull(mute_link)) {
16- return null;
17- }
18- var mute_subscription = new Y.lp.bugs.subscriber.Subscription({
19- link: mute_link,
20- spinner: Y.one('#mute-unmute-spinner'),
21- subscriber: new Y.lp.bugs.subscriber.Subscriber({
22- uri: LP.links.me,
23- subscriber_ids: subscriber_ids
24- })
25- });
26- var parent_node = mute_link.get('parentNode');
27- mute_subscription.set(
28- 'is_subscribed', !parent_node.hasClass('subscribed-false'));
29- mute_subscription.set(
30- 'is_muted', parent_node.hasClass('muted-true'));
31- mute_subscription.set(
32- 'person', mute_subscription.get('subscriber'));
33- return mute_subscription;
34-}
35-
36
37 /**
38 * We can have at most one advanced subscription overlay shown,
39@@ -310,74 +282,118 @@
40 if (LP.links.me === undefined) {
41 return;
42 }
43+ var link = Y.one('.menu-link-mute_subscription');
44+ if (Y.Lang.isNull(link)) {
45+ return;
46+ }
47+ link.addClass('js-action');
48+ setup_client_and_bug();
49+ link.on('click', _get_toggle_mute(link));
50+}
51
52- var mute_subscription = get_mute_subscription();
53- if (Y.Lang.isNull(mute_subscription)) {
54- return;
55- }
56- var mute_link = mute_subscription.get('link');
57- var parent_node = mute_link.get('parentNode');
58- mute_link.addClass('js-action');
59- mute_link.on('click', function(e) {
60- e.halt();
61+// This is a helper, factored out for reusability by setup_mute_link_handlers
62+// and toggle_mute.
63+function _get_toggle_mute(link) {
64+ var parent_node = link.get('parentNode');
65+ var spinner = Y.one('#mute-unmute-spinner');
66+ var hide_spinner = function() {
67+ link.set('display', 'inline');
68+ spinner.set('display', 'none');
69+ };
70+ var handler = new Y.lp.client.ErrorHandler();
71+ handler.showError = function(error_msg) {
72+ Y.lp.app.errors.display_error(link, error_msg);
73+ };
74+ handler.clearProgressUI = hide_spinner;
75+ return function (e) {
76+ if (!Y.Lang.isUndefined(e)) {
77+ e.halt();
78+ }
79 var is_muted = parent_node.hasClass('muted-true');
80+ var spinner_text, method_name;
81 if (! is_muted) {
82- mute_subscription.enable_spinner('Muting...');
83- mute_current_user(mute_subscription);
84+ spinner_text = 'Muting...';
85+ method_name = 'mute';
86 } else {
87- create_new_subscription_overlay(
88- mute_subscription, "Unmute subscription");
89+ spinner_text = 'Unmuting...';
90+ method_name = 'unmute';
91 }
92- });
93+ spinner.set('innerHTML', spinner_text);
94+ link.set('display', 'none');
95+ spinner.set('display', 'block');
96+ var config = {
97+ on: {
98+ success: function(response) {
99+ is_muted = ! is_muted; // We successfully toggled.
100+ var subscription = get_subscribe_self_subscription();
101+ subscription.enable_spinner('Updating...');
102+ var subscription_link = subscription.get('link');
103+ var is_subscribed = false;
104+ var is_dupe_subscribed =
105+ subscription.has_duplicate_subscriptions();
106+ var label = subscription_labels.SUBSCRIBE;
107+ update_mute_after_subscription_change(is_muted);
108+ if (is_muted) {
109+ // Remove the subscriber's name from the subscriber
110+ // list, if it's there.
111+ Y.lp.bugs.subscribers_list.remove_user_link(
112+ subscription.get('subscriber'));
113+ } else {
114+ // When unmuting, the ``response`` is the previously
115+ // muted subscription, or null.
116+ is_subscribed = ! Y.Lang.isNull(response);
117+ if (is_subscribed) {
118+ subscription.set('is_direct', true);
119+ add_user_name_link(subscription);
120+ label = subscription_labels.EDIT;
121+ }
122+ }
123+ hide_spinner();
124+ Y.lazr.anim.green_flash({ node: parent_node }).run();
125+ set_subscription_link_parent_class(
126+ subscription_link, is_subscribed, is_dupe_subscribed);
127+ subscription.disable_spinner(label);
128+ },
129+ failure: handler.getFailureHandler()
130+ },
131+ parameters: {}
132+ };
133+ lp_client.named_post(bug_repr.self_link, method_name, config);
134+ };
135+}
136+
137+/*
138+ * Toggle the mute state.
139+ */
140+
141+function toggle_mute() {
142+ if (LP.links.me === undefined) {
143+ return;
144+ }
145+ var link = Y.one('.menu-link-mute_subscription');
146+ if (Y.Lang.isNull(link)) {
147+ return;
148+ }
149+ return _get_toggle_mute(link)();
150 }
151
152 /*
153 * Update the Mute link after the user's subscriptions or mutes have
154 * changed.
155 */
156-function update_mute_after_subscription_change(mute_subscription) {
157- var mute_link = mute_subscription.get('link');
158- var parent_node = mute_link.get('parentNode');
159+function update_mute_after_subscription_change(is_muted) {
160+ var link = Y.one('.menu-link-mute_subscription');
161+ var parent_node = link.get('parentNode');
162+ if (Y.Lang.isUndefined(is_muted)) {
163+ is_muted = parent_node.hasClass('muted-true');
164+ }
165 parent_node.removeClass('hidden');
166- if (mute_subscription.get('is_muted')) {
167- parent_node.removeClass('muted-false');
168- parent_node.addClass('muted-true');
169- mute_link.setAttribute(
170- 'href', mute_link.getAttribute('href').replace(
171- /\+mute$/, '+subscribe'));
172- mute_subscription.disable_spinner("Unmute bug mail");
173- } else {
174- parent_node.removeClass('muted-true');
175- parent_node.addClass('muted-false');
176- mute_link.setAttribute(
177- 'href', mute_link.getAttribute('href').replace(
178- /\+subscribe$/, '+mute'));
179- mute_subscription.disable_spinner("Mute bug mail");
180- }
181-}
182-
183-/*
184- * Update the subscription links after the mute button has been clicked.
185- *
186- * @param mute_subscription {Object} A Y.lp.bugs.subscriber.Subscription
187- * object.
188- */
189-function update_subscription_after_mute_or_unmute(mute_subscription) {
190- var subscription = get_subscribe_self_subscription();
191- var subscription_link = subscription.get('link');
192-
193- subscription.enable_spinner('Updating...');
194- if (mute_subscription.get('is_muted')) {
195- subscription.disable_spinner(subscription_labels.SUBSCRIBE);
196- if (subscription.has_duplicate_subscriptions()) {
197- set_subscription_link_parent_class(
198- subscription_link, false, true);
199- } else {
200- set_subscription_link_parent_class(
201- subscription_link, false, false);
202- }
203- } else {
204- subscription.disable_spinner(subscription_labels.SUBSCRIBE);
205+ if (is_muted) {
206+ parent_node.replaceClass('muted-false', 'muted-true');
207+ link.set('innerHTML', "Unmute bug mail");
208+ } else {
209+ parent_node.replaceClass('muted-true', 'muted-false');
210+ link.set('innerHTML', "Mute bug mail");
211 }
212 }
213
214@@ -768,8 +784,7 @@
215 }
216
217 add_user_name_link(subscription);
218- var mute_subscription = get_mute_subscription();
219- update_mute_after_subscription_change(mute_subscription);
220+ update_mute_after_subscription_change();
221
222 // Only when the link is added to the page, indicate success.
223 Y.on('contentready', function() {
224@@ -884,95 +899,6 @@
225 }
226
227 /*
228- * Mute the current user via the LP API.
229- *
230- * @method mute_current_user
231- * @param subscription {Object} A Y.lp.bugs.subscribe.Subscription object.
232- */
233-function mute_current_user(subscription) {
234- subscription.enable_spinner('Muting...');
235- var subscription_link = subscription.get('link');
236- var subscriber = subscription.get('subscriber');
237- var bug_notification_level = subscription.get('bug_notification_level');
238-
239- var error_handler = new Y.lp.client.ErrorHandler();
240- error_handler.clearProgressUI = function () {
241- subscription.disable_spinner();
242- };
243- error_handler.showError = function (error_msg) {
244- Y.lp.app.errors.display_error(subscription_link, error_msg);
245- };
246-
247- var config = {
248- on: {
249- success: function(client) {
250- subscription.disable_spinner('Unmute bug mail');
251- var flash_node = subscription_link.get('parentNode');
252- var mute_anim = Y.lazr.anim.green_flash({ node: flash_node });
253- mute_anim.run();
254-
255- // Remove the subscriber's name from the subscriber
256- // list, if it's there.
257- Y.lp.bugs.subscribers_list.remove_user_link(subscriber);
258- subscription.set('is_muted', true);
259- update_mute_after_subscription_change(subscription);
260- update_subscription_after_mute_or_unmute(subscription);
261- },
262-
263- failure: error_handler.getFailureHandler()
264- },
265-
266- parameters: {
267- person: Y.lp.client.get_absolute_uri(
268- subscriber.get('escaped_uri'))
269- }
270- };
271- lp_client.named_post(bug_repr.self_link, 'mute', config);
272-}
273-
274-/*
275- * Unmute the current user via the LP API.
276- *
277- * @method unmute_current_user
278- * @param subscription {Object} A Y.lp.bugs.subscriber.Subscription object.
279- */
280-function unmute_current_user(subscription) {
281- subscription.enable_spinner('Unmuting...');
282- var subscription_link = subscription.get('link');
283- var subscriber = subscription.get('subscriber');
284-
285- var error_handler = new Y.lp.client.ErrorHandler();
286- error_handler.clearProgressUI = function () {
287- subscription.disable_spinner();
288- };
289- error_handler.showError = function (error_msg) {
290- Y.lp.app.errors.display_error(subscription_link, error_msg);
291- };
292-
293- var config = {
294- on: {
295- success: function(client) {
296- subscription.disable_spinner('Mute bug mail');
297- var flash_node = subscription_link.get('parentNode');
298- var anim = Y.lazr.anim.green_flash({ node: flash_node });
299- anim.run();
300- subscription.set('is_muted', false);
301- update_mute_after_subscription_change(subscription);
302- update_subscription_after_mute_or_unmute(subscription);
303- },
304-
305- failure: error_handler.getFailureHandler()
306- },
307-
308- parameters: {
309- person: Y.lp.client.get_absolute_uri(
310- subscriber.get('escaped_uri'))
311- }
312- };
313- lp_client.named_post(bug_repr.self_link, 'unmute', config);
314-}
315-
316-/*
317 * Initialize click handler for the subscribe someone else link.
318 *
319 * @method setup_subscribe_someone_else_handler
320@@ -1219,9 +1145,9 @@
321 */
322 function handle_advanced_subscription_overlay(form_data) {
323 var subscription;
324- var mute_subscription = get_mute_subscription();
325- var is_muted = (!Y.Lang.isNull(mute_subscription) &&
326- mute_subscription.get('is_muted'));
327+ var mute_link = Y.one('.menu-link-mute_subscription');
328+ var parent_node = mute_link.get('parentNode');
329+ var is_muted = parent_node.hasClass('muted-true');
330 var requested_subscriber;
331 var request_for_self = false;
332 // XXX Danilo 20110422: this is a very lousy "special string"
333@@ -1259,9 +1185,6 @@
334 on: {
335 success: function(lp_subscription) {
336 subscription.enable_spinner('Updating subscription...');
337- if (is_muted) {
338- mute_subscription.enable_spinner('Unmuting...');
339- }
340 lp_subscription.set(
341 'bug_notification_level',
342 form_data['field.bug_notification_level'][0]);
343@@ -1277,12 +1200,10 @@
344 });
345 anim.run();
346 if (is_muted) {
347- mute_subscription.set('is_muted', false);
348- mute_subscription.disable_spinner(
349- "Mute bug mail");
350- update_mute_after_subscription_change(
351- mute_subscription);
352- add_user_name_link(subscription);
353+ // We're going to assume that the user
354+ // wants to unmute also, since they
355+ // bothered to change their subscription.
356+ toggle_mute();
357 }
358 },
359 failure: function(e) {
360@@ -1315,7 +1236,7 @@
361 // a. unmute, b. unmute and subscribe, c. unsubscribe team1...
362 // "b" is treated as 'update-subscription' case, and for any
363 // of the teams, request_for_self won't be true.
364- unmute_current_user(mute_subscription);
365+ toggle_mute();
366 } else {
367 // Unsubscribe this person/team.
368 unsubscribe_current_user(subscription);
369@@ -1392,10 +1313,7 @@
370 if (team_member) {
371 subscription.set('can_be_unsubscribed', true);
372 add_temp_user_name(subscription);
373- var mute_subscription;
374- mute_subscription = get_mute_subscription();
375- update_mute_after_subscription_change(
376- mute_subscription);
377+ update_mute_after_subscription_change();
378 } else {
379 subscription.set(
380 'can_be_unsubscribed', false);
381
382=== modified file 'lib/lp/bugs/javascript/subscriber.js'
383--- lib/lp/bugs/javascript/subscriber.js 2011-04-22 16:59:16 +0000
384+++ lib/lp/bugs/javascript/subscriber.js 2011-05-20 15:07:33 +0000
385@@ -57,7 +57,7 @@
386 },
387
388 'spinner': {
389- vallue: null
390+ value: null
391 },
392
393 'bug_notification_level': {

Subscribers

People subscribed via source and target branches

to status/vote changes: