Bug 27644

Summary: Add button to SQL report editor for inserting runtime parameters
Product: Koha Reporter: Owen Leonard <oleonard>
Component: ReportsAssignee: Owen Leonard <oleonard>
Status: CLOSED FIXED QA Contact: Testopia <testopia>
Severity: enhancement    
Priority: P5 - low CC: fridolin.somers, lucas, magnus, severine.queune, testopia
Version: Main   
Hardware: All   
OS: All   
Change sponsored?: --- Patch complexity: Small patch
Documentation contact: Documentation submission:
Text to go in the release notes:
This patch adds a button menu to the SQL report CodeMirror editor for inserting runtime parameters. Each menu item triggers a modal dialog where the user can specify a parameter label and any other relevant option.
Version(s) released in:
21.05.00
Bug Depends on: 27643    
Bug Blocks: 29201, 29328, 29351, 29352    
Attachments: Screenshot of the proposed change
Bug 27644: Add button to SQL report editor for inserting runtime parameters
Bug 27644: Add button to SQL report editor for inserting runtime parameters
Bug 27644: Add button to SQL report editor for inserting runtime parameters
Bug 27644: (follow-up) Wrap strings in translation function
Bug 27644: Add button to SQL report editor for inserting runtime parameters
Bug 27644: (follow-up) Wrap strings in translation function
Bug 27644: (QA follow-up) Remove size=1 from template

Description Owen Leonard 2021-02-05 18:35:48 UTC
Created attachment 116429 [details]
Screenshot of the proposed change

I can never remember the syntax for adding runtime parameters to SQL reports so I think it would be useful to have a menu of choices for the user to choose from.
Comment 1 Owen Leonard 2021-02-08 13:35:57 UTC Comment hidden (obsolete)
Comment 2 Lucas Gass 2021-03-05 20:33:01 UTC
This is a great idea, I too can never remember this syntax. 

This works well when I edit a report. But since the 'Insert runtime parameter' button is only added inside the '[% IF ( editsql ) %]' statement it does not appear when you create a new report. 

Could we have this for new reports too?
Comment 3 Owen Leonard 2021-03-29 18:11:31 UTC Comment hidden (obsolete)
Comment 4 PTFS Europe Sandboxes 2021-03-31 11:13:33 UTC Comment hidden (obsolete)
Comment 5 Séverine Queune 2021-03-31 11:14:41 UTC
Such a nice one, thanks Owen !
Comment 6 Katrin Fischer 2021-04-03 15:11:52 UTC
This is really nice, but I believe I spotted a translation issue with the default labels:   $("#paramLabel").val("Authorized value") for an example.
Comment 7 Owen Leonard 2021-04-07 18:38:25 UTC Comment hidden (obsolete)
Comment 8 Katrin Fischer 2021-04-18 00:08:53 UTC
Created attachment 119812 [details] [review]
Bug 27644: Add button to SQL report editor for inserting runtime parameters

This patch adds a button menu to the SQL report CodeMirror editor for
inserting runtime parameters. Each menu item triggers a modal dialog
where the user can specify a parameter label and any other relevant
option.

To test, apply the patch and rebuild the staff client CSS
(https://wiki.koha-community.org/wiki/Working_with_SCSS_in_the_OPAC_and_staff_client).

- Go to Reports -> Use saved.
- Create or edit a report.
- You should see a menu button above the SQL editor field, "Insert
  runtime parameter."
- The menu should contain the options "Authorized value," "Date," "Item
  types," "Libraries," "Patron categories," and "Text field."
- Test each option. Each should trigger the display of a modal dialog
  with a heading which corresponds to your choice.
- In all cases except the "Authorized value" choice you should see a
  single form field for "label."
- Enter text in the label field and click the "Insert parameter" button.
- The correct runtime parameter should be inserted into the SQL editor.
  - If you placed a cursor somewhere in the SQL editor first, your
    parameter should be inserted in that location in the editor.
  - If you selected some text in the editor before selecting a
    parameter, the paramter should replace the selected text.
- In the case of the "Authorized value" selection, the modal dialog
  should include both a label field and a field for choosing an
  authorized value category.
- Try submitting the form without selecting an authorized value. It
  should warn you that the field is required.
- After testing the authorized value selection, try inserting another
  parameter to confirm that the authorized value selection (now hidden)
  is no longer required.

Signed-off-by: Séverine QUEUNE <severine.queune@bulac.fr>

Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>
Comment 9 Katrin Fischer 2021-04-18 00:08:57 UTC
Created attachment 119813 [details] [review]
Bug 27644: (follow-up) Wrap strings in translation function

This patch updates the in-template JavaScript so that some English
strings which were previously untranslatable. This patch wraps them in
the _() function.

To test, apply the patch and test that the correct strings are
translatable. In this example I'm testing fr-FR:

- Update a translation:

  > gulp po:update
  > cd misc/translator
  > perl translate update fr-FR

- Open the corresponding .po file for the strings pulled from
  JavaScript  e.g.  misc/translator/po/fr-FR-staff-prog.po
- Locate strings pulled from reports/guided_reports_start.tt for
  translation, e.g.:

  #: koha-tmpl/intranet-tmpl/prog/en/modules/reports/guided_reports_start.tt:1324
  #, fuzzy, c-format
  msgid "Authorized value category:"
  msgstr "Catégorie de valeur autorisée&nbsp;: "

- Edit the "msgstr" string if necessary, or remove the "fuzzy," before
  "c-format"
- Install the updated translation:

  > perl translate install fr-FR

In the staff interface, switch to the language you're testing. Confirm
that your translated strings appear. In this case, test in particular:

 - The controls on the modal window when you preview a report's SQL from
   the list of saved reports.
 - The controls and modal dialog for inserting a runtime parameter.

Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>
Comment 10 Katrin Fischer 2021-04-18 00:09:02 UTC
Created attachment 119814 [details] [review]
Bug 27644: (QA follow-up) Remove size=1 from template

Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>
Comment 11 Jonathan Druart 2021-04-21 13:30:08 UTC
Pushed to master for 21.05, thanks to everybody involved!
Comment 12 Fridolin Somers 2021-04-29 13:26:55 UTC
Enhancement not pushed to 20.11.x