From 3365665c903b95ed354b269d63d312a27d89fce7 Mon Sep 17 00:00:00 2001 From: Byron Jones Date: Tue, 15 Jul 2014 00:12:40 +0800 Subject: Bug 1036301: change the description of the "bug id" field on bugmail filtering preferences tab to "new bug" --- extensions/BugmailFilter/Extension.pm | 41 ++++++++++++---------- .../default/account/prefs/bugmail_filter.html.tmpl | 2 +- 2 files changed, 23 insertions(+), 20 deletions(-) diff --git a/extensions/BugmailFilter/Extension.pm b/extensions/BugmailFilter/Extension.pm index a5fdba922..6bcfe70d6 100644 --- a/extensions/BugmailFilter/Extension.pm +++ b/extensions/BugmailFilter/Extension.pm @@ -22,6 +22,7 @@ use Bugzilla::Extension::BugmailFilter::Filter; use Bugzilla::Field; use Bugzilla::Product; use Bugzilla::User; +use Bugzilla::Util qw(template_var); use Encode; use Sys::Syslog qw(:DEFAULT); @@ -94,42 +95,41 @@ sub user_preferences { } my $vars = $args->{vars}; + my $field_descs = template_var('field_descs'); - my @fields = @{ Bugzilla->fields({ obsolete => 0 }) }; + # load all fields into a hash for easy manipulation + my %fields = + map { $_->name => $field_descs->{$_->name} } + @{ Bugzilla->fields({ obsolete => 0 }) }; # remove time trackinger fields if (!Bugzilla->user->is_timetracker) { - foreach my $tt_field (TIMETRACKING_FIELDS) { - @fields = grep { $_->name ne $tt_field } @fields; + foreach my $field (TIMETRACKING_FIELDS) { + delete $fields{$field}; } } # remove fields which don't make any sense to filter on - foreach my $ignore_field (IGNORE_FIELDS) { - @fields = grep { $_->name ne $ignore_field } @fields; + foreach my $field (IGNORE_FIELDS) { + delete $fields{$field}; } # remove all tracking flag fields. these change too frequently to be of # value, so they only add noise to the list. - foreach my $name (@{ Bugzilla->tracking_flag_names }) { - @fields = grep { $_->name ne $name } @fields; + foreach my $field (@{ Bugzilla->tracking_flag_names }) { + delete $fields{$field}; } # add tracking flag types instead foreach my $field ( @{ Bugzilla::Extension::BugmailFilter::FakeField->tracking_flag_fields() } ) { - push @fields, $field; + $fields{$field->name} = $field->description; } - # adjust the description for selected fields. as we shouldn't touch the - # real Field objects, we remove the object and insert a FakeField object - foreach my $override_field (keys %{ FIELD_DESCRIPTION_OVERRIDE() }) { - @fields = grep { $_->name ne $override_field } @fields; - push @fields, Bugzilla::Extension::BugmailFilter::FakeField->new({ - name => $override_field, - description => FIELD_DESCRIPTION_OVERRIDE->{$override_field}, - }); + # adjust the description for selected fields + foreach my $field (keys %{ FIELD_DESCRIPTION_OVERRIDE() }) { + $fields{$field} = FIELD_DESCRIPTION_OVERRIDE->{$field}; } # some fields are present in the changed-fields x-header but are not real @@ -137,11 +137,14 @@ sub user_preferences { foreach my $field ( @{ Bugzilla::Extension::BugmailFilter::FakeField->fake_fields() } ) { - push @fields, $field; + $fields{$field->name} = $field->description; } - @fields = sort { lc($a->description) cmp lc($b->description) } @fields; - $vars->{fields} = \@fields; + $vars->{fields} = [ + sort { lc($a->{description}) cmp lc($b->{description}) } + map { { name => $_, description => $fields{$_} } } + keys %fields + ]; $vars->{relationships} = FILTER_RELATIONSHIPS(); diff --git a/extensions/BugmailFilter/template/en/default/account/prefs/bugmail_filter.html.tmpl b/extensions/BugmailFilter/template/en/default/account/prefs/bugmail_filter.html.tmpl index d2df77d22..83c8d729a 100644 --- a/extensions/BugmailFilter/template/en/default/account/prefs/bugmail_filter.html.tmpl +++ b/extensions/BugmailFilter/template/en/default/account/prefs/bugmail_filter.html.tmpl @@ -45,7 +45,7 @@ var cpts = new Array(); [% FOREACH field = fields %] [% END %] -- cgit v1.2.3-24-g4f1b