Make apps handle the order logic
Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
This commit is contained in:
parent
71b62c4203
commit
d98f7c1bd8
|
@ -77,7 +77,7 @@ class CommentsSearchProvider implements IProvider {
|
||||||
/**
|
/**
|
||||||
* @inheritDoc
|
* @inheritDoc
|
||||||
*/
|
*/
|
||||||
public function getOrder(): int {
|
public function getOrder(string $from): int {
|
||||||
return 10;
|
return 10;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -96,7 +96,7 @@ class ContactsSearchProvider implements IProvider {
|
||||||
/**
|
/**
|
||||||
* @inheritDoc
|
* @inheritDoc
|
||||||
*/
|
*/
|
||||||
public function getOrder(): int {
|
public function getOrder(string $from): int {
|
||||||
return 7;
|
return 7;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -82,7 +82,7 @@ class EventsSearchProvider extends ACalendarSearchProvider {
|
||||||
/**
|
/**
|
||||||
* @inheritDoc
|
* @inheritDoc
|
||||||
*/
|
*/
|
||||||
public function getOrder(): int {
|
public function getOrder(string $from): int {
|
||||||
return 10;
|
return 10;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -74,7 +74,7 @@ class TasksSearchProvider extends ACalendarSearchProvider {
|
||||||
/**
|
/**
|
||||||
* @inheritDoc
|
* @inheritDoc
|
||||||
*/
|
*/
|
||||||
public function getOrder(): int {
|
public function getOrder(string $from): int {
|
||||||
return 10;
|
return 10;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -77,7 +77,7 @@ class FilesSearchProvider implements IProvider {
|
||||||
/**
|
/**
|
||||||
* @inheritDoc
|
* @inheritDoc
|
||||||
*/
|
*/
|
||||||
public function getOrder(): int {
|
public function getOrder(string $from): int {
|
||||||
return 5;
|
return 5;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -75,7 +75,11 @@ class SectionSearch implements IProvider {
|
||||||
/**
|
/**
|
||||||
* @inheritDoc
|
* @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;
|
return 20;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -54,10 +54,14 @@ class UnifiedSearchController extends Controller {
|
||||||
/**
|
/**
|
||||||
* @NoAdminRequired
|
* @NoAdminRequired
|
||||||
* @NoCSRFRequired
|
* @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(
|
return new JSONResponse(
|
||||||
$this->composer->getProviders()
|
$this->composer->getProviders($from)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -33,9 +33,15 @@ export const activeApp = loadState('core', 'active-app')
|
||||||
*/
|
*/
|
||||||
export async function getTypes() {
|
export async function getTypes() {
|
||||||
try {
|
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) {
|
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) {
|
} catch (error) {
|
||||||
console.error(error)
|
console.error(error)
|
||||||
|
@ -43,29 +49,6 @@ export async function getTypes() {
|
||||||
return []
|
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
|
* Get the list of available search providers
|
||||||
*
|
*
|
||||||
|
|
|
@ -169,18 +169,7 @@ export default {
|
||||||
orderedResults() {
|
orderedResults() {
|
||||||
const ordered = {}
|
const ordered = {}
|
||||||
Object.keys(this.results)
|
Object.keys(this.results)
|
||||||
.sort((a, b) => {
|
.sort((a, b) => this.typesMap[a].order - this.typesMap[b].order)
|
||||||
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
|
|
||||||
})
|
|
||||||
.forEach(type => {
|
.forEach(type => {
|
||||||
ordered[type] = this.results[type]
|
ordered[type] = this.results[type]
|
||||||
})
|
})
|
||||||
|
|
|
@ -109,17 +109,19 @@ class SearchComposer {
|
||||||
* Get a list of all provider IDs & Names for the consecutive calls to `search`
|
* Get a list of all provider IDs & Names for the consecutive calls to `search`
|
||||||
* Sort the list by the order property
|
* Sort the list by the order property
|
||||||
*
|
*
|
||||||
|
* @param string $from the url the user is currently at
|
||||||
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function getProviders(): array {
|
public function getProviders(string $from): array {
|
||||||
$this->loadLazyProviders();
|
$this->loadLazyProviders();
|
||||||
|
|
||||||
$providers = array_values(
|
$providers = array_values(
|
||||||
array_map(function (IProvider $provider) {
|
array_map(function (IProvider $provider) use ($from) {
|
||||||
return [
|
return [
|
||||||
'id' => $provider->getId(),
|
'id' => $provider->getId(),
|
||||||
'name' => $provider->getName(),
|
'name' => $provider->getName(),
|
||||||
'order' => $provider->getOrder()
|
'order' => $provider->getOrder($from)
|
||||||
];
|
];
|
||||||
}, $this->providers)
|
}, $this->providers)
|
||||||
);
|
);
|
||||||
|
|
|
@ -68,11 +68,13 @@ interface IProvider {
|
||||||
* Get the search provider order
|
* Get the search provider order
|
||||||
* The lower the int, the higher it will be sorted (0 will be before 10)
|
* 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
|
* @return int
|
||||||
*
|
*
|
||||||
* @since 20.0.0
|
* @since 20.0.0
|
||||||
*/
|
*/
|
||||||
public function getOrder(): int;
|
public function getOrder(string $from): int;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Find matching search entries in an app
|
* Find matching search entries in an app
|
||||||
|
|
Loading…
Reference in New Issue