From 85761810309e84bdaa37dde00007e841f806746c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20Mili=C4=87?= Date: Tue, 21 Mar 2023 10:30:16 +0100 Subject: [PATCH 1/4] feature/Tweak the function copyJsonResultToClipboard --- src/main/webapp/media/js/website.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/webapp/media/js/website.js b/src/main/webapp/media/js/website.js index 72ddded1..68b8ce52 100644 --- a/src/main/webapp/media/js/website.js +++ b/src/main/webapp/media/js/website.js @@ -279,7 +279,7 @@ function copyJsonResultToClipboard(element) { r.selectNode(document.getElementById(id)); window.getSelection().removeAllRanges(); window.getSelection().addRange(r); - document.execCommand('copy'); + navigator.clipboard.writeText(window.getSelection().toString()); window.getSelection().removeAllRanges(); // Store original values var titleText = document.getElementById(element.id).title; From 2de07302cc72084a7b16a6c4767934ad675e363b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20Mili=C4=87?= Date: Wed, 3 May 2023 13:53:20 +0200 Subject: [PATCH 2/4] refactor/Avoid JavaScript warning --- src/main/webapp/media/js/website.js | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/src/main/webapp/media/js/website.js b/src/main/webapp/media/js/website.js index 68b8ce52..a7ccc417 100644 --- a/src/main/webapp/media/js/website.js +++ b/src/main/webapp/media/js/website.js @@ -274,12 +274,15 @@ function filterMessageDocs(element) { // when we press a copy icon in top left corner. // In case that action is successful the icon is changed for a 2 seconds in order to notify a user about it. function copyJsonResultToClipboard(element) { - var id = String(element.id).replace('result_copy_icon_','result_'); + var id = String(element.id).replace("result_copy_icon_", "result_"); var r = document.createRange(); r.selectNode(document.getElementById(id)); window.getSelection().removeAllRanges(); window.getSelection().addRange(r); - navigator.clipboard.writeText(window.getSelection().toString()); + navigator.clipboard.writeText(window.getSelection().toString()).then( + () => console.log("clipboard successfully set"), + () => console.log("clipboard write failed") + ); window.getSelection().removeAllRanges(); // Store original values var titleText = document.getElementById(element.id).title; @@ -287,25 +290,25 @@ function copyJsonResultToClipboard(element) { // and then change hey document.getElementById(element.id).title = ""; document.getElementById(element.id).className = "fa-regular fa-copy"; - + // Below code is GUI related i.e. to notify a user that text is copied to clipboard // -------------------------------------------------------------------------------- - + // It delays the call by ms milliseconds function defer(f, ms) { - return function() { + return function () { setTimeout(() => f.apply(this, arguments), ms); }; } - + // Function which revert icon and text to the initial state. function revertTextAndClass(titleText, iconClass) { document.getElementById(element.id).title = titleText; - document.getElementById(element.id).className = iconClass + document.getElementById(element.id).className = iconClass; } - + var revertTextAndClassDeferred = defer(revertTextAndClass, 2000); // Revert the original values of text and icon after 2 seconds - revertTextAndClassDeferred(titleText, iconClass); - + revertTextAndClassDeferred(titleText, iconClass); } + From e658e848a287e975d426505d253b1340b120e542 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20Mili=C4=87?= Date: Mon, 15 May 2023 08:49:38 +0200 Subject: [PATCH 3/4] feature/Tweak Request Header Box --- src/main/scala/code/snippet/ApiExplorer.scala | 6 +++--- src/main/webapp/index.html | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/scala/code/snippet/ApiExplorer.scala b/src/main/scala/code/snippet/ApiExplorer.scala index 84d8c772..7c0dc5d6 100644 --- a/src/main/scala/code/snippet/ApiExplorer.scala +++ b/src/main/scala/code/snippet/ApiExplorer.scala @@ -477,10 +477,10 @@ WIP to add comments on resource docs. This code copied from Sofit. val requestHeader = customRequestHeader.trim.isEmpty match { case true => Nil case false => - customRequestHeader.split("::").map(_.trim).map { + customRequestHeader.split(":::").map(_.trim).map { i => - val key = i.split(":").toList.head - val value = i.split(":").toList.reverse.head + val key = i.split("::").toList.head + val value = i.split("::").toList.reverse.head Header(key, value) }.toList } diff --git a/src/main/webapp/index.html b/src/main/webapp/index.html index 033351ce..52dcf98e 100644 --- a/src/main/webapp/index.html +++ b/src/main/webapp/index.html @@ -385,7 +385,7 @@
- +
From 616d4232393471299de5894daaeb91ae5f6e295b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20Mili=C4=87?= Date: Fri, 15 Sep 2023 09:37:29 +0200 Subject: [PATCH 4/4] bugfix/Close streams at the function gitCommit and use lazy val instead of def --- src/main/scala/code/snippet/ApiExplorer.scala | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/main/scala/code/snippet/ApiExplorer.scala b/src/main/scala/code/snippet/ApiExplorer.scala index 7c0dc5d6..eac5446c 100644 --- a/src/main/scala/code/snippet/ApiExplorer.scala +++ b/src/main/scala/code/snippet/ApiExplorer.scala @@ -1908,13 +1908,18 @@ WIP to add comments on resource docs. This code copied from Sofit. /* Return the git commit. If we can't for some reason (not a git root etc) then log and return "" */ - def gitCommit : String = { + lazy val gitCommit : String = { val commit = try { val properties = new java.util.Properties() logger.debug("Before getResourceAsStream git.properties") - properties.load(getClass().getClassLoader().getResourceAsStream("git.properties")) - logger.debug("Before get Property git.commit.id") - properties.getProperty("git.commit.id", "") + val stream = getClass().getClassLoader().getResourceAsStream("git.properties") + try { + properties.load(stream) + logger.debug("Before get Property git.commit.id") + properties.getProperty("git.commit.id", "") + } finally { + stream.close() + } } catch { case e : Throwable => { logger.warn("gitCommit says: Could not return git commit. Does resources/git.properties exist?")