Skip to content

Commit

Permalink
Add abbillity to remove multiple comments by id
Browse files Browse the repository at this point in the history
refs #8624
  • Loading branch information
majentsch committed May 7, 2015
1 parent ffd12e3 commit 4463f16
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 34 deletions.
Expand Up @@ -90,8 +90,8 @@ public function removeAllAction()
$this->translate('Confirm removal of %d comments.'),
count($this->comments)
));
$delCommentForm->setObjects($this->comments)
->setRedirectUrl(Url::fromPath('monitoring/list/downtimes'))
$delCommentForm->setComments($this->comments)
->setRedirectUrl(Url::fromPath('monitoring/list/comments'))
->handleRequest();
$this->view->delCommentForm = $delCommentForm;
}
Expand Down
Expand Up @@ -4,13 +4,21 @@
namespace Icinga\Module\Monitoring\Forms\Command\Object;

use Icinga\Module\Monitoring\Command\Object\DeleteCommentCommand;
use \Icinga\Module\Monitoring\Forms\Command\CommandForm;
use Icinga\Web\Notification;

/**
* 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)
* @see \Zend_Form::init() For the method documentation.
Expand All @@ -27,20 +35,10 @@ public function init()
public function createElements(array $formData = array())
{
$this->addElements(array(
array(
'hidden',
'comment_id',
array(
'required' => true,
'decorators' => array('ViewHelper')
)
),
array(
'hidden',
'redirect',
array(
'decorators' => array('ViewHelper')
)
array('decorators' => array('ViewHelper'))
)
));
return $this;
Expand Down Expand Up @@ -74,13 +72,11 @@ public function addSubmitButton()
*/
public function onSuccess()
{
foreach ($this->objects as $object) {
/** @var \Icinga\Module\Monitoring\Object\MonitoredObject $object */
$delComment = new DeleteCommentCommand();
$delComment
->setObject($object)
->setCommentId($this->getElement('comment_id')->getValue());
$this->getTransport($this->request)->send($delComment);
foreach ($this->comments as $comment) {
$cmd = new DeleteCommentCommand();
$cmd->setCommentId($comment->id)
->setIsService(isset($comment->service_description));
$this->getTransport($this->request)->send($cmd);
}
$redirect = $this->getElement('redirect')->getValue();
if (! empty($redirect)) {
Expand All @@ -89,4 +85,17 @@ public function onSuccess()
Notification::success($this->translate('Deleting comment..'));
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;
}
}
Expand Up @@ -64,11 +64,7 @@ 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
);
$delDowntime->setIsService(isset($downtime->service_description));
$this->getTransport($this->request)->send($delDowntime);
}
$redirect = $this->getElement('redirect')->getValue();
Expand All @@ -86,7 +82,7 @@ public function onSuccess()
*
* @return $this
*/
public function setDowntimes($downtimes)
public function setDowntimes(array $downtimes)
{
$this->downtimes = $downtimes;
return $this;
Expand Down
Expand Up @@ -83,7 +83,13 @@ if (count($comments) === 0) {
<td style="width: 2em" data-base-target="self">
<?php
$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)));
echo $delCommentForm;
?>
Expand Down
Expand Up @@ -128,7 +128,12 @@ if (count($downtimes) === 0) {
<td style="width: 2em" data-base-target="self">
<?php
$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)));
echo $delDowntimeForm;
?>
Expand Down
Expand Up @@ -5,7 +5,7 @@

use Icinga\Module\Monitoring\Controller;
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\ObjectsCommandForm;
use Icinga\Module\Monitoring\Forms\Command\Object\RemoveAcknowledgementCommandForm;
Expand Down Expand Up @@ -81,10 +81,8 @@ public function showAction()
->handleRequest();
$this->view->toggleFeaturesForm = $toggleFeaturesForm;
if (! empty($this->object->comments) && $auth->hasPermission('monitoring/command/comment/delete')) {
$delCommentForm = new DeleteCommentsCommandForm();
$delCommentForm
->setObjects($this->object)
->handleRequest();
$delCommentForm = new DeleteCommentCommandForm();
$delCommentForm->handleRequest();
$this->view->delCommentForm = $delCommentForm;
}
if (! empty($this->object->downtimes) && $auth->hasPermission('monitoring/command/downtime/delete')) {
Expand Down

0 comments on commit 4463f16

Please sign in to comment.