Skip to content

Commit

Permalink
Add data-bound setters for View (#8511)
Browse files Browse the repository at this point in the history
* Add data-bound setters for View

This allows programmatic edit of View

* Clean up

* Fix test

---------

Co-authored-by: Alexander Brandes <[email protected]>
  • Loading branch information
Vlatombe and NotMyFault authored Sep 27, 2023
1 parent 70fddd6 commit 105951c
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 13 deletions.
28 changes: 22 additions & 6 deletions core/src/main/java/hudson/model/View.java
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ public synchronized String getDescription() {

@DataBoundSetter
public synchronized void setDescription(String description) {
this.description = description;
this.description = Util.nullify(description);
}

/**
Expand Down Expand Up @@ -405,13 +405,29 @@ public boolean isFilterExecutors() {
return filterExecutors;
}

/**
* @since TODO
*/
@DataBoundSetter
public void setFilterExecutors(boolean filterExecutors) {
this.filterExecutors = filterExecutors;
}

/**
* If true, only show relevant queue items
*/
public boolean isFilterQueue() {
return filterQueue;
}

/**
* @since TODO
*/
@DataBoundSetter
public void setFilterQueue(boolean filterQueue) {
this.filterQueue = filterQueue;
}

/**
* If this view uses {@code <t:projectView>} for rendering, this method returns columns to be displayed.
*/
Expand Down Expand Up @@ -1013,13 +1029,13 @@ public final synchronized void doConfigSubmit(StaplerRequest req, StaplerRespons

submit(req);

description = Util.nullify(req.getParameter("description"));
filterExecutors = req.getParameter("filterExecutors") != null;
filterQueue = req.getParameter("filterQueue") != null;

var json = req.getSubmittedForm();
setDescription(json.optString("description"));
setFilterExecutors(json.optBoolean("filterExecutors"));
setFilterQueue(json.optBoolean("filterQueue"));
rename(req.getParameter("name"));

getProperties().rebuild(req, req.getSubmittedForm(), getApplicablePropertyDescriptors());
getProperties().rebuild(req, json, getApplicablePropertyDescriptors());

save();

Expand Down
12 changes: 6 additions & 6 deletions core/src/main/resources/hudson/model/View/configure.jelly
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@ THE SOFTWARE.
<f:entry title="${%Name}">
<f:textbox name="name" value="${it.viewName}" autocomplete="on"/>
</f:entry>
<f:entry title="${%Description}" help="/help/view-config/description.html">
<f:textarea name="description" field="description" codemirror-mode="${app.markupFormatter.codeMirrorMode}" codemirror-config="${app.markupFormatter.codeMirrorConfig}" previewEndpoint="/markupFormatter/previewDescription"/>
<f:entry field="description" title="${%Description}" help="/help/view-config/description.html">
<f:textarea codemirror-mode="${app.markupFormatter.codeMirrorMode}" codemirror-config="${app.markupFormatter.codeMirrorConfig}" previewEndpoint="/markupFormatter/previewDescription"/>
</f:entry>
<f:entry field="filterQueue">
<f:checkbox title="${%Filter build queue}" help="/help/view-config/filter-queue.html" name="filterQueue" />
<f:entry field="filterQueue" help="/help/view-config/filter-queue.html">
<f:checkbox title="${%Filter build queue}"/>
</f:entry>
<f:entry field="filterExecutors">
<f:checkbox title="${%Filter build executors}" help="/help/view-config/filter-executors.html" name="filterExecutors" />
<f:entry field="filterExecutors" help="/help/view-config/filter-executors.html">
<f:checkbox title="${%Filter build executors}"/>
</f:entry>

<!-- subtypes can put entries here. -->
Expand Down
2 changes: 1 addition & 1 deletion test/src/test/java/hudson/model/ViewDescriptorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public void invisiblePropertiesOnViewShoudBePersisted() throws Exception {


HtmlForm editViewForm = editViewPage.getFormByName("viewConfig");
editViewForm.getTextAreaByName("description").setText("This list view is awesome !");
editViewForm.getTextAreaByName("_.description").setText("This list view is awesome !");
r.submit(editViewForm);

//Check that the description is updated on view
Expand Down
14 changes: 14 additions & 0 deletions test/src/test/java/hudson/model/ViewTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,20 @@ public class ViewTest {
@Rule
public LoggerRule logging = new LoggerRule();

@Test
public void roundTrip() throws Exception {
ListView view = new ListView("foo");
view.setDescription("Some description");
view.setFilterExecutors(true);
view.setFilterQueue(true);
j.jenkins.addView(view);
j.configRoundtrip(view);

assertEquals("Some description", view.getDescription());
assertEquals(true, view.isFilterExecutors());
assertEquals(true, view.isFilterQueue());
}

@Issue("JENKINS-7100")
@Test public void xHudsonHeader() throws Exception {
assertNotNull(j.createWebClient().goTo("").getWebResponse().getResponseHeaderValue("X-Hudson"));
Expand Down

0 comments on commit 105951c

Please sign in to comment.