Skip to content

Commit ebdb48a

Browse files
(Host/Service)Controller: Add separated (searchEditor/complete)Action for parent & children tab
1 parent 3602d5a commit ebdb48a

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
@@ -317,18 +317,22 @@ public function childrenAction(): Generator
317317

318318
$viewModeSwitcher = $this->createViewModeSwitcher($paginationControl, $limitControl);
319319

320-
$searchBar = $this->createSearchBar(
321-
$nodesQuery,
322-
[
323-
$limitControl->getLimitParam(),
324-
$sortControl->getSortParam(),
325-
$viewModeSwitcher->getViewModeParam(),
326-
'name'
327-
]
328-
);
329-
330-
$searchBar->getSuggestionUrl()->setParam('isChildrenTab');
331-
$searchBar->getEditorUrl()->setParam('isChildrenTab');
320+
$preserveParams = [
321+
$limitControl->getLimitParam(),
322+
$sortControl->getSortParam(),
323+
$viewModeSwitcher->getViewModeParam(),
324+
'name'
325+
];
326+
327+
$requestParams = Url::fromRequest()->onlyWith($preserveParams)->getParams();
328+
$searchBar = $this->createSearchBar($nodesQuery, $preserveParams)
329+
->setEditorUrl(
330+
Url::fromPath('icingadb/host/children-search-editor')
331+
->setParams($requestParams)
332+
)->setSuggestionUrl(
333+
Url::fromPath('icingadb/host/children-complete')
334+
->setParams(clone $requestParams)
335+
);
332336

333337
if ($searchBar->hasBeenSent() && ! $searchBar->isValid()) {
334338
if ($searchBar->hasBeenSubmitted()) {
@@ -367,27 +371,29 @@ public function childrenAction(): Generator
367371

368372
public function completeAction(): void
369373
{
370-
$isChildrenTab = $this->params->shift('isChildrenTab');
371-
$relation = $isChildrenTab ? 'parent' : 'child';
374+
$suggestions = (new ObjectSuggestions())
375+
->setModel(DependencyNode::class)
376+
->setBaseFilter(Filter::equal("child.host.id", $this->host->id))
377+
->forRequest($this->getServerRequest());
378+
379+
$this->getDocument()->add($suggestions);
380+
}
372381

382+
public function childrenCompleteAction(): void
383+
{
373384
$suggestions = (new ObjectSuggestions())
374385
->setModel(DependencyNode::class)
375-
->setBaseFilter(Filter::equal("$relation.host.id", $this->host->id))
386+
->setBaseFilter(Filter::equal("parent.host.id", $this->host->id))
376387
->forRequest($this->getServerRequest());
377388

378389
$this->getDocument()->add($suggestions);
379390
}
380391

381392
public function searchEditorAction(): void
382393
{
383-
$isChildrenTab = $this->params->shift('isChildrenTab');
384-
$redirectUrl = $isChildrenTab
385-
? Url::fromPath('icingadb/host/children', ['name' => $this->host->name])
386-
: Url::fromPath('icingadb/host/parents', ['name' => $this->host->name]);
387-
388394
$editor = $this->createSearchEditor(
389395
DependencyNode::on($this->getDb()),
390-
$redirectUrl,
396+
Url::fromPath('icingadb/host/parents', ['name' => $this->host->name]),
391397
[
392398
LimitControl::DEFAULT_LIMIT_PARAM,
393399
SortControl::DEFAULT_SORT_PARAM,
@@ -396,9 +402,29 @@ public function searchEditorAction(): void
396402
]
397403
);
398404

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

403429
$this->getDocument()->add($editor);
404430
$this->setTitle($this->translate('Adjust Filter'));

application/controllers/ServiceController.php

Lines changed: 58 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -188,19 +188,23 @@ public function childrenAction(): Generator
188188

189189
$viewModeSwitcher = $this->createViewModeSwitcher($paginationControl, $limitControl);
190190

191-
$searchBar = $this->createSearchBar(
192-
$nodesQuery,
193-
[
194-
$limitControl->getLimitParam(),
195-
$sortControl->getSortParam(),
196-
$viewModeSwitcher->getViewModeParam(),
197-
'name',
198-
'host.name'
199-
]
200-
);
201-
202-
$searchBar->getSuggestionUrl()->setParam('isChildrenTab');
203-
$searchBar->getEditorUrl()->setParam('isChildrenTab');
191+
$preserveParams = [
192+
$limitControl->getLimitParam(),
193+
$sortControl->getSortParam(),
194+
$viewModeSwitcher->getViewModeParam(),
195+
'name',
196+
'host.name'
197+
];
198+
199+
$requestParams = Url::fromRequest()->onlyWith($preserveParams)->getParams();
200+
$searchBar = $this->createSearchBar($nodesQuery, $preserveParams)
201+
->setEditorUrl(
202+
Url::fromPath('icingadb/service/children-search-editor')
203+
->setParams($requestParams)
204+
)->setSuggestionUrl(
205+
Url::fromPath('icingadb/service/children-complete')
206+
->setParams(clone $requestParams)
207+
);
204208

205209
if ($searchBar->hasBeenSent() && ! $searchBar->isValid()) {
206210
if ($searchBar->hasBeenSubmitted()) {
@@ -330,33 +334,32 @@ public function historyAction(): Generator
330334

331335
public function completeAction(): void
332336
{
333-
$isChildrenTab = $this->params->shift('isChildrenTab');
334-
$relation = $isChildrenTab ? 'parent' : 'child';
337+
$suggestions = (new ObjectSuggestions())
338+
->setModel(DependencyNode::class)
339+
->setBaseFilter(Filter::equal("child.service.id", $this->service->id))
340+
->forRequest($this->getServerRequest());
341+
342+
$this->getDocument()->add($suggestions);
343+
}
335344

345+
public function childrenCompleteAction(): void
346+
{
336347
$suggestions = (new ObjectSuggestions())
337348
->setModel(DependencyNode::class)
338-
->setBaseFilter(Filter::equal("$relation.service.id", $this->service->id))
349+
->setBaseFilter(Filter::equal("parent.service.id", $this->service->id))
339350
->forRequest($this->getServerRequest());
340351

341352
$this->getDocument()->add($suggestions);
342353
}
343354

344355
public function searchEditorAction(): void
345356
{
346-
$isChildrenTab = $this->params->shift('isChildrenTab');
347-
$redirectUrl = $isChildrenTab
348-
? Url::fromPath(
349-
'icingadb/service/children',
350-
['name' => $this->service->name, 'host.name' => $this->service->host->name]
351-
)
352-
: Url::fromPath(
353-
'icingadb/service/parents',
354-
['name' => $this->service->name, 'host.name' => $this->service->host->name]
355-
);
356-
357357
$editor = $this->createSearchEditor(
358358
DependencyNode::on($this->getDb()),
359-
$redirectUrl,
359+
Url::fromPath(
360+
'icingadb/service/parents',
361+
['name' => $this->service->name, 'host.name' => $this->service->host->name]
362+
),
360363
[
361364
LimitControl::DEFAULT_LIMIT_PARAM,
362365
SortControl::DEFAULT_SORT_PARAM,
@@ -366,9 +369,33 @@ public function searchEditorAction(): void
366369
]
367370
);
368371

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

373400
$this->getDocument()->add($editor);
374401
$this->setTitle($this->translate('Adjust Filter'));

0 commit comments

Comments
 (0)