Skip to content

Commit ea8f68b

Browse files
nickvergessennpmbuildbot[bot]
authored andcommitted
Hand in the route and the parameters of the request
Signed-off-by: Joas Schilling <coding@schilljs.com> Signed-off-by: npmbuildbot[bot] <npmbuildbot[bot]@users.noreply.github.com>
1 parent d98f7c1 commit ea8f68b

26 files changed

Lines changed: 167 additions & 56 deletions

apps/comments/lib/Search/CommentsSearchProvider.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,11 @@ public function getName(): string {
7777
/**
7878
* @inheritDoc
7979
*/
80-
public function getOrder(string $from): int {
80+
public function getOrder(string $route, array $routeParameters): int {
81+
if ($route === 'files.View.index') {
82+
// Files first
83+
return 0;
84+
}
8185
return 10;
8286
}
8387

apps/dav/lib/Search/ContactsSearchProvider.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,11 @@ public function getName(): string {
9696
/**
9797
* @inheritDoc
9898
*/
99-
public function getOrder(string $from): int {
100-
return 7;
99+
public function getOrder(string $route, array $routeParameters): int {
100+
if ($route === 'contacts.Page.index') {
101+
return -1;
102+
}
103+
return 20;
101104
}
102105

103106
/**

apps/dav/lib/Search/EventsSearchProvider.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,10 @@ public function getName(): string {
8282
/**
8383
* @inheritDoc
8484
*/
85-
public function getOrder(string $from): int {
85+
public function getOrder(string $route, array $routeParameters): int {
86+
if ($route === 'calendar.View.index') {
87+
return -1;
88+
}
8689
return 10;
8790
}
8891

apps/dav/lib/Search/TasksSearchProvider.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,10 @@ public function getName(): string {
7474
/**
7575
* @inheritDoc
7676
*/
77-
public function getOrder(string $from): int {
77+
public function getOrder(string $route, array $routeParameters): int {
78+
if ($route === 'tasks.Page.index') {
79+
return -1;
80+
}
7881
return 10;
7982
}
8083

apps/files/lib/Search/FilesSearchProvider.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,11 @@ public function getName(): string {
7777
/**
7878
* @inheritDoc
7979
*/
80-
public function getOrder(string $from): int {
80+
public function getOrder(string $route, array $routeParameters): int {
81+
if ($route === 'files.View.index') {
82+
// Before comments
83+
return -5;
84+
}
8185
return 5;
8286
}
8387

apps/settings/lib/Search/SectionSearch.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,8 @@ public function getName(): string {
7575
/**
7676
* @inheritDoc
7777
*/
78-
public function getOrder(string $from): int {
79-
if (strpos($from, $this->urlGenerator->linkToRoute('settings.PersonalSettings.index') === 0)
80-
|| strpos($from, $this->urlGenerator->linkToRoute('settings.AdminSettings.index')) === 0) {
78+
public function getOrder(string $route, array $routeParameters): int {
79+
if ($route === 'settings.PersonalSettings.index' || $route === 'settings.AdminSettings.index') {
8180
return -1;
8281
}
8382
return 20;

core/Controller/UnifiedSearchController.php

Lines changed: 55 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@
3232
use OCP\AppFramework\Http\JSONResponse;
3333
use OCP\IRequest;
3434
use OCP\IUserSession;
35+
use OCP\Route\IRouter;
3536
use OCP\Search\ISearchQuery;
37+
use Symfony\Component\Routing\Exception\ResourceNotFoundException;
3638

3739
class UnifiedSearchController extends Controller {
3840

@@ -42,26 +44,33 @@ class UnifiedSearchController extends Controller {
4244
/** @var IUserSession */
4345
private $userSession;
4446

47+
/** @var IRouter */
48+
private $router;
49+
4550
public function __construct(IRequest $request,
4651
IUserSession $userSession,
47-
SearchComposer $composer) {
52+
SearchComposer $composer,
53+
IRouter $router) {
4854
parent::__construct('core', $request);
4955

5056
$this->composer = $composer;
5157
$this->userSession = $userSession;
58+
$this->router = $router;
5259
}
5360

5461
/**
5562
* @NoAdminRequired
5663
* @NoCSRFRequired
57-
*
64+
*
5865
* @param string $from the url the user is currently at
59-
*
66+
*
6067
* @return JSONResponse
6168
*/
62-
public function getProviders(string $from): JSONResponse {
69+
public function getProviders(string $from = ''): JSONResponse {
70+
[$route, $parameters] = $this->getRouteInformation($from);
71+
6372
return new JSONResponse(
64-
$this->composer->getProviders($from)
73+
$this->composer->getProviders($route, $parameters)
6574
);
6675
}
6776

@@ -74,17 +83,20 @@ public function getProviders(string $from): JSONResponse {
7483
* @param int|null $sortOrder
7584
* @param int|null $limit
7685
* @param int|string|null $cursor
86+
* @param string $from
7787
*
7888
* @return JSONResponse
7989
*/
8090
public function search(string $providerId,
8191
string $term = '',
8292
?int $sortOrder = null,
8393
?int $limit = null,
84-
$cursor = null): JSONResponse {
94+
$cursor = null,
95+
string $from = ''): JSONResponse {
8596
if (empty(trim($term))) {
8697
return new JSONResponse(null, Http::STATUS_BAD_REQUEST);
8798
}
99+
[$route, $routeParameters] = $this->getRouteInformation($from);
88100

89101
return new JSONResponse(
90102
$this->composer->search(
@@ -94,9 +106,45 @@ public function search(string $providerId,
94106
$term,
95107
$sortOrder ?? ISearchQuery::SORT_DATE_DESC,
96108
$limit ?? SearchQuery::LIMIT_DEFAULT,
97-
$cursor
109+
$cursor,
110+
$route,
111+
$routeParameters
98112
)
99113
)
100114
);
101115
}
116+
117+
protected function getRouteInformation(string $url): array {
118+
$routeStr = '';
119+
$parameters = [];
120+
121+
if ($url !== '') {
122+
$urlParts = parse_url($url);
123+
124+
try {
125+
$parameters = $this->router->findMatchingRoute($urlParts['path']);
126+
127+
// contacts.PageController.index => contacts.Page.index
128+
$route = $parameters['caller'];
129+
if (substr($route[1], -10) === 'Controller') {
130+
$route[1] = substr($route[1], 0, -10);
131+
}
132+
$routeStr = implode('.', $route);
133+
134+
// cleanup
135+
unset($parameters['_route'], $parameters['action'], $parameters['caller']);
136+
} catch (ResourceNotFoundException $exception) {
137+
}
138+
139+
if (isset($urlParts['query'])) {
140+
parse_str($urlParts['query'], $queryParameters);
141+
$parameters = array_merge($parameters, $queryParameters);
142+
}
143+
}
144+
145+
return [
146+
$routeStr,
147+
$parameters,
148+
];
149+
}
102150
}

core/js/dist/install.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

core/js/dist/install.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

core/js/dist/login.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)