icingadb-web/application/controllers/ServicegroupController.php
Johannes Meyer 85b9295db9 Don't shift URL params to identify objects in detail views
Parameters used to identify what will be shown need to be
preserved. Just like it's done for filters in lists.

refs #299
refs #312
2021-08-31 13:54:46 +02:00

80 lines
2.4 KiB
PHP

<?php
/* Icinga DB Web | (c) 2020 Icinga GmbH | GPLv2 */
namespace Icinga\Module\Icingadb\Controllers;
use Icinga\Exception\NotFoundError;
use Icinga\Module\Icingadb\Model\Service;
use Icinga\Module\Icingadb\Model\ServicegroupSummary;
use Icinga\Module\Icingadb\Web\Controller;
use Icinga\Module\Icingadb\Widget\ItemList\ServiceList;
use Icinga\Module\Icingadb\Widget\ItemList\ServicegroupList;
use ipl\Stdlib\Filter;
class ServicegroupController extends Controller
{
/** @var ServicegroupSummary The service group object */
protected $servicegroup;
public function init()
{
$this->assertRouteAccess('servicegroups');
$this->setTitle(t('Service Group'));
$name = $this->params->getRequired('name');
$query = ServicegroupSummary::on($this->getDb());
foreach ($query->getUnions() as $unionPart) {
$unionPart->filter(Filter::equal('servicegroup.name', $name));
}
$this->applyRestrictions($query);
$servicegroup = $query->first();
if ($servicegroup === null) {
throw new NotFoundError(t('Service group not found'));
}
$this->servicegroup = $servicegroup;
}
public function indexAction()
{
$db = $this->getDb();
$services = Service::on($db)->with([
'state',
'state.last_comment',
'icon_image',
'host',
'host.state'
])->utilize('servicegroup');
$services->getSelectBase()->where(['service_servicegroup.id = ?' => $this->servicegroup->id]);
$this->applyRestrictions($services);
$limitControl = $this->createLimitControl();
$paginationControl = $this->createPaginationControl($services);
$viewModeSwitcher = $this->createViewModeSwitcher($paginationControl, $limitControl);
$serviceList = (new ServiceList($services))
->setViewMode($viewModeSwitcher->getViewMode());
yield $this->export($services);
$this->addControl((new ServicegroupList([$this->servicegroup]))
->setViewMode('minimal')
->setDetailActionsDisabled()
->setNoSubjectLink());
$this->addControl($paginationControl);
$this->addControl($viewModeSwitcher);
$this->addControl($limitControl);
$this->addContent($serviceList);
$this->setAutorefreshInterval(10);
}
}