Skip to content

Commit

Permalink
Merge branch 'scalable-icon-support' into scalable-icon-support-2-man…
Browse files Browse the repository at this point in the history
…age-jenkins
  • Loading branch information
janfaracik committed Jan 18, 2022
2 parents df84f34 + 0987321 commit 8267600
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 13 deletions.
13 changes: 10 additions & 3 deletions core/src/main/java/hudson/Functions.java
Original file line number Diff line number Diff line change
Expand Up @@ -2291,6 +2291,7 @@ public static boolean isContextMenuVisible(Action a) {
}
}

@Restricted(NoExternalUse.class)
public static Icon tryGetIcon(String iconGuess) {
// Jenkins Symbols don't have metadata so return null
if (iconGuess == null || iconGuess.startsWith("symbol-")) {
Expand All @@ -2314,6 +2315,7 @@ public static Icon tryGetIcon(String iconGuess) {
return iconMetadata;
}

@Restricted(NoExternalUse.class)
public static String tryGetIconPath(String iconGuess, JellyContext context) {
if (iconGuess == null) {
return null;
Expand All @@ -2334,12 +2336,17 @@ public static String tryGetIconPath(String iconGuess, JellyContext context) {
}

if (iconMetadata == null) {
iconSource = rootURL + (iconGuess.startsWith("/images/") || iconGuess.startsWith("/plugin/") ? getResourcePath() : "") + getResourcePath() + iconGuess;
if (!iconGuess.startsWith("/")) {
iconGuess = "/" + iconGuess;
}

iconSource = rootURL + (iconGuess.startsWith("/images/") || iconGuess.startsWith("/plugin/") ? getResourcePath() : "") + iconGuess;
}

if (iconMetadata != null && iconMetadata.getClassSpec() != null) {
if (IconSet.tryTranslateTangoIconToSymbol(iconMetadata.getClassSpec()) != null) {
return IconSet.tryTranslateTangoIconToSymbol(iconMetadata.getClassSpec());
String translatedIcon = IconSet.tryTranslateTangoIconToSymbol(iconMetadata.getClassSpec());
if (translatedIcon != null) {
return translatedIcon;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,6 @@ class MenuItem {
/**
* Optional icon XML, if set it's used instead of @icon for the menu item
*/
@Exported
private String iconXml;

/**
Expand Down Expand Up @@ -318,6 +317,7 @@ class MenuItem {
@SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD", justification = "read by Stapler")
public ContextMenu subMenu;

@Exported
public String getIconXml() {
return iconXml;
}
Expand Down
1 change: 1 addition & 0 deletions core/src/main/java/org/jenkins/ui/icon/IconSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,7 @@ private static void initializeSVGs() {
* @param tangoIcon A tango icon in the format 'icon-* size-*', e.g. 'icon-gear icon-lg'
* @return a Jenkins Symbol (if one exists) otherwise null
*/
@Restricted(NoExternalUse.class)
public static String tryTranslateTangoIconToSymbol(String tangoIcon) {
if (tangoIcon != null) {
tangoIcon = tangoIcon.split(" ")[0];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ THE SOFTWARE.
<l:icon src="symbol-person-circle" />
</span>

<table class="jenkins-table ${iconSize == '16x16' ? 'jenkins-table--small' : iconSize == '24x24' ? 'jenkins-table--medium' : ''} sortable" id="people">
<table class="jenkins-table ${iconSize == '16x16' ? 'jenkins-table--small' : iconSize == '24x24' ? 'jenkins-table--medium' : ''} sortable" id="people" style="display: none;">
<thead>
<tr>
<th data-sort-disable="true" class="jenkins-table__cell--tight"></th>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
function display(data) {
var p = document.getElementById('people');
p.show();
var rootURL = document.head.getAttribute('data-rooturl');
for (var x = 0; data.length > x; x++) {
var e = data[x];
Expand All @@ -19,7 +20,7 @@ function display(data) {
var wrapper = document.createElement('div');
wrapper.className = 'jenkins-table__cell__button-wrapper';
d.className = 'jenkins-table__cell--tight jenkins-table__icon';
var icon = document.getElementById('person-circle-outline')
var icon = document.getElementById('person-circle')
wrapper.innerHTML = icon.children[0].outerHTML;
d.appendChild(wrapper);
r.appendChild(d);
Expand Down Expand Up @@ -55,4 +56,4 @@ function display(data) {

ts_refresh(p);
}
}
}
4 changes: 2 additions & 2 deletions core/src/main/resources/lib/layout/task.jelly
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ THE SOFTWARE.
<st:attribute name="href" use="required">
Link target. Relative to the current page.
</st:attribute>
<st:attribute name="icon">
<st:attribute name="icon" use="required">
URL to an icon image, or the icon class specification. If using an image URL,
the image should be 24x24 in size and relative to the context path of Hudson.

Common values include:

# "symbol-search" "symbol-terminal" "symbol-settings" - use a Jenkins Symbol as the icon for your task
# "symbol-search" / "symbol-terminal" / "symbol-settings" - use a Jenkins Symbol as the icon for your task
# "icon-folder icon-md" is an example of using a class spec for a medium folder icon
# "images/24x24/..." then points to the stock icon resources
# "plugin/foobar/abc/def.png" that points to "src/main/webapp/abc/def.png" in your plugin resources
Expand Down
4 changes: 2 additions & 2 deletions test/src/test/java/lib/layout/IconTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,8 @@ public void testTasks() throws Exception {
assertIconToImageOkay(taskDivs.get(4).getElementsByTagName("img").get(0), "/images/svgs/package.svg");
assertIconToSymbolOkay(taskDivs.get(5).getElementsByTagName("svg").get(0));

assertIconToImageOkay(taskDivs.get(6).getElementsByTagName("img").get(0), "plugin/xxx/icon.png");
assertIconToImageOkay(taskDivs.get(7).getElementsByTagName("img").get(0), "plugin/xxx/icon.png");
assertIconToImageOkay(taskDivs.get(6).getElementsByTagName("img").get(0), "/plugin/xxx/icon.png");
assertIconToImageOkay(taskDivs.get(7).getElementsByTagName("img").get(0), "/plugin/xxx/icon.png");
}

@TestExtension("testTasks")
Expand Down
4 changes: 2 additions & 2 deletions war/src/main/less/base/yui-compatibility.less
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,8 @@ div.yahooTree td {

svg,
img {
width: 1.2rem;
height: 1.2rem;
width: 1.2rem !important;
height: 1.2rem !important;
margin: 0.25rem 0.5rem 0.25rem 0;
}
}
Expand Down

0 comments on commit 8267600

Please sign in to comment.