Skip to content

Commit

Permalink
Merge pull request #42 from apemberton/master
Browse files Browse the repository at this point in the history
JENKINS-26036 add support for folders and other possible view containers
  • Loading branch information
pellepelster committed Jun 2, 2015
2 parents 8c9b7af + ea265bc commit ebeeb14
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 83 deletions.
6 changes: 0 additions & 6 deletions pom.xml
Expand Up @@ -52,12 +52,6 @@
</pluginRepositories>

<dependencies>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>nested-view</artifactId>
<version>1.8</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
Expand Down
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,10 +1,10 @@
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.View;

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

/**
Expand All @@ -16,25 +16,8 @@ public class WallDisplayTransientViewActionFactory extends TransientViewActionFa

@Override
public List<Action> createFor(final View view) {

List<Action> result = new ArrayList<Action>();
String viewName = view.getViewName();

if (Hudson.getInstance().getPlugin("nested-view") != null) {
ArrayList<String> viewNames = new ArrayList<String>();
viewNames.add(viewName);
ViewGroup owner = view.getOwner();
while (owner instanceof hudson.plugins.nested_view.NestedView) {
viewNames.add(((hudson.plugins.nested_view.NestedView) owner).getViewName());
owner = ((hudson.plugins.nested_view.NestedView) owner).getOwner();
}
Collections.reverse(viewNames);
viewName = StringUtils.join(viewNames, "/view/");
}

result.add(new WallDisplayViewAction(viewName));
return result;

WallDisplayViewAction action = new WallDisplayViewAction(view.getViewName(), view.getOwner().getUrl());
return Arrays.asList((Action) action);
}

}
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 ebeeb14

Please sign in to comment.