Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feature/comment-detail-view-8903'
resolves #8903
- Loading branch information
Showing
18 changed files
with
562 additions
and
108 deletions.
There are no files selected for viewing
105 changes: 105 additions & 0 deletions
105
modules/monitoring/application/controllers/CommentController.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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
98
modules/monitoring/application/controllers/CommentsController.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.