%#
%# COPYRIGHT:
%#
-%# This software is Copyright (c) 1996-2014 Best Practical Solutions, LLC
+%# This software is Copyright (c) 1996-2016 Best Practical Solutions, LLC
%# <sales@bestpractical.com>
%#
%# (Except where explicitly superseded by other copyright notices)
</%ARGS>
<%INIT>
-$r->content_type('text/tab-separated-values');
$r->header_out('Content-Disposition' => 'attachment;filename="Results.tsv"');
-my $DisplayFormat = $m->comp('/Elements/ScrubHTML', Content => $Format);
-
-my @Format = $m->comp('/Elements/CollectionAsTable/ParseFormat', Format => $DisplayFormat);
-
-my @columns;
-
-my $should_loc = { map { $_ => 1 } qw(Status) };
-
-my $col_entry = sub {
- my $col = shift;
- # in tsv output, "#" is often a comment character but we use it for "id"
- delete $col->{title}
- if $col->{title} and $col->{title} =~ /^\s*#\s*$/;
- return {
- header => loc($col->{title} || $col->{attribute}),
- map => $m->comp(
- "/Elements/ColumnMap",
- Name => $col->{attribute},
- Attr => 'value'
- ),
- should_loc => $should_loc->{$col->{attribute}},
- }
-};
-
-if ($PreserveNewLines) {
- my $col = [];
- push @columns, $col;
- for (@Format) {
- if ($_->{title} eq 'NEWLINE') {
- $col = [];
- push @columns, $col;
- }
- else {
- push @$col, $col_entry->($_);
- }
- }
-}
-else {
- push @columns, [map { $_->{attribute}
- ? $col_entry->($_)
- : () } @Format];
-}
-
-for (@columns) {
- $m->out(join("\t", map { $_->{header} } @$_)."\n");
-}
-
my $Tickets = RT::Tickets->new( $session{'CurrentUser'} );
$Tickets->FromSQL( $Query );
if ( $OrderBy =~ /\|/ ) {
$Tickets->OrderBy( FIELD => $OrderBy, ORDER => $Order );
}
-my $ii = 0;
-while (my $row = $Tickets->Next) {
- for my $col (@columns) {
- $m->out(join("\t", map {
- my $val = ProcessColumnMapValue($_->{map}, Arguments => [$row, $ii++], Escape => 0);
- $val = loc($val) if $_->{should_loc};
- # 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;
- } @$col)."\n");
- }
-}
-$m->abort();
-
+$m->comp( "/Elements/TSVExport", Collection => $Tickets, Format => $Format, PreserveNewLines => $PreserveNewLines );
</%INIT>