object/show: make downtimes look like comments

refs #8281
This commit is contained in:
Thomas Gelf 2015-06-18 14:57:58 +02:00
parent a4ab4db1ca
commit 171b1d84ef

View File

@ -1,10 +1,11 @@
<tr> <?php
<th><?= $this->translate('Downtimes'); ?></th>
<td> $addLink = '';
<?php if ($this->hasPermission('monitoring/command/downtime/schedule')) {
if ($this->hasPermission('monitoring/command/downtime/schedule')) {
/** @var \Icinga\Module\Monitoring\Object\MonitoredObject $object */ /** @var \Icinga\Module\Monitoring\Object\MonitoredObject $object */
if ($object->getType() === $object::TYPE_HOST) { if ($object->getType() === $object::TYPE_HOST) {
echo $this->qlink( $addLink = $this->qlink(
$this->translate('Schedule downtime'), $this->translate('Schedule downtime'),
'monitoring/host/schedule-downtime', 'monitoring/host/schedule-downtime',
array('host' => $object->getName()), array('host' => $object->getName()),
@ -17,7 +18,7 @@
) )
); );
} else { } else {
echo $this->qlink( $addLink = $this->qlink(
$this->translate('Schedule downtime'), $this->translate('Schedule downtime'),
'monitoring/service/schedule-downtime', 'monitoring/service/schedule-downtime',
array('host' => $object->getHost()->getName(), 'service' => $object->getName()), array('host' => $object->getHost()->getName(), 'service' => $object->getName()),
@ -30,15 +31,33 @@
) )
); );
} }
} else { }
echo '&#45;';
} ?>
</td>
</tr>
if (empty($object->comments) && ! $addLink) {
return;
}
?>
<tr>
<th><?php
echo $this->translate('Downtimes');
if (! empty($object->downtimes) && $addLink) {
echo '<br />' . $addLink;
}
?></th>
<td data-base-target="_self">
<?php if (empty($object->downtimes)): ?>
<?= $addLink ?>
<?php else: ?>
<ul class="inline-comments">
<?php foreach ($object->downtimes as $downtime): ?>
<?php <?php
foreach ($object->downtimes as $downtime) {
// Ticket hook sample // Ticket hook sample
$commentText = $this->tickets ? preg_replace_callback( $commentText = $this->tickets ? preg_replace_callback(
$this->tickets->getPattern(), $this->tickets->getPattern(),
@ -65,21 +84,33 @@ foreach ($object->downtimes as $downtime) {
} }
} }
?>
<tr> // Form is unset if the current user lacks the respective permission
<th><?= $this->escape($downtime->author_name); ?> (<?= $this->timeAgo($downtime->entry_time); ?>)</th> if (isset($delDowntimeForm)) {
<td data-base-target="_self"> $deleteButton = clone($delDowntimeForm);
<?php if (isset($delDowntimeForm)) { // Form is unset if the current user lacks the respective permission $deleteButton->populate(
$delDowntimeForm = clone $delDowntimeForm;
$delDowntimeForm->populate(
array( array(
'downtime_id' => $downtime->id, 'downtime_id' => $downtime->id,
'downtime_is_service' => $object->getType() === $object::TYPE_SERVICE 'downtime_is_service' => $object->getType() === $object::TYPE_SERVICE
) )
); );
echo $delDowntimeForm; } else {
} ?> $deleteButton = '';
<span class="sr-only"><?= $this->translate('Downtime'); ?></span><?= $state; ?> - <?= str_replace(array('\r\n', '\n'), '<br>', $commentText); ?> }
?>
<li class="comment-item">
<h3>
<span class="author"><?= $this->escape($downtime->author_name) ?></span>
<?= $this->timeAgo($downtime->entry_time) ?>
<?= $deleteButton ?>
</h3>
<p> <span class="sr-only"><?= $this->translate('Downtime'); ?></span><?= $state; ?> - <?= str_replace(array('\r\n', '\n'), '<br>', $commentText); ?></p>
</li>
<?php endforeach ?>
</ul>
<?php endif ?>
</td> </td>
</tr> </tr>
<?php } // endforeach ?>