diff --git a/Documentation/replace_macros.py b/Documentation/replace_macros.py index 6f906970dd..309a135b7f 100755 --- a/Documentation/replace_macros.py +++ b/Documentation/replace_macros.py @@ -89,7 +89,7 @@ SEARCH_BOX = """ + diff --git a/polygerrit-ui/app/elements/documentation/gr-documentation-search/gr-documentation-search.js b/polygerrit-ui/app/elements/documentation/gr-documentation-search/gr-documentation-search.js new file mode 100644 index 0000000000..f850b9d2bb --- /dev/null +++ b/polygerrit-ui/app/elements/documentation/gr-documentation-search/gr-documentation-search.js @@ -0,0 +1,81 @@ +/** + * @license + * Copyright (C) 2018 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +(function() { + 'use strict'; + + Polymer({ + is: 'gr-documentation-search', + + properties: { + /** + * URL params passed from the router. + */ + params: { + type: Object, + observer: '_paramsChanged', + }, + + _path: { + type: String, + readOnly: true, + value: '/Documentation', + }, + _documentationSearches: Array, + + _loading: { + type: Boolean, + value: true, + }, + _filter: { + type: String, + value: '', + }, + }, + + behaviors: [ + Gerrit.ListViewBehavior, + ], + + attached() { + this.dispatchEvent( + new CustomEvent('title-change', {title: 'Documentation Search'})); + }, + + _paramsChanged(params) { + this._loading = true; + this._filter = this.getFilterValue(params); + + return this._getDocumentationSearches(this._filter); + }, + + _getDocumentationSearches(filter) { + this._documentationSearches = []; + return this.$.restAPI.getDocumentationSearches(filter) + .then(searches => { + // Late response. + if (filter !== this._filter || !searches) { return; } + this._documentationSearches = searches; + this._loading = false; + }); + }, + + _computeSearchUrl(url) { + if (!url) { return ''; } + return this.getBaseUrl() + '/' + url; + }, + }); +})(); diff --git a/polygerrit-ui/app/elements/documentation/gr-documentation-search/gr-documentation-search_test.html b/polygerrit-ui/app/elements/documentation/gr-documentation-search/gr-documentation-search_test.html new file mode 100644 index 0000000000..84addb0da5 --- /dev/null +++ b/polygerrit-ui/app/elements/documentation/gr-documentation-search/gr-documentation-search_test.html @@ -0,0 +1,120 @@ + + + + +gr-documentation-search + + + + + + + + + + + + + + diff --git a/polygerrit-ui/app/elements/gr-app.html b/polygerrit-ui/app/elements/gr-app.html index 787a1c6a79..b34cd0a498 100644 --- a/polygerrit-ui/app/elements/gr-app.html +++ b/polygerrit-ui/app/elements/gr-app.html @@ -48,6 +48,7 @@ limitations under the License. + @@ -198,6 +199,11 @@ limitations under the License. +
[[_lastError.emoji]]
[[_lastError.text]]
diff --git a/polygerrit-ui/app/elements/gr-app.js b/polygerrit-ui/app/elements/gr-app.js index b0cc514d60..9c465f013b 100644 --- a/polygerrit-ui/app/elements/gr-app.js +++ b/polygerrit-ui/app/elements/gr-app.js @@ -72,6 +72,7 @@ _showCLAView: Boolean, _showEditorView: Boolean, _showPluginScreen: Boolean, + _showDocumentationSearch: Boolean, /** @type {?} */ _viewState: Object, /** @type {?} */ @@ -315,6 +316,8 @@ if (isPluginScreen) { this.async(() => this.set('_showPluginScreen', true), 1); } + this.set('_showDocumentationSearch', + view === Gerrit.Nav.View.DOCUMENTATION_SEARCH); if (this.params.justRegistered) { this.$.registrationOverlay.open(); this.$.registrationDialog.loadData().then(() => { diff --git a/polygerrit-ui/app/elements/shared/gr-rest-api-interface/gr-rest-api-interface.js b/polygerrit-ui/app/elements/shared/gr-rest-api-interface/gr-rest-api-interface.js index c0078e9d3c..2a1ad9eec1 100644 --- a/polygerrit-ui/app/elements/shared/gr-rest-api-interface/gr-rest-api-interface.js +++ b/polygerrit-ui/app/elements/shared/gr-rest-api-interface/gr-rest-api-interface.js @@ -2981,6 +2981,22 @@ }); }, + /** + * @param {string} filter + * @return {!Promise} + */ + getDocumentationSearches(filter) { + filter = filter.trim(); + const encodedFilter = encodeURIComponent(filter); + + // TODO(kaspern): Rename rest api from /projects/ to /repos/ once backend + // supports it. + return this._fetchSharedCacheURL({ + url: `/Documentation/?q=${encodedFilter}`, + anonymizedUrl: '/Documentation/?*', + }); + }, + getMergeable(changeNum) { return this._getChangeURLAndFetch({ changeNum, diff --git a/polygerrit-ui/app/test/index.html b/polygerrit-ui/app/test/index.html index 5b9ae1576e..10d3e0de57 100644 --- a/polygerrit-ui/app/test/index.html +++ b/polygerrit-ui/app/test/index.html @@ -120,6 +120,7 @@ limitations under the License. 'diff/gr-ranged-comment-layer/gr-ranged-comment-layer_test.html', 'diff/gr-selection-action-box/gr-selection-action-box_test.html', 'diff/gr-syntax-layer/gr-syntax-layer_test.html', + 'documentation/gr-documentation-search/gr-documentation-search_test.html', 'edit/gr-default-editor/gr-default-editor_test.html', 'edit/gr-edit-controls/gr-edit-controls_test.html', 'edit/gr-edit-file-controls/gr-edit-file-controls_test.html',