icingadb-web/application/controllers/DowntimeController.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

83 lines
2.1 KiB
PHP

<?php
/* Icinga DB Web | (c) 2020 Icinga GmbH | GPLv2 */
namespace Icinga\Module\Icingadb\Controllers;
use Icinga\Exception\NotFoundError;
use Icinga\Module\Icingadb\Common\CommandActions;
use Icinga\Module\Icingadb\Common\Links;
use Icinga\Module\Icingadb\Model\Downtime;
use Icinga\Module\Icingadb\Web\Controller;
use Icinga\Module\Icingadb\Widget\Detail\DowntimeDetail;
use Icinga\Module\Icingadb\Widget\ItemList\DowntimeList;
class DowntimeController extends Controller
{
use CommandActions;
/** @var Downtime */
protected $downtime;
public function init()
{
$this->setTitle(t('Downtime'));
$name = $this->params->getRequired('name');
$query = Downtime::on($this->getDb())->with([
'host',
'host.state',
'service',
'service.state',
'service.host',
'service.host.state',
'parent',
'parent.host',
'parent.host.state',
'parent.service',
'parent.service.state',
'triggered_by',
'triggered_by.host',
'triggered_by.host.state',
'triggered_by.service',
'triggered_by.service.state'
]);
$query->getSelectBase()
->where(['downtime.name = ?' => $name]);
$this->applyRestrictions($query);
$downtime = $query->first();
if ($downtime === null) {
throw new NotFoundError(t('Downtime not found'));
}
$this->downtime = $downtime;
}
public function indexAction()
{
$detail = new DowntimeDetail($this->downtime);
$this->addControl((new DowntimeList([$this->downtime]))
->setViewMode('minimal')
->setDetailActionsDisabled()
->setCaptionDisabled()
->setNoSubjectLink());
$this->addContent($detail);
$this->setAutorefreshInterval(10);
}
protected function fetchCommandTargets()
{
return [$this->downtime];
}
protected function getCommandTargetsUrl()
{
return Links::downtime($this->downtime);
}
}