Skip to content

Commit

Permalink
Add basic comment detail view
Browse files Browse the repository at this point in the history
refs #8903
  • Loading branch information
majentsch committed May 7, 2015
1 parent 2ade247 commit dedc175
Show file tree
Hide file tree
Showing 4 changed files with 248 additions and 8 deletions.
88 changes: 88 additions & 0 deletions modules/monitoring/application/controllers/CommentController.php
@@ -0,0 +1,88 @@
<?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;

/*
* 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 comment
*/
class Monitoring_CommentController extends Controller
{
protected $comment;

/**
* Add tabs
*/
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());
}

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

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;
}
}
76 changes: 76 additions & 0 deletions modules/monitoring/application/views/scripts/comment/show.phtml
@@ -0,0 +1,76 @@
<div class="controls">
<?php if (! $this->compact): ?>
<?= $this->tabs; ?>
<?php endif ?>

<?= $this->render('partials/comment/comment-header.phtml'); ?>
</div>
<div class="content">

<h3><?= $this->translate('Comment detail information') ?></h3>
<table class="avp">
<tbody>
<tr>
<?php if ($this->comment->objecttype === 'service'): ?>
<th> <?= $this->translate('Service') ?> </th>
<td>
<?= $this->icon('service', $this->translate('Service')); ?>
<?= $this->link()->service(
$this->comment->service_description,
$this->comment->service_display_name,
$this->comment->host_name,
$this->comment->host_display_name
); ?>
</td>
<?php else: ?>
<th> <?= $this->translate('Host') ?> </th>
<td>
<?= $this->icon('host', $this->translate('Host')); ?>
<?= $this->link()->host(
$this->comment->host_name,
$this->comment->host_display_name
); ?>
</td>
<?php endif ?>
</tr>

<tr>
<th><?= $this->translate('Author') ?></th>
<td><?= $this->icon('user', $this->translate('User')) ?> <?= $this->escape($this->comment->author) ?></td>
</tr>

<tr>
<th><?= $this->translate('Persistent') ?></th>
<td><?= $this->escape($this->comment->persistent) ? $this->translate('Yes') : $this->translate('No') ?></td>
</tr>

<tr>
<th><?= $this->translate('Created') ?></th>
<td><?= date('d.m.y H:i' ,$this->escape($this->comment->timestamp)) ?></td>
</tr>

<tr>
<th><?= $this->translate('Expires') ?></th>
<td>
<?= $this->comment->expiration ? sprintf(
$this->translate('This comment expires on %s at %s.'),
date('d.m.y', $this->comment->expiration),
date('H:i', $this->comment->expiration)
) : $this->translate('This comment does not expire.'); ?>
</td>
</tr>

<?php if (isset($delCommentForm)): // Form is unset if the current user lacks the respective permission ?>
<tr class="newsection">
<th><?= $this->translate('Commands') ?></th>
<td>
<?= $delCommentForm ?>
</td>
</tr>
<?php endif ?>

</tbody>
</table>

</div>

35 changes: 27 additions & 8 deletions modules/monitoring/application/views/scripts/list/comments.phtml
Expand Up @@ -15,7 +15,10 @@ if (count($comments) === 0) {
return;
}
?>
<table data-base-target="_next" class="action comments">
<table data-base-target="_next"
class="action comments multiselect"
data-icinga-multiselect-url="/icingaweb2/monitoring/comments/show"
data-icinga-multiselect-data="downtime_id">
<tbody>
<?php foreach ($comments as $comment): ?>
<?php
Expand Down Expand Up @@ -53,15 +56,31 @@ if (count($comments) === 0) {
<td>
<?php if ($comment->objecttype === 'service'): ?>
<?= $this->icon('service', $this->translate('Service')); ?>
<?= $this->link()->service(
$comment->service_description,
$comment->service_display_name,
$comment->host_name,
$comment->host_display_name
); ?>

<?= $this->qlink(
sprintf(
$this->translate('%s on %s', 'Service running on host'),
$comment->service_display_name,
$comment->host_display_name
),
'monitoring/comment/show',
array('comment_id' => $comment->id),
array('title' => sprintf(
$this->translate('Show detailed information for comment on %s for %s'),
$comment->service_display_name,
$comment->host_display_name
))) ?>
<?php else: ?>
<?= $this->icon('host', $this->translate('Host')); ?>
<?= $this->link()->host($comment->host_name, $comment->host_display_name); ?>

<?= $this->qlink(
$comment->host_display_name,
'monitoring/comment/show',
array('comment_id' => $comment->id),
array('title' => sprintf(
$this->translate('Show detailed information for comment on %s'),
$comment->host_display_name
))) ?>
<?php endif ?>
<br>
<?= $this->icon('comment', $this->translate('Comment')); ?> <?= isset($comment->author)
Expand Down
@@ -0,0 +1,57 @@
<table class="action">
<tr class="state invalid">
<td class="state">

<?php
switch ($comment->type) {
case 'flapping':
$icon = 'flapping';
$title = $this->translate('Flapping');
$tooltip = $this->translate('Comment was caused by a flapping host or service.');
break;
case 'comment':
$icon = 'user';
$title = $this->translate('User Comment');
$tooltip = $this->translate('Comment was created by an user.');
break;
case 'downtime':
$icon = 'plug';
$title = $this->translate('Downtime');
$tooltip = $this->translate('Comment was caused by a downtime.');
break;
case 'ack':
$icon = 'ok';
$title = $this->translate('Acknowledgement');
$tooltip = $this->translate('Comment was caused by an acknowledgement.');
break;
}
?>

<strong><?= $this->escape($title); ?></strong>
<br>
<?= $this->icon($icon, $tooltip) ?>
<?= $this->prefixedTimeSince($comment->timestamp); ?>
</td>

<td>
<?php if ($comment->objecttype === 'service'): ?>
<?= $this->icon('service', $this->translate('Service')); ?>
<?= $this->link()->service(
$comment->service_description,
$comment->service_display_name,
$comment->host_name,
$comment->host_display_name
); ?>
<?php else: ?>
<?= $this->icon('host', $this->translate('Host')); ?>
<?= $this->link()->host($comment->host_name, $comment->host_display_name); ?>
<?php endif ?>

<br>
<?= $this->icon('comment', $this->translate('Comment')); ?> <?= isset($comment->author)
? '[' . $comment->author . '] '
: '';
?><?= $this->escape($comment->comment); ?>
</td>
</tr>
</table>

0 comments on commit dedc175

Please sign in to comment.