Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[JENKINS-74890] Extract inline JavaScript from LogParserWriter.java #135

Merged
merged 1 commit into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions src/main/java/hudson/plugins/logparser/LogParserConsts.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package hudson.plugins.logparser;

import hudson.Functions;
import jenkins.model.Jenkins;

import java.util.Arrays;
Expand All @@ -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 "<!DOCTYPE html>\n" + "<html>\n" + "\t<head>\n"
+ "\t\t<title>log-parser plugin page</title>\n"
+ "\t\t<link type=\"text/css\" rel=\"stylesheet\" href=\""
hypery2k marked this conversation as resolved.
Show resolved Hide resolved
+ hudsonRoot + "css/style.css\" />\n"
+ "\t\t<link type=\"text/css\" rel=\"stylesheet\" href=\""
+ hudsonRoot + "css/color.css\" />\n" + "\t</head>\n"
+ "\t\t<script type=\"application/javascript\" src=\"" + hudsonRoot + pluginResourceUrl + "js/log-parser-behaviour.js\"></script>\n"
+"\t</head>\n"
+ "\t<body>\n";
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,9 @@ public static void writeReferenceHtml(final String buildRefPath,
final HashMap<String, String> linkFiles,
final List<String> extraTags) throws IOException {

final String refStart = "<script type=\"text/javascript\">\n"
+ "\tfunction toggleList(list){\n"
+ "\t\telement = document.getElementById(list).style;\n"
+ "\t\telement.display == 'none' ? element.display='block' : element.display='none';\n"
+ "\t}\n" + "</script>\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,
Expand Down Expand Up @@ -123,7 +116,7 @@ private static void writeLinks(final BufferedWriter writer,

final String linksStart = "<img src=\"" + hudsonRoot + iconLocation + statusIcon
+ "\" style=\"margin: 2px;\" width=\"24\" alt=\"" + linkListDisplayStr + " Icon\" height=\"24\" />\n"
+ "<a href=\"javascript:toggleList('" + linkListDisplayStr + "')\" target=\"_self\"><STRONG>"
+ "<a class=\"lpp-toggle-list\" href=\"#\" data-display-category=\"" + linkListDisplayStr + "\"><STRONG>"
+ linkListDisplayStr + " (" + linkListCount + ")</STRONG></a><br />\n"
+ "<ul style=\"display: none;\" id=\""
+ linkListDisplayStr + "\" >\n";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<j:set var="parseSucceeded" value="${it.result.failedToParseError == null}"/>
<j:set var="parseFailed" value="${it.result.failedToParseError != null}"/>
<j:set var="badParseRules" value="${it.result.badParsingRulesError != null}"/>
<l:layout>
<l:layout title="Parsed Console Output">
hypery2k marked this conversation as resolved.
Show resolved Hide resolved
<st:include it="${it.owner}" page="sidepanel.jelly"/>
<l:main-panel>
<j:if test="${parseSucceeded}">
Expand Down
11 changes: 11 additions & 0 deletions src/main/webapp/js/log-parser-behaviour.js
Original file line number Diff line number Diff line change
@@ -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';
})
});
});
Loading