From 9ef136f7de51e8426e247c3db4cefb149d4c11ac Mon Sep 17 00:00:00 2001 From: Jan Faracik <43062514+janfaracik@users.noreply.github.com> Date: Wed, 25 May 2022 10:19:58 +0100 Subject: [PATCH] Get symbols working --- .../main/java/hudson/model/AbstractItem.java | 2 +- core/src/main/java/hudson/model/Action.java | 1 - .../main/java/hudson/model/Actionable.java | 3 +- .../java/hudson/model/ManagementLink.java | 1 - core/src/main/java/hudson/search/Search.java | 8 +- .../main/java/hudson/search/SearchItem.java | 6 +- .../hudson/search/SearchItemCategory.java | 37 ++++-- core/src/main/java/jenkins/Symbols.java | 107 ++++++++++++++++++ war/src/main/js/api/symbols.js | 7 ++ .../command-palette/command-palette.js | 26 +++-- .../js/components/command-palette/models.js | 11 +- .../js/components/command-palette/symbols.js | 1 - 12 files changed, 180 insertions(+), 30 deletions(-) create mode 100644 core/src/main/java/jenkins/Symbols.java create mode 100644 war/src/main/js/api/symbols.js diff --git a/core/src/main/java/hudson/model/AbstractItem.java b/core/src/main/java/hudson/model/AbstractItem.java index 6a4eed7ee31a..9148ecee581e 100644 --- a/core/src/main/java/hudson/model/AbstractItem.java +++ b/core/src/main/java/hudson/model/AbstractItem.java @@ -589,7 +589,7 @@ public String getSearchUrl() { } @Override - public String getSearchItemCategory() { + public SearchItemCategory getSearchItemCategory() { return SearchItemCategory.JOBS; } diff --git a/core/src/main/java/hudson/model/Action.java b/core/src/main/java/hudson/model/Action.java index bddd094a7422..17b21a2ca7c9 100644 --- a/core/src/main/java/hudson/model/Action.java +++ b/core/src/main/java/hudson/model/Action.java @@ -26,7 +26,6 @@ import edu.umd.cs.findbugs.annotations.CheckForNull; import hudson.Functions; -import hudson.search.SearchItemCategory; /** * Object that contributes additional information, behaviors, and UIs to {@link ModelObject} diff --git a/core/src/main/java/hudson/model/Actionable.java b/core/src/main/java/hudson/model/Actionable.java index b0f0479dbb61..33cb03037202 100644 --- a/core/src/main/java/hudson/model/Actionable.java +++ b/core/src/main/java/hudson/model/Actionable.java @@ -35,7 +35,6 @@ import java.util.logging.Level; import java.util.logging.Logger; -import hudson.search.SearchItem; import hudson.search.SearchItemCategory; import jenkins.model.ModelObjectWithContextMenu; import jenkins.model.TransientActionFactory; @@ -357,7 +356,7 @@ public Object getDynamic(String token, StaplerRequest req, StaplerResponse rsp) private static final Logger LOGGER = Logger.getLogger(Actionable.class.getName()); - public String getSearchItemCategory() { + public SearchItemCategory getSearchItemCategory() { return SearchItemCategory.OTHER; } } diff --git a/core/src/main/java/hudson/model/ManagementLink.java b/core/src/main/java/hudson/model/ManagementLink.java index 4b567953a988..666c2fd12539 100644 --- a/core/src/main/java/hudson/model/ManagementLink.java +++ b/core/src/main/java/hudson/model/ManagementLink.java @@ -30,7 +30,6 @@ import hudson.ExtensionList; import hudson.ExtensionListView; import hudson.ExtensionPoint; -import hudson.search.SearchItemCategory; import hudson.security.Permission; import java.util.List; import java.util.logging.Level; diff --git a/core/src/main/java/hudson/search/Search.java b/core/src/main/java/hudson/search/Search.java index 32322f6e0e7a..e1e4036ae0a3 100644 --- a/core/src/main/java/hudson/search/Search.java +++ b/core/src/main/java/hudson/search/Search.java @@ -129,8 +129,8 @@ public void doSuggest(StaplerRequest req, StaplerResponse rsp, @QueryParameter S item.getPath(), item.item.getSearchDescription(), item.item.getSearchUrl(), - item.item.getSearchItemIcon(), - item.item.getSearchItemCategory())); + item.item.getSearchItemIcon().getClassSpec(), + item.item.getSearchItemCategory().getName())); } rsp.serveExposedBean(req, r, Flavor.JSON); @@ -210,7 +210,7 @@ public static class Item { @Exported public String description; @Exported - public Icon icon; + public String icon; @Exported public String category; @@ -218,7 +218,7 @@ public Item(String name) { this.name = name; } - public Item(String name, String description, String url, Icon icon, String category) { + public Item(String name, String description, String url, String icon, String category) { this.name = name; this.description = description; this.url = url; diff --git a/core/src/main/java/hudson/search/SearchItem.java b/core/src/main/java/hudson/search/SearchItem.java index e541e658c52a..cce6553f64bb 100644 --- a/core/src/main/java/hudson/search/SearchItem.java +++ b/core/src/main/java/hudson/search/SearchItem.java @@ -60,13 +60,17 @@ default String getSearchDescription() { } // TODO - default String getSearchItemCategory() { + default SearchItemCategory getSearchItemCategory() { return SearchItemCategory.OTHER; } // TODO // Overrides the icon from search item category default Icon getSearchItemIcon() { + if (getSearchItemCategory() != null) { + return getSearchItemCategory().getIcon(); + } + return null; } diff --git a/core/src/main/java/hudson/search/SearchItemCategory.java b/core/src/main/java/hudson/search/SearchItemCategory.java index 6e63571638bf..1a1950b89518 100644 --- a/core/src/main/java/hudson/search/SearchItemCategory.java +++ b/core/src/main/java/hudson/search/SearchItemCategory.java @@ -1,13 +1,30 @@ package hudson.search; -public class SearchItemCategory { - public final static String PAGES = "Pages"; - public final static String SETTINGS = "Settings"; - public final static String VIEWS = "Views"; - public final static String JOBS = "Jobs"; - public final static String BUILDS = "Builds"; - public final static String PEOPLE = "People"; - public final static String NODES = "Nodes"; - public final static String IN_PAGE_ACTIONS = "In-page action"; - public final static String OTHER = "Other"; +import org.jenkins.ui.icon.Icon; + +public enum SearchItemCategory { + PAGES("Pages", "symbol-details"), + SETTINGS("Settings", "symbol-settings"), + VIEWS("Views", "symbol-settings"), + JOBS("Jobs", "symbol-reload"), + BUILDS("Builds", "symbol-settings"), + PEOPLE("People", "symbol-person"), + NODES("Nodes", "symbol-computer"), + OTHER("Other", "symbol-cube"); + + private final String name; + private final Icon icon; + + SearchItemCategory(String name, String iconSource) { + this.name = name; + this.icon = new Icon(iconSource, ""); + } + + public String getName() { + return name; + } + + public Icon getIcon() { + return icon; + } } diff --git a/core/src/main/java/jenkins/Symbols.java b/core/src/main/java/jenkins/Symbols.java new file mode 100644 index 000000000000..8e0c811f34b1 --- /dev/null +++ b/core/src/main/java/jenkins/Symbols.java @@ -0,0 +1,107 @@ +/* + * The MIT License + * + * Copyright (c) 2015, CloudBees, Inc. + * + * 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; + +import hudson.Extension; +import hudson.model.RootAction; +import hudson.util.HttpResponses; +import net.sf.json.JSONObject; +import org.jenkins.ui.icon.IconSet; +import org.kohsuke.accmod.Restricted; +import org.kohsuke.accmod.restrictions.NoExternalUse; +import org.kohsuke.stapler.HttpResponse; +import org.kohsuke.stapler.StaplerRequest; + +import java.util.Locale; + +import static hudson.Functions.extractPluginNameFromIconSrc; + +/** + * Internationalization REST (ish) API. + * @author tom.fennelly@gmail.com + * @since 2.0 + */ +@Extension +@Restricted(NoExternalUse.class) +public class Symbols implements RootAction { + + @Override + public String getIconFileName() { + return null; + } + + @Override + public String getDisplayName() { + return null; + } + + @Override + public String getUrlName() { + return "symbols"; + } + + /** + * Get a localised resource bundle. + *
+ * URL: {@code i18n/resourceBundle}. + *
+ * Parameters: + *