Skip to content

Commit

Permalink
Initial commit, working search overlay
Browse files Browse the repository at this point in the history
  • Loading branch information
janfaracik committed Mar 24, 2022
1 parent e3f8bc0 commit b330661
Show file tree
Hide file tree
Showing 18 changed files with 722 additions and 33 deletions.
5 changes: 5 additions & 0 deletions core/src/main/java/hudson/AboutJenkins.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ public String getDescription() {
return Messages.AboutJenkins_Description();
}

// @Override
// public String getSearchDescription() {
// return "Version " + Functions.getVersion();
// }

@Restricted(NoExternalUse.class)
public URL getLicensesURL() {
return AboutJenkins.class.getResource("/META-INF/licenses.xml");
Expand Down
6 changes: 6 additions & 0 deletions core/src/main/java/hudson/model/AbstractItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import hudson.model.queue.SubTask;
import hudson.model.queue.Tasks;
import hudson.model.queue.WorkUnit;
import hudson.search.SearchItemCategory;
import hudson.security.ACL;
import hudson.security.ACLContext;
import hudson.security.AccessControlled;
Expand Down Expand Up @@ -587,6 +588,11 @@ public String getSearchUrl() {
return getShortUrl();
}

@Override
public String getSearchItemCategory() {
return SearchItemCategory.JOBS;
}

@Override
@Exported(visibility = 999, name = "url")
public final String getAbsoluteUrl() {
Expand Down
1 change: 1 addition & 0 deletions core/src/main/java/hudson/model/Action.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

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}
Expand Down
7 changes: 7 additions & 0 deletions core/src/main/java/hudson/model/Actionable.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@
import java.util.concurrent.CopyOnWriteArrayList;
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;
import org.kohsuke.stapler.StaplerRequest;
Expand Down Expand Up @@ -353,4 +356,8 @@ public Object getDynamic(String token, StaplerRequest req, StaplerResponse rsp)
}

private static final Logger LOGGER = Logger.getLogger(Actionable.class.getName());

public String getSearchItemCategory() {
return SearchItemCategory.OTHER;
}
}
1 change: 1 addition & 0 deletions core/src/main/java/hudson/model/ManagementLink.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
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;
Expand Down
27 changes: 25 additions & 2 deletions core/src/main/java/hudson/search/Search.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import jenkins.model.Jenkins;
import jenkins.util.MemoryReductionUtil;
import jenkins.util.SystemProperties;
import org.jenkins.ui.icon.Icon;
import org.kohsuke.accmod.Restricted;
import org.kohsuke.accmod.restrictions.NoExternalUse;
import org.kohsuke.stapler.Ancestor;
Expand Down Expand Up @@ -123,8 +124,14 @@ public void doSuggestOpenSearch(StaplerRequest req, StaplerResponse rsp, @QueryP
*/
public void doSuggest(StaplerRequest req, StaplerResponse rsp, @QueryParameter String query) throws IOException, ServletException {
Result r = new Result();
for (SuggestedItem item : getSuggestions(req, query))
r.suggestions.add(new Item(item.getPath()));
for (SuggestedItem item : getSuggestions(req, query)) {
r.suggestions.add(new Item(
item.getPath(),
item.item.getSearchDescription(),
item.item.getSearchUrl(),
item.item.getSearchItemIcon(),
item.item.getSearchItemCategory()));
}

rsp.serveExposedBean(req, r, Flavor.JSON);
}
Expand Down Expand Up @@ -195,13 +202,29 @@ public static class Result {

@ExportedBean(defaultVisibility = 999)
public static class Item {
@Exported
public String url;
@Exported
@SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD", justification = "read by Stapler")
public String name;
@Exported
public String description;
@Exported
public Icon icon;
@Exported
public String category;

public Item(String name) {
this.name = name;
}

public Item(String name, String description, String url, Icon icon, String category) {
this.name = name;
this.description = description;
this.url = url;
this.icon = icon;
this.category = category;
}
}

private enum Mode {
Expand Down
16 changes: 16 additions & 0 deletions core/src/main/java/hudson/search/SearchItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
package hudson.search;

import hudson.model.Build;
import org.jenkins.ui.icon.Icon;

/**
* Represents an item reachable from {@link SearchIndex}.
Expand Down Expand Up @@ -54,6 +55,21 @@ public interface SearchItem {

String getSearchUrl();

default String getSearchDescription() {
return null;
}

// TODO
default String getSearchItemCategory() {
return SearchItemCategory.OTHER;
}

// TODO
// Overrides the icon from search item category
default Icon getSearchItemIcon() {
return null;
}

/**
* Returns the {@link SearchIndex} to further search sub items inside this item.
*
Expand Down
13 changes: 13 additions & 0 deletions core/src/main/java/hudson/search/SearchItemCategory.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
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";
}
10 changes: 5 additions & 5 deletions core/src/main/java/jenkins/model/Jenkins.java
Original file line number Diff line number Diff line change
Expand Up @@ -2377,11 +2377,11 @@ public String getSearchUrl() {
@Override
public SearchIndexBuilder makeSearchIndex() {
SearchIndexBuilder builder = super.makeSearchIndex();
if (hasPermission(ADMINISTER)) {
builder.add("configure", "config", "configure")
.add("manage")
.add("log");
}
// if (hasPermission(ADMINISTER)) {
// builder.add("configure", "config", "configure")
// .add("manage")
// .add("log");
// }
builder.add(new CollectionSearchIndex<TopLevelItem>() {
@Override
protected SearchItem get(String key) { return getItemByFullName(key, TopLevelItem.class); }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?jelly escape-by-default='true'?>
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:i="jelly:fmt" xmlns:x="jelly:xml">
<header id="page-header" class="page-header">
<j:set var="searchURL" value="${h.searchURL}"/>
<header id="page-header" class="page-header" data-search-url="${searchURL + 'suggest'}" data-search-help-url="${searchHelpUrl}">
<div class="page-header__brand">
<div class="logo">
<a id="jenkins-home-link" href="${rootURL}/">
Expand All @@ -17,29 +18,11 @@
</a>
</div>

<div class="searchbox hidden-xs">
<!-- search box -->
<j:set var="searchURL" value="${h.searchURL}"/>
<form action="${searchURL}" method="get" style="position:relative;" class="no-json" name="search" role="search">
<!-- this div is used to calculate the width of the text box -->
<div id="search-box-sizer"/>
<div id="searchform">
<input name="q" placeholder="${searchPlaceholder}" id="search-box" class="main-search__input" value="${request.getParameter('q')}" role="searchbox" />

<span class="main-search__icon-leading">
<l:icon src="symbol-search"/>
</span>
<a href="${searchHelpUrl}" class="main-search__icon-trailing">
<l:icon src="symbol-help-circle"/>
</a>

<div id="search-box-completion" />
<script>createSearchBox("${searchURL}");</script>
</div>
</form>
</div>

<div class="login page-header__hyperlinks">
<button id="button-spotlight" tooltip="${%Search}">
<l:icon src="symbol-search" />
</button>

<div id="visible-am-insertion" class="page-header__am-wrapper" />
<div id="visible-sec-am-insertion" class="page-header__am-wrapper" />

Expand Down
10 changes: 7 additions & 3 deletions core/src/main/resources/lib/layout/layout.jelly
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ THE SOFTWARE.
<x:doctype name="html" />
<html class="${h.isUiRefreshEnabled() ? 'ui-refresh' : ''}">
<head data-rooturl="${rootURL}" data-resurl="${resURL}" data-imagesurl="${imagesURL}" resURL="${resURL}"
data-extensions-available="${extensionsAvailable}"
data-crumb-header="${h.getCrumbRequestField()}" data-crumb-value="${h.getCrumb(request)}"
data-extensions-available="${extensionsAvailable}"
data-crumb-header="${h.getCrumbRequestField()}" data-crumb-value="${h.getCrumb(request)}"
data-unit-test="${h.isUnitTest}">
${h.checkPermission(it,permission)}
${h.checkAnyPermission(it, permissions)}
Expand Down Expand Up @@ -150,7 +150,7 @@ THE SOFTWARE.
<!--l:yui module="editor" suffix="-beta" /-->

<script src="${resURL}/scripts/polyfills.js" type="text/javascript" />

<script src="${resURL}/scripts/hudson-behavior.js" type="text/javascript"></script>
<script src="${resURL}/scripts/sortable.js" type="text/javascript"/>

Expand Down Expand Up @@ -186,6 +186,8 @@ THE SOFTWARE.
</head>
<body id="jenkins" class="yui-skin-sam ${layoutType} jenkins-${h.version}" data-version="${h.version}" data-model-type="${it.class.name}">

<l:search />

<j:if test="${layoutType!='full-screen'}">
<!-- for accessibility, skip the entire navigation bar and etc and go straight to the head of the content -->
<a href="#skip2content" class="skiplink">Skip to content</a>
Expand Down Expand Up @@ -253,6 +255,8 @@ THE SOFTWARE.
</footer>
</j:if>

<script src="${resURL}/jsbundles/search.js" type="text/javascript"/>

<!-- SVG sprite polyfill for IE 11.
Loaded at the end in order to not make modern browsers wait for it. This causes a flash-of-no-icons on IE 11 -->
<script src="${resURL}/scripts/svgxuse.min.js" type="text/javascript" async="true" />
Expand Down
60 changes: 60 additions & 0 deletions core/src/main/resources/lib/layout/search.jelly
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<!--
The MIT License
Copyright (c) 2022, Jenkins contributors
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:s="jelly:stapler" xmlns:l="/lib/layout">
<s:documentation>
The command center overlay for Jenkins
</s:documentation>

<div id="command-center-i18n" class="i18n"
data-no-results-for="${%No results for}"
data-help="${%Help}"
data-get-help="${%Get help using Jenkins search}"
/>

<div id="command-center-backdrop" class="jenkins-command-center__backdrop" />

<div id="command-center" class="jenkins-command-center__wrapper">
<div class="jenkins-command-center">
<div class="jenkins-command-center__search">
<div class="icon">
<l:icon src="symbol-search" />
</div>
<input id="command-bar" placeholder="${%Search}" type="search" autocomplete="off" autocorrect="off"
autocapitalize="off" spellcheck="false" />
<div class="keyboard-shortcuts">
<span id="command-center-shortcut-modifier" class="shortcut">⌘</span>
<l:icon src="symbol-add" />
<span class="shortcut">K</span>
</div>
</div>
<div id="search-results-container" class="jenkins-command-center__results-container">
<div id="search-results" class="jenkins-command-center__results" />
</div>
</div>
</div>

<script src="${resURL}/jsbundles/search.js" type="text/javascript" />
</j:jelly>
3 changes: 3 additions & 0 deletions war/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,13 @@
"@babel/preset-env": "^7.7.4",
"babel-loader": "^8.0.6",
"bootstrap": "3.3.5",
"core-js": "^3.19.0",
"hotkeys-js": "^3.8.7",
"jenkins-js-modules": "^1.5.0",
"jquery": "3.5.1",
"lodash": "^4.17.20",
"raf": "^3.4.1",
"regenerator-runtime": "^0.13.9",
"sortablejs": "^1.13.0",
"window-handle": "^1.0.0"
},
Expand Down
Loading

0 comments on commit b330661

Please sign in to comment.