Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[JENKINS-20052] Refactor ListView getItems (#4466)
* Refactor ListView getItems Signed-off-by: Raihaan Shouhell <raihaan.shouhell@autodesk.com> * Minor Refactor * Optimization for specific case * Migrate statusfilter to viewjobfilter * Use unboxed boolean so we don't have to deal with null * UI Changes * Add tests and use pre-auth filters * Add test with a simple filter * Remove old tests as the new tests should cover this * Change annotation * Only iterate if there are names or a regex pattern
- Loading branch information
Showing
8 changed files
with
290 additions
and
127 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
/* | ||
* The MIT License | ||
* | ||
* Copyright (c) 20020, Autodesk, Inc., Raihaan Shouhell | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in | ||
* all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
* THE SOFTWARE. | ||
*/ | ||
package hudson.views; | ||
|
||
import hudson.Extension; | ||
import hudson.model.Descriptor; | ||
import hudson.model.TopLevelItem; | ||
import hudson.model.View; | ||
import jenkins.model.ParameterizedJobMixIn; | ||
import org.kohsuke.accmod.Restricted; | ||
import org.kohsuke.accmod.restrictions.NoExternalUse; | ||
import org.kohsuke.stapler.DataBoundConstructor; | ||
|
||
import edu.umd.cs.findbugs.annotations.NonNull; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
/** | ||
* Job Filter that will filter jobs based on its disabled status | ||
*/ | ||
@Restricted(NoExternalUse.class) | ||
public final class StatusFilter extends ViewJobFilter { | ||
|
||
private final boolean statusFilter; | ||
|
||
/** | ||
* Creates a new status filter based on supplied boolean | ||
* @param statusFilter true for enabled jobs only and false for disabled jobs only | ||
*/ | ||
@DataBoundConstructor | ||
public StatusFilter(boolean statusFilter) { | ||
this.statusFilter = statusFilter; | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
@Override | ||
public List<TopLevelItem> filter(List<TopLevelItem> added, List<TopLevelItem> all, View filteringView) { | ||
List<TopLevelItem> filtered = new ArrayList<>(); | ||
for (TopLevelItem item : added) { | ||
if (!(item instanceof ParameterizedJobMixIn.ParameterizedJob) // TODO or better to call the more generic Job.isBuildable? | ||
|| ((ParameterizedJobMixIn.ParameterizedJob<?,?>) item).isDisabled() ^ statusFilter) | ||
filtered.add(item); | ||
} | ||
return filtered; | ||
} | ||
|
||
/** | ||
* The setting of the job status filter | ||
* @return true if only enabled jobs are shown and false if only disabled jobs are shown | ||
*/ | ||
public boolean getStatusFilter() { | ||
return statusFilter; | ||
} | ||
|
||
@Extension | ||
public static class StatusFilterDescriptor extends Descriptor<ViewJobFilter> { | ||
public StatusFilterDescriptor() { | ||
super(StatusFilter.class); | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
@NonNull | ||
@Override | ||
public String getDisplayName() { | ||
return Messages.StatusFilter_DisplayName(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
core/src/main/resources/hudson/views/StatusFilter/config.jelly
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<!-- | ||
The MIT License | ||
Copyright (c) 2020, Autodesk, Inc., Raihaan Shouhell | ||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. | ||
--> | ||
|
||
<?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:entry title="${%Status Filter}" help="/help/view-config/statusFilter.html"> | ||
<select name="statusFilter" class="setting-input"> | ||
<f:option value="1" selected="${it.statusFilter==true}">${%Enabled jobs only}</f:option> | ||
<f:option value="2" selected="${it.statusFilter==false}">${%Disabled jobs only}</f:option> | ||
</select> | ||
</f:entry> | ||
</j:jelly> |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.