Skip to content

Commit aa33908

Browse files
(Host/Service)Controller: Add separated (searchEditor/complete)Action for parent & children tab
1 parent 6d52ef6 commit aa33908

File tree

2 files changed

+108
-55
lines changed

2 files changed

+108
-55
lines changed

application/controllers/HostController.php

Lines changed: 50 additions & 24 deletions
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(clone $requestParams)
341+
);
338342

339343
if ($searchBar->hasBeenSent() && ! $searchBar->isValid()) {
340344
if ($searchBar->hasBeenSubmitted()) {
@@ -373,27 +377,29 @@ 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]);
393-
394400
$editor = $this->createSearchEditor(
395401
DependencyNode::on($this->getDb()),
396-
$redirectUrl,
402+
Url::fromPath('icingadb/host/parents', ['name' => $this->host->name]),
397403
[
398404
LimitControl::DEFAULT_LIMIT_PARAM,
399405
SortControl::DEFAULT_SORT_PARAM,
@@ -402,9 +408,29 @@ public function searchEditorAction(): void
402408
]
403409
);
404410

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

409435
$this->getDocument()->add($editor);
410436
$this->setTitle($this->translate('Adjust Filter'));

application/controllers/ServiceController.php

Lines changed: 58 additions & 31 deletions
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(clone $requestParams)
213+
);
210214

211215
if ($searchBar->hasBeenSent() && ! $searchBar->isValid()) {
212216
if ($searchBar->hasBeenSubmitted()) {
@@ -336,33 +340,32 @@ 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());
347+
348+
$this->getDocument()->add($suggestions);
349+
}
341350

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(
359-
'icingadb/service/parents',
360-
['name' => $this->service->name, 'host.name' => $this->service->host->name]
361-
);
362-
363363
$editor = $this->createSearchEditor(
364364
DependencyNode::on($this->getDb()),
365-
$redirectUrl,
365+
Url::fromPath(
366+
'icingadb/service/parents',
367+
['name' => $this->service->name, 'host.name' => $this->service->host->name]
368+
),
366369
[
367370
LimitControl::DEFAULT_LIMIT_PARAM,
368371
SortControl::DEFAULT_SORT_PARAM,
@@ -372,9 +375,33 @@ public function searchEditorAction(): void
372375
]
373376
);
374377

375-
if ($isChildrenTab) {
376-
$editor->getSuggestionUrl()->setParam('isChildrenTab');
377-
}
378+
$this->getDocument()->add($editor);
379+
$this->setTitle($this->translate('Adjust Filter'));
380+
}
381+
382+
public function childrenSearchEditorAction(): void
383+
{
384+
$preserveParams = [
385+
LimitControl::DEFAULT_LIMIT_PARAM,
386+
SortControl::DEFAULT_SORT_PARAM,
387+
ViewModeSwitcher::DEFAULT_VIEW_MODE_PARAM,
388+
'name',
389+
'host.name'
390+
];
391+
392+
$editor = $this->createSearchEditor(
393+
DependencyNode::on($this->getDb()),
394+
Url::fromPath(
395+
'icingadb/service/children',
396+
['name' => $this->service->name, 'host.name' => $this->service->host->name]
397+
),
398+
$preserveParams
399+
);
400+
401+
$editor->setSuggestionUrl(
402+
Url::fromPath('icingadb/service/children-complete')
403+
->setParams(Url::fromRequest()->onlyWith($preserveParams)->getParams())
404+
);
378405

379406
$this->getDocument()->add($editor);
380407
$this->setTitle($this->translate('Adjust Filter'));

0 commit comments

Comments
 (0)