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 bb511aa commit 30610c2
Show file tree
Hide file tree
Showing 2 changed files with 115 additions and 24 deletions.
134 changes: 110 additions & 24 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));

Check failure on line 58 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

Instantiated class Icinga\Module\Icingadb\Widget\Detail\ObjectHeader not found.

Check failure on line 58 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 #1 $control of method ipl\Web\Compat\CompatController::addControl() expects ipl\Html\ValidHtml, Icinga\Module\Icingadb\Widget\Detail\ObjectHeader given.

Check failure on line 58 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

Instantiated class Icinga\Module\Icingadb\Widget\Detail\ObjectHeader not found.

Check failure on line 58 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 #1 $control of method ipl\Web\Compat\CompatController::addControl() expects ipl\Html\ValidHtml, Icinga\Module\Icingadb\Widget\Detail\ObjectHeader given.

$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.2 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.3 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.2 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.3 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(new HtmlElement('div', null, Text::create($this->group->display_name)));

Check failure on line 130 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

Call to static method create() on an unknown class Icinga\Module\Icingadb\Controllers\Text.

Check failure on line 130 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

Instantiated class Icinga\Module\Icingadb\Controllers\HtmlElement not found.

Check failure on line 130 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 #1 $control of method ipl\Web\Compat\CompatController::addControl() expects ipl\Html\ValidHtml, Icinga\Module\Icingadb\Controllers\HtmlElement given.

Check failure on line 130 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

Call to static method create() on an unknown class Icinga\Module\Icingadb\Controllers\Text.

Check failure on line 130 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

Instantiated class Icinga\Module\Icingadb\Controllers\HtmlElement not found.

Check failure on line 130 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 #1 $control of method ipl\Web\Compat\CompatController::addControl() expects ipl\Html\ValidHtml, Icinga\Module\Icingadb\Controllers\HtmlElement given.

Expand All @@ -136,18 +136,74 @@ 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->setAutorefreshInterval(10);
}

public function childrenAction()
{
$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();
}
Expand Down Expand Up @@ -195,6 +251,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 +298,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 30610c2

Please sign in to comment.