Skip to content

Commit

Permalink
JENKINS-26036 add support for folders and other possible view containers
Browse files Browse the repository at this point in the history
  • Loading branch information
apemberton committed May 31, 2015
1 parent 8c9b7af commit ef94a3a
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 58 deletions.
Expand Up @@ -4,7 +4,6 @@
*/
package de.pellepelster.jenkins.walldisplay;

import java.util.Date;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;
import org.kohsuke.stapler.export.Exported;
Expand Down
@@ -1,12 +1,17 @@
package de.pellepelster.jenkins.walldisplay;

import hudson.model.*;
import org.apache.commons.lang.StringUtils;
import hudson.model.Action;
import hudson.model.TransientViewActionFactory;
import hudson.model.ViewGroup;
import hudson.model.Hudson;
import hudson.model.View;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import org.apache.commons.lang.StringUtils;

/**
* Adds the walldisplay link action to all views
*
Expand All @@ -31,8 +36,7 @@ public List<Action> createFor(final View view) {
Collections.reverse(viewNames);
viewName = StringUtils.join(viewNames, "/view/");
}

result.add(new WallDisplayViewAction(viewName));
result.add(new WallDisplayViewAction(viewName, view.getOwner().getUrl()));
return result;

}
Expand Down
Expand Up @@ -8,44 +8,43 @@

/**
* Action providing the link to the actual walldisplay page
*
*
* @author Christian Pelster
*/
public class WallDisplayViewAction implements Action {

private static final String ENCODING = "UTF-8";
private String viewName;

public WallDisplayViewAction(String viewName) {
this.viewName = viewName;
}

public String getIconFileName() {
return "/plugin/jenkinswalldisplay/images/icon.png";
}

public String getDisplayName() {
return "Wall Display";
}

public String getUrlName() {

String encodedUrl = null;
String encodedViewName = null;
String rootUrl = getRootUrl();
try {
encodedUrl = URLEncoder.encode(rootUrl, ENCODING);
encodedViewName = URLEncoder.encode(viewName, ENCODING);
} catch (UnsupportedEncodingException e) {
encodedUrl = rootUrl;
encodedViewName = viewName;
}
return String
.format("%s/plugin/jenkinswalldisplay/walldisplay.html?viewName=%s&jenkinsUrl=%s",
rootUrl, encodedViewName, encodedUrl);
}

protected String getRootUrl() {
return Hudson.getInstance().getRootUrl();
}
private static final String ENCODING = "UTF-8";
private String viewName;
private String viewOwnerUrl;

public WallDisplayViewAction(String viewName, String viewOwnerUrl) {
this.viewName = viewName;
this.viewOwnerUrl = viewOwnerUrl;
}

public String getIconFileName() {
return "/plugin/jenkinswalldisplay/images/icon.png";
}

public String getDisplayName() {
return "Wall Display";
}

public String getUrlName() {
String hudsonUrl = getRootUrl();
try {
hudsonUrl = URLEncoder.encode(hudsonUrl, ENCODING);
viewName = URLEncoder.encode(viewName, ENCODING);
} catch (UnsupportedEncodingException e) {
// TODO
}
return String
.format("%splugin/jenkinswalldisplay/walldisplay.html?viewName=%s&jenkinsUrl=%s%s",
getRootUrl(), viewName, hudsonUrl, viewOwnerUrl);
}

public String getRootUrl(){
return Hudson.getInstance().getRootUrl();
}

}
10 changes: 7 additions & 3 deletions src/main/webapp/walldisplay.js
Expand Up @@ -120,8 +120,12 @@ function blink(objs){
});
}

function jobHasColor(job) {
return typeof job.color !== "undefined"
}

function isJobBuilding(job) {
return job.color.substr(-6) === "_anime";
return jobHasColor(job) && job.color.substr(-6) === "_anime";
}

function jobHasHealthReport(job) {
Expand Down Expand Up @@ -205,7 +209,7 @@ function repaint(){
var isBuilding = isJobBuilding(job);
var jobColor = job.color;

if(job.color.substr(-6) === "_anime"){
if(isBuilding){
jobColor = job.color.substr(0, job.color.length - 6);
}

Expand Down Expand Up @@ -441,7 +445,7 @@ function getJobs(jobNames){

var jobFilteredOut = false;

if(!showDisabledBuilds && job.color === 'disabled'){
if(!jobHasColor(job) || (!showDisabledBuilds && job.color === 'disabled')){
add = false;
jobFilteredOut = true;
}
Expand Down
Expand Up @@ -19,6 +19,7 @@ public class WallDisplayViewActionTest extends HudsonTestCase {

private String rootUrl;
private String encodedRootUrl;
private String viewOwnerUrl;

/**
* Instantiates a new WallDisplayViewAction with a stubbed root URL
Expand All @@ -28,10 +29,11 @@ public class WallDisplayViewActionTest extends HudsonTestCase {
* @return a new WallDisplayViewAction instance
* @throws IOException
*/
public WallDisplayViewAction newAction(String viewName) throws IOException {
WallDisplayViewAction action = spy(new WallDisplayViewAction(viewName));
rootUrl = getURL().toExternalForm();
encodedRootUrl = URLEncoder.encode(rootUrl, "UTF-8");
public WallDisplayViewAction newAction(String viewName, String viewOwnerUrl) throws IOException {
WallDisplayViewAction action = spy(new WallDisplayViewAction(viewName, viewOwnerUrl));
this.rootUrl = getURL().toExternalForm();
this.encodedRootUrl = URLEncoder.encode(rootUrl, "UTF-8");
this.viewOwnerUrl = viewOwnerUrl;
doReturn(rootUrl).when(action).getRootUrl();
return action;
}
Expand All @@ -43,11 +45,11 @@ public WallDisplayViewAction newAction(String viewName) throws IOException {
*/
@Test
public void testGetUrlNameAllView() throws IOException {
WallDisplayViewAction action = newAction("All");
assertEquals(
rootUrl
+ "/plugin/jenkinswalldisplay/walldisplay.html?viewName=All&jenkinsUrl="
+ encodedRootUrl, action.getUrlName());
WallDisplayViewAction action = newAction("All", "/job/abc");
String urlName = rootUrl
+ "plugin/jenkinswalldisplay/walldisplay.html?viewName=All&jenkinsUrl="
+ encodedRootUrl + viewOwnerUrl;
assertEquals(urlName, action.getUrlName());
}

/**
Expand All @@ -58,11 +60,11 @@ public void testGetUrlNameAllView() throws IOException {
*/
@Test
public void testGetUrlNameEncodedView() throws IOException {
WallDisplayViewAction action = newAction("+Dashboard");
assertEquals(
rootUrl
+ "/plugin/jenkinswalldisplay/walldisplay.html?viewName=%2BDashboard&jenkinsUrl="
+ encodedRootUrl, action.getUrlName());
WallDisplayViewAction action = newAction("+Dashboard", "");
String urlName = rootUrl
+ "plugin/jenkinswalldisplay/walldisplay.html?viewName=%2BDashboard&jenkinsUrl="
+ encodedRootUrl + viewOwnerUrl;
assertEquals(urlName, action.getUrlName());
}

}

0 comments on commit ef94a3a

Please sign in to comment.