From 1a1b3e20e470a945dd9f5fab1d99174b10cbb141 Mon Sep 17 00:00:00 2001 From: "John Molakvoæ (skjnldsv)" Date: Mon, 3 Aug 2020 12:54:37 +0200 Subject: Fix unified search MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: John Molakvoæ (skjnldsv) Signed-off-by: npmbuildbot[bot] --- core/src/components/HeaderMenu.vue | 206 ++++++++++++++++++++ core/src/components/UnifiedSearch/SearchResult.vue | 211 +++++++++++++++++++++ .../src/components/login/PasswordLessLoginForm.vue | 2 +- core/src/service/WebAuthnAuthenticationService.js | 37 ---- core/src/services/UnifiedSearchService.js | 52 +++++ core/src/services/WebAuthnAuthenticationService.js | 37 ++++ core/src/unified-search.js | 47 +++++ core/src/views/UnifiedSearch.vue | 1 - 8 files changed, 554 insertions(+), 39 deletions(-) create mode 100644 core/src/components/HeaderMenu.vue create mode 100644 core/src/components/UnifiedSearch/SearchResult.vue delete mode 100644 core/src/service/WebAuthnAuthenticationService.js create mode 100644 core/src/services/UnifiedSearchService.js create mode 100644 core/src/services/WebAuthnAuthenticationService.js create mode 100644 core/src/unified-search.js (limited to 'core/src') diff --git a/core/src/components/HeaderMenu.vue b/core/src/components/HeaderMenu.vue new file mode 100644 index 00000000000..2cc5b79d6dd --- /dev/null +++ b/core/src/components/HeaderMenu.vue @@ -0,0 +1,206 @@ + + + + + + diff --git a/core/src/components/UnifiedSearch/SearchResult.vue b/core/src/components/UnifiedSearch/SearchResult.vue new file mode 100644 index 00000000000..832770c9abe --- /dev/null +++ b/core/src/components/UnifiedSearch/SearchResult.vue @@ -0,0 +1,211 @@ + + + + + diff --git a/core/src/components/login/PasswordLessLoginForm.vue b/core/src/components/login/PasswordLessLoginForm.vue index 0cd7cb81cfe..df774599f92 100644 --- a/core/src/components/login/PasswordLessLoginForm.vue +++ b/core/src/components/login/PasswordLessLoginForm.vue @@ -41,7 +41,7 @@ import { startAuthentication, finishAuthentication, -} from '../../service/WebAuthnAuthenticationService' +} from '../../services/WebAuthnAuthenticationService' import LoginButton from './LoginButton' class NoValidCredentials extends Error { diff --git a/core/src/service/WebAuthnAuthenticationService.js b/core/src/service/WebAuthnAuthenticationService.js deleted file mode 100644 index 91f19177066..00000000000 --- a/core/src/service/WebAuthnAuthenticationService.js +++ /dev/null @@ -1,37 +0,0 @@ -/** - * @copyright 2020, Roeland Jago Douma - * - * @author Roeland Jago Douma - * - * @license GNU AGPL version 3 or any later version - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -import Axios from '@nextcloud/axios' -import { generateUrl } from '@nextcloud/router' - -export function startAuthentication(loginName) { - const url = generateUrl('/login/webauthn/start') - - return Axios.post(url, { loginName }) - .then(resp => resp.data) -} - -export function finishAuthentication(data) { - const url = generateUrl('/login/webauthn/finish') - - return Axios.post(url, { data }) - .then(resp => resp.data) -} diff --git a/core/src/services/UnifiedSearchService.js b/core/src/services/UnifiedSearchService.js new file mode 100644 index 00000000000..2e63f19767d --- /dev/null +++ b/core/src/services/UnifiedSearchService.js @@ -0,0 +1,52 @@ +/** + * @copyright 2020, John Molakvoæ + * + * @author John Molakvoæ + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +import { generateUrl } from '@nextcloud/router' +import { loadState } from '@nextcloud/initial-state' +import axios from '@nextcloud/axios' + +export const defaultLimit = loadState('unified-search', 'limit-default') + +/** + * Get the list of available search providers + */ +export async function getTypes() { + try { + const { data } = await axios.get(generateUrl('/search/providers')) + if (Array.isArray(data) && data.length > 0) { + return data + } + } catch (error) { + console.error(error) + } + return [] +} + +/** + * Get the list of available search providers + * + * @param {string} type the type to search + * @param {string} query the search + * @returns {Promise} + */ +export function search(type, query) { + return axios.get(generateUrl(`/search/providers/${type}/search?term=${query}`)) +} diff --git a/core/src/services/WebAuthnAuthenticationService.js b/core/src/services/WebAuthnAuthenticationService.js new file mode 100644 index 00000000000..91f19177066 --- /dev/null +++ b/core/src/services/WebAuthnAuthenticationService.js @@ -0,0 +1,37 @@ +/** + * @copyright 2020, Roeland Jago Douma + * + * @author Roeland Jago Douma + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +import Axios from '@nextcloud/axios' +import { generateUrl } from '@nextcloud/router' + +export function startAuthentication(loginName) { + const url = generateUrl('/login/webauthn/start') + + return Axios.post(url, { loginName }) + .then(resp => resp.data) +} + +export function finishAuthentication(data) { + const url = generateUrl('/login/webauthn/finish') + + return Axios.post(url, { data }) + .then(resp => resp.data) +} diff --git a/core/src/unified-search.js b/core/src/unified-search.js new file mode 100644 index 00000000000..ba975d78564 --- /dev/null +++ b/core/src/unified-search.js @@ -0,0 +1,47 @@ +/** + * @copyright Copyright (c) 2020 John Molakvoæ + * + * @author John Molakvoæ + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +import { getRequestToken } from '@nextcloud/auth' +import { generateFilePath } from '@nextcloud/router' +import { translate as t, translatePlural as n } from '@nextcloud/l10n' +import Vue from 'vue' + +import UnifiedSearch from './views/UnifiedSearch.vue' + +// eslint-disable-next-line camelcase +__webpack_nonce__ = btoa(getRequestToken()) + +// eslint-disable-next-line camelcase +__webpack_public_path__ = generateFilePath('core', '', 'js/') + +Vue.mixin({ + methods: { + t, + n, + }, +}) + +export default new Vue({ + el: '#unified-search', + // eslint-disable-next-line vue/match-component-file-name + name: 'UnifiedSearchRoot', + render: h => h(UnifiedSearch), +}) diff --git a/core/src/views/UnifiedSearch.vue b/core/src/views/UnifiedSearch.vue index 099ed7c325f..4535e1fde5a 100644 --- a/core/src/views/UnifiedSearch.vue +++ b/core/src/views/UnifiedSearch.vue @@ -451,7 +451,6 @@ export default { const entry = event.target const results = this.getResultsList() const index = [...results].findIndex(search => search === entry) - console.info(entry, index) if (index > -1) { // let's not use focusIndex as the entry is already focused this.focused = index -- cgit v1.2.3