You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by dk...@apache.org on 2021/08/03 01:59:03 UTC

[sling-whiteboard] branch master updated: Improving the UI handling and calling out the bundling of TLN

This is an automated email from the ASF dual-hosted git repository.

dklco pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-whiteboard.git


The following commit(s) were added to refs/heads/master by this push:
     new c369b1b  Improving the UI handling and calling out the bundling of TLN
c369b1b is described below

commit c369b1bbba2c990cfe05d706efdb1ba5050f5fa6
Author: Dan Klco <kl...@adobe.com>
AuthorDate: Mon Aug 2 21:58:55 2021 -0400

    Improving the UI handling and calling out the bundling of TLN
---
 org.apache.sling.repoinit.webconsole/NOTICE        |  4 +++
 org.apache.sling.repoinit.webconsole/pom.xml       |  6 ++--
 .../repoinit/webconsole/RepoInitWebConsole.java    | 35 ++++++++++++----------
 .../resources/res/ui/{tln.min.css => repoinit.css} | 14 ++++++++-
 .../src/main/resources/res/ui/repoinit.js          | 23 +++++++-------
 .../src/main/resources/res/ui/tln.min.css          | 16 ----------
 .../src/main/resources/res/ui/tln.min.js           | 16 ----------
 .../src/main/resources/tpl/main.html               | 19 ++----------
 8 files changed, 54 insertions(+), 79 deletions(-)

diff --git a/org.apache.sling.repoinit.webconsole/NOTICE b/org.apache.sling.repoinit.webconsole/NOTICE
new file mode 100644
index 0000000..276df41
--- /dev/null
+++ b/org.apache.sling.repoinit.webconsole/NOTICE
@@ -0,0 +1,4 @@
+Apache Sling RepoInit Webconsole
+Copyright 2021 The Apache Software Foundation
+
+This product bundles Textarea with Line Numbers (TLN), which is available under a "Apache 2.0" license. More information available at https://github.com/MatheusAvellar/textarea-line-numbers
\ No newline at end of file
diff --git a/org.apache.sling.repoinit.webconsole/pom.xml b/org.apache.sling.repoinit.webconsole/pom.xml
index 20c2c9d..5bb4c68 100644
--- a/org.apache.sling.repoinit.webconsole/pom.xml
+++ b/org.apache.sling.repoinit.webconsole/pom.xml
@@ -53,10 +53,8 @@
                         <exclude>velocity.log</exclude>
                         <!-- don't check anything in target -->
                         <exclude>target/*</exclude>
-                        <!-- for some reason Rat doesn't seem to pick up that PPTs are binary -->
-                        <exclude>src/test/resources/*.ppt</exclude>
-                        <!-- exclude verify text -->
-                        <exclude>src/test/resources/*.txt</exclude>
+                        <!-- exclude TLN files (which did not have the license header) -->
+                        <exclude>src/main/resources/res/ui/tln.min.*</exclude>
                     </excludes>
                 </configuration>
                 <executions>
diff --git a/org.apache.sling.repoinit.webconsole/src/main/java/org/apache/sling/repoinit/webconsole/RepoInitWebConsole.java b/org.apache.sling.repoinit.webconsole/src/main/java/org/apache/sling/repoinit/webconsole/RepoInitWebConsole.java
index 716f64b..9567eb6 100644
--- a/org.apache.sling.repoinit.webconsole/src/main/java/org/apache/sling/repoinit/webconsole/RepoInitWebConsole.java
+++ b/org.apache.sling.repoinit.webconsole/src/main/java/org/apache/sling/repoinit/webconsole/RepoInitWebConsole.java
@@ -22,7 +22,10 @@ import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
 import java.nio.charset.StandardCharsets;
 import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
 
 import javax.jcr.Session;
 import javax.servlet.Servlet;
@@ -57,7 +60,15 @@ public class RepoInitWebConsole extends AbstractWebConsolePlugin {
 
     public static final String CONSOLE_LABEL = "repoinit";
     public static final String CONSOLE_TITLE = "RepoInit";
-    static final String RES_LOC = CONSOLE_LABEL + "/res/ui";
+    private static final String RES_LOC = CONSOLE_LABEL + "/res/ui/";
+
+    private static final Map<String, String> RESOURCES = new HashMap<>();
+    static {
+        RESOURCES.put("repoinit.css", "text/css");
+        RESOURCES.put("tln.min.css", "text/css");
+        RESOURCES.put("tln.min.js", "application/javascript");
+        RESOURCES.put("repoinit.js", "application/javascript");
+    }
 
     @Reference
     protected SlingRepository slingRepository;
@@ -108,21 +119,15 @@ public class RepoInitWebConsole extends AbstractWebConsolePlugin {
     @Override
     protected void doGet(HttpServletRequest request, HttpServletResponse response)
             throws ServletException, IOException {
-        if (request.getRequestURI().endsWith(RES_LOC + "/tln.min.css")) {
-            response.setContentType("text/css");
-            IOUtils.copy(getClass().getClassLoader().getResourceAsStream("res/ui/tln.min.css"),
-                    response.getOutputStream());
-        } else if (request.getRequestURI().endsWith(RES_LOC + "/tln.min.js")) {
-            response.setContentType("application/javascript");
-            IOUtils.copy(getClass().getClassLoader().getResourceAsStream("res/ui/tln.min.js"),
-                    response.getOutputStream());
-        } else if (request.getRequestURI().endsWith(RES_LOC + "/repoinit.js")) {
-            response.setContentType("application/javascript");
-            IOUtils.copy(getClass().getClassLoader().getResourceAsStream("res/ui/repoinit.js"),
-                    response.getOutputStream());
-        } else {
-            super.doGet(request, response);
+        for (Entry<String, String> res : RESOURCES.entrySet()) {
+            if (request.getRequestURI().endsWith(RES_LOC + res.getKey())) {
+                response.setContentType(res.getValue());
+                IOUtils.copy(getClass().getClassLoader().getResourceAsStream("res/ui/" + res.getKey()),
+                        response.getOutputStream());
+                return;
+            }
         }
+        super.doGet(request, response);
     }
 
     @SuppressWarnings("deprecated")
diff --git a/org.apache.sling.repoinit.webconsole/src/main/resources/res/ui/tln.min.css b/org.apache.sling.repoinit.webconsole/src/main/resources/res/ui/repoinit.css
similarity index 52%
copy from org.apache.sling.repoinit.webconsole/src/main/resources/res/ui/tln.min.css
copy to org.apache.sling.repoinit.webconsole/src/main/resources/res/ui/repoinit.css
index b8f121a..bb2eed0 100644
--- a/org.apache.sling.repoinit.webconsole/src/main/resources/res/ui/tln.min.css
+++ b/org.apache.sling.repoinit.webconsole/src/main/resources/res/ui/repoinit.css
@@ -14,4 +14,16 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-.tln-active,.tln-wrapper,.tln-line{margin:0;border:0;padding:0;outline:0;box-sizing:border-box;vertical-align:middle;list-style:none}.tln-active{display:inline-block;padding:.625em;width:calc(100% - 3em);height:100%;word-break:break-all;border:1px solid #aeaeae;background-color:#fff;resize:none;overflow-wrap:normal;overflow-x:auto;white-space:pre;font:1em/1.5 "Roboto Mono",monospace}.tln-wrapper{width:3em;padding:.6875em .3125em 2.1875em;height:100%;word-break:break-all;overflow:hidden;d [...]
\ No newline at end of file
+pre {
+  border: 1px solid silver;
+}
+.d-none {
+  display: none;
+}
+.wrapper, pre {
+  position: relative;
+  height: 300px;
+  width: 100%;
+  margin: 15px auto;
+  overflow: auto;
+}
diff --git a/org.apache.sling.repoinit.webconsole/src/main/resources/res/ui/repoinit.js b/org.apache.sling.repoinit.webconsole/src/main/resources/res/ui/repoinit.js
index 935139c..038628c 100644
--- a/org.apache.sling.repoinit.webconsole/src/main/resources/res/ui/repoinit.js
+++ b/org.apache.sling.repoinit.webconsole/src/main/resources/res/ui/repoinit.js
@@ -18,6 +18,7 @@ TLN.append_line_numbers("source");
 
 const sourceEl = document.getElementById("source");
 const resultsContainer = document.getElementById("results-container");
+const parsedContainerEl = document.getElementById("parsed-container");
 const parsedEl = document.getElementById("parsed");
 const featureEl = document.getElementById("feature");
 const featureContainerEl = document.getElementById("feature-container");
@@ -26,25 +27,29 @@ const executeCbx = document.getElementById("execute");
 const messagesEl = document.getElementById("messages");
 
 goButton.addEventListener("click", async function () {
-  goButton.disabled = true;
-  sourceEl.disabled = true;
+  // clear everything out
+  goButton.disabled = sourceEl.disabled = true;
   resultsContainer.classList.add("d-none");
-  featureContainerEl.classList.add("d-none");
+  featureEl.innerText = parsedEl.innerText = messagesEl.innerHTML = "";
+
+  // get the response
   const res = await fetch(`repoinit?execute=${executeCbx.checked}`, {
     method: "post",
     body: sourceEl.value,
   });
   const json = await res.json();
 
-  messagesEl.innerHTML = "";
+  // add the messages
   json.messages.forEach((m) => {
     const par = document.createElement("p");
     par.innerText = m;
     messagesEl.appendChild(par);
   });
 
-  if (json.succeeded) {
+  // if there are operations diplay the statements and feature
+  if (json.operations) {
     parsedEl.innerText = JSON.stringify(json.operations, null, 2);
+    parsedContainerEl.classList.remove("d-none");
     featureEl.innerText = JSON.stringify(
       {
         "repoinit:TEXT|true": sourceEl.value.split("\n"),
@@ -53,11 +58,9 @@ goButton.addEventListener("click", async function () {
       2
     );
     featureContainerEl.classList.remove("d-none");
-  } else {
-    parsedEl.innerText = "";
-    featureEl.innerText = "";
   }
+
+  // show the results
   resultsContainer.classList.remove("d-none");
-  goButton.disabled = false;
-  sourceEl.disabled = false;
+  goButton.disabled = sourceEl.disabled = false;
 });
diff --git a/org.apache.sling.repoinit.webconsole/src/main/resources/res/ui/tln.min.css b/org.apache.sling.repoinit.webconsole/src/main/resources/res/ui/tln.min.css
index b8f121a..f122362 100644
--- a/org.apache.sling.repoinit.webconsole/src/main/resources/res/ui/tln.min.css
+++ b/org.apache.sling.repoinit.webconsole/src/main/resources/res/ui/tln.min.css
@@ -1,17 +1 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
 .tln-active,.tln-wrapper,.tln-line{margin:0;border:0;padding:0;outline:0;box-sizing:border-box;vertical-align:middle;list-style:none}.tln-active{display:inline-block;padding:.625em;width:calc(100% - 3em);height:100%;word-break:break-all;border:1px solid #aeaeae;background-color:#fff;resize:none;overflow-wrap:normal;overflow-x:auto;white-space:pre;font:1em/1.5 "Roboto Mono",monospace}.tln-wrapper{width:3em;padding:.6875em .3125em 2.1875em;height:100%;word-break:break-all;overflow:hidden;d [...]
\ No newline at end of file
diff --git a/org.apache.sling.repoinit.webconsole/src/main/resources/res/ui/tln.min.js b/org.apache.sling.repoinit.webconsole/src/main/resources/res/ui/tln.min.js
index 70de129..9e37d88 100644
--- a/org.apache.sling.repoinit.webconsole/src/main/resources/res/ui/tln.min.js
+++ b/org.apache.sling.repoinit.webconsole/src/main/resources/res/ui/tln.min.js
@@ -1,17 +1 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
 const TLN={eventList:{},update_line_numbers:function(e,t){let n=e.value.split("\n").length-t.children.length;if(n>0){const e=document.createDocumentFragment();for(;n>0;){const t=document.createElement("span");t.className="tln-line",e.appendChild(t),n--}t.appendChild(e)}for(;n<0;)t.removeChild(t.lastChild),n++},append_line_numbers:function(e){const t=document.getElementById(e);if(null==t)return console.warn("[tln.js] Couldn't find textarea of id '"+e+"'");if(-1!=t.className.indexOf("tln-a [...]
\ No newline at end of file
diff --git a/org.apache.sling.repoinit.webconsole/src/main/resources/tpl/main.html b/org.apache.sling.repoinit.webconsole/src/main/resources/tpl/main.html
index 3e7560c..ea1d630 100644
--- a/org.apache.sling.repoinit.webconsole/src/main/resources/tpl/main.html
+++ b/org.apache.sling.repoinit.webconsole/src/main/resources/tpl/main.html
@@ -4,22 +4,7 @@
     in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See
     the License for the specific language governing permissions and limitations under the License. -->
 <link rel="stylesheet" type="text/css" href="repoinit/res/ui/tln.min.css" />
-<style type="text/css">
-  pre {
-    border: 1px solid silver;
-  }
-  .d-none {
-    display: none;
-  }
-  .wrapper,
-  pre {
-    position: relative;
-    height: 300px;
-    width: 100%;
-    margin: 15px auto;
-    overflow: auto;
-  }
-</style>
+<link rel="stylesheet" type="text/css" href="repoinit/res/ui/repoinit.css" />
 <p class="statline ui-state-highlight">Source</p>
 <p>Test and verify Repository Initialization (repoint) scripts</p>
 <div class="wrapper">
@@ -30,7 +15,7 @@
 <label for="execute">Execute</label>
 <div class="d-none" id="results-container">
   <div class="statline ui-state-highlight" id="messages"></div>
-  <div id="parsed-container">
+  <div class="d-none" id="parsed-container">
     <p class="statline ui-state-highlight">Parsed Statements</p>
     <pre id="parsed"></pre>
   </div>