Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace handbuilt html with jelly for flow durability #205

Merged
merged 5 commits into from
Jul 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,14 @@
import hudson.model.AbstractDescribableImpl;
import hudson.model.Descriptor;
import hudson.security.Permission;
import hudson.util.FormValidation;
import hudson.util.ListBoxModel;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import jenkins.model.Jenkins;
import net.sf.json.JSONObject;
import org.kohsuke.stapler.QueryParameter;
import org.kohsuke.stapler.StaplerRequest;

import edu.umd.cs.findbugs.annotations.CheckForNull;
Expand Down Expand Up @@ -46,6 +52,15 @@ public void setDurabilityHint(FlowDurabilityHint hint){
save();
}

public FormValidation doCheckDurabilityHint(@QueryParameter("durabilityHint") String durabilityHint) {
FlowDurabilityHint flowDurabilityHint = Arrays.stream(FlowDurabilityHint.values())
.filter(f -> f.name().equals(durabilityHint))
.findFirst()
.orElse(GlobalDefaultFlowDurabilityLevel.SUGGESTED_DURABILITY_HINT);

return FormValidation.ok(flowDurabilityHint.getTooltip());
}

@Override
public boolean configure(StaplerRequest req, JSONObject json) {
// TODO verify if this is covered by permissions checks or we need an explicit check here.
Expand All @@ -64,12 +79,18 @@ public boolean configure(StaplerRequest req, JSONObject json) {
return true;
}

public static FlowDurabilityHint getSuggestedDurabilityHint() {
return GlobalDefaultFlowDurabilityLevel.SUGGESTED_DURABILITY_HINT;
}
public ListBoxModel doFillDurabilityHintItems() {
ListBoxModel options = new ListBoxModel();

options.add("None: use pipeline default (" + GlobalDefaultFlowDurabilityLevel.SUGGESTED_DURABILITY_HINT.name() + ")", "null");

List<ListBoxModel.Option> mappedOptions = Arrays.stream(FlowDurabilityHint.values())
.map(hint -> new ListBoxModel.Option(hint.getDescription(), hint.name()))
.collect(Collectors.toList());

options.addAll(mappedOptions);

public static FlowDurabilityHint[] getDurabilityHintValues() {
return FlowDurabilityHint.values();
return options;
}

@NonNull
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,8 @@
<?jelly escape-by-default='true'?>
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form">
<f:section title="Pipeline Speed/Durability Settings">
<f:entry title="${%Pipeline Default Speed/Durability Level}" field="durabilityHint">
<select class="setting-input" name="durabilityHint">
<f:option value="null" selected="${instance[field] == null}">None: use pipeline default (<j:out value="${descriptor.suggestedDurabilityHint.name()}" />)</f:option>
<j:forEach var="it" items="${descriptor.durabilityHintValues}">
<j:set var="optionBody" encode="false">${it.description}</j:set>
<option value="${it.name()}"
selected="${(it==instance[field]) ? 'true':null}"
tooltip="${it.tooltip}"><j:out value="${optionBody}"/></option>
</j:forEach>
</select>
<f:section title="${%Pipeline Speed / Durability}">
<f:entry title="${%Default Speed / Durability Level}" field="durabilityHint">
<f:select />
</f:entry>
</f:section>
<br/><br/>
</j:jelly>