Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[JENKINS-20995] Default Priority always shows 1-5
Fixed problem where Default Priority Dropdown
always showed 1-5.
Updated default handling to reuse set values 
when switching strategy.
  • Loading branch information
emsa23 committed Dec 12, 2013
1 parent 60a6aba commit adb35b8
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 21 deletions.
Expand Up @@ -24,10 +24,15 @@
package jenkins.advancedqueue.sorter.strategy;

import hudson.util.ListBoxModel;

import java.io.IOException;

import javax.servlet.ServletException;

import jenkins.advancedqueue.PrioritySorterConfiguration;
import jenkins.advancedqueue.sorter.SorterStrategy;
import jenkins.advancedqueue.sorter.SorterStrategyDescriptor;

import org.kohsuke.stapler.QueryParameter;

/**
Expand Down Expand Up @@ -62,6 +67,11 @@ public final int getDefaultPriority() {
return defaultPriority;
}

public ListBoxModel doFillDefaultPriorityItems() {
// TODO: replace by dynamic retrieval
throw new RuntimeException();
}

public abstract static class MultiBucketStrategyDescriptor extends SorterStrategyDescriptor {

public ListBoxModel doUpdateDefaultPriorityItems(@QueryParameter("value") String strValue) {
Expand All @@ -75,6 +85,11 @@ public ListBoxModel doUpdateDefaultPriorityItems(@QueryParameter("value") String
return items;
}

public ListBoxModel doDefaultPriority(@QueryParameter("value") String value) throws IOException,
ServletException {
return doUpdateDefaultPriorityItems(value);
}

private ListBoxModel internalFillDefaultPriorityItems(int value) {
ListBoxModel items = new ListBoxModel();
for (int i = 1; i <= value; i++) {
Expand All @@ -83,22 +98,36 @@ private ListBoxModel internalFillDefaultPriorityItems(int value) {
return items;
}

public ListBoxModel doDefaultPriority(@QueryParameter("value") String value) throws IOException,
ServletException {
return doFillDefaultPriorityItems();
private MultiBucketStrategy getStrategy() {
SorterStrategy strategy = PrioritySorterConfiguration.get().getStrategy();
if (strategy == null || !(strategy instanceof MultiBucketStrategy)) {
return null;
}
return (MultiBucketStrategy) strategy;
}

public ListBoxModel doFillDefaultPriorityItems() {
// TODO: replace by dynamic retrieval
return internalFillDefaultPriorityItems(DEFAULT_PRIORITIES_NUMBER);
MultiBucketStrategy strategy = getStrategy();
if (strategy == null) {
return internalFillDefaultPriorityItems(DEFAULT_PRIORITIES_NUMBER);
}
return internalFillDefaultPriorityItems(strategy.getNumberOfPriorities());
}

public int getDefaultPrioritiesNumber() {
return DEFAULT_PRIORITIES_NUMBER;
MultiBucketStrategy strategy = getStrategy();
if (strategy == null) {
return DEFAULT_PRIORITIES_NUMBER;
}
return strategy.getNumberOfPriorities();
}

public int getDefaultPriority() {
return DEFAULT_PRIORITY;
MultiBucketStrategy strategy = getStrategy();
if (strategy == null) {
return DEFAULT_PRIORITY;
}
return strategy.getDefaultPriority();
}
}
}
@@ -1,5 +1,4 @@
<j:jelly xmlns:j="jelly:core" xmlns:f="/lib/form" xmlns:st="jelly:stapler">
<script src="${rootURL}/plugin/PrioritySorter/scripts.js"/>
<f:section title="Priority Sorter">
<j:if test="${instance.legacyMode}">
<f:optionalBlock title="${%Switch to Advanced Priority Sorter Mode}"
Expand Down
28 changes: 15 additions & 13 deletions src/main/webapp/scripts.js
Expand Up @@ -2,19 +2,21 @@ document.observe("dom:loaded", function() {
prioritySorterGlobalConfUpdate();
});

Element.prototype.triggerEvent = function(eventName)
{
if (document.createEvent)
{
var evt = document.createEvent('HTMLEvents');
evt.initEvent(eventName, true, true);

return this.dispatchEvent(evt);
}

if (this.fireEvent)
return this.fireEvent('on' + eventName);
}

function prioritySorterGlobalConfUpdate()
{
strategy=document.getElementById('ps_strategy').value;
allowPriorityOnJobs=document.getElementById('ps_allowPriorityOnJobs')
defaultPriority=document.getElementById('ps_defaultPriority')
numberOfPriorities=document.getElementById('ps_numberOfPriorities')
if(strategy == 'FIFO') {
allowPriorityOnJobs.disabled=true
numberOfPriorities.disabled=true
defaultPriority.disabled=true
} else {
allowPriorityOnJobs.disabled=false
numberOfPriorities.disabled=false
defaultPriority.disabled=false
}
$('ps_numberOfPriorities').triggerEvent('change')
}

0 comments on commit adb35b8

Please sign in to comment.