diff --git a/pom.xml b/pom.xml index 4b077ce2..a30ce143 100644 --- a/pom.xml +++ b/pom.xml @@ -51,6 +51,10 @@ org.jenkins-ci.plugins script-security + + io.jenkins.plugins + ionicons-api + org.jenkins-ci.main diff --git a/src/main/java/hudson/matrix/LabelAxis.java b/src/main/java/hudson/matrix/LabelAxis.java index eae12501..f0fd987f 100644 --- a/src/main/java/hudson/matrix/LabelAxis.java +++ b/src/main/java/hudson/matrix/LabelAxis.java @@ -24,17 +24,17 @@ package hudson.matrix; import hudson.Extension; +import java.io.IOException; +import java.util.Set; import jenkins.model.Jenkins; import hudson.model.labels.LabelAtom; -import org.apache.commons.lang.StringUtils; +import org.kohsuke.accmod.Restricted; +import org.kohsuke.accmod.restrictions.NoExternalUse; import org.kohsuke.stapler.DataBoundConstructor; import java.util.ArrayList; import java.util.List; -import static hudson.Functions.htmlAttributeEscape; -import static hudson.Functions.jsStringEscape; - /** * {@link Axis} that selects label expressions. * @@ -56,16 +56,9 @@ public String getValueString() { return String.join("/", getValues()); } - public String getValueStringHtmlEscaped() { - final List values = getValues(); - StringBuilder str = new StringBuilder(); - for (String value : values) { - if (str.length() > 0) { - str.append('/'); - } - str.append(htmlAttributeEscape(value)); - } - return str.toString(); + @Restricted(NoExternalUse.class) + public boolean isChecked(String name) { + return getValues().contains(name); } @Extension @@ -85,13 +78,42 @@ public boolean isInstantiable() { return !j.getNodes().isEmpty() || !j.clouds.isEmpty(); } - public String buildLabelCheckBox(LabelAtom la) { - final String escapedName = jsStringEscape(htmlAttributeEscape(la.getName())); - final String escapedDescription = jsStringEscape(StringUtils.isEmpty(la.getDescription()) ? "" : - htmlAttributeEscape(la.getDescription())); - return ""; + @Restricted(NoExternalUse.class) + public LabelLists getLabelLists() { + return new LabelLists(); + } + + @Restricted(NoExternalUse.class) + public String getSaveDescription(LabelAtom labelAtom) throws IOException { + // remove line breaks as html tooltip will replace linebreaks with
. + // This ensures that the description is displayed in the same way as on the label + return Jenkins.get().getMarkupFormatter().translate(labelAtom.getDescription()). + replaceAll("\r", "").replaceAll("\n", ""); + } + } + + @Restricted(NoExternalUse.class) + public static class LabelLists { + private List machines = new ArrayList<>(); + private List labels = new ArrayList<>(); + + public LabelLists() { + Set labelsAtoms = Jenkins.get().getLabelAtoms(); + labelsAtoms.forEach(atom -> { + if (atom.isSelfLabel()) { + machines.add(atom); + } else { + labels.add(atom); + } + }); + } + + public List getMachines() { + return machines; + } + + public List getLabels() { + return labels; } } } diff --git a/src/main/resources/hudson/matrix/LabelAxis/config.jelly b/src/main/resources/hudson/matrix/LabelAxis/config.jelly index 01066ef2..d2ad6d19 100644 --- a/src/main/resources/hudson/matrix/LabelAxis/config.jelly +++ b/src/main/resources/hudson/matrix/LabelAxis/config.jelly @@ -27,17 +27,45 @@ THE SOFTWARE. -
- - - -
- - - +
+ + + +
+ +
+
${%Labels} + +
+
+ +
+ +
+
+
+
+
+ +
+
${%Individual Agents} + +
+
+ +
+ +
+
+
+
+
- +
+ diff --git a/src/main/resources/hudson/matrix/LabelAxis/label-axis.css b/src/main/resources/hudson/matrix/LabelAxis/label-axis.css new file mode 100644 index 00000000..74857f04 --- /dev/null +++ b/src/main/resources/hudson/matrix/LabelAxis/label-axis.css @@ -0,0 +1,27 @@ +.mp-label-axis__button { + min-height: 20px; + height: 20px; + padding: 0.5rem 0.3rem; +} + +.mp-label-axis__button[data-hidden=false] { + rotate: 180deg; +} + +.mp-label-axis__container > .jenkins-form-label { + display:flex; + gap: 5px; + align-items: center; +} + +.mp-label-axis { + display: flex; + gap: 10px; + flex-direction: column; + max-height: 300px; + overflow: auto; +} + +.mp-label-axis__tooltip { + width: fit-content; +} diff --git a/src/main/resources/hudson/matrix/LabelAxis/label-axis.js b/src/main/resources/hudson/matrix/LabelAxis/label-axis.js new file mode 100644 index 00000000..60da299b --- /dev/null +++ b/src/main/resources/hudson/matrix/LabelAxis/label-axis.js @@ -0,0 +1,16 @@ +Behaviour.specify(".mp-label-axis__button", "mp-label-container", 0, function(btn) { + btn.addEventListener("click", function(evt) { + const container = btn.closest(".mp-label-axis__container"); + if (container) { + const labelList = container.querySelector(".mp-label-axis__list"); + if (labelList) { + labelList.classList.toggle("jenkins-hidden"); + if (btn.dataset.hidden === "true") { + btn.dataset.hidden = "false"; + } else { + btn.dataset.hidden = "true"; + } + } + } + }); +}); diff --git a/src/main/resources/hudson/matrix/MatrixProject/configure-entries.jelly b/src/main/resources/hudson/matrix/MatrixProject/configure-entries.jelly index 9c6bed92..da6a902d 100644 --- a/src/main/resources/hudson/matrix/MatrixProject/configure-entries.jelly +++ b/src/main/resources/hudson/matrix/MatrixProject/configure-entries.jelly @@ -59,11 +59,6 @@ THE SOFTWARE. - - - -