Skip to content

Commit

Permalink
JENKINS-31625 small adjustments to the new code to follow a few conve…
Browse files Browse the repository at this point in the history
…ntions
  • Loading branch information
kinow committed Jul 2, 2017
1 parent 24113d5 commit e31a02d
Show file tree
Hide file tree
Showing 8 changed files with 124 additions and 108 deletions.
Expand Up @@ -65,7 +65,7 @@ public abstract class AbstractScriptableParameter extends AbstractUnoChoiceParam
/**
* Used to split values when scripts return values like A=2, B=3.
*/
protected static final String EQUALS = "=";
protected static final String EQUALS = "=";
/**
* Constant used to add the project in the environment variables map.
*/
Expand Down
37 changes: 28 additions & 9 deletions src/main/java/org/biouno/unochoice/CascadeChoiceParameter.java
Expand Up @@ -61,7 +61,9 @@ public class CascadeChoiceParameter extends AbstractCascadableParameter {
private final Boolean filterable;

/**
* Filter Length
* Filter length. Defines a minimum number of characters that must be entered before the filter
* is activated. If this value is, for example, 4, then only when the 5th element is entered,
* then the filter will be activated.
*/
private final Integer filterLength;

Expand All @@ -74,15 +76,34 @@ public class CascadeChoiceParameter extends AbstractCascadableParameter {
* @param choiceType choice type
* @param referencedParameters referenced parameters
* @param filterable filter flag
* @param filterLength length when filter start filtering
* @deprecated see JENKINS-32149
*/
public CascadeChoiceParameter(String name, String description, Script script,
String choiceType, String referencedParameters, Boolean filterable, Integer filterLength) {
String choiceType, String referencedParameters, Boolean filterable) {
super(name, description, script, referencedParameters);
this.choiceType = StringUtils.defaultIfBlank(choiceType, PARAMETER_TYPE_SINGLE_SELECT);
this.filterable = filterable;
this.filterLength = filterLength;
this.filterLength = null;
}

/**
* Constructor called from Jelly with parameters.
*
* @param name name
* @param description description
* @param randomName parameter random generated name (uuid)
* @param script script
* @param choiceType choice type
* @param referencedParameters referenced parameters
* @param filterable filter flag
* @deprecated see JENKINS-31625
*/
public CascadeChoiceParameter(String name, String description, String randomName, Script script,
String choiceType, String referencedParameters, Boolean filterable) {
super(name, description, randomName, script, referencedParameters);
this.choiceType = StringUtils.defaultIfBlank(choiceType, PARAMETER_TYPE_SINGLE_SELECT);
this.filterable = filterable;
this.filterLength = null;
}

/**
Expand All @@ -95,7 +116,7 @@ public CascadeChoiceParameter(String name, String description, Script script,
* @param choiceType choice type
* @param referencedParameters referenced parameters
* @param filterable filter flag
* @param filterLength length when filter start filtering
* @param filterLength filter length
*/
@DataBoundConstructor
public CascadeChoiceParameter(String name, String description, String randomName, Script script,
Expand Down Expand Up @@ -128,11 +149,9 @@ public Boolean getFilterable() {
* @return filter length
*/
public Integer getFilterLength() {
if (filterLength == null) {
return 1;
}
return filterLength;
return filterLength == null ? 1 : filterLength;
}

// --- descriptor

@Extension
Expand Down
7 changes: 1 addition & 6 deletions src/main/java/org/biouno/unochoice/ChoiceParameter.java
Expand Up @@ -43,11 +43,6 @@ public class ChoiceParameter extends AbstractScriptableParameter {
*/
private static final long serialVersionUID = -4449319038169585222L;

/**
* Default length to active filter feature.
*/
private static final int DEFAULT_FILTER_LENGTH = 1;

/**
* Choice type.
*/
Expand Down Expand Up @@ -139,7 +134,7 @@ public Boolean getFilterable() {
* @return filter length
*/
public Integer getFilterLength() {
return filterLength == null ? DEFAULT_FILTER_LENGTH : filterLength;
return filterLength == null ? 1 : filterLength;
}

// --- descriptor
Expand Down
Expand Up @@ -55,7 +55,7 @@
<f:entry title="${%Enable filters}" field="filterable" help="${rootURL}/../plugin/uno-choice/help-filterableParameters.html">
<f:checkbox name="parameter.filterable" checked="${instance.filterable}">${%Filterable}</f:checkbox>
</f:entry>
<f:entry title="${%Start filtered length}" field="filterLength" help="${rootURL}/../plugin/uno-choice/help-filterLengthParameters.html">
<f:textbox name="parameter.filterLength" default="1">${%FilterLength}</f:textbox>
<f:entry title="${%Filter starts after N chars}" field="filterLength" help="${rootURL}/../plugin/uno-choice/help-filterLengthParameters.html">
<f:textbox name="parameter.filterLength" default="1" value="${instance.filterLength}" />
</f:entry>
</j:jelly>
Expand Up @@ -52,7 +52,7 @@
<f:entry title="${%Enable filters}" field="filterable" help="${rootURL}/../plugin/uno-choice/help-filterableParameters.html">
<f:checkbox name="parameter.filterable" checked="${instance.filterable}">${%Filterable}</f:checkbox>
</f:entry>
<f:entry title="${%Start filtered length}" field="filterLength" help="${rootURL}/../plugin/uno-choice/help-filterLengthParameters.html">
<f:textbox name="parameter.filterLength" default="1">${%FilterLength}</f:textbox>
<f:entry title="${%Filter starts after N chars}" field="filterLength" help="${rootURL}/../plugin/uno-choice/help-filterLengthParameters.html">
<f:textbox name="parameter.filterLength" default="1" value="${instance.filterLength}" />
</f:entry>
</j:jelly>
Expand Up @@ -547,7 +547,7 @@ var UnoChoice = UnoChoice || (function($) {
*
* @param paramElement parameter HTML element being filtered
* @param filterElement HTML element where the user enter the filter
* @param filterLength length when filter start filtering
* @param filterLength filter length
*/
/* public */ function FilterElement(paramElement, filterElement, filterLength) {
this.paramElement = paramElement;
Expand Down Expand Up @@ -610,7 +610,8 @@ var UnoChoice = UnoChoice || (function($) {
return this.originalArray;
}
/**
* @return length when filter start filtering
* Get the filter length.
* @return filter length
*/
FilterElement.prototype.getFilterLength = function() {
return this.filterLength;
Expand Down Expand Up @@ -645,7 +646,7 @@ var UnoChoice = UnoChoice || (function($) {
var filteredElement = _self.getParameterElement();
var text = filterElement.value.toLowerCase();
if (text.length != 0 && text.length < _self.getFilterLength()) {
console.log("Filter pattern to short " + text.length + " < " + _self.getFilterLength());
//console.log("Filter pattern too short: [" + text.length + " < " + _self.getFilterLength() + "]");
return;
}
var options = _self.originalArray;
Expand Down
3 changes: 2 additions & 1 deletion src/main/webapp/help-filterLengthParameters.html
@@ -1,5 +1,6 @@
<div>
<p>
The length of the pattern of the filter when the filter starts to work.
How many characters a user must enter before the filter is applied. For example, if this value
is 4, so only after the 5th character is entered the filter will start working.
</p>
</div>

0 comments on commit e31a02d

Please sign in to comment.