diff options
author | Byron Jones <bjones@mozilla.com> | 2012-08-07 07:24:15 +0200 |
---|---|---|
committer | Byron Jones <bjones@mozilla.com> | 2012-08-07 07:24:15 +0200 |
commit | f94befed1c326a403550182b3fb56e6731e5d276 (patch) | |
tree | 827fc441fabbd7785fb90ffaa44501b4eaf753fd | |
parent | 88c13e9f2694db2d91f0f76f0d485395921135e2 (diff) | |
download | bugzilla-f94befed1c326a403550182b3fb56e6731e5d276.tar.gz bugzilla-f94befed1c326a403550182b3fb56e6731e5d276.tar.xz |
Bug 778971: show components watched via watch-users on the "component watching" preferences tab
-rw-r--r-- | extensions/ComponentWatching/Extension.pm | 56 | ||||
-rw-r--r-- | extensions/ComponentWatching/template/en/default/account/prefs/component_watch.html.tmpl | 142 |
2 files changed, 146 insertions, 52 deletions
diff --git a/extensions/ComponentWatching/Extension.pm b/extensions/ComponentWatching/Extension.pm index 2b583ee4e..00c0e49d3 100644 --- a/extensions/ComponentWatching/Extension.pm +++ b/extensions/ComponentWatching/Extension.pm @@ -62,8 +62,8 @@ sub db_schema_abstract_schema { sub install_update_db { my $dbh = Bugzilla->dbh; $dbh->bz_add_column( - 'components', - 'watch_user', + 'components', + 'watch_user', { TYPE => 'INT3', REFERENCES => { @@ -151,7 +151,7 @@ sub object_end_of_update { my $old_id = $old_object->watch_user ? $old_object->watch_user->id : 0; my $new_id = $object->watch_user ? $object->watch_user->id : 0; - return unless $old_id == $new_id; + return if $old_id == $new_id; $changes->{watch_user} = [ $old_id ? $old_id : undef, $new_id ? $new_id : undef ]; } @@ -230,9 +230,10 @@ sub user_preferences { } } - $vars->{'add_product'} = $input->{'product'}; + $vars->{'add_product'} = $input->{'product'}; $vars->{'add_component'} = $input->{'component'}; - $vars->{'watches'} = _getWatches($user); + $vars->{'watches'} = _getWatches($user); + $vars->{'user_watches'} = _getUserWatches($user); $$handled = 1; } @@ -335,7 +336,7 @@ sub _getWatches { my $dbh = Bugzilla->dbh; my $sth = $dbh->prepare(" - SELECT product_id, component_id + SELECT product_id, component_id FROM component_watch WHERE user_id = ? "); @@ -355,7 +356,40 @@ sub _getWatches { push @watches, \%watch; } - @watches = sort { + @watches = sort { + $a->{'product'}->name cmp $b->{'product'}->name + || $a->{'component'}->name cmp $b->{'component'}->name + } @watches; + + return \@watches; +} + +sub _getUserWatches { + my ($user) = @_; + my $dbh = Bugzilla->dbh; + + my $sth = $dbh->prepare(" + SELECT components.product_id, components.id as component, profiles.login_name + FROM watch + INNER JOIN components ON components.watch_user = watched + INNER JOIN profiles ON profiles.userid = watched + WHERE watcher = ? + "); + $sth->execute($user->id); + my @watches; + while (my ($productId, $componentId, $login) = $sth->fetchrow_array) { + my $product = Bugzilla::Product->new($productId); + next unless $product && $user->can_access_product($product); + + my %watch = ( + product => $product, + component => Bugzilla::Component->new($componentId), + user => Bugzilla::User->check($login), + ); + push @watches, \%watch; + } + + @watches = sort { $a->{'product'}->name cmp $b->{'product'}->name || $a->{'component'}->name cmp $b->{'component'}->name } @watches; @@ -368,7 +402,7 @@ sub _addProductWatch { my $dbh = Bugzilla->dbh; my $sth = $dbh->prepare(" - SELECT 1 + SELECT 1 FROM component_watch WHERE user_id = ? AND product_id = ? AND component_id IS NULL "); @@ -393,7 +427,7 @@ sub _addComponentWatch { my $dbh = Bugzilla->dbh; my $sth = $dbh->prepare(" - SELECT 1 + SELECT 1 FROM component_watch WHERE user_id = ? AND (component_id = ? OR (product_id = ? AND component_id IS NULL)) @@ -435,13 +469,13 @@ sub _addDefaultSettings { my $dbh = Bugzilla->dbh; my $sth = $dbh->prepare(" - SELECT 1 + SELECT 1 FROM email_setting WHERE user_id = ? AND relationship = ? "); $sth->execute($user->id, REL_COMPONENT_WATCHER); return if $sth->fetchrow_array; - + my @defaultEvents = ( EVT_OTHER, EVT_COMMENT, diff --git a/extensions/ComponentWatching/template/en/default/account/prefs/component_watch.html.tmpl b/extensions/ComponentWatching/template/en/default/account/prefs/component_watch.html.tmpl index 0eed6b3b3..05c1453db 100644 --- a/extensions/ComponentWatching/template/en/default/account/prefs/component_watch.html.tmpl +++ b/extensions/ComponentWatching/template/en/default/account/prefs/component_watch.html.tmpl @@ -9,6 +9,7 @@ [%# initialise product to component mapping #%] [% SET selectable_products = user.get_selectable_products %] +[% SET dont_show_button = 1 %] <script> var Dom = YAHOO.util.Dom; @@ -66,14 +67,31 @@ function onSelectComponent() { } else { Dom.get('watch-user-div').style.display = 'none'; } + Dom.get('add').disabled = Dom.get('component').selectedIndex == -1; } YAHOO.util.Event.onDOMReady(onSelectProduct); + +function onRemoveChange() { + var cbs = Dom.get('remove_table').getElementsByTagName('input'); + for (var i = 0, l = cbs.length; i < l; i++) { + if (cbs[i].checked) { + Dom.get('remove').disabled = false; + return; + } + } + Dom.get('remove').disabled = true; +} + +YAHOO.util.Event.onDOMReady(onRemoveChange); + </script> <p> -Select the components you want to watch. To watch all components in a product, -watch "__Any__". + Select the components you want to watch. + To watch all components in a product, watch "__Any__".<br> + Use <a href="userprefs.cgi?tab=email">Email Preferences</a> to filter which + notification emails you receive. </p> <table border="0" cellpadding="3" cellspacing="0"> @@ -116,57 +134,99 @@ watch "__Any__". </tr> </table> -<p> -Use <a href="userprefs.cgi?tab=email">Email Preferences</a> to filter which -notification emails you receive. -</p> - <hr> <p> -You are currently watching: + You are currently watching: </p> [% IF watches.size %] -<table border="0" cellpadding="5" cellspacing="0"> -<tr> - <td> </td> - <td><b>Product</b></td> - <td><b>Component</b></td> -</tr> -[% FOREACH watch IN watches %] + <table border="0" cellpadding="3" cellspacing="0" id="remove_table"> <tr> - [% IF (watch.component) %] - <td><input type="checkbox" name="del_[% watch.product.id FILTER html %]_[% watch.component.id FILTER html %]" value="1"></td> - <td>[% watch.component.product.name FILTER html %]</td> - <td> - <a href="buglist.cgi?product=[% watch.product.name FILTER uri ~%] - &component=[% watch.component.name FILTER uri %]&resolution=---"> - [% watch.component.name FILTER html %] - </a> - </td> - [% ELSE %] - <td><input type="checkbox" name="del_[% watch.product.id FILTER html %]" value="1"></td> - <td>[% watch.product.name FILTER html %]</td> - <td> - <a href="describecomponents.cgi?product=[% watch.product.name FILTER html %]"> - __Any__ - </a> - </td> - [% END %] + <td> </td> + <td><b>Product</b></td> + <td> <b>Component</b></td> </tr> -[% END %] -</table> + [% FOREACH watch IN watches %] + <tr> + [% IF (watch.component) %] + <td> + <input type="checkbox" onChange="onRemoveChange()" id="cwdel_[% loop.count %]" value="1" + name="del_[% watch.product.id FILTER html %]_[% watch.component.id FILTER html %]"> + </td> + <td> + <label for="cwdel_[% loop.count %]"> + [% watch.component.product.name FILTER html %] + </label> + </td> + <td> + <a href="buglist.cgi?product=[% watch.product.name FILTER url_quote ~%] + &component=[% watch.component.name FILTER url_quote %]&resolution=---"> + [% watch.component.name FILTER html %] + </a> + </td> + [% ELSE %] + <td> + <input type="checkbox" onChange="onRemoveChange()" id="cwdel_[% loop.count %]" value="1" + name="del_[% watch.product.id FILTER html %]" value="1"> + </td> + <td> + <label for="cwdel_[% loop.count %]"> + [% watch.product.name FILTER html %] + </label> + </td> + <td> + <a href="describecomponents.cgi?product=[% watch.product.name FILTER url_quote %]"> + __Any__ + </a> + </td> + [% END %] + </tr> + [% END %] + </table> -<p> -Select the items you want to stop watching. -</p> + <input id="remove" type="submit" value="Remove Selected"> [% ELSE %] -<p> -<i>You are not watching any components.</i> -</p> + <p> + <i>You are not watching any components directly.</i> + </p> + +[% END %] + +[% IF user_watches.size %] + + <hr> + <p> + [% watches.size ? "In addition," : "However," %] + you are watching the following components by watching users: + </p> + + <table border="0" cellpadding="3" cellspacing="0"> + <tr> + <td><b>User</b></td> + <td> <b>Product</b></td> + <td> <b>Component</b></td> + </tr> + [% FOREACH watch IN user_watches %] + <tr> + <td>[% watch.user.login FILTER html %]</td> + <td> [% watch.component.product.name FILTER html %]</td> + <td> + <a href="buglist.cgi?product=[% watch.product.name FILTER url_quote ~%] + &component=[% watch.component.name FILTER url_quote %]&resolution=---"> + [% watch.component.name FILTER html %] + </a> + </td> + </tr> + [% END %] + </table> + + <p> + Use <a href="userprefs.cgi?tab=email#new_watched_by_you">Email Preferences</a> + to manage this list. + </p> [% END %] |