Skip to content

Commit 7847f6e

Browse files
RedundancygroupController: Separate (searchEditor/complete)Action for members & children tab (#1128)
1 parent 75c242e commit 7847f6e

File tree

1 file changed

+57
-31
lines changed

1 file changed

+57
-31
lines changed

Diff for: application/controllers/RedundancygroupController.php

+57-31
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public function indexAction(): void
9797
public function membersAction(): Generator
9898
{
9999
$this->loadGroup();
100-
$nodesQuery = $this->fetchNodes(true);
100+
$nodesQuery = $this->fetchDependencyNodes(true);
101101

102102
$limitControl = $this->createLimitControl();
103103
$paginationControl = $this->createPaginationControl($nodesQuery);
@@ -159,7 +159,7 @@ public function membersAction(): Generator
159159
public function childrenAction(): Generator
160160
{
161161
$this->loadGroup();
162-
$nodesQuery = $this->fetchNodes();
162+
$nodesQuery = $this->fetchDependencyNodes();
163163

164164
$limitControl = $this->createLimitControl();
165165
$paginationControl = $this->createPaginationControl($nodesQuery);
@@ -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'));
@@ -291,17 +317,17 @@ protected function setTitleTab(string $name): void
291317
}
292318

293319
/**
294-
* Fetch the nodes for the current group
320+
* Fetch the dependency nodes of the current group
295321
*
296-
* @param bool $fetchParents Whether to fetch the parents or the children
322+
* @param bool $parents Whether to fetch the parents or the children
297323
*
298324
* @return Query
299325
*/
300-
private function fetchNodes(bool $fetchParents = false): Query
326+
private function fetchDependencyNodes(bool $parents = false): Query
301327
{
302328
$filterColumn = sprintf(
303329
'%s.redundancy_group.id',
304-
$fetchParents ? 'child' : 'parent'
330+
$parents ? 'child' : 'parent'
305331
);
306332

307333
$query = DependencyNode::on($this->getDb())

0 commit comments

Comments
 (0)