From 3c8be8bf7a945d6901b277f8bea19b9347337f2f Mon Sep 17 00:00:00 2001 From: Owen Leonard Date: Mon, 22 Feb 2021 12:36:08 +0000 Subject: [PATCH] Bug 27747: Add CodeMirror custom syntax highlighting for column placeholders This patch adds some additional configuration to CodeMirror so that column placeholders have a distinct color in the CodeMirror SQL editor. To test, apply the patch and create or edit an SQL report which contains one or more column placeholders, e.g. [[itemnumber|Item number]], [[borrowernumber|Borrower number]], etc. Confirm that when editing the SQL, these placeholders should appear as red text. Save your report and view it. The syntax highlighting should be updated in this view too. Signed-off-by: Lucas Gass Signed-off-by: Lucas Gass Signed-off-by: Nick Clemens Signed-off-by: Jonathan Druart --- .../modules/reports/guided_reports_start.tt | 41 ++++++++++++------- 1 file changed, 27 insertions(+), 14 deletions(-) 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 ab9478ac45..11cfc366ee 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 @@ -47,6 +47,9 @@ .cm-sqlParams { color: #11917B; } + .cm-columnPlaceholder { + color: #BF2D5D; + } #mana_search_errortext { font-family: monospace; font-weight: bold; } [% Asset.css("css/reports.css") | $raw %] @@ -1420,22 +1423,32 @@ } /* overlay a syntax-highlighting definition on top of the existing sql one */ - CodeMirror.defineMode("sqlParams", function(config, parserConfig) { - var sqlParamsOverlay = { + CodeMirror.defineMode("sqlPlaceholders", function(config, parserConfig) { + var sqlPlaceholdersOverlay = { token: function(stream, state) { - var ch; - if (stream.match("<<")) { - while ((ch = stream.next()) != null) - if (ch == ">" && stream.next() == ">") { - stream.eat(">"); - return "sqlParams"; + var ch; + + if (stream.match("<<")) { + while ((ch = stream.next()) != null) + if (ch == ">" && stream.next() == ">") { + stream.eat(">"); + return "sqlParams"; + } + } + + if (stream.match("[[")) { + while ((ch = stream.next()) != null) + if (ch == "]" && stream.next() == "]") break; + stream.eat("]"); + return "columnPlaceholder"; + } + + else if (stream.next() != null) { + return null; } - } - while (stream.next() != null && !stream.match("<<", false)) {} - return null; } }; - return CodeMirror.overlayMode(CodeMirror.getMode(config, parserConfig.backdrop || "text/x-sql"), sqlParamsOverlay); + return CodeMirror.overlayMode(CodeMirror.getMode(config, parserConfig.backdrop || "text/x-sql"), sqlPlaceholdersOverlay); }); var MSG_CONFIRM_DELETE = _("Are you sure you want to delete this report? This cannot be undone."); @@ -1454,7 +1467,7 @@ var editor = CodeMirror.fromTextArea(sql, { lineNumbers: true, - mode: "sqlParams", /* text/x-sql plus custom sqlParams configuration */ + mode: "sqlPlaceholders", /* text/x-sql plus custom sqlPlaceholders configuration */ lineWrapping: true, smartIndent: false }); @@ -1476,7 +1489,7 @@ [% IF ( showsql ) %] var editor = CodeMirror.fromTextArea(sql, { lineNumbers: false, - mode: "sqlParams", /* text/x-sql plus custom sqlParams configuration */ + mode: "sqlPlaceholders", /* text/x-sql plus custom sqlPlaceholders configuration */ lineWrapping: true, readOnly: true }); -- 2.39.5