Permalink
Browse files

added custom sort order property

  • Loading branch information...
1 parent 67d41f9 commit 11eefae7d2e1fd8faf4e972eb37b09384379dec9 @pellepelster pellepelster committed Apr 27, 2016
View
25 src/main/java/de/pellepelster/jenkins/walldisplay/WallDisplayJobProperty.java
@@ -21,11 +21,13 @@
private String wallDisplayName = null;
private String wallDisplayBgPicture = null;
+ private String wallDisplayOrder = null;
@DataBoundConstructor
- public WallDisplayJobProperty(String wallDisplayName, String wallDisplayBgPicture) {
+ public WallDisplayJobProperty(String wallDisplayName, String wallDisplayBgPicture,String wallDisplayOrder) {
this.wallDisplayName = wallDisplayName;
this.wallDisplayBgPicture = wallDisplayBgPicture;
+ this.wallDisplayOrder = wallDisplayOrder;
}
@Exported
@@ -38,6 +40,11 @@ public String getWallDisplayBgPicture() {
return wallDisplayBgPicture;
}
+ @Exported
+ public String getWallDisplayOrder() {
+ return wallDisplayOrder;
+ }
+
@Extension
public static final class DescriptorImpl extends JobPropertyDescriptor {
@@ -59,12 +66,17 @@ public String getBgPicture() {
return "";
}
+ public String getOrder() {
+ return "";
+ }
+
@Override
public JobProperty<?> newInstance(StaplerRequest req,
JSONObject formData) throws FormException {
String wallDisplayName = null;
String wallDisplayBgPicture = null;
+ String wallDisplayOrder = null;
if (formData.has("wallDisplayNameDynamic")) {
JSONObject wallDisplayNameDynamic = formData.getJSONObject("wallDisplayNameDynamic");
@@ -80,7 +92,16 @@ public String getBgPicture() {
wallDisplayBgPicture = wallDisplayBgPictureDynamic.getString("wallDisplayBgPicture").toString();
}
}
- return new WallDisplayJobProperty(wallDisplayName, wallDisplayBgPicture);
+
+ if (formData.has("wallDisplayOrderDynamic")) {
+ JSONObject wallDisplayOrderDynamic = formData.getJSONObject("wallDisplayOrderDynamic");
+
+ if (wallDisplayOrderDynamic != null && wallDisplayOrderDynamic.has("wallDisplayOrder") && !wallDisplayOrderDynamic.get("wallDisplayOrder").toString().trim().isEmpty()) {
+ wallDisplayOrder = wallDisplayOrderDynamic.get("wallDisplayOrder").toString();
+ }
+ }
+
+ return new WallDisplayJobProperty(wallDisplayName, wallDisplayBgPicture, wallDisplayOrder);
}
}
}
View
2 src/main/java/de/pellepelster/jenkins/walldisplay/WallDisplayPlugin.java
@@ -36,7 +36,7 @@
public static final String[] buildRange = new String[]{"All", "Active this month", "Active this week", "Active today"};
public static final String[] sortOrder = new String[]{"Job Name",
- "Job Status"};
+ "Job Status", "Job Order"};
@Exported
public Configuration config;
View
5 src/main/resources/de/pellepelster/jenkins/walldisplay/WallDisplayJobProperty/config.jelly
@@ -19,6 +19,11 @@ xmlns:f="/lib/form">
<f:textbox name="wallDisplayBgPicture" value="${instance.wallDisplayBgPicture}" />
</f:entry>
</f:optionalBlock>
+ <f:optionalBlock name="wallDisplayOrderDynamic" title="${%walldisplay.orderdynamic}" checked="${instance.wallDisplayOrder != null}">
+ <f:entry title="${%walldisplay.order}" field="wallDisplayOrder">
+ <f:textbox name="wallDisplayOrder" value="${instance.wallDisplayOrder}" />
+ </f:entry>
+ </f:optionalBlock>
</table>
</f:block>
View
5 ...in/resources/de/pellepelster/jenkins/walldisplay/WallDisplayJobProperty/config.properties
@@ -2,4 +2,7 @@ walldisplay.name=Walldisplay text
walldisplay.dynamic=Use custom text for Walldisplay
walldisplay.bgpicture=Background picture
-walldisplay.bgpdynamic=Use custom picture for Walldisplay
+walldisplay.bgpdynamic=Use custom picture for Walldisplay
+
+walldisplay.order=Walldisplay order
+walldisplay.orderdynamic=Use custom ordering for Walldisplay
View
13 src/main/webapp/utils.js
@@ -111,6 +111,19 @@ function getLongestJob(jobs, showBuildNumber, showLastStableTimeAgo, showDetails
return job;
}
+function getJobOrder(job) {
+
+ var jobOrder = "";
+
+ $.each(job.property, function(index, property){
+ if(property.wallDisplayOrder != null && property.wallDisplayOrder != ""){
+ jobOrder = property.wallDisplayOrder;
+ }
+ });
+
+ return jobOrder;
+}
+
function getJobTitle(job) {
var jobTitle = job.displayName;
View
15 src/main/webapp/walldisplay.js
@@ -429,7 +429,7 @@ function getJobs(jobList){
url: jobInfo.url + "/api/json",
dataType: "json",
data: {
- "tree": "displayName,healthReport[score],property[wallDisplayName,wallDisplayBgPicture],name,color,priority,lastStableBuild[timestamp]," +
+ "tree": "displayName,healthReport[score],property[wallDisplayOrder,wallDisplayName,wallDisplayBgPicture],name,color,priority,lastStableBuild[timestamp]," +
"lastBuild[number,timestamp,duration,actions[parameters[name,value],claimed,claimedBy,reason,failCount,skipCount,totalCount],culprits[fullName,property[address]]]," +
"lastCompletedBuild[number,timestamp,duration,actions[parameters[name,value],claimed,claimedBy,reason, failCount,skipCount,totalCount],culprits[fullName,property[address]]]," +
"lastSuccessfulBuild[duration]"
@@ -504,7 +504,18 @@ function getJobs(jobList){
} else if (sortOrder == "job priority")
{
sort = job1.priority - job2.priority;
- }
+ } else if (sortOrder == "job order")
+ {
+
+ var order1 = parseInt(getJobOrder(job1), 10);
+ var order2 = parseInt(getJobOrder(job2), 10);
+
+ if (!isNaN(order1) && !isNaN(order2)) {
+ sort = order1 - order2;
+ } else {
+ sort = getJobOrder(job1).localeCompare(getJobOrder(job2));
+ }
+ }
if(sort == 0){
sort = getJobText(job1, showBuildNumber, showLastStableTimeAgo, showDetails, showJunitResults)

0 comments on commit 11eefae

Please sign in to comment.