[Rt-commit] rt branch, 4.2/grouping-ordering, created. rt-4.1.8-312-g2cac383

Alex Vandiver alexmv at bestpractical.com
Fri May 17 15:41:37 EDT 2013


The branch, 4.2/grouping-ordering has been created
        at  2cac3835f732ac584351d2a00506ce996a36736c (commit)

- Log -----------------------------------------------------------------
commit 2cac3835f732ac584351d2a00506ce996a36736c
Author: Alex Vandiver <alexmv at bestpractical.com>
Date:   Fri May 17 07:27:03 2013 -0400

    Allow the configuration to specify the ordering of the groupings

diff --git a/etc/RT_Config.pm.in b/etc/RT_Config.pm.in
index a56891f..4810bb4 100755
--- a/etc/RT_Config.pm.in
+++ b/etc/RT_Config.pm.in
@@ -852,34 +852,37 @@ Set(@CustomFieldValuesSources, ());
 =item C<%CustomFieldGroupings>
 
 This option affects the display of ticket and user custom fields in the
-web interface. It does not address the sorting of custom fields. The
-order that custom fields are rendered is controlled by the Ticket
-Custom Fields tab in Queue Configuration in the Admin UI.
+web interface. It does not address the sorting of custom fields within
+the groupings; which is controlled by the Ticket Custom Fields tab in
+Queue Configuration in the Admin UI.
 
 A nested datastructure defines how to group together custom fields
 under a mix of built-in and arbitrary headings ("groupings").
 
-Set C<%CustomFieldGroupings> to a nested hash similar to the following:
+Set C<%CustomFieldGroupings> to a nested structure similar to the following:
 
     Set(%CustomFieldGroupings,
-        'RT::Ticket' => {
+        'RT::Ticket' => [
             'Grouping Name'     => ['CF Name', 'Another CF'],
             'Another Grouping'  => ['Some CF'],
             'Dates'             => ['Shipped date'],
-        },
-        'RT::User' => {
+        ],
+        'RT::User' => [
             'Phones' => ['Fax number'],
-        },
+        ],
     );
 
-The first level keys are record types for which CFs may be used, and the values
-are hashrefs.  The second level keys are the grouping names and the values are
-array refs containing a list of CF names.
-
-There are several special built-in groupings which RT displays in specific
-places (usually the collapsible box of the same title). You may only
-append Custom Fields to the list in these boxes, not reorder or remove
-core fields.
+The first level keys are record types for which CFs may be used, and the
+values are either hashrefs or arrayrefs -- if arrayrefs, then the
+ordering is preserved during display, otherwise groupings are displayed
+alphabetically.  The second level keys are the grouping names and the
+values are array refs containing a list of CF names.
+
+There are several special built-in groupings which RT displays in
+specific places (usually the collapsible box of the same title).  The
+ordering of these standard groupings cannot be modified.  You may also
+only append Custom Fields to the list in these boxes, not reorder or
+remove core fields.
 
 For C<RT::Ticket>, these groupings are: C<Basics>, C<Dates>, C<Links>, C<People>
 
diff --git a/lib/RT/Config.pm b/lib/RT/Config.pm
index a2cc28c..754c59f 100644
--- a/lib/RT/Config.pm
+++ b/lib/RT/Config.pm
@@ -788,15 +788,26 @@ our %META = (
             }
 
             for my $class (keys %$groups) {
-                unless (ref($groups->{$class}) eq 'HASH') {
-                    RT->Logger->error("Config option \%CustomFieldGroupings{$class} is not a HASH; ignoring");
+                my @h;
+                if (ref($groups->{$class}) eq 'HASH') {
+                    push @h, $_, $groups->{$class}->{$_}
+                        for sort {lc($a) cmp lc($b)} keys %{ $groups->{$class} };
+                } elsif (ref($groups->{$class}) eq 'ARRAY') {
+                    @h = @{ $groups->{$class} };
+                } else {
+                    RT->Logger->error("Config option \%CustomFieldGroupings{$class} is not a HASH or ARRAY; ignoring");
                     delete $groups->{$class};
                     next;
                 }
-                for my $group (keys %{ $groups->{$class} }) {
-                    unless (ref($groups->{$class}{$group}) eq 'ARRAY') {
+
+                $groups->{$class} = [];
+                while (@h) {
+                    my $group = shift @h;
+                    my $ref   = shift @h;
+                    if (ref($ref) eq 'ARRAY') {
+                        push @{$groups->{$class}}, $group => $ref;
+                    } else {
                         RT->Logger->error("Config option \%CustomFieldGroupings{$class}{$group} is not an ARRAY; ignoring");
-                        delete $groups->{$class}{$group};
                     }
                 }
             }
diff --git a/lib/RT/CustomField.pm b/lib/RT/CustomField.pm
index 302a822..799b641 100644
--- a/lib/RT/CustomField.pm
+++ b/lib/RT/CustomField.pm
@@ -1275,16 +1275,19 @@ sub Groupings {
 
     my @groups;
     if ( $record_class ) {
-        push @groups, keys %{ $config->{$record_class} || {} };
-        push @groups, keys %{ $BUILTIN_GROUPINGS{$record_class} || {} };
+        push @groups, sort {lc($a) cmp lc($b)} keys %{ $BUILTIN_GROUPINGS{$record_class} || {} };
+        my @order = @{ $config->{$record_class} || [] };
+        while (@order) {
+            push @groups, shift(@order);
+            shift(@order);
+        }
     } else {
-        push @groups, map { keys %$_ } values %$config;
-        push @groups, map { keys %$_ } values %BUILTIN_GROUPINGS;
+        my %all = (%$config, %BUILTIN_GROUPINGS);
+        @groups = sort {lc($a) cmp lc($b)} map {$self->Groupings($_)} grep {$_} keys(%all);
     }
 
     my %seen;
     return
-        sort { lc($a) cmp lc($b) }
         grep defined && length && !$seen{lc $_}++,
         @groups;
 }
diff --git a/lib/RT/CustomFields.pm b/lib/RT/CustomFields.pm
index 48e571d..7e01b68 100644
--- a/lib/RT/CustomFields.pm
+++ b/lib/RT/CustomFields.pm
@@ -123,9 +123,10 @@ sub LimitToGrouping {
     my $config = RT->Config->Get('CustomFieldGroupings');
        $config = {} unless ref($config) eq 'HASH';
        $config = $config->{ref($obj) || $obj} || {};
+    my %h = @{$config};
 
     if ( $grouping ) {
-        my $list = $config->{$grouping};
+        my $list = $h{$grouping};
         unless ( $list and ref($list) eq 'ARRAY' and @$list ) {
             return $self->Limit( FIELD => 'id', VALUE => 0, ENTRYAGGREGATOR => 'AND' );
         }
@@ -134,7 +135,7 @@ sub LimitToGrouping {
         }
     } else {
         my @list = map {@$_} grep defined && ref($_) eq 'ARRAY',
-            values %{ $config };
+            values %h;
 
         return unless @list;
         foreach ( @list ) {

-----------------------------------------------------------------------


More information about the Rt-commit mailing list