From c9a15b73f01796e1f6f71e5eca8efbee94958af5 Mon Sep 17 00:00:00 2001 From: Owen Leonard Date: Fri, 5 Feb 2021 18:28:15 +0000 Subject: [PATCH] Bug 27644: Add button to SQL report editor for inserting runtime parameters MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 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 Signed-off-by: Katrin Fischer Signed-off-by: Jonathan Druart --- .../prog/css/src/staff-global.scss | 18 +++ .../modules/reports/guided_reports_start.tt | 152 +++++++++++++++++- 2 files changed, 167 insertions(+), 3 deletions(-) diff --git a/koha-tmpl/intranet-tmpl/prog/css/src/staff-global.scss b/koha-tmpl/intranet-tmpl/prog/css/src/staff-global.scss index dd1211569e..6d9db96973 100644 --- a/koha-tmpl/intranet-tmpl/prog/css/src/staff-global.scss +++ b/koha-tmpl/intranet-tmpl/prog/css/src/staff-global.scss @@ -951,6 +951,12 @@ fieldset { width: unset; } } + + .dropdown-menu { + li { + padding-bottom: 0; + } + } } } @@ -1701,6 +1707,18 @@ i { white-space: nowrap; } +.form-group { + label { + display: block; + margin-bottom: 5px; + } + + div { + &.hint { + margin: 5px 0; + } + } +} .blocker { color: #990000; diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/reports/guided_reports_start.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/reports/guided_reports_start.tt index a002e404c3..ac2a96362b 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/reports/guided_reports_start.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/reports/guided_reports_start.tt @@ -1,5 +1,6 @@ [% USE raw %] [% USE Asset %] +[% USE AuthorisedValues %] [% USE KohaDates %] [% USE Koha %] [% USE TablesSettings %] @@ -1151,6 +1152,7 @@
SQL:
+ [% PROCESS insert_runtime_parameter %] Required
@@ -1260,10 +1262,9 @@
SQL: -
+ [% PROCESS insert_runtime_parameter %] - Required -
+ Required
@@ -1341,6 +1342,40 @@ + + + [% MACRO jsinclude BLOCK %] [% Asset.js("js/charts.js") | $raw %] [% Asset.js("lib/d3c3/d3.min.js") | $raw %] @@ -1447,6 +1482,46 @@ }); [% END %] + function showParamModal( category ){ + var modal = $("#runtime_parameters"); + var modalTitle = $("#runtime_parametersLabel"); + switch ( category ){ + case "insertAuthVal": + modalTitle.text( _("Insert authorized value parameter") ); + $("#paramLabel").val("Authorized value") + $("#authorised_value_category").show(); + $("#authorised_value").prop("required", true ).attr("required", "required"); + break; + case "insertDate": + modalTitle.text( _("Insert date parameter") ); + $("#paramLabel").val("Date") + $("#param_category").val("date"); + break; + case "insertItemtypes": + modalTitle.text( _("Insert item types parameter") ); + $("#paramLabel").val("Item type") + $("#param_category").val("itemtypes"); + break; + case "insertBranches": + modalTitle.text( _("Insert libraries parameter") ); + $("#paramLabel").val("Library") + $("#param_category").val("branches"); + break; + case "insertCategorycode": + modalTitle.text( _("Insert patron category parameter") ); + $("#paramLabel").val("Patron category") + $("#param_category").val("categorycode"); + break; + case "insertText": + modalTitle.text( _("Insert text parameter") ); + $("#paramLabel").val("Text") + $("#param_category").val(""); + break; + } + $("#paramLabel").select(); + modal.modal("show"); + } + function load_group_subgroups () { var group = $("#group_select").val(); var sg = $("#subgroup"); @@ -1830,6 +1905,61 @@ $("#group_select").on("change",function(){ load_group_subgroups(); }); + + $(".insertParam").on("click", function(e){ + e.preventDefault(); + var category = this.id; + showParamModal( category ); + }); + + $("#runtime_parameters").on("shown.bs.modal", function(){ + $("#paramLabel").focus(); + }); + + $("#runtime_parameters").on("hide.bs.modal", function(){ + $("#send_runtime_parameter")[0].reset(); + $("#authorised_value_category").val("").hide(); + $("#authorised_value").prop("required", false ).removeAttr("required"); + }); + + $("#send_runtime_parameter").on("submit", function(e){ + e.preventDefault(); + /* Get form values */ + var paramLabel = $("#paramLabel").val(); + var param_category = $("#param_category").val(); + var categoryLabel = $("#authorised_value").val(); + // Get CodeMirror environment variables + var selection = editor.getSelection(); + var doc = editor.getDoc(); + var cursor = doc.getCursor(); + var pos = { + line: cursor.line, + ch: cursor.ch + } + /* Build runtime parameter text string */ + var text = ""; + if( paramLabel && param_category ){ + text += paramLabel + "|" + param_category; + } else if( paramLabel ) { + text += paramLabel; + } else if( param_category ){ + text += param_category; + } + if( text != "" ){ + text = " <<" + text + ">> "; + if( selection.length > 0){ + editor.replaceSelection(text); + } else { + doc.replaceRange(text, pos); + } + } + $("#runtime_parameters").modal("hide"); + }); + + $("#authorised_value").on("change", function(){ + $("#param_category").val( $(this).val() ); + }); + [% END %] $(".delete").on("click",function(){ @@ -2099,3 +2229,19 @@ [% END %] + +[% BLOCK insert_runtime_parameter %] +
+ + +
+[% END %] -- 2.39.5