From d98f7c1bd83fc03fd297ebeac6279ffe17316950 Mon Sep 17 00:00:00 2001 From: "John Molakvoæ (skjnldsv)" Date: Tue, 4 Aug 2020 18:15:09 +0200 Subject: Make apps handle the order logic MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: John Molakvoæ (skjnldsv) --- core/Controller/UnifiedSearchController.php | 8 +++++-- core/src/services/UnifiedSearchService.js | 33 +++++++---------------------- core/src/views/UnifiedSearch.vue | 13 +----------- 3 files changed, 15 insertions(+), 39 deletions(-) (limited to 'core') diff --git a/core/Controller/UnifiedSearchController.php b/core/Controller/UnifiedSearchController.php index ecc5192ff31..4aaa1b9b067 100644 --- a/core/Controller/UnifiedSearchController.php +++ b/core/Controller/UnifiedSearchController.php @@ -54,10 +54,14 @@ class UnifiedSearchController extends Controller { /** * @NoAdminRequired * @NoCSRFRequired + * + * @param string $from the url the user is currently at + * + * @return JSONResponse */ - public function getProviders(): JSONResponse { + public function getProviders(string $from): JSONResponse { return new JSONResponse( - $this->composer->getProviders() + $this->composer->getProviders($from) ); } diff --git a/core/src/services/UnifiedSearchService.js b/core/src/services/UnifiedSearchService.js index ff9a4aebe2a..bc8cca19ce8 100644 --- a/core/src/services/UnifiedSearchService.js +++ b/core/src/services/UnifiedSearchService.js @@ -33,9 +33,15 @@ export const activeApp = loadState('core', 'active-app') */ export async function getTypes() { try { - const { data } = await axios.get(generateUrl('/search/providers')) + const { data } = await axios.get(generateUrl('/search/providers'), { + params: { + // Sending which location we're currently at + from: window.location.pathname.replace('/index.php', '') + window.location.search, + }, + }) if (Array.isArray(data) && data.length > 0) { - return sortProviders(data) + // Providers are sorted by the api based on their order key + return data } } catch (error) { console.error(error) @@ -43,29 +49,6 @@ export async function getTypes() { return [] } -/** - * Sort the providers by the current active app - * - * @param {Array} providers the providers list - * @returns {Array} - */ -export function sortProviders(providers) { - providers.sort((a, b) => { - if (a.id.startsWith(activeApp) && b.id.startsWith(activeApp)) { - return a.order - b.order - } - - if (a.id.startsWith(activeApp)) { - return -1 - } - if (b.id.startsWith(activeApp)) { - return 1 - } - return 0 - }) - return providers -} - /** * Get the list of available search providers * diff --git a/core/src/views/UnifiedSearch.vue b/core/src/views/UnifiedSearch.vue index d7ad58ae202..4e32bdbedd1 100644 --- a/core/src/views/UnifiedSearch.vue +++ b/core/src/views/UnifiedSearch.vue @@ -169,18 +169,7 @@ export default { orderedResults() { const ordered = {} Object.keys(this.results) - .sort((a, b) => { - if (a.startsWith(activeApp) && b.startsWith(activeApp)) { - return this.typesMap[a].order - this.typesMap[b].order - } - if (a.startsWith(activeApp)) { - return -1 - } - if (b.startsWith(activeApp)) { - return 1 - } - return 0 - }) + .sort((a, b) => this.typesMap[a].order - this.typesMap[b].order) .forEach(type => { ordered[type] = this.results[type] }) -- cgit v1.2.3