Skip to content

Commit

Permalink
wip: reset it
Browse files Browse the repository at this point in the history
  • Loading branch information
sukhwinder33445 committed Nov 12, 2024
1 parent 52f4653 commit 41b3f9e
Show file tree
Hide file tree
Showing 2 changed files with 116 additions and 26 deletions.
137 changes: 111 additions & 26 deletions application/controllers/RedundancygroupController.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use Icinga\Module\Icingadb\Widget\Detail\ObjectHeader;
use Icinga\Module\Icingadb\Widget\Detail\RedundancyGroupDetail;
use Icinga\Module\Icingadb\Widget\ItemList\DependencyNodeList;
use ipl\Orm\Query;
use ipl\Stdlib\Filter;
use ipl\Web\Control\LimitControl;
use ipl\Web\Control\SortControl;
Expand Down Expand Up @@ -51,10 +52,18 @@ public function init(): void
throw new NotFoundError(t('Redundancy Group not found'));
}

$this->addControl(new ObjectHeader($this->group));

$this->setTitleTab($this->getRequest()->getActionName());
$this->setTitle($this->group->display_name);

$this->addControl(new ObjectHeader($this->group));

$this->addFooter(
new DependencyNodeStatistics(
RedundancyGroupSummary::on($this->getDb())
->filter(Filter::equal('id', $this->groupId))
->first()
)
);
}

public function indexAction()

Check failure on line 69 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::indexAction() has no return type specified.

Check failure on line 69 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::indexAction() has no return type specified.
Expand All @@ -75,21 +84,12 @@ public function indexAction()

public function membersAction()

Check failure on line 85 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::membersAction() has no return type specified.

Check failure on line 85 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::membersAction() has no return type specified.
{
$membersQuery = DependencyNode::on($this->getDb())
->with([
'host',
'host.state',
'service',
'service.state',
'service.host',
'service.host.state'
])
->filter(Filter::equal('child.redundancy_group.id', $this->groupId));
$nodesQuery = $this->fetchNodes(true);

$limitControl = $this->createLimitControl();
$paginationControl = $this->createPaginationControl($membersQuery);
$paginationControl = $this->createPaginationControl($nodesQuery);
$sortControl = $this->createSortControl(
$membersQuery,
$nodesQuery,
[
'name' => t('Name'),
'severity desc, last_state_change desc' => t('Severity'),
Expand All @@ -99,7 +99,7 @@ public function membersAction()
);
$viewModeSwitcher = $this->createViewModeSwitcher($paginationControl, $limitControl);

$searchBar = $this->createSearchBar($membersQuery,
$searchBar = $this->createSearchBar($nodesQuery,
Links::redundancyGroupMembers($this->group),
[
$limitControl->getLimitParam(),
Expand All @@ -123,9 +123,9 @@ public function membersAction()
$filter = $searchBar->getFilter();
}

$membersQuery->filter($filter);
$nodesQuery->filter($filter);

yield $this->export($membersQuery);
yield $this->export($nodesQuery);

$this->addControl($paginationControl);
$this->addControl($sortControl);
Expand All @@ -134,23 +134,78 @@ public function membersAction()
$this->addControl($searchBar);

$this->addContent(
(new DependencyNodeList($membersQuery->execute()))
(new DependencyNodeList($nodesQuery->execute()))
->setViewMode($viewModeSwitcher->getViewMode())
);

$this->addFooter(
new DependencyNodeStatistics(
RedundancyGroupSummary::on($this->getDb())
->filter(Filter::equal('id', $this->groupId))
->first()
)
);

if (! $searchBar->hasBeenSubmitted() && $searchBar->hasBeenSent()) {
$this->sendMultipartUpdate();
}

$this->getTabs()->activate('members');
$this->setAutorefreshInterval(10);
}

public function childrenAction()

Check failure on line 149 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::childrenAction() has no return type specified.

Check failure on line 149 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::childrenAction() has no return type specified.
{
$nodesQuery = $this->fetchNodes();

$limitControl = $this->createLimitControl();
$paginationControl = $this->createPaginationControl($nodesQuery);
$sortControl = $this->createSortControl(
$nodesQuery,
[
'name' => t('Name'),
'severity desc, last_state_change desc' => t('Severity'),
'state' => t('Current State'),
'last_state_change desc' => t('Last State Change')
]
);
$viewModeSwitcher = $this->createViewModeSwitcher($paginationControl, $limitControl);

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

$searchBar->getSuggestionUrl()->addParams(['id' => $this->groupId]);

if ($searchBar->hasBeenSent() && ! $searchBar->isValid()) {
if ($searchBar->hasBeenSubmitted()) {
$filter = $this->getFilter();
} else {
$this->addControl($searchBar);
$this->sendMultipartUpdate();
return;
}
} else {
$filter = $searchBar->getFilter();
}

$nodesQuery->filter($filter);

yield $this->export($nodesQuery);

$this->addControl($paginationControl);
$this->addControl($sortControl);
$this->addControl($limitControl);
$this->addControl($viewModeSwitcher);
$this->addControl($searchBar);

$this->addContent(
(new DependencyNodeList($nodesQuery->execute()))
->setViewMode($viewModeSwitcher->getViewMode())
);


if (! $searchBar->hasBeenSubmitted() && $searchBar->hasBeenSent()) {
$this->sendMultipartUpdate();
}

$this->setAutorefreshInterval(10);
}
Expand Down Expand Up @@ -195,6 +250,10 @@ protected function createTabs(): Tabs
->add('members', [
'label' => t('Members'),
'url' => Links::redundancyGroupMembers($this->group)
])
->add('children', [
'label' => t('Children'),
'url' => Links::redundancyGroupChildren($this->group)
]);

return $tabs;
Expand Down Expand Up @@ -238,4 +297,30 @@ protected function getCommandTargetsUrl(): Url
{
return Links::redundancyGroup($this->group);
}

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

return DependencyNode::on($this->getDb())
->with([
'host',
'host.state',
'service',
'service.state',
'service.host',
'service.host.state'
])
->filter(Filter::equal($filterColumn, $this->groupId));
}
}
5 changes: 5 additions & 0 deletions library/Icingadb/Common/Links.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,11 @@ public static function redundancyGroupMembers(RedundancyGroup $group): Url
return Url::fromPath('icingadb/redundancygroup/members', ['id' => bin2hex($group->id)]);
}

public static function redundancyGroupChildren(RedundancyGroup $group): Url
{
return Url::fromPath('icingadb/redundancygroup/children', ['id' => bin2hex($group->id)]);
}

public static function toggleHostsFeatures(): Url
{
return Url::fromPath('icingadb/hosts/toggle-features');
Expand Down

0 comments on commit 41b3f9e

Please sign in to comment.