Skip to content

Commit 2ad8533

Browse files
RedundancygroupController: Add separated (searchEditor/complete)Action for members & children tab
1 parent 9eea87d commit 2ad8533

File tree

1 file changed

+51
-25
lines changed

1 file changed

+51
-25
lines changed

application/controllers/RedundancygroupController.php

Lines changed: 51 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -174,19 +174,22 @@ public function childrenAction(): Generator
174174
);
175175
$viewModeSwitcher = $this->createViewModeSwitcher($paginationControl, $limitControl);
176176

177-
$searchBar = $this->createSearchBar(
178-
$nodesQuery,
179-
[
180-
$limitControl->getLimitParam(),
181-
$sortControl->getSortParam(),
182-
$viewModeSwitcher->getViewModeParam(),
183-
'id'
184-
]
185-
);
186-
187-
$searchBar->getSuggestionUrl()->setParam('isChildrenTab');
188-
$searchBar->getEditorUrl()
189-
->setParams((clone $searchBar->getEditorUrl()->getParams())->set('isChildrenTab', true));
177+
$preserveParams = [
178+
$limitControl->getLimitParam(),
179+
$sortControl->getSortParam(),
180+
$viewModeSwitcher->getViewModeParam(),
181+
'id'
182+
];
183+
184+
$requestParams = Url::fromRequest()->onlyWith($preserveParams)->getParams();
185+
$searchBar = $this->createSearchBar($nodesQuery, $preserveParams)
186+
->setEditorUrl(
187+
Url::fromPath('icingadb/redundancygroup/children-search-editor')
188+
->setParams($requestParams)
189+
)->setSuggestionUrl(
190+
Url::fromPath('icingadb/redundancygroup/children-complete')
191+
->setParams(clone $requestParams)
192+
);
190193

191194
if ($searchBar->hasBeenSent() && ! $searchBar->isValid()) {
192195
if ($searchBar->hasBeenSubmitted()) {
@@ -224,28 +227,31 @@ public function childrenAction(): Generator
224227

225228
public function completeAction(): void
226229
{
227-
$isChildrenTab = $this->params->shift('isChildrenTab');
228-
$column = $isChildrenTab ? 'parent' : 'child';
230+
$suggestions = (new ObjectSuggestions())
231+
->setModel(DependencyNode::class)
232+
->onlyWithCustomVarSources(['host', 'service', 'hostgroup', 'servicegroup'])
233+
->setBaseFilter(Filter::equal("child.redundancy_group.id", $this->groupId))
234+
->forRequest($this->getServerRequest());
235+
236+
$this->getDocument()->add($suggestions);
237+
}
229238

239+
public function childrenCompleteAction(): void
240+
{
230241
$suggestions = (new ObjectSuggestions())
231242
->setModel(DependencyNode::class)
232-
->setBaseFilter(Filter::equal("$column.redundancy_group.id", $this->groupId))
233243
->onlyWithCustomVarSources(['host', 'service', 'hostgroup', 'servicegroup'])
244+
->setBaseFilter(Filter::equal("parent.redundancy_group.id", $this->groupId))
234245
->forRequest($this->getServerRequest());
235246

236247
$this->getDocument()->add($suggestions);
237248
}
238249

239250
public function searchEditorAction(): void
240251
{
241-
$isChildrenTab = $this->params->shift('isChildrenTab');
242-
$redirectUrl = $isChildrenTab
243-
? Url::fromPath('icingadb/redundancygroup/children', ['id' => $this->groupId])
244-
: Url::fromPath('icingadb/redundancygroup/members', ['id' => $this->groupId]);
245-
246252
$editor = $this->createSearchEditor(
247253
DependencyNode::on($this->getDb()),
248-
$redirectUrl,
254+
Url::fromPath('icingadb/redundancygroup/members', ['id' => $this->groupId]),
249255
[
250256
LimitControl::DEFAULT_LIMIT_PARAM,
251257
SortControl::DEFAULT_SORT_PARAM,
@@ -254,9 +260,29 @@ public function searchEditorAction(): void
254260
]
255261
);
256262

257-
if ($isChildrenTab) {
258-
$editor->getSuggestionUrl()->setParam('isChildrenTab');
259-
}
263+
$this->getDocument()->add($editor);
264+
$this->setTitle($this->translate('Adjust Filter'));
265+
}
266+
267+
public function childrenSearchEditorAction(): void
268+
{
269+
$preserveParams = [
270+
LimitControl::DEFAULT_LIMIT_PARAM,
271+
SortControl::DEFAULT_SORT_PARAM,
272+
ViewModeSwitcher::DEFAULT_VIEW_MODE_PARAM,
273+
'id'
274+
];
275+
276+
$editor = $this->createSearchEditor(
277+
DependencyNode::on($this->getDb()),
278+
Url::fromPath('icingadb/redundancygroup/children', ['id' => $this->groupId]),
279+
$preserveParams
280+
);
281+
282+
$editor->setSuggestionUrl(
283+
Url::fromPath('icingadb/redundancygroup/children-complete')
284+
->setParams(Url::fromRequest()->onlyWith($preserveParams)->getParams())
285+
);
260286

261287
$this->getDocument()->add($editor);
262288
$this->setTitle($this->translate('Adjust Filter'));

0 commit comments

Comments
 (0)