From c495449268cb26e93c2e7ac3f11ddfa6abcd0aa3 Mon Sep 17 00:00:00 2001
From: Yaroslav Afenkin <91559310+yaroslavafenkin@users.noreply.github.com>
Date: Fri, 22 Nov 2024 16:54:53 +0200
Subject: [PATCH] [JENKINS-74890] Extract inline JavaScript from
`LogParserWriter.java`
---
.../hudson/plugins/logparser/LogParserConsts.java | 9 +++++----
.../hudson/plugins/logparser/LogParserWriter.java | 9 +--------
.../plugins/logparser/LogParserAction/index.jelly | 2 +-
src/main/webapp/js/log-parser-behaviour.js | 11 +++++++++++
4 files changed, 18 insertions(+), 13 deletions(-)
create mode 100644 src/main/webapp/js/log-parser-behaviour.js
diff --git a/src/main/java/hudson/plugins/logparser/LogParserConsts.java b/src/main/java/hudson/plugins/logparser/LogParserConsts.java
index 16f599a..87bce6e 100755
--- a/src/main/java/hudson/plugins/logparser/LogParserConsts.java
+++ b/src/main/java/hudson/plugins/logparser/LogParserConsts.java
@@ -1,5 +1,6 @@
package hudson.plugins.logparser;
+import hudson.Functions;
import jenkins.model.Jenkins;
import java.util.Arrays;
@@ -25,12 +26,12 @@ public class LogParserConsts {
public static String getHtmlOpeningTags() {
final String hudsonRoot = Jenkins.get().getRootUrl();
+ final String pluginResourceUrl = String.format("%s/plugin/log-parser/", Jenkins.RESOURCE_PATH).substring(1);
+
return "\n" + "\n" + "\t
\n"
+ "\t\tlog-parser plugin page\n"
- + "\t\t\n"
- + "\t\t\n" + "\t\n"
+ + "\t\t\n"
+ +"\t\n"
+ "\t\n";
}
diff --git a/src/main/java/hudson/plugins/logparser/LogParserWriter.java b/src/main/java/hudson/plugins/logparser/LogParserWriter.java
index 3d4f90e..8d0df31 100755
--- a/src/main/java/hudson/plugins/logparser/LogParserWriter.java
+++ b/src/main/java/hudson/plugins/logparser/LogParserWriter.java
@@ -50,16 +50,9 @@ public static void writeReferenceHtml(final String buildRefPath,
final HashMap linkFiles,
final List extraTags) throws IOException {
- final String refStart = "\n";
-
try (BufferedWriter writer = new BufferedWriter(new FileWriter(buildRefPath))) {
// Hudson stylesheets
writer.write(LogParserConsts.getHtmlOpeningTags());
- writer.write(refStart); // toggle links javascript
// Write Errors
writeLinks(writer, LogParserConsts.ERROR, headerForSection,
statusCountPerSection, iconTable, linkListDisplay,
@@ -123,7 +116,7 @@ private static void writeLinks(final BufferedWriter writer,
final String linksStart = "\n"
- + ""
+ + ""
+ linkListDisplayStr + " (" + linkListCount + ")
\n"
+ "\n";
diff --git a/src/main/resources/hudson/plugins/logparser/LogParserAction/index.jelly b/src/main/resources/hudson/plugins/logparser/LogParserAction/index.jelly
index 5a4eb21..7d2e138 100755
--- a/src/main/resources/hudson/plugins/logparser/LogParserAction/index.jelly
+++ b/src/main/resources/hudson/plugins/logparser/LogParserAction/index.jelly
@@ -4,7 +4,7 @@
-
+
diff --git a/src/main/webapp/js/log-parser-behaviour.js b/src/main/webapp/js/log-parser-behaviour.js
new file mode 100644
index 0000000..6406ab3
--- /dev/null
+++ b/src/main/webapp/js/log-parser-behaviour.js
@@ -0,0 +1,11 @@
+window.addEventListener("DOMContentLoaded", () => {
+ document.querySelectorAll(".lpp-toggle-list").forEach((toggle) => {
+ toggle.addEventListener("click", (event) => {
+ event.preventDefault();
+ const { displayCategory } = event.target.closest(".lpp-toggle-list").dataset;
+
+ element = document.getElementById(displayCategory).style;
+ element.display = element.display == 'none' ? 'block' : 'none';
+ })
+ });
+});