display date custom fields as real dates, #23121
authorMark Wells <mark@freeside.biz>
Wed, 29 May 2013 20:15:22 +0000 (13:15 -0700)
committerMark Wells <mark@freeside.biz>
Wed, 29 May 2013 20:15:22 +0000 (13:15 -0700)
rt/lib/RT/Interface/Web_Vendor.pm
rt/share/html/Elements/ColumnMap
rt/share/html/Elements/RT__Ticket/ColumnMap
rt/share/html/Search/Elements/ResultsStructuredView

index ae7f089..fb2b807 100644 (file)
@@ -553,5 +553,32 @@ sub ProcessUpdateMessage {
     return @results;
 }
 
+sub default_FormatDate { $_[0]->AsString }
+
+sub ProcessColumnMapValue {
+    my $value = shift;
+    my %args = ( Arguments => [],
+                 Escape => 1,
+                 FormatDate => \&default_FormatDate,
+                 @_ );
+
+    if ( ref $value ) {
+        if ( ref $value eq 'RT::Date' ) {
+            return $args{FormatDate}->($value);
+        } elsif ( UNIVERSAL::isa( $value, 'CODE' ) ) {
+            my @tmp = $value->( @{ $args{'Arguments'} } );
+            return ProcessColumnMapValue( ( @tmp > 1 ? \@tmp : $tmp[0] ), %args );
+        } elsif ( UNIVERSAL::isa( $value, 'ARRAY' ) ) {
+            return join '', map ProcessColumnMapValue( $_, %args ), @$value;
+        } elsif ( UNIVERSAL::isa( $value, 'SCALAR' ) ) {
+            return $$value;
+        }
+    }
+
+    return $m->interp->apply_escapes( $value, 'h' ) if $args{'Escape'};
+    return $value;
+}
+
+
 1;
 
index f268a5d..878950b 100644 (file)
@@ -64,8 +64,7 @@ my $COLUMN_MAP = {
     Created => {
         attribute => 'Created',
         title     => 'Created', # loc
-        date      => sub { return $_[0]->CreatedObj },
-        value     => sub { return $_[0]->CreatedObj->AsString }
+        value     => sub { return $_[0]->CreatedObj },
     },
     CreatedRelative => {
         attribute => 'Created',
@@ -80,8 +79,7 @@ my $COLUMN_MAP = {
     LastUpdated => {
         attribute => 'LastUpdated',
         title     => 'Last Updated', # loc
-        date      => sub { return $_[0]->LastUpdatedObj },
-        value     => sub { return $_[0]->LastUpdatedObj->AsString }
+        value     => sub { return $_[0]->LastUpdatedObj },
     },
     LastUpdatedRelative => {
         attribute => 'LastUpdated',
@@ -101,15 +99,31 @@ my $COLUMN_MAP = {
             # Display custom field contents, separated by newlines.
             # For Image custom fields we also show a thumbnail here.
 
-            my $values = $_[0]->CustomFieldValues( $_[-1] );
-            my @values = map {
-                (
-                    ($_->CustomFieldObj->Type eq 'Image')
-                        ? \($m->scomp( '/Elements/ShowCustomFieldImage', Object => $_ ))
-                        : $_->Content
-                ),
-                \'<br />',
-            } @{ $values->ItemsArrayRef };
+            my $object = shift;
+            my $cfname = pop;
+            my $values = $object->CustomFieldValues( $cfname );
+            return if $values->Count == 0;
+            my @values;
+            # it is guaranteed to be the same type for all fields, right?
+            my $v = $values->First;
+            my $cftype = $v->CustomFieldObj->Type;
+
+            do {
+                if ($cftype eq 'Image') {
+                    push @values, 
+                        \($m->scomp( '/Elements/ShowCustomFieldImage',
+                                      Object => $v ));
+                } elsif ( $cftype eq 'Date' or $cftype eq 'DateTime' ) {
+                    # then actually return the date object;
+                    # ProcessColumnMapValue will stringify it
+                    my $DateObj = RT::Date->new( $session{'CurrentUser'} );
+                    $DateObj->Set(Format => 'unknown', Value => $v->Content);
+                    push @values, $DateObj;
+                } else {
+                    push @values, $v->Content;
+                }
+                push @values, \'<br />'; # this is deeply silly
+            } while ($v = $values->Next);
             pop @values; # Remove that last <br />
             return @values;
         },
index 787862d..239e581 100644 (file)
@@ -220,32 +220,27 @@ $COLUMN_MAP = {
     Starts => {
         title     => 'Starts', # loc
         attribute => 'Starts',
-        date      => sub { return $_[0]->StartsObj },
-        value     => sub { return $_[0]->StartsObj->AsString }
+        value     => sub { return $_[0]->StartsObj }
     },
     Started => {
         title     => 'Started', # loc
         attribute => 'Started',
-        date      => sub { return $_[0]->StartedObj },
-        value     => sub { return $_[0]->StartedObj->AsString }
+        value     => sub { return $_[0]->StartedObj },
     },
     Told => {
         title     => 'Told', # loc
         attribute => 'Told',
-        date      => sub { return $_[0]->ToldObj },
-        value     => sub { return $_[0]->ToldObj->AsString }
+        value     => sub { return $_[0]->ToldObj },
     },
     Due => {
         title     => 'Due', # loc
         attribute => 'Due',
-        date      => sub { return $_[0]->DueObj },
-        value     => sub { return $_[0]->DueObj->AsString }
+        value     => sub { return $_[0]->DueObj },
     },
     Resolved => {
         title     => 'Resolved', # loc
         attribute => 'Resolved',
-        date      => sub { return $_[0]->ResolvedObj },
-        value     => sub { return $_[0]->ResolvedObj->AsString }
+        value     => sub { return $_[0]->ResolvedObj }
     },
     UpdateStatus => {
         title => 'New messages', # loc
index 495f0d0..0e9457c 100644 (file)
@@ -132,7 +132,7 @@ while ( my $Ticket = $Tickets->Next()) {
 
             if ( !exists $ColumnMap->{$col}{'value'} ) {
                 my $map = {};
-                foreach ('attribute', 'value', 'date') {
+                foreach ('attribute', 'value') {
                     $map->{$_} = $m->comp(
                         '/Elements/ColumnMap',
                         Class => 'RT__Ticket',
@@ -140,19 +140,13 @@ while ( my $Ticket = $Tickets->Next()) {
                         Attr  => $_,
                     );
                 }
-                # Canonicalize dates
-                if ( defined $map->{'date'} ) {
-                    $map->{value} = sub { 
-                        my $DateObj = $map->{'date'}->(@_) or return undef;
-                        $FormatDate->($DateObj);
-                    };
-                }
                 $ColumnMap->{$col} = $map;
             }
 
             push @out, ProcessColumnMapValue(
                 $ColumnMap->{$col}{'value'},
                 Arguments => [ $Ticket, $row ],
+                FormatDate => $FormatDate,
             );
         } #foreach $subcol
         $value = join('', '<span>', @out, '</span>');