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
=== modified file 'lib/lp/bugs/javascript/bugtask_index_portlets.js'
--- lib/lp/bugs/javascript/bugtask_index_portlets.js 2011-05-18 18:34:19 +0000
+++ lib/lp/bugs/javascript/bugtask_index_portlets.js 2011-05-20 15:07:33 +0000
@@ -246,34 +246,6 @@
246 }, '.unsub-icon');246 }, '.unsub-icon');
247}247}
248248
249/*
250 * Set up and return a Subscription object for the mute link.
251 * @method get_mute_subscription
252 */
253function get_mute_subscription() {
254 setup_client_and_bug();
255 var mute_link = Y.one('.menu-link-mute_subscription');
256 if (Y.Lang.isNull(mute_link)) {
257 return null;
258 }
259 var mute_subscription = new Y.lp.bugs.subscriber.Subscription({
260 link: mute_link,
261 spinner: Y.one('#mute-unmute-spinner'),
262 subscriber: new Y.lp.bugs.subscriber.Subscriber({
263 uri: LP.links.me,
264 subscriber_ids: subscriber_ids
265 })
266 });
267 var parent_node = mute_link.get('parentNode');
268 mute_subscription.set(
269 'is_subscribed', !parent_node.hasClass('subscribed-false'));
270 mute_subscription.set(
271 'is_muted', parent_node.hasClass('muted-true'));
272 mute_subscription.set(
273 'person', mute_subscription.get('subscriber'));
274 return mute_subscription;
275}
276
277249
278/**250/**
279 * We can have at most one advanced subscription overlay shown,251 * We can have at most one advanced subscription overlay shown,
@@ -310,74 +282,118 @@
310 if (LP.links.me === undefined) {282 if (LP.links.me === undefined) {
311 return;283 return;
312 }284 }
285 var link = Y.one('.menu-link-mute_subscription');
286 if (Y.Lang.isNull(link)) {
287 return;
288 }
289 link.addClass('js-action');
290 setup_client_and_bug();
291 link.on('click', _get_toggle_mute(link));
292}
313293
314 var mute_subscription = get_mute_subscription();294// This is a helper, factored out for reusability by setup_mute_link_handlers
315 if (Y.Lang.isNull(mute_subscription)) {295// and toggle_mute.
316 return;296function _get_toggle_mute(link) {
317 }297 var parent_node = link.get('parentNode');
318 var mute_link = mute_subscription.get('link');298 var spinner = Y.one('#mute-unmute-spinner');
319 var parent_node = mute_link.get('parentNode');299 var hide_spinner = function() {
320 mute_link.addClass('js-action');300 link.set('display', 'inline');
321 mute_link.on('click', function(e) {301 spinner.set('display', 'none');
322 e.halt();302 };
303 var handler = new Y.lp.client.ErrorHandler();
304 handler.showError = function(error_msg) {
305 Y.lp.app.errors.display_error(link, error_msg);
306 };
307 handler.clearProgressUI = hide_spinner;
308 return function (e) {
309 if (!Y.Lang.isUndefined(e)) {
310 e.halt();
311 }
323 var is_muted = parent_node.hasClass('muted-true');312 var is_muted = parent_node.hasClass('muted-true');
313 var spinner_text, method_name;
324 if (! is_muted) {314 if (! is_muted) {
325 mute_subscription.enable_spinner('Muting...');315 spinner_text = 'Muting...';
326 mute_current_user(mute_subscription);316 method_name = 'mute';
327 } else {317 } else {
328 create_new_subscription_overlay(318 spinner_text = 'Unmuting...';
329 mute_subscription, "Unmute subscription");319 method_name = 'unmute';
330 }320 }
331 });321 spinner.set('innerHTML', spinner_text);
322 link.set('display', 'none');
323 spinner.set('display', 'block');
324 var config = {
325 on: {
326 success: function(response) {
327 is_muted = ! is_muted; // We successfully toggled.
328 var subscription = get_subscribe_self_subscription();
329 subscription.enable_spinner('Updating...');
330 var subscription_link = subscription.get('link');
331 var is_subscribed = false;
332 var is_dupe_subscribed =
333 subscription.has_duplicate_subscriptions();
334 var label = subscription_labels.SUBSCRIBE;
335 update_mute_after_subscription_change(is_muted);
336 if (is_muted) {
337 // Remove the subscriber's name from the subscriber
338 // list, if it's there.
339 Y.lp.bugs.subscribers_list.remove_user_link(
340 subscription.get('subscriber'));
341 } else {
342 // When unmuting, the ``response`` is the previously
343 // muted subscription, or null.
344 is_subscribed = ! Y.Lang.isNull(response);
345 if (is_subscribed) {
346 subscription.set('is_direct', true);
347 add_user_name_link(subscription);
348 label = subscription_labels.EDIT;
349 }
350 }
351 hide_spinner();
352 Y.lazr.anim.green_flash({ node: parent_node }).run();
353 set_subscription_link_parent_class(
354 subscription_link, is_subscribed, is_dupe_subscribed);
355 subscription.disable_spinner(label);
356 },
357 failure: handler.getFailureHandler()
358 },
359 parameters: {}
360 };
361 lp_client.named_post(bug_repr.self_link, method_name, config);
362 };
363}
364
365/*
366 * Toggle the mute state.
367 */
368
369function toggle_mute() {
370 if (LP.links.me === undefined) {
371 return;
372 }
373 var link = Y.one('.menu-link-mute_subscription');
374 if (Y.Lang.isNull(link)) {
375 return;
376 }
377 return _get_toggle_mute(link)();
332}378}
333379
334/*380/*
335 * Update the Mute link after the user's subscriptions or mutes have381 * Update the Mute link after the user's subscriptions or mutes have
336 * changed.382 * changed.
337 */383 */
338function update_mute_after_subscription_change(mute_subscription) {384function update_mute_after_subscription_change(is_muted) {
339 var mute_link = mute_subscription.get('link');385 var link = Y.one('.menu-link-mute_subscription');
340 var parent_node = mute_link.get('parentNode');386 var parent_node = link.get('parentNode');
387 if (Y.Lang.isUndefined(is_muted)) {
388 is_muted = parent_node.hasClass('muted-true');
389 }
341 parent_node.removeClass('hidden');390 parent_node.removeClass('hidden');
342 if (mute_subscription.get('is_muted')) {391 if (is_muted) {
343 parent_node.removeClass('muted-false');392 parent_node.replaceClass('muted-false', 'muted-true');
344 parent_node.addClass('muted-true');393 link.set('innerHTML', "Unmute bug mail");
345 mute_link.setAttribute(394 } else {
346 'href', mute_link.getAttribute('href').replace(395 parent_node.replaceClass('muted-true', 'muted-false');
347 /\+mute$/, '+subscribe'));396 link.set('innerHTML', "Mute bug mail");
348 mute_subscription.disable_spinner("Unmute bug mail");
349 } else {
350 parent_node.removeClass('muted-true');
351 parent_node.addClass('muted-false');
352 mute_link.setAttribute(
353 'href', mute_link.getAttribute('href').replace(
354 /\+subscribe$/, '+mute'));
355 mute_subscription.disable_spinner("Mute bug mail");
356 }
357}
358
359/*
360 * Update the subscription links after the mute button has been clicked.
361 *
362 * @param mute_subscription {Object} A Y.lp.bugs.subscriber.Subscription
363 * object.
364 */
365function update_subscription_after_mute_or_unmute(mute_subscription) {
366 var subscription = get_subscribe_self_subscription();
367 var subscription_link = subscription.get('link');
368
369 subscription.enable_spinner('Updating...');
370 if (mute_subscription.get('is_muted')) {
371 subscription.disable_spinner(subscription_labels.SUBSCRIBE);
372 if (subscription.has_duplicate_subscriptions()) {
373 set_subscription_link_parent_class(
374 subscription_link, false, true);
375 } else {
376 set_subscription_link_parent_class(
377 subscription_link, false, false);
378 }
379 } else {
380 subscription.disable_spinner(subscription_labels.SUBSCRIBE);
381 }397 }
382}398}
383399
@@ -768,8 +784,7 @@
768 }784 }
769785
770 add_user_name_link(subscription);786 add_user_name_link(subscription);
771 var mute_subscription = get_mute_subscription();787 update_mute_after_subscription_change();
772 update_mute_after_subscription_change(mute_subscription);
773788
774 // Only when the link is added to the page, indicate success.789 // Only when the link is added to the page, indicate success.
775 Y.on('contentready', function() {790 Y.on('contentready', function() {
@@ -884,95 +899,6 @@
884}899}
885900
886/*901/*
887 * Mute the current user via the LP API.
888 *
889 * @method mute_current_user
890 * @param subscription {Object} A Y.lp.bugs.subscribe.Subscription object.
891 */
892function mute_current_user(subscription) {
893 subscription.enable_spinner('Muting...');
894 var subscription_link = subscription.get('link');
895 var subscriber = subscription.get('subscriber');
896 var bug_notification_level = subscription.get('bug_notification_level');
897
898 var error_handler = new Y.lp.client.ErrorHandler();
899 error_handler.clearProgressUI = function () {
900 subscription.disable_spinner();
901 };
902 error_handler.showError = function (error_msg) {
903 Y.lp.app.errors.display_error(subscription_link, error_msg);
904 };
905
906 var config = {
907 on: {
908 success: function(client) {
909 subscription.disable_spinner('Unmute bug mail');
910 var flash_node = subscription_link.get('parentNode');
911 var mute_anim = Y.lazr.anim.green_flash({ node: flash_node });
912 mute_anim.run();
913
914 // Remove the subscriber's name from the subscriber
915 // list, if it's there.
916 Y.lp.bugs.subscribers_list.remove_user_link(subscriber);
917 subscription.set('is_muted', true);
918 update_mute_after_subscription_change(subscription);
919 update_subscription_after_mute_or_unmute(subscription);
920 },
921
922 failure: error_handler.getFailureHandler()
923 },
924
925 parameters: {
926 person: Y.lp.client.get_absolute_uri(
927 subscriber.get('escaped_uri'))
928 }
929 };
930 lp_client.named_post(bug_repr.self_link, 'mute', config);
931}
932
933/*
934 * Unmute the current user via the LP API.
935 *
936 * @method unmute_current_user
937 * @param subscription {Object} A Y.lp.bugs.subscriber.Subscription object.
938 */
939function unmute_current_user(subscription) {
940 subscription.enable_spinner('Unmuting...');
941 var subscription_link = subscription.get('link');
942 var subscriber = subscription.get('subscriber');
943
944 var error_handler = new Y.lp.client.ErrorHandler();
945 error_handler.clearProgressUI = function () {
946 subscription.disable_spinner();
947 };
948 error_handler.showError = function (error_msg) {
949 Y.lp.app.errors.display_error(subscription_link, error_msg);
950 };
951
952 var config = {
953 on: {
954 success: function(client) {
955 subscription.disable_spinner('Mute bug mail');
956 var flash_node = subscription_link.get('parentNode');
957 var anim = Y.lazr.anim.green_flash({ node: flash_node });
958 anim.run();
959 subscription.set('is_muted', false);
960 update_mute_after_subscription_change(subscription);
961 update_subscription_after_mute_or_unmute(subscription);
962 },
963
964 failure: error_handler.getFailureHandler()
965 },
966
967 parameters: {
968 person: Y.lp.client.get_absolute_uri(
969 subscriber.get('escaped_uri'))
970 }
971 };
972 lp_client.named_post(bug_repr.self_link, 'unmute', config);
973}
974
975/*
976 * Initialize click handler for the subscribe someone else link.902 * Initialize click handler for the subscribe someone else link.
977 *903 *
978 * @method setup_subscribe_someone_else_handler904 * @method setup_subscribe_someone_else_handler
@@ -1219,9 +1145,9 @@
1219 */1145 */
1220function handle_advanced_subscription_overlay(form_data) {1146function handle_advanced_subscription_overlay(form_data) {
1221 var subscription;1147 var subscription;
1222 var mute_subscription = get_mute_subscription();1148 var mute_link = Y.one('.menu-link-mute_subscription');
1223 var is_muted = (!Y.Lang.isNull(mute_subscription) &&1149 var parent_node = mute_link.get('parentNode');
1224 mute_subscription.get('is_muted'));1150 var is_muted = parent_node.hasClass('muted-true');
1225 var requested_subscriber;1151 var requested_subscriber;
1226 var request_for_self = false;1152 var request_for_self = false;
1227 // XXX Danilo 20110422: this is a very lousy "special string"1153 // XXX Danilo 20110422: this is a very lousy "special string"
@@ -1259,9 +1185,6 @@
1259 on: {1185 on: {
1260 success: function(lp_subscription) {1186 success: function(lp_subscription) {
1261 subscription.enable_spinner('Updating subscription...');1187 subscription.enable_spinner('Updating subscription...');
1262 if (is_muted) {
1263 mute_subscription.enable_spinner('Unmuting...');
1264 }
1265 lp_subscription.set(1188 lp_subscription.set(
1266 'bug_notification_level',1189 'bug_notification_level',
1267 form_data['field.bug_notification_level'][0]);1190 form_data['field.bug_notification_level'][0]);
@@ -1277,12 +1200,10 @@
1277 });1200 });
1278 anim.run();1201 anim.run();
1279 if (is_muted) {1202 if (is_muted) {
1280 mute_subscription.set('is_muted', false);1203 // We're going to assume that the user
1281 mute_subscription.disable_spinner(1204 // wants to unmute also, since they
1282 "Mute bug mail");1205 // bothered to change their subscription.
1283 update_mute_after_subscription_change(1206 toggle_mute();
1284 mute_subscription);
1285 add_user_name_link(subscription);
1286 }1207 }
1287 },1208 },
1288 failure: function(e) {1209 failure: function(e) {
@@ -1315,7 +1236,7 @@
1315 // a. unmute, b. unmute and subscribe, c. unsubscribe team1...1236 // a. unmute, b. unmute and subscribe, c. unsubscribe team1...
1316 // "b" is treated as 'update-subscription' case, and for any1237 // "b" is treated as 'update-subscription' case, and for any
1317 // of the teams, request_for_self won't be true.1238 // of the teams, request_for_self won't be true.
1318 unmute_current_user(mute_subscription);1239 toggle_mute();
1319 } else {1240 } else {
1320 // Unsubscribe this person/team.1241 // Unsubscribe this person/team.
1321 unsubscribe_current_user(subscription);1242 unsubscribe_current_user(subscription);
@@ -1392,10 +1313,7 @@
1392 if (team_member) {1313 if (team_member) {
1393 subscription.set('can_be_unsubscribed', true);1314 subscription.set('can_be_unsubscribed', true);
1394 add_temp_user_name(subscription);1315 add_temp_user_name(subscription);
1395 var mute_subscription;1316 update_mute_after_subscription_change();
1396 mute_subscription = get_mute_subscription();
1397 update_mute_after_subscription_change(
1398 mute_subscription);
1399 } else {1317 } else {
1400 subscription.set(1318 subscription.set(
1401 'can_be_unsubscribed', false);1319 'can_be_unsubscribed', false);
14021320
=== modified file 'lib/lp/bugs/javascript/subscriber.js'
--- lib/lp/bugs/javascript/subscriber.js 2011-04-22 16:59:16 +0000
+++ lib/lp/bugs/javascript/subscriber.js 2011-05-20 15:07:33 +0000
@@ -57,7 +57,7 @@
57 },57 },
5858
59 'spinner': {59 'spinner': {
60 vallue: null60 value: null
61 },61 },
6262
63 'bug_notification_level': {63 'bug_notification_level': {

Subscribers

People subscribed via source and target branches

to status/vote changes: