]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
Bug 897915 - Field lists not sorted alphabetically
authorSimon Green <sgreen@redhat.com>
Sun, 10 Aug 2014 07:42:10 +0000 (17:42 +1000)
committerSimon Green <sgreen@redhat.com>
Sun, 10 Aug 2014 07:42:10 +0000 (17:42 +1000)
r=dkl, a=sgreen

Bugzilla/Template.pm
t/011pod.t
template/en/default/search/boolean-charts.html.tmpl
template/en/default/search/search-report-select.html.tmpl

index b36249b2f21872da39798b5fcd6ac39a59bb9f9b..52ccee593c0711d28d9c76ab5ce15b03cc70d2d1 100644 (file)
@@ -611,6 +611,21 @@ $Template::Stash::LIST_OPS->{ clone } =
       return [@$list];
   };
 
+# Allow us to sort the list of fields correctly
+$Template::Stash::LIST_OPS->{ sort_by_field_name } =
+    sub {
+        sub field_name {
+            if ($_[0] eq 'noop') {
+                # Sort --- first
+                return '';
+            }
+            # Otherwise sort by field_desc or description
+            return $_[1]{$_[0]} || $_[0];
+        }
+        my ($list, $field_desc) = @_;
+        return [ sort { lc field_name($a, $field_desc) cmp lc field_name($b, $field_desc) } @$list ];
+    };
+
 # Allow us to still get the scalar if we use the list operation ".0" on it,
 # as we often do for defaults in query.cgi and other places.
 $Template::Stash::SCALAR_OPS->{ 0 } = 
index c3ec39898deca7d7e3d31ec4a384764ae07e632d..fc66bca63b335d124dc5ec9181e4b86627c568bf 100644 (file)
@@ -32,6 +32,7 @@ use constant SUB_WHITELIST => (
     'Bugzilla::FlagType' => qr/^sqlify_criteria$/,
     'Bugzilla::JobQueue' => qr/(?:^work_once|work_until_done|subprocess_worker)$/,
     'Bugzilla::Search'   => qr/^SPECIAL_PARSING$/,
+    'Bugzilla::Template' => qr/^field_name$/,
 );
 
 # These modules do not need to be documented, generally because they
index 901de050199aa38b4ce2111e5eb48683868cf04d..bfb4e7bf1bb46d71190a7b977db556b947fd02e8 100644 (file)
               id="f[% cond_num FILTER html %]"
               onchange="fix_query_string(this)"
               class="custom_search_form_field">
-        [% FOREACH field = fields %]
+        [%# Turn the array in to a hash with the name as the key %]
+        [%
+          field_hash = {};
+          FOREACH field IN fields;
+            field_hash.${field.name} = field;
+          END;
+        %]
+        [% FOREACH field_name = field_hash.keys.sort_by_field_name(field_descs) %]
+          [% field = field_hash.$field_name %]
           <option value="[% field.name FILTER html %]"
                   [%~ ' selected="selected"' IF field.name == condition.f %]>
             [% field_descs.${field.name} || field.description FILTER html %]
index 93b4c44f8c73e93994eff393b26a4d85bb32afe5..40eeda1c13961db7f19d8659cb0e6453372e8e7c 100644 (file)
@@ -17,7 +17,7 @@
   <select name="[% name FILTER html %]">
     <option value="">&lt;none&gt;</option>
     
-    [% FOREACH field = report_columns.keys.sort %]
+    [% FOREACH field = report_columns.keys.sort_by_field_name(field_descs) %]
       [% NEXT IF field == "classification" AND !Param('useclassification') %]
       [% NEXT IF field == "target_milestone" AND !Param('usetargetmilestone') %]
       [% NEXT IF field == "qa_contact" AND !Param('useqacontact') %]