[Rt-commit] rt branch, 4.2/chart-label-looks-like-number, created. rt-4.2.2-32-gc1c8827

Jim Brandt jbrandt at bestpractical.com
Tue Feb 11 14:22:44 EST 2014


The branch, 4.2/chart-label-looks-like-number has been created
        at  c1c882747c8527d653f5a25439a9af1829119699 (commit)

- Log -----------------------------------------------------------------
commit c1c882747c8527d653f5a25439a9af1829119699
Author: Jim Brandt <jbrandt at bestpractical.com>
Date:   Tue Feb 11 14:21:04 2014 -0500

    Sort chart values numerically if they all look like numbers

diff --git a/lib/RT/Report/Tickets.pm b/lib/RT/Report/Tickets.pm
index 3561434..3dab64e 100644
--- a/lib/RT/Report/Tickets.pm
+++ b/lib/RT/Report/Tickets.pm
@@ -643,13 +643,34 @@ sub SortEntries {
         my $idx = $i+1;
         my $method;
 
-        my $order = $group_by->{'META'}{Sort} || 'label';
+        # If this is a CF, traverse the values being used for labels.
+        # If they all look like numbers or undef, flag for a numeric sort
+
+        my $looks_like_number;
+        if ( $group_by->{'KEY'} eq 'CF' ){
+            $looks_like_number = 1;
+
+            foreach my $item (@data){
+                my $cf_label = $item->[0]->RawValue($group_by->{'NAME'});
+
+                $looks_like_number = 0
+                    unless (not defined $cf_label)
+                    or Scalar::Util::looks_like_number( $cf_label );
+            }
+        }
+
+        my $order = $looks_like_number ? 'numeric label' : 'label';
+        $order //= $group_by->{'META'}{Sort};
+
         if ( $order eq 'label' ) {
             push @SORT_OPS, sub { $_[0][$idx] cmp $_[1][$idx] };
             $method = 'LabelValue';
         }
         elsif ( $order eq 'numeric label' ) {
-            push @SORT_OPS, sub { $_[0][$idx] <=> $_[1][$idx] };
+            push @SORT_OPS, sub {
+                # Suppress warning for (no value) entries
+                no warnings 'numeric';
+                $_[0][$idx] <=> $_[1][$idx] };
             $method = 'LabelValue';
         }
         elsif ( $order eq 'raw' ) {

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


More information about the rt-commit mailing list