Add abbillity to remove multiple comments by id

refs #8624
This commit is contained in:
Matthias Jentsch 2015-05-07 15:11:54 +02:00
parent ffd12e325c
commit 4463f16f04
6 changed files with 48 additions and 34 deletions

View File

@ -90,8 +90,8 @@ class Monitoring_CommentsController extends Controller
$this->translate('Confirm removal of %d comments.'), $this->translate('Confirm removal of %d comments.'),
count($this->comments) count($this->comments)
)); ));
$delCommentForm->setObjects($this->comments) $delCommentForm->setComments($this->comments)
->setRedirectUrl(Url::fromPath('monitoring/list/downtimes')) ->setRedirectUrl(Url::fromPath('monitoring/list/comments'))
->handleRequest(); ->handleRequest();
$this->view->delCommentForm = $delCommentForm; $this->view->delCommentForm = $delCommentForm;
} }

View File

@ -4,13 +4,21 @@
namespace Icinga\Module\Monitoring\Forms\Command\Object; namespace Icinga\Module\Monitoring\Forms\Command\Object;
use Icinga\Module\Monitoring\Command\Object\DeleteCommentCommand; use Icinga\Module\Monitoring\Command\Object\DeleteCommentCommand;
use \Icinga\Module\Monitoring\Forms\Command\CommandForm;
use Icinga\Web\Notification; use Icinga\Web\Notification;
/** /**
* Form for deleting host or service comments * Form for deleting host or service comments
*/ */
class DeleteCommentsCommandForm extends ObjectsCommandForm class DeleteCommentsCommandForm extends CommandForm
{ {
/**
* The comments deleted on success
*
* @var array
*/
protected $comments;
/** /**
* (non-PHPDoc) * (non-PHPDoc)
* @see \Zend_Form::init() For the method documentation. * @see \Zend_Form::init() For the method documentation.
@ -27,20 +35,10 @@ class DeleteCommentsCommandForm extends ObjectsCommandForm
public function createElements(array $formData = array()) public function createElements(array $formData = array())
{ {
$this->addElements(array( $this->addElements(array(
array(
'hidden',
'comment_id',
array(
'required' => true,
'decorators' => array('ViewHelper')
)
),
array( array(
'hidden', 'hidden',
'redirect', 'redirect',
array( array('decorators' => array('ViewHelper'))
'decorators' => array('ViewHelper')
)
) )
)); ));
return $this; return $this;
@ -74,13 +72,11 @@ class DeleteCommentsCommandForm extends ObjectsCommandForm
*/ */
public function onSuccess() public function onSuccess()
{ {
foreach ($this->objects as $object) { foreach ($this->comments as $comment) {
/** @var \Icinga\Module\Monitoring\Object\MonitoredObject $object */ $cmd = new DeleteCommentCommand();
$delComment = new DeleteCommentCommand(); $cmd->setCommentId($comment->id)
$delComment ->setIsService(isset($comment->service_description));
->setObject($object) $this->getTransport($this->request)->send($cmd);
->setCommentId($this->getElement('comment_id')->getValue());
$this->getTransport($this->request)->send($delComment);
} }
$redirect = $this->getElement('redirect')->getValue(); $redirect = $this->getElement('redirect')->getValue();
if (! empty($redirect)) { if (! empty($redirect)) {
@ -89,4 +85,17 @@ class DeleteCommentsCommandForm extends ObjectsCommandForm
Notification::success($this->translate('Deleting comment..')); Notification::success($this->translate('Deleting comment..'));
return true; return true;
} }
/**
* Set the comments to be deleted upon success
*
* @param array $comments
*
* @return this fluent interface
*/
public function setComments(array $comments)
{
$this->comments = $comments;
return $this;
}
} }

View File

@ -64,11 +64,7 @@ class DeleteDowntimesCommandForm extends CommandForm
foreach ($this->downtimes as $downtime) { foreach ($this->downtimes as $downtime) {
$delDowntime = new DeleteDowntimeCommand(); $delDowntime = new DeleteDowntimeCommand();
$delDowntime->setDowntimeId($downtime->id); $delDowntime->setDowntimeId($downtime->id);
$delDowntime->setDowntimeType( $delDowntime->setIsService(isset($downtime->service_description));
isset($downtime->service_description) ?
DeleteDowntimeCommand::DOWNTIME_TYPE_SERVICE :
DeleteDowntimeCommand::DOWNTIME_TYPE_HOST
);
$this->getTransport($this->request)->send($delDowntime); $this->getTransport($this->request)->send($delDowntime);
} }
$redirect = $this->getElement('redirect')->getValue(); $redirect = $this->getElement('redirect')->getValue();
@ -86,7 +82,7 @@ class DeleteDowntimesCommandForm extends CommandForm
* *
* @return $this * @return $this
*/ */
public function setDowntimes($downtimes) public function setDowntimes(array $downtimes)
{ {
$this->downtimes = $downtimes; $this->downtimes = $downtimes;
return $this; return $this;

View File

@ -83,7 +83,13 @@ if (count($comments) === 0) {
<td style="width: 2em" data-base-target="self"> <td style="width: 2em" data-base-target="self">
<?php <?php
$delCommentForm = clone $delCommentForm; $delCommentForm = clone $delCommentForm;
$delCommentForm->populate(array('comment_id' => $comment->id, 'redirect' => $this->url)); $delCommentForm->populate(
array(
'comment_id' => $comment->id,
'comment_is_service' => isset($comment->service_description),
'redirect' => $this->url
)
);
$delCommentForm->setAction($this->url('monitoring/comment/remove', array('comment_id' => $comment->id))); $delCommentForm->setAction($this->url('monitoring/comment/remove', array('comment_id' => $comment->id)));
echo $delCommentForm; echo $delCommentForm;
?> ?>

View File

@ -128,7 +128,12 @@ if (count($downtimes) === 0) {
<td style="width: 2em" data-base-target="self"> <td style="width: 2em" data-base-target="self">
<?php <?php
$delDowntimeForm = clone $delDowntimeForm; $delDowntimeForm = clone $delDowntimeForm;
$delDowntimeForm->populate(array('downtime_id' => $downtime->id, 'redirect' => $this->url)); $delDowntimeForm->populate(
array(
'downtime_id' => $downtime->id,
'redirect' => $this->url
)
);
$delDowntimeForm->setAction($this->url('monitoring/downtime/remove', array('downtime_id' => $downtime->id))); $delDowntimeForm->setAction($this->url('monitoring/downtime/remove', array('downtime_id' => $downtime->id)));
echo $delDowntimeForm; echo $delDowntimeForm;
?> ?>

View File

@ -5,7 +5,7 @@ namespace Icinga\Module\Monitoring\Web\Controller;
use Icinga\Module\Monitoring\Controller; use Icinga\Module\Monitoring\Controller;
use Icinga\Module\Monitoring\Forms\Command\Object\CheckNowCommandForm; use Icinga\Module\Monitoring\Forms\Command\Object\CheckNowCommandForm;
use Icinga\Module\Monitoring\Forms\Command\Object\DeleteCommentsCommandForm; use Icinga\Module\Monitoring\Forms\Command\Object\DeleteCommentCommandForm;
use Icinga\Module\Monitoring\Forms\Command\Object\DeleteDowntimeCommandForm; use Icinga\Module\Monitoring\Forms\Command\Object\DeleteDowntimeCommandForm;
use Icinga\Module\Monitoring\Forms\Command\Object\ObjectsCommandForm; use Icinga\Module\Monitoring\Forms\Command\Object\ObjectsCommandForm;
use Icinga\Module\Monitoring\Forms\Command\Object\RemoveAcknowledgementCommandForm; use Icinga\Module\Monitoring\Forms\Command\Object\RemoveAcknowledgementCommandForm;
@ -81,10 +81,8 @@ abstract class MonitoredObjectController extends Controller
->handleRequest(); ->handleRequest();
$this->view->toggleFeaturesForm = $toggleFeaturesForm; $this->view->toggleFeaturesForm = $toggleFeaturesForm;
if (! empty($this->object->comments) && $auth->hasPermission('monitoring/command/comment/delete')) { if (! empty($this->object->comments) && $auth->hasPermission('monitoring/command/comment/delete')) {
$delCommentForm = new DeleteCommentsCommandForm(); $delCommentForm = new DeleteCommentCommandForm();
$delCommentForm $delCommentForm->handleRequest();
->setObjects($this->object)
->handleRequest();
$this->view->delCommentForm = $delCommentForm; $this->view->delCommentForm = $delCommentForm;
} }
if (! empty($this->object->downtimes) && $auth->hasPermission('monitoring/command/downtime/delete')) { if (! empty($this->object->downtimes) && $auth->hasPermission('monitoring/command/downtime/delete')) {