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

[JENKINS-19142] Prompt user whether to add the job to the current view #2529

Merged
merged 2 commits into from Sep 9, 2016
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
27 changes: 23 additions & 4 deletions core/src/main/java/hudson/model/ListView.java
Expand Up @@ -302,17 +302,36 @@ public Boolean getStatusFilter() {
return statusFilter;
}

/**
* Determines the initial state of the checkbox.
*
* @return true when the view is empty or already contains jobs specified by name.
*/
@Restricted(NoExternalUse.class) // called from newJob_button-bar view
@SuppressWarnings("unused") // called from newJob_button-bar view
public boolean isAddToCurrentView() {
synchronized(this) {
return !jobNames.isEmpty() || // There are already items in this view specified by name
(jobFilters.isEmpty() && includePattern == null) // No other way to include items is used
;
}
}

@Override
@RequirePOST
public Item doCreateItem(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException {
JSONObject form = req.getSubmittedForm();
boolean addToCurrentView = form.has("addToCurrentView") && form.getBoolean("addToCurrentView");
ItemGroup<? extends TopLevelItem> ig = getOwnerItemGroup();
if (ig instanceof ModifiableItemGroup) {
TopLevelItem item = ((ModifiableItemGroup<? extends TopLevelItem>)ig).doCreateItem(req, rsp);
if(item!=null) {
synchronized (this) {
jobNames.add(item.getRelativeNameFrom(getOwnerItemGroup()));
if (item!=null) {
if (addToCurrentView) {
synchronized (this) {
jobNames.add(item.getRelativeNameFrom(getOwnerItemGroup()));
}
owner.save();
}
owner.save();
}
return item;
}
Expand Down
@@ -0,0 +1,29 @@
<!--
The MIT License

Copyright (c) 2016, CloudBees

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" xmlns:i="jelly:fmt">
<button type="submit" id="ok-button">OK</button>
<f:checkbox title="${%Add to current view}" field="addToCurrentView" checked="${it.addToCurrentView}"/>
</j:jelly>
2 changes: 1 addition & 1 deletion core/src/main/resources/hudson/model/View/newJob.jelly
Expand Up @@ -66,7 +66,7 @@ THE SOFTWARE.

<div class="footer">
<div class="btn-decorator">
<button type="submit" id="ok-button">OK</button>
<st:include page="newJobButtonBar.jelly"/>
</div>
</div>
</form>
Expand Down
28 changes: 28 additions & 0 deletions core/src/main/resources/hudson/model/View/newJobButtonBar.jelly
@@ -0,0 +1,28 @@
<!--
The MIT License

Copyright (c) 2016, CloudBees

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" xmlns:i="jelly:fmt">
<button type="submit" id="ok-button">OK</button>
</j:jelly>
6 changes: 6 additions & 0 deletions war/src/main/js/widgets/add/addform.less
Expand Up @@ -32,6 +32,12 @@
text-align: center;
z-index: 10;

input[type=checkbox] {
width: auto;
min-width: auto;
margin-right: 0px;
}

button[type=submit] {
padding: 5px 20px;
background-color: rgb(204, 221, 238);
Expand Down