Skip to content

Commit

Permalink
[JENKINS-21192] - Added a "Reset defaults button"
Browse files Browse the repository at this point in the history
Related to https://issues.jenkins-ci.org/browse/JENKINS-21192

Signed-off-by: Oleg Nenashev <nenashev@synopsys.com>
  • Loading branch information
oleg-nenashev committed Jan 1, 2014
1 parent fa7f794 commit 74c46af
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 9 deletions.
Expand Up @@ -109,19 +109,26 @@ public boolean hasConfiguredFilters() {
public JobsFilter getFilters() {
return hasConfiguredFilters()
? contextMap.get(getSessionId()).getFiltersConfig()
: new JobsFilter(this,
: getDefaultFilters();
}

/**
* Gets default search options for UI.
* @since 0.2
*/
public JobsFilter getDefaultFilters() {
return new JobsFilter(this,
defaultJobFilters.getAll(ViewJobFilter.class),
defaultIncludeRegex, null);
}

/**
* An override for future versions.
*/
public boolean isAutomaticRefreshEnabled() {
return false;
}



/**
* Checks that the auto-refresh is enabled for the page.
*/
Expand Down Expand Up @@ -159,23 +166,39 @@ public List<TopLevelItem> getItems() {
return res;
}

public void doSearchSubmit(StaplerRequest req, StaplerResponse rsp) throws IOException, UnsupportedEncodingException, ServletException, Descriptor.FormException {
public void doSearchSubmit(StaplerRequest req, StaplerResponse rsp)
throws IOException, UnsupportedEncodingException, ServletException,
Descriptor.FormException {
Hudson.getInstance().checkPermission(View.READ);

// Get filters
// Get filters and write them to the cache
JobsFilter filter = new JobsFilter(req, this);
updateSearchCache(filter);

// Redirect to the current page in order to reload list with filters
rsp.sendRedirect(".");
}

public void updateSearchCache(JobsFilter filter) {
// Put Context to the map
if (contextMap==null) {
synchronized(this) {
contextMap = new UserContextCache();
}
}
contextMap.put(getSessionId(), new UserContext(filter));

// Redirect to the current page in order to reload list with filters
}

/**
* Resets default values of the session.
* @since 0.2
*/
public void doResetDefaultSearchOptions(StaplerRequest req, StaplerResponse rsp)
throws IOException {
Hudson.getInstance().checkPermission(View.READ);
updateSearchCache(getDefaultFilters());
rsp.sendRedirect(".");
}
}

@Extension
public static final class DescriptorImpl extends ViewDescriptor {
Expand Down
Expand Up @@ -43,6 +43,12 @@
<f:submit value="${%Submit}" />
</f:block>
</f:form>
<f:form method="post" name="config" action="resetDefaultSearchOptions">
<f:block>
<f:submit value="${%Reset Defaults}" />
</f:block>
</f:form>


<st:include page="main.jelly" class="hudson.model.ListView"/>
<!--HACK: Clean cache-->
Expand Down

0 comments on commit 74c46af

Please sign in to comment.