Skip to content

Commit 733ca62

Browse files
committed
Fix styling of select boxes for issue and version parameter
1 parent 984160c commit 733ca62

File tree

4 files changed

+56
-51
lines changed

4 files changed

+56
-51
lines changed

src/main/java/hudson/plugins/jira/listissuesparameter/JiraIssueParameterDefinition.java

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,22 +22,18 @@
2222
import com.atlassian.jira.rest.client.api.domain.IssueField;
2323
import hudson.Extension;
2424
import hudson.cli.CLICommand;
25-
import hudson.model.Job;
26-
import hudson.model.ParameterDefinition;
27-
import hudson.model.ParameterValue;
25+
import hudson.model.*;
2826
import hudson.plugins.jira.JiraSession;
2927
import hudson.plugins.jira.JiraSite;
28+
import hudson.util.ListBoxModel;
3029
import java.io.IOException;
3130
import java.util.ArrayList;
3231
import java.util.List;
3332
import java.util.concurrent.TimeoutException;
3433
import net.sf.json.JSONObject;
3534
import org.apache.commons.lang.StringUtils;
3635
import org.jenkinsci.Symbol;
37-
import org.kohsuke.stapler.DataBoundConstructor;
38-
import org.kohsuke.stapler.DataBoundSetter;
39-
import org.kohsuke.stapler.Stapler;
40-
import org.kohsuke.stapler.StaplerRequest2;
36+
import org.kohsuke.stapler.*;
4137

4238
public class JiraIssueParameterDefinition extends ParameterDefinition {
4339
private static final long serialVersionUID = 3927562542249244416L;
@@ -72,10 +68,20 @@ public ParameterValue createValue(CLICommand command, String value) throws IOExc
7268
return new JiraIssueParameterValue(getName(), value);
7369
}
7470

71+
public ListBoxModel doFillValueItems() {
72+
ListBoxModel items = new ListBoxModel();
73+
74+
items.add("Dummy 1", "dummy1");
75+
return items;
76+
}
77+
7578
public List<JiraIssueParameterDefinition.Result> getIssues()
7679
throws IOException, TimeoutException, RestClientException {
7780
Job<?, ?> job = Stapler.getCurrentRequest2().findAncestorObject(Job.class);
81+
return getIssues(job);
82+
}
7883

84+
private List<JiraIssueParameterDefinition.Result> getIssues(Job<?, ?> job) {
7985
JiraSite site = JiraSite.get(job);
8086
if (site == null) {
8187
throw new IllegalStateException(
@@ -122,6 +128,19 @@ public static class DescriptorImpl extends ParameterDescriptor {
122128
public String getDisplayName() {
123129
return "Jira Issue Parameter";
124130
}
131+
132+
public ListBoxModel doFillValueItems(@AncestorInPath Job<?, ?> job, @QueryParameter String name) {
133+
ListBoxModel items = new ListBoxModel();
134+
ParametersDefinitionProperty prop = job.getProperty(ParametersDefinitionProperty.class);
135+
if (prop != null) {
136+
ParameterDefinition def = prop.getParameterDefinition(name);
137+
if (def instanceof JiraIssueParameterDefinition jiraIssueDef) {
138+
List<Result> issueValues = jiraIssueDef.getIssues(job);
139+
issueValues.forEach(it -> items.add(it.summary, it.key));
140+
}
141+
}
142+
return items;
143+
}
125144
}
126145

127146
public static class Result {

src/main/java/hudson/plugins/jira/versionparameter/JiraVersionParameterDefinition.java

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,18 @@
77
import hudson.model.Job;
88
import hudson.model.ParameterDefinition;
99
import hudson.model.ParameterValue;
10+
import hudson.model.ParametersDefinitionProperty;
1011
import hudson.plugins.jira.JiraSession;
1112
import hudson.plugins.jira.JiraSite;
13+
import hudson.util.ListBoxModel;
1214
import java.io.IOException;
1315
import java.util.List;
1416
import java.util.Objects;
1517
import java.util.regex.Pattern;
1618
import java.util.stream.Collectors;
1719
import net.sf.json.JSONObject;
1820
import org.jenkinsci.Symbol;
19-
import org.kohsuke.stapler.DataBoundConstructor;
20-
import org.kohsuke.stapler.Stapler;
21-
import org.kohsuke.stapler.StaplerRequest2;
21+
import org.kohsuke.stapler.*;
2222

2323
public class JiraVersionParameterDefinition extends ParameterDefinition {
2424
private static final long serialVersionUID = 4232979892748310160L;
@@ -69,7 +69,10 @@ public ParameterValue createValue(CLICommand command, String value) throws IOExc
6969

7070
public List<JiraVersionParameterDefinition.Result> getVersions() throws IOException, RestClientException {
7171
Job<?, ?> contextJob = Stapler.getCurrentRequest2().findAncestorObject(Job.class);
72+
return getVersions(contextJob);
73+
}
7274

75+
private List<JiraVersionParameterDefinition.Result> getVersions(Job<?, ?> contextJob) {
7376
JiraSite site = JiraSite.get(contextJob);
7477
if (site == null) {
7578
throw new IllegalStateException(
@@ -173,6 +176,19 @@ public static class DescriptorImpl extends ParameterDescriptor {
173176
public String getDisplayName() {
174177
return "Jira Release Version Parameter";
175178
}
179+
180+
public ListBoxModel doFillVersionItems(@AncestorInPath Job<?, ?> job, @QueryParameter String name) {
181+
ListBoxModel items = new ListBoxModel();
182+
ParametersDefinitionProperty prop = job.getProperty(ParametersDefinitionProperty.class);
183+
if (prop != null) {
184+
ParameterDefinition def = prop.getParameterDefinition(name);
185+
if (def instanceof JiraVersionParameterDefinition jiraVersionDef) {
186+
List<JiraVersionParameterDefinition.Result> issueValues = jiraVersionDef.getVersions(job);
187+
issueValues.forEach(it -> items.add(it.name));
188+
}
189+
}
190+
return items;
191+
}
176192
}
177193

178194
public static class Result {

src/main/resources/hudson/plugins/jira/listissuesparameter/JiraIssueParameterDefinition/index.jelly

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,25 +17,10 @@ limitations under the License.
1717
<?jelly escape-by-default='true'?>
1818
<j:jelly xmlns:j="jelly:core" xmlns:f="/lib/form">
1919
<j:set var="escapeEntryTitleAndDescription" value="false"/>
20-
<f:entry title="${h.escape(it.name)}" description="${it.formattedDescription}">
21-
<!-- this div is required because of ParametersDefinitionProperty.java#117 -->
22-
<div name="parameter">
20+
<j:set var="instance" value="${it}"/>
21+
<j:set var="descriptor" value="${it.descriptor}"/>
22+
<f:entry field="value" title="${h.escape(it.name)}" description="${it.formattedDescription}">
2323
<input type="hidden" name="name" value="${it.name}"/>
24-
<j:choose>
25-
<j:when test="${it.issues == null or it.issues.size() == 0}">
26-
<!-- no tags at all -->
27-
${%No issues matched the search.}<br/>
28-
${%If you trigger the build, it will likely fail.}
29-
</j:when>
30-
<j:otherwise>
31-
<!-- everything is fine, we can display the drop-down list to the user -->
32-
<select name="value">
33-
<j:forEach var="issue" items="${it.issues}">
34-
<option value="${issue.key}">${issue.key}: ${issue.summary}</option>
35-
</j:forEach>
36-
</select>
37-
</j:otherwise>
38-
</j:choose>
39-
</div>
24+
<f:select/>
4025
</f:entry>
4126
</j:jelly>
Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,11 @@
11
<!-- this is the page fragment displayed when triggering a new build -->
22
<?jelly escape-by-default='true'?>
33
<j:jelly xmlns:j="jelly:core" xmlns:f="/lib/form">
4-
<j:set var="escapeEntryTitleAndDescription" value="false"/>
5-
<f:entry title="${h.escape(it.name)}" description="${it.formattedDescription}">
6-
<!-- this div is required because of ParametersDefinitionProperty.java#117 -->
7-
<div name="parameter">
8-
<input type="hidden" name="name" value="${it.name}"/>
9-
<j:choose>
10-
<j:when test="${it.versions == null or it.versions.size() == 0}">
11-
<!-- no tags at all -->
12-
${%No versions found meeting your filter criteria.}<br/>
13-
${%If you trigger the build, it will likely fail.}
14-
</j:when>
15-
<j:otherwise>
16-
<!-- everything is fine, we can display the drop-down list to the user -->
17-
<select name="version">
18-
<j:forEach var="version" items="${it.versions}">
19-
<option value="${version.name}">${version.name}</option>
20-
</j:forEach>
21-
</select>
22-
</j:otherwise>
23-
</j:choose>
24-
</div>
25-
</f:entry>
4+
<j:set var="escapeEntryTitleAndDescription" value="false"/>
5+
<j:set var="instance" value="${it}"/>
6+
<j:set var="descriptor" value="${it.descriptor}"/>
7+
<f:entry field="version" title="${h.escape(it.name)}" description="${it.formattedDescription}">
8+
<input type="hidden" name="name" value="${it.name}"/>
9+
<f:select/>
10+
</f:entry>
2611
</j:jelly>

0 commit comments

Comments
 (0)