monitoring: Fix mess in CommentsController and the related view script

This commit is contained in:
Eric Lippmann 2015-08-27 16:04:24 +02:00
parent 78701ab2b6
commit 2533ebc8d5
2 changed files with 28 additions and 27 deletions

View File

@ -9,28 +9,33 @@ use Icinga\Module\Monitoring\Forms\Command\Object\DeleteCommentsCommandForm;
use Icinga\Web\Url; use Icinga\Web\Url;
/** /**
* Display detailed information about a comment * Display detailed information about comments
*/ */
class CommentsController extends Controller class CommentsController extends Controller
{ {
/** /**
* The fetched comments * The comments view
* *
* @var array * @var \Icinga\Module\Monitoring\DataView\Comment
*/ */
protected $comments; protected $comments;
/** /**
* Fetch all comments matching the current filter and add tabs * Filter from request
* *
* @throws Zend_Controller_Action_Exception * @var Filter
*/
protected $filter;
/**
* Fetch all comments matching the current filter and add tabs
*/ */
public function init() public function init()
{ {
$this->filter = Filter::fromQueryString(str_replace( $this->filter = Filter::fromQueryString(str_replace(
'comment_id', 'comment_id',
'comment_internal_id', 'comment_internal_id',
(string)$this->params (string) $this->params
)); ));
$query = $this->backend->select()->from('comment', array( $query = $this->backend->select()->from('comment', array(
'id' => 'comment_internal_id', 'id' => 'comment_internal_id',
@ -48,19 +53,16 @@ class CommentsController extends Controller
))->addFilter($this->filter); ))->addFilter($this->filter);
$this->applyRestriction('monitoring/filter/objects', $query); $this->applyRestriction('monitoring/filter/objects', $query);
$this->comments = $query->getQuery()->fetchAll(); $this->comments = $query;
if (false === $this->comments) {
throw new Zend_Controller_Action_Exception($this->translate('Comment not found'));
}
$this->getTabs()->add( $this->getTabs()->add(
'comments', 'comments',
array( array(
'icon' => 'comment',
'label' => $this->translate('Comments') . sprintf(' (%d)', $query->count()),
'title' => $this->translate( 'title' => $this->translate(
'Display detailed information about multiple comments.' 'Display detailed information about multiple comments.'
), ),
'icon' => 'comment',
'label' => $this->translate('Comments') . sprintf(' (%d)', count($this->comments)),
'url' =>'monitoring/comments/show' 'url' =>'monitoring/comments/show'
) )
)->activate('comments'); )->activate('comments');
@ -91,9 +93,9 @@ class CommentsController extends Controller
$delCommentForm->setTitle($this->view->translate('Remove all Comments')); $delCommentForm->setTitle($this->view->translate('Remove all Comments'));
$delCommentForm->addDescription(sprintf( $delCommentForm->addDescription(sprintf(
$this->translate('Confirm removal of %d comments.'), $this->translate('Confirm removal of %d comments.'),
count($this->comments) $this->comments->count()
)); ));
$delCommentForm->setComments($this->comments) $delCommentForm->setComments($this->comments->fetchAll())
->setRedirectUrl($listCommentsLink) ->setRedirectUrl($listCommentsLink)
->handleRequest(); ->handleRequest();
$this->view->delCommentForm = $delCommentForm; $this->view->delCommentForm = $delCommentForm;

View File

@ -1,19 +1,18 @@
<div class="controls"> <div class="controls">
<?php if (! $this->compact): ?> <?php if (! $this->compact): ?>
<?= $this->tabs; ?> <?= $this->tabs ?>
<?php endif ?> <?php endif ?>
<div data-base-target='_next'> <div data-base-target='_next'>
<?= $this->render('partials/comment/comments-header.phtml'); ?> <?= $this->render('partials/comment/comments-header.phtml') ?>
</div> </div>
</div> </div>
<div class="content multi-commands"> <div class="content multi-commands">
<h3><?= $this->icon('reschedule') ?> <?= $this->translate('Commands') ?> </h3> <h3><?= $this->icon('reschedule') ?><?= $this->translate('Commands') ?></h3>
<?= $this->qlink( <?= $this->qlink(
sprintf( sprintf(
$this->translate('Remove %d comments'), $this->translate('Remove %d comments'),
count($comments) $comments->count()
), ),
$removeAllLink, $removeAllLink,
null, null,