Fix downtime removal command in detail view
Use removal command for single downtimes in detail view. Move removing single and multiple downtimees into seperate forms. refs #8902
This commit is contained in:
parent
a46dece136
commit
d316b31cbb
|
@ -4,7 +4,7 @@
|
||||||
use Icinga\Module\Monitoring\Controller;
|
use Icinga\Module\Monitoring\Controller;
|
||||||
use Icinga\Module\Monitoring\Object\Service;
|
use Icinga\Module\Monitoring\Object\Service;
|
||||||
use Icinga\Module\Monitoring\Object\Host;
|
use Icinga\Module\Monitoring\Object\Host;
|
||||||
use Icinga\Module\Monitoring\Forms\Command\Object\DeleteDowntimeQuickCommandForm;
|
use Icinga\Module\Monitoring\Forms\Command\Object\DeleteDowntimeCommandForm;
|
||||||
use Icinga\Web\Url;
|
use Icinga\Web\Url;
|
||||||
use Icinga\Web\Widget\Tabextension\DashboardAction;
|
use Icinga\Web\Widget\Tabextension\DashboardAction;
|
||||||
|
|
||||||
|
@ -100,11 +100,17 @@ class Monitoring_DowntimeController extends Controller
|
||||||
{
|
{
|
||||||
$this->assertPermission('monitoring/command/downtime/delete');
|
$this->assertPermission('monitoring/command/downtime/delete');
|
||||||
|
|
||||||
$delDowntimeForm = new DeleteDowntimeQuickCommandForm();
|
$delDowntimeForm = new DeleteDowntimeCommandForm();
|
||||||
$delDowntimeForm->setDowntimes(array($this->downtime))
|
$delDowntimeForm->setAction(
|
||||||
->populate(
|
Url::fromPath('monitoring/downtime/show')
|
||||||
array('redirect' => Url::fromPath('monitoring/list/downtimes'))
|
->setParam('downtime_id', $this->downtime->id)
|
||||||
);
|
);
|
||||||
|
$delDowntimeForm->populate(
|
||||||
|
array(
|
||||||
|
'redirect' => Url::fromPath('monitoring/list/downtimes'),
|
||||||
|
'downtime_id' => $this->downtime->id
|
||||||
|
)
|
||||||
|
);
|
||||||
$delDowntimeForm->handleRequest();
|
$delDowntimeForm->handleRequest();
|
||||||
return $delDowntimeForm;
|
return $delDowntimeForm;
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@ use Icinga\Data\Filter\Filter;
|
||||||
use Icinga\Module\Monitoring\Controller;
|
use Icinga\Module\Monitoring\Controller;
|
||||||
use Icinga\Module\Monitoring\Object\Service;
|
use Icinga\Module\Monitoring\Object\Service;
|
||||||
use Icinga\Module\Monitoring\Object\Host;
|
use Icinga\Module\Monitoring\Object\Host;
|
||||||
use Icinga\Module\Monitoring\Forms\Command\Object\DeleteDowntimeCommandForm;
|
use Icinga\Module\Monitoring\Forms\Command\Object\DeleteDowntimesCommandForm;
|
||||||
use Icinga\Web\Url;
|
use Icinga\Web\Url;
|
||||||
use Icinga\Web\Widget\Tabextension\DashboardAction;
|
use Icinga\Web\Widget\Tabextension\DashboardAction;
|
||||||
|
|
||||||
|
@ -107,7 +107,7 @@ class Monitoring_DowntimesController extends Controller
|
||||||
$this->view->downtimes = $this->downtimes;
|
$this->view->downtimes = $this->downtimes;
|
||||||
$this->view->listAllLink = Url::fromPath('monitoring/list/downtimes')
|
$this->view->listAllLink = Url::fromPath('monitoring/list/downtimes')
|
||||||
->setQueryString($this->filter->toQueryString());
|
->setQueryString($this->filter->toQueryString());
|
||||||
$delDowntimeForm = new DeleteDowntimeCommandForm();
|
$delDowntimeForm = new DeleteDowntimesCommandForm();
|
||||||
$delDowntimeForm->setTitle($this->view->translate('Remove all Downtimes'));
|
$delDowntimeForm->setTitle($this->view->translate('Remove all Downtimes'));
|
||||||
$delDowntimeForm->addDescription(sprintf(
|
$delDowntimeForm->addDescription(sprintf(
|
||||||
$this->translate('Confirm removal of %d downtimes.'),
|
$this->translate('Confirm removal of %d downtimes.'),
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
use Icinga\Module\Monitoring\Controller;
|
use Icinga\Module\Monitoring\Controller;
|
||||||
use Icinga\Module\Monitoring\Backend;
|
use Icinga\Module\Monitoring\Backend;
|
||||||
use Icinga\Module\Monitoring\Forms\Command\Object\DeleteCommentCommandForm;
|
use Icinga\Module\Monitoring\Forms\Command\Object\DeleteCommentCommandForm;
|
||||||
use Icinga\Module\Monitoring\Forms\Command\Object\DeleteDowntimeQuickCommandForm;
|
use Icinga\Module\Monitoring\Forms\Command\Object\DeleteDowntimeCommandForm;
|
||||||
use Icinga\Web\Url;
|
use Icinga\Web\Url;
|
||||||
use Icinga\Web\Widget\Tabextension\DashboardAction;
|
use Icinga\Web\Widget\Tabextension\DashboardAction;
|
||||||
use Icinga\Web\Widget\Tabextension\OutputFormat;
|
use Icinga\Web\Widget\Tabextension\OutputFormat;
|
||||||
|
@ -294,7 +294,7 @@ class Monitoring_ListController extends Controller
|
||||||
));
|
));
|
||||||
|
|
||||||
if ($this->Auth()->hasPermission('monitoring/command/downtime/delete')) {
|
if ($this->Auth()->hasPermission('monitoring/command/downtime/delete')) {
|
||||||
$this->view->delDowntimeForm = new DeleteDowntimeQuickCommandForm();
|
$this->view->delDowntimeForm = new DeleteDowntimeCommandForm();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -12,8 +12,6 @@ use Icinga\Web\Notification;
|
||||||
*/
|
*/
|
||||||
class DeleteDowntimeCommandForm extends CommandForm
|
class DeleteDowntimeCommandForm extends CommandForm
|
||||||
{
|
{
|
||||||
protected $downtimes;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* (non-PHPDoc)
|
* (non-PHPDoc)
|
||||||
* @see \Zend_Form::init() For the method documentation.
|
* @see \Zend_Form::init() For the method documentation.
|
||||||
|
@ -22,50 +20,76 @@ class DeleteDowntimeCommandForm extends CommandForm
|
||||||
{
|
{
|
||||||
$this->setAttrib('class', 'inline');
|
$this->setAttrib('class', 'inline');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* (non-PHPDoc)
|
* (non-PHPDoc)
|
||||||
* @see \Icinga\Web\Form::createElements() For the method documentation.
|
* @see \Icinga\Web\Form::createElements() For the method documentation.
|
||||||
*/
|
*/
|
||||||
public function createElements(array $formData = array())
|
public function createElements(array $formData = array())
|
||||||
{
|
{
|
||||||
$this->addElements(array(
|
$this->addElements(
|
||||||
array(
|
array(
|
||||||
'hidden',
|
|
||||||
'redirect',
|
|
||||||
array(
|
array(
|
||||||
'decorators' => array('ViewHelper')
|
'hidden',
|
||||||
|
'downtime_id',
|
||||||
|
array(
|
||||||
|
'decorators' => array('ViewHelper')
|
||||||
|
)
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'hidden',
|
||||||
|
'redirect',
|
||||||
|
array(
|
||||||
|
'decorators' => array('ViewHelper')
|
||||||
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
));
|
);
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* (non-PHPDoc)
|
|
||||||
* @see \Icinga\Web\Form::getSubmitLabel() For the method documentation.
|
|
||||||
*/
|
|
||||||
public function getSubmitLabel()
|
|
||||||
{
|
|
||||||
return $this->translatePlural('Remove', 'Remove All', count($this->downtimes));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* (non-PHPDoc)
|
* (non-PHPDoc)
|
||||||
* @see \Icinga\Web\Form::onSuccess() For the method documentation.
|
* @see \Icinga\Web\Form::addSubmitButton() For the method documentation.
|
||||||
|
*/
|
||||||
|
public function addSubmitButton()
|
||||||
|
{
|
||||||
|
$this->addElement(
|
||||||
|
'button',
|
||||||
|
'btn_submit',
|
||||||
|
array(
|
||||||
|
'ignore' => true,
|
||||||
|
'escape' => false,
|
||||||
|
'type' => 'submit',
|
||||||
|
'class' => 'link-like',
|
||||||
|
'label' => $this->getView()->icon('trash'),
|
||||||
|
'title' => $this->translate('Delete this downtime'),
|
||||||
|
'decorators' => array('ViewHelper')
|
||||||
|
)
|
||||||
|
);
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* (non-PHPDoc)
|
||||||
|
* @see \Icinga\Web\Form::onSuccess() For the method documentation.
|
||||||
*/
|
*/
|
||||||
public function onSuccess()
|
public function onSuccess()
|
||||||
{
|
{
|
||||||
foreach ($this->downtimes as $downtime) {
|
$id = $this->getElement('downtime_id')->getValue();
|
||||||
$delDowntime = new DeleteDowntimeCommand();
|
|
||||||
$delDowntime->setDowntimeId($downtime->id);
|
// Presence of downtime id, only delete this specific downtime
|
||||||
$delDowntime->setDowntimeType(
|
$firstDowntime = $this->downtimes[0];
|
||||||
isset($downtime->service_description) ?
|
|
||||||
DeleteDowntimeCommand::DOWNTIME_TYPE_SERVICE :
|
$delDowntime = new DeleteDowntimeCommand();
|
||||||
DeleteDowntimeCommand::DOWNTIME_TYPE_HOST
|
$delDowntime->setDowntimeId($id);
|
||||||
);
|
$delDowntime->setDowntimeType(
|
||||||
$this->getTransport($this->request)->send($delDowntime);
|
isset($firstDowntime->service_description) ?
|
||||||
}
|
DeleteDowntimeCommand::DOWNTIME_TYPE_SERVICE :
|
||||||
|
DeleteDowntimeCommand::DOWNTIME_TYPE_HOST
|
||||||
|
);
|
||||||
|
$this->getTransport($this->request)->send($delDowntime);
|
||||||
|
|
||||||
$redirect = $this->getElement('redirect')->getValue();
|
$redirect = $this->getElement('redirect')->getValue();
|
||||||
if (! empty($redirect)) {
|
if (! empty($redirect)) {
|
||||||
$this->setRedirectUrl($redirect);
|
$this->setRedirectUrl($redirect);
|
||||||
|
@ -73,17 +97,4 @@ class DeleteDowntimeCommandForm extends CommandForm
|
||||||
Notification::success($this->translate('Deleting downtime.'));
|
Notification::success($this->translate('Deleting downtime.'));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Set the downtimes to be deleted upon success
|
|
||||||
*
|
|
||||||
* @param type $downtimes
|
|
||||||
*
|
|
||||||
* @return $this
|
|
||||||
*/
|
|
||||||
public function setDowntimes($downtimes)
|
|
||||||
{
|
|
||||||
$this->downtimes = $downtimes;
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,36 +0,0 @@
|
||||||
<?php
|
|
||||||
/* Icinga Web 2 | (c) 2013-2015 Icinga Development Team | GPLv2+ */
|
|
||||||
|
|
||||||
namespace Icinga\Module\Monitoring\Forms\Command\Object;
|
|
||||||
|
|
||||||
use Icinga\Module\Monitoring\Command\Object\DeleteDowntimeCommand;
|
|
||||||
use \Icinga\Module\Monitoring\Forms\Command\CommandForm;
|
|
||||||
use Icinga\Web\Notification;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Form for deleting host or service downtimes
|
|
||||||
*/
|
|
||||||
class DeleteDowntimeQuickCommandForm extends DeleteDowntimeCommandForm
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* (non-PHPDoc)
|
|
||||||
* @see \Icinga\Web\Form::addSubmitButton() For the method documentation.
|
|
||||||
*/
|
|
||||||
public function addSubmitButton()
|
|
||||||
{
|
|
||||||
$this->addElement(
|
|
||||||
'button',
|
|
||||||
'btn_submit',
|
|
||||||
array(
|
|
||||||
'ignore' => true,
|
|
||||||
'escape' => false,
|
|
||||||
'type' => 'submit',
|
|
||||||
'class' => 'link-like',
|
|
||||||
'label' => $this->getView()->icon('trash'),
|
|
||||||
'title' => $this->translate('Delete this downtime'),
|
|
||||||
'decorators' => array('ViewHelper')
|
|
||||||
)
|
|
||||||
);
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -0,0 +1,89 @@
|
||||||
|
<?php
|
||||||
|
/* Icinga Web 2 | (c) 2013-2015 Icinga Development Team | GPLv2+ */
|
||||||
|
|
||||||
|
namespace Icinga\Module\Monitoring\Forms\Command\Object;
|
||||||
|
|
||||||
|
use Icinga\Module\Monitoring\Command\Object\DeleteDowntimeCommand;
|
||||||
|
use \Icinga\Module\Monitoring\Forms\Command\CommandForm;
|
||||||
|
use Icinga\Web\Notification;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Form for deleting host or service downtimes
|
||||||
|
*/
|
||||||
|
class DeleteDowntimesCommandForm extends CommandForm
|
||||||
|
{
|
||||||
|
protected $downtimes;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* (non-PHPDoc)
|
||||||
|
* @see \Zend_Form::init() For the method documentation.
|
||||||
|
*/
|
||||||
|
public function init()
|
||||||
|
{
|
||||||
|
$this->setAttrib('class', 'inline');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* (non-PHPDoc)
|
||||||
|
* @see \Icinga\Web\Form::createElements() For the method documentation.
|
||||||
|
*/
|
||||||
|
public function createElements(array $formData = array())
|
||||||
|
{
|
||||||
|
$this->addElements(array(
|
||||||
|
array(
|
||||||
|
'hidden',
|
||||||
|
'redirect',
|
||||||
|
array(
|
||||||
|
'decorators' => array('ViewHelper')
|
||||||
|
)
|
||||||
|
)
|
||||||
|
));
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* (non-PHPDoc)
|
||||||
|
* @see \Icinga\Web\Form::getSubmitLabel() For the method documentation.
|
||||||
|
*/
|
||||||
|
public function getSubmitLabel()
|
||||||
|
{
|
||||||
|
return $this->translatePlural('Remove', 'Remove All', count($this->downtimes));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* (non-PHPDoc)
|
||||||
|
* @see \Icinga\Web\Form::onSuccess() For the method documentation.
|
||||||
|
*/
|
||||||
|
public function onSuccess()
|
||||||
|
{
|
||||||
|
foreach ($this->downtimes as $downtime) {
|
||||||
|
$delDowntime = new DeleteDowntimeCommand();
|
||||||
|
$delDowntime->setDowntimeId($downtime->id);
|
||||||
|
$delDowntime->setDowntimeType(
|
||||||
|
isset($downtime->service_description) ?
|
||||||
|
DeleteDowntimeCommand::DOWNTIME_TYPE_SERVICE :
|
||||||
|
DeleteDowntimeCommand::DOWNTIME_TYPE_HOST
|
||||||
|
);
|
||||||
|
$this->getTransport($this->request)->send($delDowntime);
|
||||||
|
}
|
||||||
|
$redirect = $this->getElement('redirect')->getValue();
|
||||||
|
if (! empty($redirect)) {
|
||||||
|
$this->setRedirectUrl($redirect);
|
||||||
|
}
|
||||||
|
Notification::success($this->translate('Deleting downtime.'));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the downtimes to be deleted upon success
|
||||||
|
*
|
||||||
|
* @param type $downtimes
|
||||||
|
*
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function setDowntimes($downtimes)
|
||||||
|
{
|
||||||
|
$this->downtimes = $downtimes;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
}
|
|
@ -89,9 +89,7 @@ abstract class MonitoredObjectController extends Controller
|
||||||
}
|
}
|
||||||
if (! empty($this->object->downtimes) && $auth->hasPermission('monitoring/command/downtime/delete')) {
|
if (! empty($this->object->downtimes) && $auth->hasPermission('monitoring/command/downtime/delete')) {
|
||||||
$delDowntimeForm = new DeleteDowntimeCommandForm();
|
$delDowntimeForm = new DeleteDowntimeCommandForm();
|
||||||
$delDowntimeForm
|
$delDowntimeForm->handleRequest();
|
||||||
->setDowntimes($this->object->downtimes)
|
|
||||||
->handleRequest();
|
|
||||||
$this->view->delDowntimeForm = $delDowntimeForm;
|
$this->view->delDowntimeForm = $delDowntimeForm;
|
||||||
}
|
}
|
||||||
$this->view->object = $this->object;
|
$this->view->object = $this->object;
|
||||||
|
|
Loading…
Reference in New Issue