Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RedundancygroupController: Separate (searchEditor/complete)Action for members & children tab #1128

Merged
merged 2 commits into from
Jan 22, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 57 additions & 31 deletions application/controllers/RedundancygroupController.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
$groupId = $this->params->shiftRequired('id');
}

$this->groupId = $groupId;

Check failure on line 48 in application/controllers/RedundancygroupController.php

View workflow job for this annotation

GitHub Actions / phpstan / Static analysis with phpstan and php 7.3 on ubuntu-latest

Property Icinga\Module\Icingadb\Controllers\RedundancygroupController::$groupId (string) does not accept mixed.

Check failure on line 48 in application/controllers/RedundancygroupController.php

View workflow job for this annotation

GitHub Actions / phpstan / Static analysis with phpstan and php 7.2 on ubuntu-latest

Property Icinga\Module\Icingadb\Controllers\RedundancygroupController::$groupId (string) does not accept mixed.
}

/**
Expand All @@ -59,7 +59,7 @@

$this->applyRestrictions($query);

$this->group = $query->first();

Check failure on line 62 in application/controllers/RedundancygroupController.php

View workflow job for this annotation

GitHub Actions / phpstan / Static analysis with phpstan and php 7.3 on ubuntu-latest

Property Icinga\Module\Icingadb\Controllers\RedundancygroupController::$group (Icinga\Module\Icingadb\Model\RedundancyGroup) does not accept ipl\Orm\Model|null.

Check failure on line 62 in application/controllers/RedundancygroupController.php

View workflow job for this annotation

GitHub Actions / phpstan / Static analysis with phpstan and php 7.2 on ubuntu-latest

Property Icinga\Module\Icingadb\Controllers\RedundancygroupController::$group (Icinga\Module\Icingadb\Model\RedundancyGroup) does not accept ipl\Orm\Model|null.

if ($this->group === null) {
$this->httpNotFound($this->translate('Redundancy Group not found'));
Expand All @@ -73,9 +73,9 @@

$this->applyRestrictions($summary);

$this->groupSummary = $summary->first();

Check failure on line 76 in application/controllers/RedundancygroupController.php

View workflow job for this annotation

GitHub Actions / phpstan / Static analysis with phpstan and php 7.3 on ubuntu-latest

Property Icinga\Module\Icingadb\Controllers\RedundancygroupController::$groupSummary (Icinga\Module\Icingadb\Model\RedundancyGroupSummary) does not accept ipl\Orm\Model|null.

Check failure on line 76 in application/controllers/RedundancygroupController.php

View workflow job for this annotation

GitHub Actions / phpstan / Static analysis with phpstan and php 7.2 on ubuntu-latest

Property Icinga\Module\Icingadb\Controllers\RedundancygroupController::$groupSummary (Icinga\Module\Icingadb\Model\RedundancyGroupSummary) does not accept ipl\Orm\Model|null.

$this->addControl(new RedundancyGroupHeader($this->group, $this->groupSummary));

Check failure on line 78 in application/controllers/RedundancygroupController.php

View workflow job for this annotation

GitHub Actions / phpstan / Static analysis with phpstan and php 7.3 on ubuntu-latest

Parameter #2 $summary of class Icinga\Module\Icingadb\Widget\Detail\RedundancyGroupHeader constructor expects Icinga\Module\Icingadb\Model\RedundancyGroupSummary, ipl\Orm\Model|null given.

Check failure on line 78 in application/controllers/RedundancygroupController.php

View workflow job for this annotation

GitHub Actions / phpstan / Static analysis with phpstan and php 7.2 on ubuntu-latest

Parameter #2 $summary of class Icinga\Module\Icingadb\Widget\Detail\RedundancyGroupHeader constructor expects Icinga\Module\Icingadb\Model\RedundancyGroupSummary, ipl\Orm\Model|null given.
}

public function indexAction(): void
Expand All @@ -97,7 +97,7 @@
public function membersAction(): Generator
{
$this->loadGroup();
$nodesQuery = $this->fetchNodes(true);
$nodesQuery = $this->fetchDependencyNodes(true);

$limitControl = $this->createLimitControl();
$paginationControl = $this->createPaginationControl($nodesQuery);
Expand Down Expand Up @@ -159,7 +159,7 @@
public function childrenAction(): Generator
{
$this->loadGroup();
$nodesQuery = $this->fetchNodes();
$nodesQuery = $this->fetchDependencyNodes();

$limitControl = $this->createLimitControl();
$paginationControl = $this->createPaginationControl($nodesQuery);
Expand All @@ -174,19 +174,22 @@
);
$viewModeSwitcher = $this->createViewModeSwitcher($paginationControl, $limitControl);

$searchBar = $this->createSearchBar(
$nodesQuery,
[
$limitControl->getLimitParam(),
$sortControl->getSortParam(),
$viewModeSwitcher->getViewModeParam(),
'id'
]
);

$searchBar->getSuggestionUrl()->setParam('isChildrenTab');
$searchBar->getEditorUrl()
->setParams((clone $searchBar->getEditorUrl()->getParams())->set('isChildrenTab', true));
$preserveParams = [
$limitControl->getLimitParam(),
$sortControl->getSortParam(),
$viewModeSwitcher->getViewModeParam(),
'id'
];

$requestParams = Url::fromRequest()->onlyWith($preserveParams)->getParams();
$searchBar = $this->createSearchBar($nodesQuery, $preserveParams)
->setEditorUrl(
Url::fromPath('icingadb/redundancygroup/children-search-editor')
->setParams($requestParams)
)->setSuggestionUrl(
Url::fromPath('icingadb/redundancygroup/children-complete')
->setParams(clone $requestParams)
);

if ($searchBar->hasBeenSent() && ! $searchBar->isValid()) {
if ($searchBar->hasBeenSubmitted()) {
Expand Down Expand Up @@ -224,28 +227,31 @@

public function completeAction(): void
{
$isChildrenTab = $this->params->shift('isChildrenTab');
$column = $isChildrenTab ? 'parent' : 'child';
$suggestions = (new ObjectSuggestions())
->setModel(DependencyNode::class)
->onlyWithCustomVarSources(['host', 'service', 'hostgroup', 'servicegroup'])
->setBaseFilter(Filter::equal("child.redundancy_group.id", $this->groupId))
->forRequest($this->getServerRequest());

$this->getDocument()->add($suggestions);
}

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

$this->getDocument()->add($suggestions);
}

public function searchEditorAction(): void
{
$isChildrenTab = $this->params->shift('isChildrenTab');
$redirectUrl = $isChildrenTab
? Url::fromPath('icingadb/redundancygroup/children', ['id' => $this->groupId])
: Url::fromPath('icingadb/redundancygroup/members', ['id' => $this->groupId]);

$editor = $this->createSearchEditor(
DependencyNode::on($this->getDb()),
$redirectUrl,
Url::fromPath('icingadb/redundancygroup/members', ['id' => $this->groupId]),
[
LimitControl::DEFAULT_LIMIT_PARAM,
SortControl::DEFAULT_SORT_PARAM,
Expand All @@ -254,9 +260,29 @@
]
);

if ($isChildrenTab) {
$editor->getSuggestionUrl()->setParam('isChildrenTab');
}
$this->getDocument()->add($editor);
$this->setTitle($this->translate('Adjust Filter'));
}

public function childrenSearchEditorAction(): void
{
$preserveParams = [
LimitControl::DEFAULT_LIMIT_PARAM,
SortControl::DEFAULT_SORT_PARAM,
ViewModeSwitcher::DEFAULT_VIEW_MODE_PARAM,
'id'
];

$editor = $this->createSearchEditor(
DependencyNode::on($this->getDb()),
Url::fromPath('icingadb/redundancygroup/children', ['id' => $this->groupId]),
$preserveParams
);

$editor->setSuggestionUrl(
Url::fromPath('icingadb/redundancygroup/children-complete')
->setParams(Url::fromRequest()->onlyWith($preserveParams)->getParams())
);

$this->getDocument()->add($editor);
$this->setTitle($this->translate('Adjust Filter'));
Expand Down Expand Up @@ -291,17 +317,17 @@
}

/**
* Fetch the nodes for the current group
* Fetch the dependency nodes of the current group
*
* @param bool $fetchParents Whether to fetch the parents or the children
* @param bool $parents Whether to fetch the parents or the children
*
* @return Query
*/
private function fetchNodes(bool $fetchParents = false): Query
private function fetchDependencyNodes(bool $parents = false): Query
{
$filterColumn = sprintf(
'%s.redundancy_group.id',
$fetchParents ? 'child' : 'parent'
$parents ? 'child' : 'parent'
);

$query = DependencyNode::on($this->getDb())
Expand All @@ -322,7 +348,7 @@
return $query;
}

protected function fetchCommandTargets()

Check failure on line 351 in application/controllers/RedundancygroupController.php

View workflow job for this annotation

GitHub Actions / phpstan / Static analysis with phpstan and php 7.3 on ubuntu-latest

Method Icinga\Module\Icingadb\Controllers\RedundancygroupController::fetchCommandTargets() has no return type specified.

Check failure on line 351 in application/controllers/RedundancygroupController.php

View workflow job for this annotation

GitHub Actions / phpstan / Static analysis with phpstan and php 7.2 on ubuntu-latest

Method Icinga\Module\Icingadb\Controllers\RedundancygroupController::fetchCommandTargets() has no return type specified.
{
$filter = Filter::all(Filter::equal('child.redundancy_group.id', $this->groupId));

Expand Down
Loading