Bug 34456: Add the ability to download a template rendered report as a file

Bug 34136 adds the ability to render a report using a notice template rather than displaying data in a table. It would be even more useful to be able to download the contents as a file where the notice subject can be used as the filename so the filename can be generated dynamically ( such as adding the current date as part of the filename ).

Test Plan:
1) Follow the test plan for Bug 34136
2) Run your report
3) Note under the Download menu the new item "Download as" with the
   subject line for your template
4) Click that link, note the file contains the contents of your report!

Signed-off-by: Sam Lau <samalau@gmail.com>
Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
This commit is contained in:
Kyle M Hall 2023-08-02 07:56:46 -04:00 committed by Tomas Cohen Arazi
parent 1e53f48efe
commit 6fccc1dcb5
No known key found for this signature in database
GPG Key ID: 0A272EA1B2F3C15F
2 changed files with 17 additions and 1 deletions

View File

@ -134,6 +134,9 @@
<li><a id="csv" href="/cgi-bin/koha/reports/guided_reports.pl?reports=1&phase=Export&amp;format=csv&amp;report_id=[% id | html %]&amp;reportname=[% name |uri %][% PROCESS params %]">[% PROCESS 'delimiter_text.inc' %]</a></li>
<li><a id="tab" href="/cgi-bin/koha/reports/guided_reports.pl?reports=1&phase=Export&amp;format=tab&amp;report_id=[% id | html %]&amp;reportname=[% name |uri %][% PROCESS params %]">Tab separated text</a></li>
<li><a id="ods" href="/cgi-bin/koha/reports/guided_reports.pl?reports=1&phase=Export&amp;format=ods&amp;report_id=[% id | html %]&amp;reportname=[% name |uri %][% PROCESS params %]">Open Document Spreadsheet</a></li>
[% IF processed_notice_title %]
<li><a id="template" href="/cgi-bin/koha/reports/guided_reports.pl?reports=1&phase=Export&amp;format=template&amp;report_id=[% id | html %]&amp;template=[% template_id | html %]&amp;reportname=[% name |uri %][% PROCESS params %]">Download as <i>[% processed_notice_title | html %]</i></a></li>
[% END %]
[% IF (results.json) %]
<li><a id="download-chart" href="#">Chart (.svg)</a></li>
[% END %]

View File

@ -884,7 +884,13 @@ elsif ($phase eq 'Run this report'){
my $data = $sth2->fetchall_arrayref( {} );
my $notice_rendered =
process_tt( $notice_template->content, { data => $data, report_id => $report_id } );
$template->param( processed_notice => $notice_rendered );
my $title_rendered =
process_tt( $notice_template->title, { data => $data, report_id => $report_id } );
$template->param(
template_id => $template_id,
processed_notice => $notice_rendered,
processed_notice_title => $title_rendered,
);
}
$template->param(
@ -983,6 +989,13 @@ elsif ($phase eq 'Export'){
$content .= $_ while <$ods_fh>;
unlink $ods_filepath;
}
elsif ( $format eq 'template' ) {
my $template_id = $input->param('template');
my $notice_template = Koha::Notice::Templates->find($template_id);
my $data = $sth->fetchall_arrayref({});
$content = process_tt( $notice_template->content, { data => $data, report_id => $report_id, for_download => 1 } );
$reportfilename = process_tt( $notice_template->title, { data => $data, report_id => $report_id } );
}
}
print $input->header(
-type => $type,