Skip to content

Commit

Permalink
Merge pull request #10106 from timja/ballColorTd-table
Browse files Browse the repository at this point in the history
[JENKINS-74868] Use new build status symbols in multi branch projects
  • Loading branch information
krisstern authored Jan 3, 2025
2 parents 238c498 + e1dff1a commit 89f48c5
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 39 deletions.
67 changes: 38 additions & 29 deletions core/src/main/resources/lib/hudson/ballColorTd.jelly
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ THE SOFTWARE.
<?jelly escape-by-default='true'?>
<j:jelly xmlns:j="jelly:core" xmlns:x="jelly:xml" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form">
<st:documentation>
Display the ball in a TD.
<st:attribute name="it" type="hudson.model.BallColor">
Color of the ball or null to skip drawing.
Display the build status icon in a table cell.
<st:attribute name="it" type="hudson.model.StatusIcon">
Icon to be displayed.
</st:attribute>
<st:attribute name="iconSizeClass">
Specifies the size of the icon. If unspecified, it inherits from
Expand Down Expand Up @@ -56,33 +56,42 @@ THE SOFTWARE.
</j:choose>
</j:if>

<j:choose>
<j:when test="${iconClassName != null}">
<l:icon class="${iconClassName} ${subIconSizeClass}" alt="${it.description}" tooltip="${it.description}" />
</j:when>
<j:otherwise>
<!-- "it" is not a hudson.model.BallColor. Let's try figure out the icon from its URL. -->
<j:set var="iconUrl" value="${it.getImageOf(iconSize)}"/>
<j:if test="${iconUrl.startsWith(imagesURL)}">
<!-- Normalize the icon URL -->
<j:set var="iconUrl" value="${iconUrl.substring(imagesURL.length() + 1)}"/>
</j:if>
<!-- if its actually a BallColor then use the appropriate build symbol -->
<j:if test="${attrs.it.baseColor != null}">
<l:icon src="symbol-status-${attrs.it.iconName}" class="${subIconSizeClass}" alt="${it.description}" tooltip="${it.description}" />
</j:if>

<j:if test="${attrs.it.baseColor == null}">
<j:choose>
<j:when test="${iconClassName != null}">
<l:icon class="${iconClassName} ${subIconSizeClass}" alt="${it.description}" tooltip="${it.description}"/>
</j:when>
<j:otherwise>
<!-- "it" is not a hudson.model.BallColor. Let's try figure out the icon from its URL. -->
<j:set var="iconUrl" value="${it.getImageOf(iconSize)}"/>
<j:if test="${iconUrl.startsWith(imagesURL)}">
<!-- Normalize the icon URL -->
<j:set var="iconUrl" value="${iconUrl.substring(imagesURL.length() + 1)}"/>
</j:if>

<!-- See if we can get an Icon def from the URL -->
<j:set var="icon" value="${icons.getIconByUrl(iconUrl)}"/>
<j:choose>
<j:when test="${icon != null}">
<!-- We found the Icon def -->
<l:icon class="${icon.classSpec}" alt="${it.description}" tooltip="${it.description}" style="${attrs.style}" />
</j:when>
<j:otherwise>
<!-- We don't seem to have this icon in the IconSet... fallback again... -->
<j:set var="iconUrl" value="${it.getImageOf(iconSize)}"/>
<l:icon src="${iconUrl}" class="${iconSizeClass}" alt="${it.description}" tooltip="${it.description}" style="${attrs.style}" />
</j:otherwise>
</j:choose>
</j:otherwise>
</j:choose>
<!-- See if we can get an Icon def from the URL -->
<j:set var="icon" value="${icons.getIconByUrl(iconUrl)}"/>
<j:choose>
<j:when test="${icon != null}">
<!-- We found the Icon def -->
<l:icon class="${icon.classSpec}" alt="${it.description}" tooltip="${it.description}"
style="${attrs.style}"/>
</j:when>
<j:otherwise>
<!-- We don't seem to have this icon in the IconSet... fallback again... -->
<j:set var="iconUrl" value="${it.getImageOf(iconSize)}"/>
<l:icon src="${iconUrl}" class="${iconSizeClass}" alt="${it.description}" tooltip="${it.description}"
style="${attrs.style}"/>
</j:otherwise>
</j:choose>
</j:otherwise>
</j:choose>
</j:if>
</j:if>
</div>
</td>
Expand Down
16 changes: 6 additions & 10 deletions test/src/test/java/lib/layout/IconTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,14 @@ public void testBallColorTd() throws Exception {
HtmlPage p = j.createWebClient().goTo("testBallColorTd");

DomElement ballColorAborted = p.getElementById("ballColorAborted");
List<DomElement> ballIcons = StreamSupport.stream(ballColorAborted.getChildElements().spliterator(), false).collect(Collectors.toList());
assertIconToSvgIconOkay(ballIcons.get(0).getFirstElementChild(), "icon-aborted icon-md");
assertThat("Aborted", is(ballColorAborted.getTextContent()));
HtmlElement symbol = ballColorAborted.getElementsByTagName("svg").get(0);
assertThat("icon-md", is(symbol.getAttribute("class")));

assertIconToSymbolOkay(symbol);

DomElement statusIcons = p.getElementById("statusIcons");
List<DomElement> statusIconsList = StreamSupport.stream(statusIcons.getChildElements().spliterator(), false).collect(Collectors.toList());
List<DomElement> statusIconsList = StreamSupport.stream(statusIcons.getChildElements().spliterator(), false).toList();

assertIconToSvgOkay(statusIconsList.get(0).getFirstElementChild().getNextElementSibling(), "icon-user icon-xlg");

Expand Down Expand Up @@ -182,13 +185,6 @@ private void assertIconToSvgOkay(DomElement icon, String classSpec) {
}
}

private void assertIconToSvgIconOkay(DomElement icon, String classSpec) {
assertThat(icon.getTagName(), is("span"));
if (classSpec != null) {
assertThat(icon.getAttribute("class"), endsWith(classSpec));
}
}

private void assertIconToSymbolOkay(DomElement icon) {
assertThat("svg", is(icon.getTagName()));
}
Expand Down

0 comments on commit 89f48c5

Please sign in to comment.