monitoring: Reduce DowntimeController complexity
This commit is contained in:
parent
a50d2110be
commit
b82306e2bb
|
@ -18,17 +18,10 @@ class DowntimeController extends Controller
|
|||
/**
|
||||
* The fetched downtime
|
||||
*
|
||||
* @var stdClass
|
||||
* @var object
|
||||
*/
|
||||
protected $downtime;
|
||||
|
||||
/**
|
||||
* If the downtime is a service or not
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected $isService;
|
||||
|
||||
/**
|
||||
* Fetch the downtime matching the given id and add tabs
|
||||
*/
|
||||
|
@ -59,29 +52,20 @@ class DowntimeController extends Controller
|
|||
))->where('downtime_internal_id', $downtimeId);
|
||||
$this->applyRestriction('monitoring/filter/objects', $query);
|
||||
|
||||
$this->downtime = $query->getQuery()->fetchRow();
|
||||
if ($this->downtime === false) {
|
||||
if (false === $this->downtime = $query->fetchRow()) {
|
||||
$this->httpNotFound($this->translate('Downtime not found'));
|
||||
}
|
||||
|
||||
if (isset($this->downtime->service_description)) {
|
||||
$this->isService = true;
|
||||
} else {
|
||||
$this->isService = false;
|
||||
}
|
||||
$this->getTabs()->add(
|
||||
'downtime',
|
||||
array(
|
||||
|
||||
$this->getTabs()
|
||||
->add(
|
||||
'downtime',
|
||||
array(
|
||||
'title' => $this->translate(
|
||||
'Display detailed information about a downtime.'
|
||||
),
|
||||
'icon' => 'plug',
|
||||
'label' => $this->translate('Downtime'),
|
||||
'url' =>'monitoring/downtimes/show'
|
||||
)
|
||||
)->activate('downtime')->extend(new DashboardAction());
|
||||
'icon' => 'plug',
|
||||
'label' => $this->translate('Downtime'),
|
||||
'title' => $this->translate('Display detailed information about a downtime.'),
|
||||
'url' =>'monitoring/downtimes/show'
|
||||
)
|
||||
)->activate('downtime')->extend(new DashboardAction());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -89,52 +73,27 @@ class DowntimeController extends Controller
|
|||
*/
|
||||
public function showAction()
|
||||
{
|
||||
$isService = isset($this->downtime->service_description);
|
||||
$this->view->downtime = $this->downtime;
|
||||
$this->view->isService = $this->isService;
|
||||
$this->view->stateName = isset($this->downtime->service_description) ?
|
||||
Service::getStateText($this->downtime->service_state) :
|
||||
Host::getStateText($this->downtime->host_state);
|
||||
$this->view->isService = $isService;
|
||||
$this->view->listAllLink = Url::fromPath('monitoring/list/downtimes');
|
||||
$this->view->showHostLink = Url::fromPath('monitoring/host/show')
|
||||
->setParam('host', $this->downtime->host_name);
|
||||
$this->view->showHostLink = Url::fromPath('monitoring/host/show')->setParam('host', $this->downtime->host_name);
|
||||
$this->view->showServiceLink = Url::fromPath('monitoring/service/show')
|
||||
->setParam('host', $this->downtime->host_name)
|
||||
->setParam('service', $this->downtime->service_description);
|
||||
$this->view->stateName = $isService ? Service::getStateText($this->downtime->service_state)
|
||||
: Host::getStateText($this->downtime->host_state);
|
||||
|
||||
if ($this->hasPermission('monitoring/command/downtime/delete')) {
|
||||
$this->view->delDowntimeForm = $this->createDelDowntimeForm();
|
||||
$this->view->delDowntimeForm->populate(
|
||||
array(
|
||||
'redirect' => Url::fromPath('monitoring/list/downtimes'),
|
||||
'downtime_id' => $this->downtime->id,
|
||||
'downtime_is_service' => $this->isService
|
||||
)
|
||||
);
|
||||
$form = new DeleteDowntimeCommandForm();
|
||||
$form
|
||||
->populate(array(
|
||||
'downtime_id' => $this->downtime->id,
|
||||
'downtime_is_service' => $isService,
|
||||
'redirect' => Url::fromPath('monitoring/list/downtimes'),
|
||||
))
|
||||
->handleRequest();
|
||||
$this->view->delDowntimeForm = $form;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Receive DeleteDowntimeCommandForm post from other controller
|
||||
*/
|
||||
public function removeAction()
|
||||
{
|
||||
$this->assertHttpMethod('POST');
|
||||
$this->createDelDowntimeForm();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a command form to delete a single comment
|
||||
*
|
||||
* @return DeleteDowntimeCommandForm
|
||||
*/
|
||||
private function createDelDowntimeForm()
|
||||
{
|
||||
$this->assertPermission('monitoring/command/downtime/delete');
|
||||
$delDowntimeForm = new DeleteDowntimeCommandForm();
|
||||
$delDowntimeForm->setAction(
|
||||
Url::fromPath('monitoring/downtime/show')
|
||||
->setParam('downtime_id', $this->downtime->id)
|
||||
);
|
||||
$delDowntimeForm->handleRequest();
|
||||
return $delDowntimeForm;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue