Skip to content

Commit

Permalink
Fix downtime removal command in detail view
Browse files Browse the repository at this point in the history
Use removal command for single downtimes in detail view. Move removing single and multiple downtimees into seperate forms.

refs #8902
  • Loading branch information
majentsch committed May 7, 2015
1 parent a46dece commit d316b31
Show file tree
Hide file tree
Showing 7 changed files with 155 additions and 87 deletions.
18 changes: 12 additions & 6 deletions modules/monitoring/application/controllers/DowntimeController.php
Expand Up @@ -4,7 +4,7 @@
use Icinga\Module\Monitoring\Controller;
use Icinga\Module\Monitoring\Object\Service;
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\Widget\Tabextension\DashboardAction;

Expand Down Expand Up @@ -100,11 +100,17 @@ private function createDelDowntimeForm()
{
$this->assertPermission('monitoring/command/downtime/delete');

$delDowntimeForm = new DeleteDowntimeQuickCommandForm();
$delDowntimeForm->setDowntimes(array($this->downtime))
->populate(
array('redirect' => Url::fromPath('monitoring/list/downtimes'))
);
$delDowntimeForm = new DeleteDowntimeCommandForm();
$delDowntimeForm->setAction(
Url::fromPath('monitoring/downtime/show')
->setParam('downtime_id', $this->downtime->id)
);
$delDowntimeForm->populate(
array(
'redirect' => Url::fromPath('monitoring/list/downtimes'),
'downtime_id' => $this->downtime->id
)
);
$delDowntimeForm->handleRequest();
return $delDowntimeForm;
}
Expand Down
Expand Up @@ -5,7 +5,7 @@
use Icinga\Module\Monitoring\Controller;
use Icinga\Module\Monitoring\Object\Service;
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\Widget\Tabextension\DashboardAction;

Expand Down Expand Up @@ -107,7 +107,7 @@ public function removeAllAction()
$this->view->downtimes = $this->downtimes;
$this->view->listAllLink = Url::fromPath('monitoring/list/downtimes')
->setQueryString($this->filter->toQueryString());
$delDowntimeForm = new DeleteDowntimeCommandForm();
$delDowntimeForm = new DeleteDowntimesCommandForm();
$delDowntimeForm->setTitle($this->view->translate('Remove all Downtimes'));
$delDowntimeForm->addDescription(sprintf(
$this->translate('Confirm removal of %d downtimes.'),
Expand Down
4 changes: 2 additions & 2 deletions modules/monitoring/application/controllers/ListController.php
Expand Up @@ -4,7 +4,7 @@
use Icinga\Module\Monitoring\Controller;
use Icinga\Module\Monitoring\Backend;
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\Widget\Tabextension\DashboardAction;
use Icinga\Web\Widget\Tabextension\OutputFormat;
Expand Down Expand Up @@ -294,7 +294,7 @@ public function downtimesAction()
));

if ($this->Auth()->hasPermission('monitoring/command/downtime/delete')) {
$this->view->delDowntimeForm = new DeleteDowntimeQuickCommandForm();
$this->view->delDowntimeForm = new DeleteDowntimeCommandForm();
}
}

Expand Down
Expand Up @@ -12,8 +12,6 @@
*/
class DeleteDowntimeCommandForm extends CommandForm
{
protected $downtimes;

/**
* (non-PHPDoc)
* @see \Zend_Form::init() For the method documentation.
Expand All @@ -22,68 +20,81 @@ 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(
$this->addElements(
array(
'hidden',
'redirect',
array(
'decorators' => array('ViewHelper')
'hidden',
'downtime_id',
array(
'decorators' => array('ViewHelper')
)
),
array(
'hidden',
'redirect',
array(
'decorators' => array('ViewHelper')
)
)
)
));
);
return $this;
}

/**
* (non-PHPDoc)
* @see \Icinga\Web\Form::getSubmitLabel() For the method documentation.
* @see \Icinga\Web\Form::addSubmitButton() For the method documentation.
*/
public function getSubmitLabel()
public function addSubmitButton()
{
return $this->translatePlural('Remove', 'Remove All', count($this->downtimes));
$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.
* @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);
}
$id = $this->getElement('downtime_id')->getValue();

// Presence of downtime id, only delete this specific downtime
$firstDowntime = $this->downtimes[0];

$delDowntime = new DeleteDowntimeCommand();
$delDowntime->setDowntimeId($id);
$delDowntime->setDowntimeType(
isset($firstDowntime->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;
}
}

This file was deleted.

@@ -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;
}
}
Expand Up @@ -89,9 +89,7 @@ public function showAction()
}
if (! empty($this->object->downtimes) && $auth->hasPermission('monitoring/command/downtime/delete')) {
$delDowntimeForm = new DeleteDowntimeCommandForm();
$delDowntimeForm
->setDowntimes($this->object->downtimes)
->handleRequest();
$delDowntimeForm->handleRequest();
$this->view->delDowntimeForm = $delDowntimeForm;
}
$this->view->object = $this->object;
Expand Down

0 comments on commit d316b31

Please sign in to comment.