Bug 34136 - Add ability to render a report using a notice template
Summary: Add ability to render a report using a notice template
Status: RESOLVED FIXED
Alias: None
Product: Koha
Classification: Unclassified
Component: Reports (show other bugs)
Version: Main
Hardware: All All
: P5 - low enhancement (vote)
Assignee: Kyle M Hall
QA Contact: Katrin Fischer
URL:
Keywords:
Depends on: 33030
Blocks: 34456 36158
  Show dependency treegraph
 
Reported: 2023-06-27 18:20 UTC by Kyle M Hall
Modified: 2024-02-26 09:09 UTC (History)
6 users (show)

See Also:
Change sponsored?: ---
Patch complexity: ---
Documentation contact: Caroline Cyr La Rose
Documentation submission: https://gitlab.com/koha-community/koha-manual/-/merge_requests/803
Text to go in the release notes:
With this feature you can use a notice template for rendering the results of a report in the reports module. As you can use Template Toolkit and HTML in notices, this gives you a lot of flexibility to create for example a nice print format for your data. Once a notice has been created with the module 'Reports' selected, you will have the option to run your report using the template.
Version(s) released in:
23.11.00


Attachments
Bug 34136: Add ability to render a report using a notice template (8.04 KB, patch)
2023-06-27 18:27 UTC, Kyle M Hall
Details | Diff | Splinter Review
Bug 34136: Add ability to render a report using a notice template (8.08 KB, patch)
2023-07-06 15:26 UTC, Sam Lau
Details | Diff | Splinter Review
Bug 34136: Add ability to render a report using a notice template (8.09 KB, patch)
2023-08-02 11:11 UTC, Kyle M Hall
Details | Diff | Splinter Review
Bug 34136: Add ability to render a report using a notice template (8.10 KB, patch)
2023-08-03 16:03 UTC, Kyle M Hall
Details | Diff | Splinter Review
Bug 34136: Add ability to render a report using a notice template (8.18 KB, patch)
2023-10-23 21:59 UTC, Katrin Fischer
Details | Diff | Splinter Review
Bug 34136: (QA follow-up) Change Report to Reports as category in notices and slips (3.15 KB, patch)
2023-10-23 21:59 UTC, Katrin Fischer
Details | Diff | Splinter Review
Bug 34136: (QA follow-up) Perltidy (1.88 KB, patch)
2023-10-23 21:59 UTC, Katrin Fischer
Details | Diff | Splinter Review

Note You need to log in before you can comment on or make changes to this bug.
Description Kyle M Hall 2023-06-27 18:20:33 UTC
Sometimes it is useful to display the results of a report in a non-table format. We should be able to create notice templates to render reports.
Comment 1 Kyle M Hall 2023-06-27 18:27:07 UTC
Created attachment 152769 [details] [review]
Bug 34136: Add ability to render a report using a notice template

Sometimes it is useful to display the results of a report in a non-table format. We should be able to create notice templates to render reports.

Test Plan:
1) Apply this patch
2) Restart all the things!
3) Create a new notice template using the new "Report" option from the
   "New notice" pulldown.
4) In the "Print" area, paste the following template:

[% FOREACH b IN data %]
<div class="panel panel-default">
  <div class="panel-heading">[% b.surname %], [% b.firstname %]</div>
  <div class="panel-body">Expiration: [% b.dateexpiry %]</div>
  <div class="panel-footer">ID: [% b.borrowernumber %]</div>
</div>
[% END %]

5) Create a report with the query: SELECT * FROM borrowers
6) Once the report is saved, use the new "Run with template" option to
   select the template you just created.
7) Note that instead of the results being a paged table, you instead
   see the results rendered as cards!
Comment 2 Sam Lau 2023-06-28 15:18:16 UTC
After I created the new notice template using the report option when I try to go to Reports and then select 'create from SQL', the page did not load and I'm left with this error:

Could not compile /kohadevbox/koha/reports/guided_reports.pl: Can't locate Koha/TemplateUtils.pm in @INC (you may need to install the Koha::TemplateUtils module) (@INC contains: /kohadevbox/koha /kohadevbox/koha/lib /kohadevbox/koha/installer /kohadevbox/koha/lib/installer /etc/perl /usr/local/lib/aarch64-linux-gnu/perl/5.32.1 /usr/local/share/perl/5.32.1 /usr/lib/aarch64-linux-gnu/perl5/5.32 /usr/share/perl5 /usr/lib/aarch64-linux-gnu/perl-base /usr/lib/aarch64-linux-gnu/perl/5.32 /usr/share/perl/5.32 /usr/local/lib/site_perl /var/lib/koha/kohadev/plugins) at /kohadevbox/koha/reports/guided_reports.pl line 41.
BEGIN failed--compilation aborted at /kohadevbox/koha/reports/guided_reports.pl line 41.
 at /usr/share/perl5/CGI/Compile.pm line 144

It is also important to note that before creating a new notice template, the report page loads perfectly fine.
Comment 3 Kyle M Hall 2023-07-03 13:23:39 UTC
(In reply to Sam Lau from comment #2)
> After I created the new notice template using the report option when I try
> to go to Reports and then select 'create from SQL', the page did not load
> and I'm left with this error:


My bad! I forgot to add the dependent bug on bugzilla.
Comment 4 Sam Lau 2023-07-06 15:26:31 UTC
Created attachment 153100 [details] [review]
Bug 34136: Add ability to render a report using a notice template

Sometimes it is useful to display the results of a report in a non-table format. We should be able to create notice templates to render reports.

Test Plan:
1) Apply this patch
2) Restart all the things!
3) Create a new notice template using the new "Report" option from the
   "New notice" pulldown.
4) In the "Print" area, paste the following template:

[% FOREACH b IN data %]
<div class="panel panel-default">
  <div class="panel-heading">[% b.surname %], [% b.firstname %]</div>
  <div class="panel-body">Expiration: [% b.dateexpiry %]</div>
  <div class="panel-footer">ID: [% b.borrowernumber %]</div>
</div>
[% END %]

5) Create a report with the query: SELECT * FROM borrowers
6) Once the report is saved, use the new "Run with template" option to
   select the template you just created.
7) Note that instead of the results being a paged table, you instead
   see the results rendered as cards!

Signed-off-by: Sam Lau <samalau@gmail.com>
Comment 5 Kyle M Hall 2023-08-02 11:11:18 UTC
Created attachment 154153 [details] [review]
Bug 34136: Add ability to render a report using a notice template

Sometimes it is useful to display the results of a report in a non-table format. We should be able to create notice templates to render reports.

Test Plan:
1) Apply this patch
2) Restart all the things!
3) Create a new notice template using the new "Report" option from the
   "New notice" pulldown.
4) In the "Print" area, paste the following template:

[% FOREACH b IN data %]
<div class="panel panel-default">
  <div class="panel-heading">[% b.surname %], [% b.firstname %]</div>
  <div class="panel-body">Expiration: [% b.dateexpiry %]</div>
  <div class="panel-footer">ID: [% b.borrowernumber %]</div>
</div>
[% END %]

5) Create a report with the query: SELECT * FROM borrowers
6) Once the report is saved, use the new "Run with template" option to
   select the template you just created.
7) Note that instead of the results being a paged table, you instead
   see the results rendered as cards!

Signed-off-by: Sam Lau <samalau@gmail.com>
Comment 6 Sally 2023-08-02 15:18:54 UTC
This is a brilliant development - can't wait to see this in Koha.
Comment 7 Kyle M Hall 2023-08-03 16:03:01 UTC
Created attachment 154227 [details] [review]
Bug 34136: Add ability to render a report using a notice template

Sometimes it is useful to display the results of a report in a non-table format. We should be able to create notice templates to render reports.

Test Plan:
1) Apply this patch
2) Restart all the things!
3) Create a new notice template using the new "Report" option from the
   "New notice" pulldown.
4) In the "Print" area, paste the following template:

[% FOREACH b IN data %]
<div class="panel panel-default">
  <div class="panel-heading">[% b.surname %], [% b.firstname %]</div>
  <div class="panel-body">Expiration: [% b.dateexpiry %]</div>
  <div class="panel-footer">ID: [% b.borrowernumber %]</div>
</div>
[% END %]

5) Create a report with the query: SELECT * FROM borrowers
6) Once the report is saved, use the new "Run with template" option to
   select the template you just created.
7) Note that instead of the results being a paged table, you instead
   see the results rendered as cards!

Signed-off-by: Sam Lau <samalau@gmail.com>
Comment 8 Katrin Fischer 2023-10-23 21:58:09 UTC
I absolutely love the idea of this. But I worry a little about usability:

* The templates are likely to work only with specific reports. The list of templates could grow really long. This will create a situation where you have a long list of templates you could apply and a need to 'guess' which would work or belongs to the report. I wonder if we should not create some link between template and report that works/goes with it.

* We absolutely need documentation for this: Needs to be added to print, uses a 'data' object with the db columns etc.
Comment 9 Katrin Fischer 2023-10-23 21:59:26 UTC
Created attachment 157694 [details] [review]
Bug 34136: Add ability to render a report using a notice template

Sometimes it is useful to display the results of a report in a non-table format. We should be able to create notice templates to render reports.

Test Plan:
1) Apply this patch
2) Restart all the things!
3) Create a new notice template using the new "Report" option from the
   "New notice" pulldown.
4) In the "Print" area, paste the following template:

[% FOREACH b IN data %]
<div class="panel panel-default">
  <div class="panel-heading">[% b.surname %], [% b.firstname %]</div>
  <div class="panel-body">Expiration: [% b.dateexpiry %]</div>
  <div class="panel-footer">ID: [% b.borrowernumber %]</div>
</div>
[% END %]

5) Create a report with the query: SELECT * FROM borrowers
6) Once the report is saved, use the new "Run with template" option to
   select the template you just created.
7) Note that instead of the results being a paged table, you instead
   see the results rendered as cards!

Signed-off-by: Sam Lau <samalau@gmail.com>
Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>
Comment 10 Katrin Fischer 2023-10-23 21:59:29 UTC
Created attachment 157695 [details] [review]
Bug 34136: (QA follow-up) Change Report to Reports as category in notices and slips

Looking at the other entries for the module in notices we most often
use the actual module name: patrons, suggestions, holds, etc.

So I updated "Report" to "Reports" to match that pattern.

Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>
Comment 11 Katrin Fischer 2023-10-23 21:59:32 UTC
Created attachment 157696 [details] [review]
Bug 34136: (QA follow-up) Perltidy

Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>
Comment 12 Tomás Cohen Arazi 2023-10-27 19:52:13 UTC
Pushed to master for 23.11.

Nice work everyone, thanks!
Comment 13 Fridolin Somers 2023-11-08 07:40:10 UTC
Depends on Bug 33030 not in 23.05.x
Comment 14 Caroline Cyr La Rose 2023-12-22 19:12:58 UTC
This is a very interesting feature! Thank you all.
Comment 15 Caroline Cyr La Rose 2023-12-22 19:14:42 UTC
(In reply to Katrin Fischer from comment #8)

> 
> * We absolutely need documentation for this: Needs to be added to print,
> uses a 'data' object with the db columns etc.

For the manual, I only reproduced the example that was here as I don't know a lot of TT except the very basic basics. We should definitely have a wiki page about this...
Comment 16 Kyle M Hall 2024-01-02 14:47:55 UTC
(In reply to Caroline Cyr La Rose from comment #15)
> (In reply to Katrin Fischer from comment #8)
> 
> > 
> > * We absolutely need documentation for this: Needs to be added to print,
> > uses a 'data' object with the db columns etc.
> 
> For the manual, I only reproduced the example that was here as I don't know
> a lot of TT except the very basic basics. We should definitely have a wiki
> page about this...

Agreed. A library of report/template combos would be very useful. The only times I've used this feature so far are so specific as to be useless to other libraries. I do wonder if we should have an optional template section on the existing reports library wiki page, or if we should start a separate page.