[Rt-commit] rt branch, 4.2/cf-display-in-searches, created. rt-4.1.6-162-ge3fcdec

Thomas Sibley trs at bestpractical.com
Wed Feb 6 14:47:28 EST 2013


The branch, 4.2/cf-display-in-searches has been created
        at  e3fcdec49893cdeed23a2ccbef01ce8ffceefd4c (commit)

- Log -----------------------------------------------------------------
commit ee2c9df0c6bf3e5ec1151db85a53eb19c29dcaf7
Author: Thomas Sibley <trs at bestpractical.com>
Date:   Tue Feb 5 19:36:41 2013 -0800

    Display CF values in searches using the standard display components
    
    All types of custom fields are now rendered in search results, instead
    of revealing their internal values.  Multiple values are displayed as a
    true list, instead of newline separated, to better match
    /Elements/ShowCustomFields.
    
    Values linked to a URL template and AJAX included content are still
    ignored.

diff --git a/share/html/Elements/ColumnMap b/share/html/Elements/ColumnMap
index e999b76..508af75 100644
--- a/share/html/Elements/ColumnMap
+++ b/share/html/Elements/ColumnMap
@@ -109,18 +109,23 @@ my $COLUMN_MAP = {
                 $m->notes($key, $cf);
             }
 
-            # Display custom field contents, separated by newlines.
-            # For Image custom fields we also show a thumbnail here.
+            my $comp = $m->comp_exists("/Elements/ShowCustomField".$cf->Type)
+                     ? "/Elements/ShowCustomField".$cf->Type
+                     : undef;
+
             my $values = $cf->ValuesForObject( $_[0] );
             my @values = map {
-                (
-                    ($cf->Type eq 'Image')
-                        ? \($m->scomp( '/Elements/ShowCustomFieldImage', Object => $_ ))
-                        : $_->Content
-                ),
-                \'<br />',
+                $comp
+                    ? \($m->scomp( $comp, Object => $_ ))
+                    : $_->Content
             } @{ $values->ItemsArrayRef };
-            pop @values; # Remove that last <br />
+
+            if (@values > 1) {
+                for my $value (splice @values) {
+                    push @values, \"<li>", $value, \"</li> ";
+                }
+                @values = (\"<ul class='cf-values'>", @values, \"</ul>");
+            }
             return @values;
         },
     },
diff --git a/share/html/NoAuth/css/base/collection.css b/share/html/NoAuth/css/base/collection.css
index cb4fdd8..df0381e 100644
--- a/share/html/NoAuth/css/base/collection.css
+++ b/share/html/NoAuth/css/base/collection.css
@@ -48,3 +48,8 @@
 table.collection td:first-child, table.collection th:first-child {
     padding-left: 1em;
 }
+
+.collection-as-table ul.cf-values {
+    margin-top: 0;
+    margin-bottom: 0;
+}

commit 34b51dbf5ed701fa4f5c46ac26add074d8f7bb96
Author: Thomas Sibley <trs at bestpractical.com>
Date:   Tue Feb 5 19:41:45 2013 -0800

    Scrub HTML from the spreadsheet view of ticket searches
    
    This prevents the web display parts of column map from leaking into the
    spreadsheet, such as through custom fields.  However, multiple value CFs
    are now output all run together instead of separated by "<br>" elements.
    Whether this is an improvement or not depends on your point of view, but
    it will be remedied to something saner in a following commit.
    
    Any HTML entities are also decoded so that no HTML should be left.

diff --git a/share/html/Search/Results.tsv b/share/html/Search/Results.tsv
index 9150774..5e62913 100644
--- a/share/html/Search/Results.tsv
+++ b/share/html/Search/Results.tsv
@@ -52,7 +52,11 @@ $OrderBy => 'id'
 $Order => 'ASC'
 $PreserveNewLines => 0
 </%ARGS>
+<%ONCE>
+my $no_html = HTML::Scrubber->new( deny => '*' );
+</%ONCE>
 <%INIT>
+require HTML::Entities;
 
 $r->content_type('application/vnd.ms-excel');
 
@@ -127,6 +131,8 @@ while (my $row = $Tickets->Next) {
             # remove tabs from all field values, they screw up the tsv
             $val = '' unless defined $val;
             $val =~ s/(?:\n|\r)//g; $val =~ s{\t}{    }g;
+            $val = $no_html->scrub($val);
+            $val = HTML::Entities::decode_entities($val);
             Encode::encode_utf8($val);
         } @$col)."\n");
     }

commit 3f27cfdc2b10436a320eac9593496a31b252b809
Author: Thomas Sibley <trs at bestpractical.com>
Date:   Wed Feb 6 10:44:00 2013 -0800

    Split the CustomField column map into multiple functions
    
    By separating the cached load from the actual rendering, the CustomField
    value definition is more extensible by local overlays or plugins.
    Explicitly passing an array of RT::ObjectCustomFieldValue objects to
    render provides a way to filter rendered values cleanly.

diff --git a/share/html/Elements/ColumnMap b/share/html/Elements/ColumnMap
index 508af75..011309c 100644
--- a/share/html/Elements/ColumnMap
+++ b/share/html/Elements/ColumnMap
@@ -53,7 +53,8 @@ $Attr  => undef
 <%ONCE>
 
 # This is scary and should totally be refactored -- jesse
-my $COLUMN_MAP = {
+my $COLUMN_MAP;
+$COLUMN_MAP = {
     id => {
         attribute => 'id',
         title    => 'id', # loc
@@ -96,6 +97,11 @@ my $COLUMN_MAP = {
         attribute => sub { return shift @_ },
         title     => sub { return pop @_ },
         value     => sub {
+            my $self = $COLUMN_MAP->{CustomField};
+            my $cf   = $self->{load}->(@_);
+            return $self->{render}->( $cf, $cf->ValuesForObject($_[0])->ItemsArrayRef );
+        },
+        load      => sub {
             # Cache the CF object on a per-request basis, to avoid
             # having to load it for every row
             my $key = join("-","CF",
@@ -108,17 +114,19 @@ my $COLUMN_MAP = {
                 $cf = $_[0]->LoadCustomFieldByIdentifier($_[-1]);
                 $m->notes($key, $cf);
             }
-
+            return $cf;
+        },
+        render    => sub {
+            my ($cf, $ocfvs) = @_;
             my $comp = $m->comp_exists("/Elements/ShowCustomField".$cf->Type)
                      ? "/Elements/ShowCustomField".$cf->Type
                      : undef;
 
-            my $values = $cf->ValuesForObject( $_[0] );
             my @values = map {
                 $comp
                     ? \($m->scomp( $comp, Object => $_ ))
                     : $_->Content
-            } @{ $values->ItemsArrayRef };
+            } @$ocfvs;
 
             if (@values > 1) {
                 for my $value (splice @values) {

commit d1e9d48bafe729b225cb32bc66680aaf3c619076
Author: Thomas Sibley <trs at bestpractical.com>
Date:   Wed Feb 6 11:26:14 2013 -0800

    Move substitution of newlines with <br>s into ProcessColumnMapValue()
    
    ProcessColumnMapValue() lets us do the line break substitution only if
    we're processing a value that isn't native HTML.  Column map values can
    now return scalar refs containing newlines without them getting mangled.
    
    The original intent, as added in bb64635, was to preserve newlines in
    textarea custom field values.  This behaviour is maintained since column
    map CFs are now rendered through the standard components.

diff --git a/lib/RT/Interface/Web.pm b/lib/RT/Interface/Web.pm
index b88aca1..819ceba 100644
--- a/lib/RT/Interface/Web.pm
+++ b/lib/RT/Interface/Web.pm
@@ -3345,10 +3345,13 @@ sub ProcessColumnMapValue {
         } elsif ( UNIVERSAL::isa( $value, 'SCALAR' ) ) {
             return $$value;
         }
+    } else {
+        if ($args{'Escape'}) {
+            $value = $m->interp->apply_escapes( $value, 'h' );
+            $value =~ s/\n/<br>/g if defined $value;
+        }
+        return $value;
     }
-
-    return $m->interp->apply_escapes( $value, 'h' ) if $args{'Escape'};
-    return $value;
 }
 
 =head2 GetPrincipalsMap OBJECT, CATEGORIES
diff --git a/share/html/Elements/CollectionAsTable/Row b/share/html/Elements/CollectionAsTable/Row
index bbcfd22..e83eb41 100644
--- a/share/html/Elements/CollectionAsTable/Row
+++ b/share/html/Elements/CollectionAsTable/Row
@@ -130,7 +130,6 @@ foreach my $column (@Format) {
             Arguments => [$record, $i],
         );
     }
-    s/\n/<br \/>/gs for grep defined $_, @out;
 
     $m->out( $_ .'="'. $m->interp->apply_escapes( $attrs{$_} => 'h' ) .'"' )
         foreach grep $attrs{$_}, qw(align style colspan);
diff --git a/share/html/Elements/ColumnMap b/share/html/Elements/ColumnMap
index 011309c..f0af6d6 100644
--- a/share/html/Elements/ColumnMap
+++ b/share/html/Elements/ColumnMap
@@ -130,7 +130,7 @@ $COLUMN_MAP = {
 
             if (@values > 1) {
                 for my $value (splice @values) {
-                    push @values, \"<li>", $value, \"</li> ";
+                    push @values, \"<li>", $value, \"</li> \n";
                 }
                 @values = (\"<ul class='cf-values'>", @values, \"</ul>");
             }

commit e3fcdec49893cdeed23a2ccbef01ce8ffceefd4c
Author: Thomas Sibley <trs at bestpractical.com>
Date:   Wed Feb 6 11:34:00 2013 -0800

    Separate image CF filenames from thumbnails with a visible newline
    
    The newline was never visible on ticket display.  However, it was
    visible for ticket searches since the collection list code used to
    substitute \n for <br> (until d1e9d48).  The visual line break is more
    pleasing, so include it everywhere.

diff --git a/share/html/Elements/ShowCustomFieldImage b/share/html/Elements/ShowCustomFieldImage
index 0779696..c53e7f8 100644
--- a/share/html/Elements/ShowCustomFieldImage
+++ b/share/html/Elements/ShowCustomFieldImage
@@ -46,7 +46,7 @@
 %#
 %# END BPS TAGGED BLOCK }}}
 %    my $url = RT->Config->Get('WebPath') . "/Download/CustomFieldValue/".$Object->Id.'/'.$m->interp->apply_escapes($Object->Content, 'u');
-<a href="<% $url %>"><% $Object->Content %></a>
+<a href="<% $url %>"><% $Object->Content %></a><br>
 <img type="<% $Object->ContentType %>" height="64" src="<% $url %>" align="middle" />
 <%ARGS>
 $Object

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


More information about the Rt-commit mailing list