From 37aef45426f4b831bbced64783568f8104b42dcb Mon Sep 17 00:00:00 2001 From: Dave Lawrence Date: Tue, 3 Sep 2013 17:57:42 -0400 Subject: Bug 912232 - Show tracking flag bug counts in tracking flag list as well as on the edit page --- extensions/TrackingFlags/lib/Admin.pm | 6 +++--- extensions/TrackingFlags/lib/Flag.pm | 13 ++++++------- .../en/default/pages/tracking_flags_admin_edit.html.tmpl | 7 +++++++ .../en/default/pages/tracking_flags_admin_list.html.tmpl | 14 +++++++++++++- 4 files changed, 29 insertions(+), 11 deletions(-) diff --git a/extensions/TrackingFlags/lib/Admin.pm b/extensions/TrackingFlags/lib/Admin.pm index 3529d30a7..2796a102d 100644 --- a/extensions/TrackingFlags/lib/Admin.pm +++ b/extensions/TrackingFlags/lib/Admin.pm @@ -37,7 +37,7 @@ our @EXPORT = qw( sub admin_list { my ($vars) = @_; - + $vars->{show_bug_counts} = Bugzilla->input_params->{show_bug_counts}; $vars->{flags} = [ Bugzilla::Extension::TrackingFlags::Flag->get_all() ]; } @@ -75,7 +75,7 @@ sub admin_edit { $vars->{flag} = $flag_obj; $vars->{values} = _flag_values_to_json($values); $vars->{visibility} = _flag_visibility_to_json($visibilities); - $vars->{can_delete} = !$flag_obj->has_bug_values; + $vars->{can_delete} = !$flag_obj->bug_count; if ($vars->{mode} eq 'new') { $vars->{message} = 'tracking_flag_created'; @@ -93,7 +93,7 @@ sub admin_edit { $vars->{flag} = $flag; $vars->{values} = _flag_values_to_json($flag->values); $vars->{visibility} = _flag_visibility_to_json($flag->visibility); - $vars->{can_delete} = !$flag->has_bug_values; + $vars->{can_delete} = !$flag->bug_count; } elsif ($vars->{mode} eq 'copy') { # copy - load the source flag diff --git a/extensions/TrackingFlags/lib/Flag.pm b/extensions/TrackingFlags/lib/Flag.pm index f35b661eb..26780a2b1 100644 --- a/extensions/TrackingFlags/lib/Flag.pm +++ b/extensions/TrackingFlags/lib/Flag.pm @@ -223,7 +223,7 @@ sub remove_from_db { } # Check to see if tracking_flags_bugs table has records - if ($self->has_bug_values) { + if ($self->bug_count) { ThrowUserError('tracking_flag_has_contents', { flag => $self }); } @@ -396,15 +396,14 @@ sub bug_flag { return $self->{'bug_flag'} = Bugzilla::Extension::TrackingFlags::Flag::Bug->new($params); } -sub has_bug_values { +sub bug_count { my ($self) = @_; - return $self->{'has_bug_values'} if defined $self->{'has_bug_values'}; + return $self->{'bug_count'} if defined $self->{'bug_count'}; my $dbh = Bugzilla->dbh; - return $self->{'has_bug_values'} = scalar $dbh->selectrow_array(" - SELECT 1 + return $self->{'bug_count'} = scalar $dbh->selectrow_array(" + SELECT COUNT(bug_id) FROM tracking_flags_bugs - WHERE tracking_flag_id = ? " . - $dbh->sql_limit(1), + WHERE tracking_flag_id = ?", undef, $self->flag_id); } diff --git a/extensions/TrackingFlags/template/en/default/pages/tracking_flags_admin_edit.html.tmpl b/extensions/TrackingFlags/template/en/default/pages/tracking_flags_admin_edit.html.tmpl index 0c4a443f9..97a9e5a02 100644 --- a/extensions/TrackingFlags/template/en/default/pages/tracking_flags_admin_edit.html.tmpl +++ b/extensions/TrackingFlags/template/en/default/pages/tracking_flags_admin_edit.html.tmpl @@ -102,6 +102,13 @@ var selected_components = [ +[% IF mode == 'edit' %] + + [% terms.Bug %] Count + [% flag.bug_count FILTER html %] + +[% END %] + [%# values %] diff --git a/extensions/TrackingFlags/template/en/default/pages/tracking_flags_admin_list.html.tmpl b/extensions/TrackingFlags/template/en/default/pages/tracking_flags_admin_list.html.tmpl index e310bcee5..5ea68dd98 100644 --- a/extensions/TrackingFlags/template/en/default/pages/tracking_flags_admin_list.html.tmpl +++ b/extensions/TrackingFlags/template/en/default/pages/tracking_flags_admin_list.html.tmpl @@ -20,6 +20,9 @@ Type Sort Key Active + [% IF show_bug_counts %] + [% terms.Bugs %] + [% END %]   @@ -44,8 +47,13 @@ [% flag.is_active ? "Yes" : "No" %] + [% IF show_bug_counts %] + + [% flag.bug_count FILTER html %] + + [% END %] - Copy + Copy [% END %] @@ -54,6 +62,10 @@
Add Flag | + [% IF !show_bug_counts %] + + Show [% terms.bug %] counts (slower) | + [% END %]
-- cgit v1.2.3-24-g4f1b