Skip to content

Commit 013432d

Browse files
(Host/Service)Controller: Add separated (searchEditor/complete)Action for parent & children tab
1 parent 47b30c2 commit 013432d

File tree

2 files changed

+121
-64
lines changed

2 files changed

+121
-64
lines changed

Diff for: application/controllers/HostController.php

+57-29
Original file line numberDiff line numberDiff line change
@@ -323,18 +323,22 @@ public function childrenAction(): Generator
323323

324324
$viewModeSwitcher = $this->createViewModeSwitcher($paginationControl, $limitControl);
325325

326-
$searchBar = $this->createSearchBar(
327-
$nodesQuery,
328-
[
329-
$limitControl->getLimitParam(),
330-
$sortControl->getSortParam(),
331-
$viewModeSwitcher->getViewModeParam(),
332-
'name'
333-
]
334-
);
335-
336-
$searchBar->getSuggestionUrl()->setParam('isChildrenTab');
337-
$searchBar->getEditorUrl()->setParam('isChildrenTab');
326+
$preserveParams = [
327+
$limitControl->getLimitParam(),
328+
$sortControl->getSortParam(),
329+
$viewModeSwitcher->getViewModeParam(),
330+
'name'
331+
];
332+
333+
$requestParams = Url::fromRequest()->onlyWith($preserveParams)->getParams();
334+
$searchBar = $this->createSearchBar($nodesQuery, $preserveParams)
335+
->setEditorUrl(
336+
Url::fromPath('icingadb/host/children-search-editor')
337+
->setParams($requestParams)
338+
)->setSuggestionUrl(
339+
Url::fromPath('icingadb/host/children-complete')
340+
->setParams($requestParams)
341+
);
338342

339343
if ($searchBar->hasBeenSent() && ! $searchBar->isValid()) {
340344
if ($searchBar->hasBeenSubmitted()) {
@@ -373,38 +377,62 @@ public function childrenAction(): Generator
373377

374378
public function completeAction(): void
375379
{
376-
$isChildrenTab = $this->params->shift('isChildrenTab');
377-
$relation = $isChildrenTab ? 'parent' : 'child';
380+
$suggestions = (new ObjectSuggestions())
381+
->setModel(DependencyNode::class)
382+
->setBaseFilter(Filter::equal("child.host.id", $this->host->id))
383+
->forRequest($this->getServerRequest());
384+
385+
$this->getDocument()->add($suggestions);
386+
}
378387

388+
public function childrenCompleteAction(): void
389+
{
379390
$suggestions = (new ObjectSuggestions())
380391
->setModel(DependencyNode::class)
381-
->setBaseFilter(Filter::equal("$relation.host.id", $this->host->id))
392+
->setBaseFilter(Filter::equal("parent.host.id", $this->host->id))
382393
->forRequest($this->getServerRequest());
383394

384395
$this->getDocument()->add($suggestions);
385396
}
386397

387398
public function searchEditorAction(): void
388399
{
389-
$isChildrenTab = $this->params->shift('isChildrenTab');
390-
$redirectUrl = $isChildrenTab
391-
? Url::fromPath('icingadb/host/children', ['name' => $this->host->name])
392-
: Url::fromPath('icingadb/host/parents', ['name' => $this->host->name]);
400+
$preserveParams = [
401+
LimitControl::DEFAULT_LIMIT_PARAM,
402+
SortControl::DEFAULT_SORT_PARAM,
403+
ViewModeSwitcher::DEFAULT_VIEW_MODE_PARAM,
404+
'name'
405+
];
393406

394407
$editor = $this->createSearchEditor(
395408
DependencyNode::on($this->getDb()),
396-
$redirectUrl,
397-
[
398-
LimitControl::DEFAULT_LIMIT_PARAM,
399-
SortControl::DEFAULT_SORT_PARAM,
400-
ViewModeSwitcher::DEFAULT_VIEW_MODE_PARAM,
401-
'name'
402-
]
409+
Url::fromPath('icingadb/host/parents', ['name' => $this->host->name]),
410+
$preserveParams
403411
);
404412

405-
if ($isChildrenTab) {
406-
$editor->getSuggestionUrl()->setParam('isChildrenTab');
407-
}
413+
$this->getDocument()->add($editor);
414+
$this->setTitle($this->translate('Adjust Filter'));
415+
}
416+
417+
public function childrenSearchEditorAction(): void
418+
{
419+
$preserveParams = [
420+
LimitControl::DEFAULT_LIMIT_PARAM,
421+
SortControl::DEFAULT_SORT_PARAM,
422+
ViewModeSwitcher::DEFAULT_VIEW_MODE_PARAM,
423+
'name'
424+
];
425+
426+
$editor = $this->createSearchEditor(
427+
DependencyNode::on($this->getDb()),
428+
Url::fromPath('icingadb/host/children', ['name' => $this->host->name]),
429+
$preserveParams
430+
);
431+
432+
$editor->setSuggestionUrl(
433+
Url::fromPath('icingadb/host/children-complete')
434+
->setParams(Url::fromRequest()->onlyWith($preserveParams)->getParams())
435+
);
408436

409437
$this->getDocument()->add($editor);
410438
$this->setTitle($this->translate('Adjust Filter'));

Diff for: application/controllers/ServiceController.php

+64-35
Original file line numberDiff line numberDiff line change
@@ -194,19 +194,23 @@ public function childrenAction(): Generator
194194

195195
$viewModeSwitcher = $this->createViewModeSwitcher($paginationControl, $limitControl);
196196

197-
$searchBar = $this->createSearchBar(
198-
$nodesQuery,
199-
[
200-
$limitControl->getLimitParam(),
201-
$sortControl->getSortParam(),
202-
$viewModeSwitcher->getViewModeParam(),
203-
'name',
204-
'host.name'
205-
]
206-
);
207-
208-
$searchBar->getSuggestionUrl()->setParam('isChildrenTab');
209-
$searchBar->getEditorUrl()->setParam('isChildrenTab');
197+
$preserveParams = [
198+
$limitControl->getLimitParam(),
199+
$sortControl->getSortParam(),
200+
$viewModeSwitcher->getViewModeParam(),
201+
'name',
202+
'host.name'
203+
];
204+
205+
$requestParams = Url::fromRequest()->onlyWith($preserveParams)->getParams();
206+
$searchBar = $this->createSearchBar($nodesQuery, $preserveParams)
207+
->setEditorUrl(
208+
Url::fromPath('icingadb/service/children-search-editor')
209+
->setParams($requestParams)
210+
)->setSuggestionUrl(
211+
Url::fromPath('icingadb/service/children-complete')
212+
->setParams($requestParams)
213+
);
210214

211215
if ($searchBar->hasBeenSent() && ! $searchBar->isValid()) {
212216
if ($searchBar->hasBeenSubmitted()) {
@@ -336,45 +340,70 @@ public function historyAction(): Generator
336340

337341
public function completeAction(): void
338342
{
339-
$isChildrenTab = $this->params->shift('isChildrenTab');
340-
$relation = $isChildrenTab ? 'parent' : 'child';
343+
$suggestions = (new ObjectSuggestions())
344+
->setModel(DependencyNode::class)
345+
->setBaseFilter(Filter::equal("child.service.id", $this->service->id))
346+
->forRequest($this->getServerRequest());
341347

348+
$this->getDocument()->add($suggestions);
349+
}
350+
351+
public function childrenCompleteAction(): void
352+
{
342353
$suggestions = (new ObjectSuggestions())
343354
->setModel(DependencyNode::class)
344-
->setBaseFilter(Filter::equal("$relation.service.id", $this->service->id))
355+
->setBaseFilter(Filter::equal("parent.service.id", $this->service->id))
345356
->forRequest($this->getServerRequest());
346357

347358
$this->getDocument()->add($suggestions);
348359
}
349360

350361
public function searchEditorAction(): void
351362
{
352-
$isChildrenTab = $this->params->shift('isChildrenTab');
353-
$redirectUrl = $isChildrenTab
354-
? Url::fromPath(
355-
'icingadb/service/children',
356-
['name' => $this->service->name, 'host.name' => $this->service->host->name]
357-
)
358-
: Url::fromPath(
363+
$preserveParams = [
364+
LimitControl::DEFAULT_LIMIT_PARAM,
365+
SortControl::DEFAULT_SORT_PARAM,
366+
ViewModeSwitcher::DEFAULT_VIEW_MODE_PARAM,
367+
'name',
368+
'host.name'
369+
];
370+
371+
$editor = $this->createSearchEditor(
372+
DependencyNode::on($this->getDb()),
373+
Url::fromPath(
359374
'icingadb/service/parents',
360375
['name' => $this->service->name, 'host.name' => $this->service->host->name]
361-
);
376+
),
377+
$preserveParams
378+
);
379+
380+
$this->getDocument()->add($editor);
381+
$this->setTitle($this->translate('Adjust Filter'));
382+
}
383+
384+
public function childrenSearchEditorAction(): void
385+
{
386+
$preserveParams = [
387+
LimitControl::DEFAULT_LIMIT_PARAM,
388+
SortControl::DEFAULT_SORT_PARAM,
389+
ViewModeSwitcher::DEFAULT_VIEW_MODE_PARAM,
390+
'name',
391+
'host.name'
392+
];
362393

363394
$editor = $this->createSearchEditor(
364395
DependencyNode::on($this->getDb()),
365-
$redirectUrl,
366-
[
367-
LimitControl::DEFAULT_LIMIT_PARAM,
368-
SortControl::DEFAULT_SORT_PARAM,
369-
ViewModeSwitcher::DEFAULT_VIEW_MODE_PARAM,
370-
'name',
371-
'host.name'
372-
]
396+
Url::fromPath(
397+
'icingadb/service/children',
398+
['name' => $this->service->name, 'host.name' => $this->service->host->name]
399+
),
400+
$preserveParams
373401
);
374402

375-
if ($isChildrenTab) {
376-
$editor->getSuggestionUrl()->setParam('isChildrenTab');
377-
}
403+
$editor->setSuggestionUrl(
404+
Url::fromPath('icingadb/service/children-complete')
405+
->setParams(Url::fromRequest()->onlyWith($preserveParams)->getParams())
406+
);
378407

379408
$this->getDocument()->add($editor);
380409
$this->setTitle($this->translate('Adjust Filter'));

0 commit comments

Comments
 (0)