Skip to content

Commit

Permalink
Merge branch 'feature/comment-detail-view-8903'
Browse files Browse the repository at this point in the history
resolves #8903
  • Loading branch information
majentsch committed May 7, 2015
2 parents 2ade247 + 7c8ff44 commit f2d89ae
Show file tree
Hide file tree
Showing 18 changed files with 562 additions and 108 deletions.
105 changes: 105 additions & 0 deletions modules/monitoring/application/controllers/CommentController.php
@@ -0,0 +1,105 @@
<?php
/* Icinga Web 2 | (c) 2013-2015 Icinga Development Team | GPLv2+ */

use Icinga\Module\Monitoring\Controller;
use Icinga\Module\Monitoring\Forms\Command\Object\DeleteCommentCommandForm;
use Icinga\Web\Url;
use Icinga\Web\Widget\Tabextension\DashboardAction;

/**
* Display detailed information about a comment
*/
class Monitoring_CommentController extends Controller
{
/**
* The fetched comment
*
* @var stdClass
*/
protected $comment;

/**
* Fetch the first comment with the given id and add tabs
*
* @throws Zend_Controller_Action_Exception
*/
public function init()
{
$commentId = $this->params->get('comment_id');

$this->comment = $this->backend->select()->from('comment', array(
'id' => 'comment_internal_id',
'objecttype' => 'comment_objecttype',
'comment' => 'comment_data',
'author' => 'comment_author_name',
'timestamp' => 'comment_timestamp',
'type' => 'comment_type',
'persistent' => 'comment_is_persistent',
'expiration' => 'comment_expiration',
'host_name',
'service_description',
'host_display_name',
'service_display_name'
))->where('comment_internal_id', $commentId)->getQuery()->fetchRow();

if (false === $this->comment) {
throw new Zend_Controller_Action_Exception($this->translate('Comment not found'));
}

$this->getTabs()->add(
'comment',
array(
'title' => $this->translate(
'Display detailed information about a comment.'
),
'icon' => 'comment',
'label' => $this->translate('Comment'),
'url' =>'monitoring/comments/show'
)
)->activate('comment')->extend(new DashboardAction());
}

/**
* Display comment detail view
*/
public function showAction()
{
$this->view->comment = $this->comment;
if ($this->hasPermission('monitoring/command/comment/delete')) {
$this->view->delCommentForm = $this->createDelCommentForm();
}
}

/**
* Receive DeleteCommentCommandForm post from other controller
*/
public function removeAction()
{
$this->assertHttpMethod('POST');
$this->createDelCommentForm();
}

/**
* Create a command form to delete a single comment
*
* @return DeleteCommentCommandForm
*/
private function createDelCommentForm()
{
$this->assertPermission('monitoring/command/comment/delete');

$delCommentForm = new DeleteCommentCommandForm();
$delCommentForm->setAction(
Url::fromPath('monitoring/comment/show')
->setParam('comment_id', $this->comment->id)
);
$delCommentForm->populate(
array(
'redirect' => Url::fromPath('monitoring/list/comments'),
'comment_id' => $this->comment->id
)
);
$delCommentForm->handleRequest();
return $delCommentForm;
}
}
98 changes: 98 additions & 0 deletions modules/monitoring/application/controllers/CommentsController.php
@@ -0,0 +1,98 @@
<?php
/* Icinga Web 2 | (c) 2013-2015 Icinga Development Team | GPLv2+ */

use Icinga\Module\Monitoring\Controller;
use Icinga\Module\Monitoring\Forms\Command\Object\DeleteCommentCommandForm;
use Icinga\Web\Url;
use Icinga\Web\Widget\Tabextension\DashboardAction;
use Icinga\Data\Filter\Filter;

/**
* Display detailed information about a comment
*/
class Monitoring_CommentsController extends Controller
{
/**
* The fetched comments
*
* @var array
*/
protected $comments;

/**
* Fetch all comments matching the current filter and add tabs
*
* @throws Zend_Controller_Action_Exception
*/
public function init()
{
$this->filter = Filter::fromQueryString(str_replace(
'comment_id',
'comment_internal_id',
(string)$this->params
));
$this->comments = $this->backend->select()->from('comment', array(
'id' => 'comment_internal_id',
'objecttype' => 'comment_objecttype',
'comment' => 'comment_data',
'author' => 'comment_author_name',
'timestamp' => 'comment_timestamp',
'type' => 'comment_type',
'persistent' => 'comment_is_persistent',
'expiration' => 'comment_expiration',
'host_name',
'service_description',
'host_display_name',
'service_display_name'
))->addFilter($this->filter)->getQuery()->fetchAll();

if (false === $this->comments) {
throw new Zend_Controller_Action_Exception($this->translate('Comment not found'));
}

$this->getTabs()->add(
'comments',
array(
'title' => $this->translate(
'Display detailed information about multiple comments.'
),
'icon' => 'comment',
'label' => $this->translate('Comments'),
'url' =>'monitoring/comments/show'
)
)->activate('comments');
}

/**
* Display the detail view for a comment list
*/
public function showAction()
{
$this->view->comments = $this->comments;
$this->view->listAllLink = Url::fromPath('monitoring/list/comments')
->setQueryString($this->filter->toQueryString());
$this->view->removeAllLink = Url::fromPath('monitoring/comments/remove-all')
->setParams($this->params);
}

/**
* Display the form for removing a comment list
*/
public function removeAllAction()
{
$this->assertPermission('monitoring/command/comment/delete');
$this->view->comments = $this->comments;
$this->view->listAllLink = Url::fromPath('monitoring/list/comments')
->setQueryString($this->filter->toQueryString());
$delCommentForm = new DeleteCommentCommandForm();
$delCommentForm->setTitle($this->view->translate('Remove all Comments'));
$delCommentForm->addDescription(sprintf(
$this->translate('Confirm removal of %d comments.'),
count($this->comments)
));
$delCommentForm->setObjects($this->comments)
->setRedirectUrl(Url::fromPath('monitoring/list/downtimes'))
->handleRequest();
$this->view->delCommentForm = $delCommentForm;
}
}
47 changes: 35 additions & 12 deletions modules/monitoring/application/controllers/DowntimeController.php
Expand Up @@ -8,23 +8,29 @@
use Icinga\Web\Url;
use Icinga\Web\Widget\Tabextension\DashboardAction;

/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/

/**
* Display detailed information about a downtime
*/
class Monitoring_DowntimeController extends Controller
{
/**
* The fetched downtime
*
* @var stdClass
*/
protected $downtime;


/**
* If the downtime is a service or not
*
* @var boolean
*/
protected $isService;

/**
* Add tabs
* Fetch the downtime matching the given id and add tabs
*
* @throws Zend_Controller_Action_Exception
*/
public function init()
{
Expand Down Expand Up @@ -63,7 +69,7 @@ public function init()
} else {
$this->isService = false;
}

$this->getTabs()
->add(
'downtime',
Expand All @@ -77,7 +83,10 @@ public function init()
)
)->activate('downtime')->extend(new DashboardAction());
}


/**
* Display the detail view for a downtime
*/
public function showAction()
{
$this->view->downtime = $this->downtime;
Expand All @@ -95,7 +104,21 @@ public function showAction()
$this->view->delDowntimeForm = $this->createDelDowntimeForm();
}
}


/**
* 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');
Expand Down

0 comments on commit f2d89ae

Please sign in to comment.