aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohn Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>2020-08-04 18:15:09 +0200
committerJohn Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>2020-08-05 11:37:45 +0200
commitd98f7c1bd83fc03fd297ebeac6279ffe17316950 (patch)
tree4f1f261e1033f441a0deaa30f5aeb56cbbb51c43
parent71b62c4203a25beefeab73f73668919c813e3a50 (diff)
downloadnextcloud-server-d98f7c1bd83fc03fd297ebeac6279ffe17316950.tar.gz
nextcloud-server-d98f7c1bd83fc03fd297ebeac6279ffe17316950.zip
Make apps handle the order logic
Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
-rw-r--r--apps/comments/lib/Search/CommentsSearchProvider.php2
-rw-r--r--apps/dav/lib/Search/ContactsSearchProvider.php2
-rw-r--r--apps/dav/lib/Search/EventsSearchProvider.php2
-rw-r--r--apps/dav/lib/Search/TasksSearchProvider.php2
-rw-r--r--apps/files/lib/Search/FilesSearchProvider.php2
-rw-r--r--apps/settings/lib/Search/SectionSearch.php6
-rw-r--r--core/Controller/UnifiedSearchController.php8
-rw-r--r--core/src/services/UnifiedSearchService.js33
-rw-r--r--core/src/views/UnifiedSearch.vue13
-rw-r--r--lib/private/Search/SearchComposer.php8
-rw-r--r--lib/public/Search/IProvider.php4
11 files changed, 33 insertions, 49 deletions
diff --git a/apps/comments/lib/Search/CommentsSearchProvider.php b/apps/comments/lib/Search/CommentsSearchProvider.php
index 3d503cf5c51..bab10a58eeb 100644
--- a/apps/comments/lib/Search/CommentsSearchProvider.php
+++ b/apps/comments/lib/Search/CommentsSearchProvider.php
@@ -77,7 +77,7 @@ class CommentsSearchProvider implements IProvider {
/**
* @inheritDoc
*/
- public function getOrder(): int {
+ public function getOrder(string $from): int {
return 10;
}
diff --git a/apps/dav/lib/Search/ContactsSearchProvider.php b/apps/dav/lib/Search/ContactsSearchProvider.php
index d87f87d7591..82fa44a7a26 100644
--- a/apps/dav/lib/Search/ContactsSearchProvider.php
+++ b/apps/dav/lib/Search/ContactsSearchProvider.php
@@ -96,7 +96,7 @@ class ContactsSearchProvider implements IProvider {
/**
* @inheritDoc
*/
- public function getOrder(): int {
+ public function getOrder(string $from): int {
return 7;
}
diff --git a/apps/dav/lib/Search/EventsSearchProvider.php b/apps/dav/lib/Search/EventsSearchProvider.php
index 6d264ae482e..c9ce11a297d 100644
--- a/apps/dav/lib/Search/EventsSearchProvider.php
+++ b/apps/dav/lib/Search/EventsSearchProvider.php
@@ -82,7 +82,7 @@ class EventsSearchProvider extends ACalendarSearchProvider {
/**
* @inheritDoc
*/
- public function getOrder(): int {
+ public function getOrder(string $from): int {
return 10;
}
diff --git a/apps/dav/lib/Search/TasksSearchProvider.php b/apps/dav/lib/Search/TasksSearchProvider.php
index 9a0a87eb5ab..6c07cfd00f3 100644
--- a/apps/dav/lib/Search/TasksSearchProvider.php
+++ b/apps/dav/lib/Search/TasksSearchProvider.php
@@ -74,7 +74,7 @@ class TasksSearchProvider extends ACalendarSearchProvider {
/**
* @inheritDoc
*/
- public function getOrder(): int {
+ public function getOrder(string $from): int {
return 10;
}
diff --git a/apps/files/lib/Search/FilesSearchProvider.php b/apps/files/lib/Search/FilesSearchProvider.php
index d0a4bf56624..ce6f705f72c 100644
--- a/apps/files/lib/Search/FilesSearchProvider.php
+++ b/apps/files/lib/Search/FilesSearchProvider.php
@@ -77,7 +77,7 @@ class FilesSearchProvider implements IProvider {
/**
* @inheritDoc
*/
- public function getOrder(): int {
+ public function getOrder(string $from): int {
return 5;
}
diff --git a/apps/settings/lib/Search/SectionSearch.php b/apps/settings/lib/Search/SectionSearch.php
index 6e7b930046c..d949d93fb61 100644
--- a/apps/settings/lib/Search/SectionSearch.php
+++ b/apps/settings/lib/Search/SectionSearch.php
@@ -75,7 +75,11 @@ class SectionSearch implements IProvider {
/**
* @inheritDoc
*/
- public function getOrder(): int {
+ public function getOrder(string $from): int {
+ if (strpos($from, $this->urlGenerator->linkToRoute('settings.PersonalSettings.index') === 0)
+ || strpos($from, $this->urlGenerator->linkToRoute('settings.AdminSettings.index')) === 0) {
+ return -1;
+ }
return 20;
}
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)
@@ -44,29 +50,6 @@ export async function getTypes() {
}
/**
- * 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
*
* @param {string} type the type to search
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]
})
diff --git a/lib/private/Search/SearchComposer.php b/lib/private/Search/SearchComposer.php
index 7ba6296c9de..f86626909c4 100644
--- a/lib/private/Search/SearchComposer.php
+++ b/lib/private/Search/SearchComposer.php
@@ -109,17 +109,19 @@ class SearchComposer {
* Get a list of all provider IDs & Names for the consecutive calls to `search`
* Sort the list by the order property
*
+ * @param string $from the url the user is currently at
+ *
* @return array
*/
- public function getProviders(): array {
+ public function getProviders(string $from): array {
$this->loadLazyProviders();
$providers = array_values(
- array_map(function (IProvider $provider) {
+ array_map(function (IProvider $provider) use ($from) {
return [
'id' => $provider->getId(),
'name' => $provider->getName(),
- 'order' => $provider->getOrder()
+ 'order' => $provider->getOrder($from)
];
}, $this->providers)
);
diff --git a/lib/public/Search/IProvider.php b/lib/public/Search/IProvider.php
index 66db62c6829..5a6cfb3fd03 100644
--- a/lib/public/Search/IProvider.php
+++ b/lib/public/Search/IProvider.php
@@ -68,11 +68,13 @@ interface IProvider {
* Get the search provider order
* The lower the int, the higher it will be sorted (0 will be before 10)
*
+ * @param string $from the url the user is currently at. (e.g. /apps/files/?dir=/&fileid=982)
+ *
* @return int
*
* @since 20.0.0
*/
- public function getOrder(): int;
+ public function getOrder(string $from): int;
/**
* Find matching search entries in an app