-
-
Notifications
You must be signed in to change notification settings - Fork 8.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
Appearance
system configuration page (#8403)
* Add `Appearance` system configuration page * Use one-column layout * Add developer guidance
- Loading branch information
Showing
5 changed files
with
230 additions
and
0 deletions.
There are no files selected for viewing
53 changes: 53 additions & 0 deletions
53
core/src/main/java/jenkins/appearance/AppearanceCategory.java
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,53 @@ | ||
/* | ||
* The MIT License | ||
* | ||
* Copyright (c) 2023, Tim Jacomb | ||
* | ||
* 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 jenkins.appearance; | ||
|
||
import hudson.Extension; | ||
import jenkins.model.GlobalConfigurationCategory; | ||
|
||
/** | ||
* <p>Global configuration of appearance configuration.</p> | ||
* | ||
* <p>This should be used for Plugins that contribute to the look and feel of Jenkins. | ||
* Theming, header and footer changes, information density are all good examples. | ||
* API plugins for UI components that are used by other plugins also fit into that, e.g. source code display.</p> | ||
* | ||
* <p>Configuration specific to a single plugin that is not related to the overall look and feel of Jenkins may not belong here.</p> | ||
* | ||
* <p>If a plugin has a single global configuration it should separate appearance and general configuration to different classes.</p> | ||
* | ||
*/ | ||
@Extension | ||
public class AppearanceCategory extends GlobalConfigurationCategory { | ||
@Override | ||
public String getShortDescription() { | ||
return Messages.AppearanceCategory_DisplayName(); | ||
} | ||
|
||
@Override | ||
public String getDisplayName() { | ||
return Messages.AppearanceCategory_Description(); | ||
} | ||
} |
110 changes: 110 additions & 0 deletions
110
core/src/main/java/jenkins/appearance/AppearanceGlobalConfiguration.java
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,110 @@ | ||
/* | ||
* The MIT License | ||
* | ||
* Copyright (c) 2023, Tim Jacomb | ||
* | ||
* 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 jenkins.appearance; | ||
|
||
import edu.umd.cs.findbugs.annotations.NonNull; | ||
import hudson.Extension; | ||
import hudson.Functions; | ||
import hudson.model.Descriptor; | ||
import hudson.model.ManagementLink; | ||
import hudson.util.FormApply; | ||
import java.io.IOException; | ||
import java.util.function.Predicate; | ||
import java.util.logging.Level; | ||
import java.util.logging.Logger; | ||
import javax.servlet.ServletException; | ||
import jenkins.model.Jenkins; | ||
import net.sf.json.JSONObject; | ||
import org.kohsuke.accmod.Restricted; | ||
import org.kohsuke.accmod.restrictions.NoExternalUse; | ||
import org.kohsuke.stapler.StaplerRequest; | ||
import org.kohsuke.stapler.StaplerResponse; | ||
import org.kohsuke.stapler.verb.POST; | ||
|
||
@Extension | ||
public class AppearanceGlobalConfiguration extends ManagementLink { | ||
|
||
private static final Logger LOGGER = Logger.getLogger(AppearanceGlobalConfiguration.class.getName()); | ||
|
||
@Restricted(NoExternalUse.class) | ||
public static final Predicate<Descriptor> FILTER = input -> input.getCategory() instanceof AppearanceCategory; | ||
|
||
@Override | ||
public String getIconFileName() { | ||
if (Functions.getSortedDescriptorsForGlobalConfigByDescriptor(FILTER).isEmpty()) { | ||
return null; | ||
} | ||
|
||
return "symbol-brush-outline"; | ||
} | ||
|
||
@Override | ||
public String getDisplayName() { | ||
return Messages.AppearanceGlobalConfiguration_DisplayName(); | ||
} | ||
|
||
@Override | ||
public String getDescription() { | ||
return Messages.AppearanceGlobalConfiguration_Description(); | ||
} | ||
|
||
@Override | ||
public String getUrlName() { | ||
return "appearance"; | ||
} | ||
|
||
@NonNull | ||
@Override | ||
public Category getCategory() { | ||
return Category.CONFIGURATION; | ||
} | ||
|
||
@POST | ||
public synchronized void doConfigure(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException, Descriptor.FormException { | ||
boolean result = configure(req, req.getSubmittedForm()); | ||
LOGGER.log(Level.FINE, "appearance saved: " + result); | ||
FormApply.success(req.getContextPath() + "/manage").generateResponse(req, rsp, null); | ||
} | ||
|
||
private boolean configure(StaplerRequest req, JSONObject json) throws Descriptor.FormException, IOException { | ||
Jenkins j = Jenkins.get(); | ||
j.checkPermission(Jenkins.MANAGE); | ||
|
||
boolean result = true; | ||
for (Descriptor<?> d : Functions.getSortedDescriptorsForGlobalConfigByDescriptor(FILTER)) { | ||
result &= configureDescriptor(req, json, d); | ||
} | ||
j.save(); | ||
|
||
return result; | ||
} | ||
|
||
private boolean configureDescriptor(StaplerRequest req, JSONObject json, Descriptor<?> d) throws Descriptor.FormException { | ||
String name = d.getJsonSafeClassName(); | ||
JSONObject js = json.has(name) ? json.getJSONObject(name) : new JSONObject(); // if it doesn't have the property, the method returns invalid null object. | ||
json.putAll(js); | ||
return d.configure(req, js); | ||
} | ||
} |
61 changes: 61 additions & 0 deletions
61
core/src/main/resources/jenkins/appearance/AppearanceGlobalConfiguration/index.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,61 @@ | ||
<!-- | ||
The MIT License | ||
Copyright (c) 2023, Tim Jacomb | ||
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:l="/lib/layout" xmlns:f="/lib/form"> | ||
<l:layout title="${%Appearance}" permissions="${app.MANAGE_AND_SYSTEM_READ}" type="one-column"> | ||
<j:set var="readOnlyMode" value="${!app.hasPermission(app.MANAGE)}"/> | ||
<l:main-panel> | ||
<l:app-bar title="${%Appearance}"/> | ||
|
||
<div class="behavior-loading"> | ||
<l:spinner text="${%Loading}"/> | ||
</div> | ||
|
||
<f:form method="post" name="config" action="configure" class="jenkins-form"> | ||
<j:set var="instance" value="${it}" /> | ||
<j:set var="descriptor" value="${instance.descriptor}" /> | ||
|
||
<j:forEach var="descriptor" items="${h.getSortedDescriptorsForGlobalConfigByDescriptor(it.FILTER)}"> | ||
<j:set var="instance" value="${descriptor}" /> | ||
<f:rowSet name="${descriptor.jsonSafeClassName}"> | ||
<st:include page="${descriptor.globalConfigPage}" from="${descriptor}" /> | ||
</f:rowSet> | ||
</j:forEach> | ||
|
||
<l:hasAdministerOrManage> | ||
<f:bottomButtonBar> | ||
<f:submit value="${%Save}" /> | ||
<f:apply /> | ||
</f:bottomButtonBar> | ||
</l:hasAdministerOrManage> | ||
</f:form> | ||
|
||
<l:hasAdministerOrManage> | ||
<st:adjunct includes="lib.form.confirm" /> | ||
</l:hasAdministerOrManage> | ||
|
||
</l:main-panel> | ||
</l:layout> | ||
</j:jelly> |
5 changes: 5 additions & 0 deletions
5
core/src/main/resources/jenkins/appearance/Messages.properties
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,5 @@ | ||
AppearanceGlobalConfiguration.DisplayName=Appearance | ||
AppearanceGlobalConfiguration.Description=Configure the look and feel of Jenkins | ||
|
||
AppearanceCategory.DisplayName=Appearance | ||
AppearanceCategory.Description=Configure the look and feel of Jenkins |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.