Deduplicate code and fix layout
Move icon rendering code into a separate for better maintainabillity. refs #8665
This commit is contained in:
parent
c0cf6e4918
commit
ee6c669441
|
@ -50,6 +50,7 @@ class Monitoring_ServicesController extends Controller
|
|||
protected function handleCommandForm(ObjectsCommandForm $form)
|
||||
{
|
||||
$this->serviceList->setColumns(array(
|
||||
'host_icon_image',
|
||||
'host_name',
|
||||
'host_output',
|
||||
'host_state',
|
||||
|
@ -94,6 +95,7 @@ class Monitoring_ServicesController extends Controller
|
|||
->handleRequest();
|
||||
$this->view->checkNowForm = $checkNowForm;
|
||||
$this->serviceList->setColumns(array(
|
||||
'host_icon_image',
|
||||
'host_name',
|
||||
'host_output',
|
||||
'host_state',
|
||||
|
|
|
@ -0,0 +1,46 @@
|
|||
<?php
|
||||
/* Icinga Web 2 | (c) 2013-2015 Icinga Development Team | GPLv2+ */
|
||||
|
||||
/**
|
||||
* Generate icons to describe a given hosts state
|
||||
*/
|
||||
class Zend_View_Helper_IconImage extends Zend_View_Helper_Abstract
|
||||
{
|
||||
/**
|
||||
* Create dispatch instance
|
||||
*
|
||||
* @return \Zend_View_Helper_IconImage
|
||||
*/
|
||||
public function iconImage()
|
||||
{
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the image_icon of a MonitoredObject
|
||||
*
|
||||
* @param MonitoredObject|stdClass $object The host or service
|
||||
* @return string
|
||||
*/
|
||||
public function host($object)
|
||||
{
|
||||
if ($object->host_icon_image && ! preg_match('/[\'"]/', $object->host_icon_image)) {
|
||||
return $this->view->icon($this->view->resolveMacros($object->host_icon_image, $object));
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the image_icon of a MonitoredObject
|
||||
*
|
||||
* @param MonitoredObject|stdClass $object The host or service
|
||||
* @return string
|
||||
*/
|
||||
public function service($object)
|
||||
{
|
||||
if ($object->service_icon_image && ! preg_match('/[\'"]/', $object->service_icon_image)) {
|
||||
return $this->view->icon($this->view->resolveMacros($object->service_icon_image, $object));
|
||||
}
|
||||
return '';
|
||||
}
|
||||
}
|
|
@ -52,9 +52,7 @@ if (count($hosts) === 0) {
|
|||
|
||||
<!-- Host / Status / Output -->
|
||||
<td>
|
||||
<?php if ($host->host_icon_image && ! preg_match('/[\'"]/', $host->host_icon_image)): ?>
|
||||
<?= $this->icon($this->resolveMacros($host->host_icon_image, $host)) ?>
|
||||
<?php endif ?>
|
||||
<?= $this->iconImage()->host($host) ?>
|
||||
<?= implode(' ', $this->hostFlags($host)) ?>
|
||||
<?= $this->qlink(
|
||||
$host->host_display_name,
|
||||
|
@ -75,7 +73,7 @@ if (count($hosts) === 0) {
|
|||
'host' => $host->host_name,
|
||||
'service_problem' => 1,
|
||||
'service_handled' => 0
|
||||
),
|
||||
),
|
||||
array(
|
||||
'style' => 'font-weight: normal',
|
||||
'title' => sprintf(
|
||||
|
|
|
@ -58,12 +58,8 @@ if (count($services) === 0) {
|
|||
|
||||
<td>
|
||||
<div class="sparkline-box"><?= $this->perfdata($service->service_perfdata, true, 8) ?> </div>
|
||||
|
||||
<?= $this->iconImage()->service($service) ?>
|
||||
<?= implode(' ', $this->serviceFlags($service)); ?>
|
||||
|
||||
<?php if ($service->service_icon_image && ! preg_match('/[\'"]/', $service->service_icon_image)): ?>
|
||||
<?= $this->icon($this->resolveMacros($service->service_icon_image, $service)) ?>
|
||||
<?php endif ?>
|
||||
<?= $this->qlink(
|
||||
$service->service_display_name,
|
||||
$serviceLink,
|
||||
|
|
|
@ -9,9 +9,7 @@ use Icinga\Module\Monitoring\Object\Host;
|
|||
<?= $this->prefixedTimeSince($object->host_last_state_change, true); ?>
|
||||
</td>
|
||||
<td>
|
||||
<?php if ($object->host_icon_image && ! preg_match('/[\'"]/', $object->host_icon_image)): ?>
|
||||
<?= $this->icon($this->resolveMacros($object->host_icon_image, $object)) ?>
|
||||
<?php endif ?>
|
||||
<?= $this->iconImage()->host($object) ?>
|
||||
<strong><?= $this->escape($object->host_display_name); ?></strong>
|
||||
<?php if ($object->host_display_name !== $object->host_name): ?>
|
||||
<small>(<?= $this->escape($object->host_name); ?>)</small>
|
||||
|
@ -23,4 +21,4 @@ use Icinga\Module\Monitoring\Object\Host;
|
|||
<?= $this->render('partials/host/statusicons.phtml'); ?>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</table>
|
||||
|
|
|
@ -17,10 +17,8 @@ $i = 0;
|
|||
<tr class="state <?= Host::getStateText($host->host_state); ?><?= $host->host_handled ? ' handled' : '' ?>">
|
||||
<td class="state"><?= Host::getStateText($host->host_state, true); ?><br /></td>
|
||||
<td>
|
||||
<?= $this->iconImage()->host($host) ?>
|
||||
<?= implode(' ', $this->hostFlags($host)) ?>
|
||||
<?php if ($host->host_icon_image && ! preg_match('/[\'"]/', $host->host_icon_image)): ?>
|
||||
<?= $this->icon($this->resolveMacros($host->host_icon_image, $host)) ?>
|
||||
<?php endif ?>
|
||||
<b><?= $this->escape($host->getName()); ?></b><br>
|
||||
<?= $this->escape($host->host_output) ?>
|
||||
</td>
|
||||
|
|
|
@ -10,9 +10,7 @@ use Icinga\Module\Monitoring\Object\Service;
|
|||
<?= $this->prefixedTimeSince($object->host_last_state_change, true); ?>
|
||||
</td>
|
||||
<td>
|
||||
<?php if ($object->host_icon_image && ! preg_match('/[\'"]/', $object->host_icon_image)): ?>
|
||||
<?= $this->icon($this->resolveMacros($object->host_icon_image, $object)) ?>
|
||||
<?php endif ?>
|
||||
<?= $this->iconImage()->service($object) ?>
|
||||
<strong><?= $this->escape($object->host_display_name); ?></strong>
|
||||
<?php if ($object->host_display_name !== $object->host_name): ?>
|
||||
<small>(<?= $this->escape($object->host_name); ?>)</small>
|
||||
|
@ -30,9 +28,7 @@ use Icinga\Module\Monitoring\Object\Service;
|
|||
<?= $this->prefixedTimeSince($object->service_last_state_change, true); ?>
|
||||
</td>
|
||||
<td>
|
||||
<?php if ($object->service_icon_image && ! preg_match('/[\'"]/', $object->service_icon_image)): ?>
|
||||
<?= $this->icon($this->resolveMacros($object->service_icon_image, $object)) ?>
|
||||
<?php endif ?>
|
||||
<?= $this->iconImage()->host($object) ?>
|
||||
<strong><?= $this->translate('Service'); ?>: <?= $this->escape($object->service_display_name); ?></strong>
|
||||
<?php if ($object->service_display_name !== $object->service_description): ?>
|
||||
<small>(<?= $this->escape($object->service_description); ?>)</small>
|
||||
|
|
|
@ -15,10 +15,8 @@ $i = 0;
|
|||
<tr class="state <?= Service::getStateText($service->service_state); ?><?= $service->service_handled ? ' handled' : '' ?>">
|
||||
<td class="state"><?= Service::getStateText($service->service_state, true); ?><br /></td>
|
||||
<td>
|
||||
<?= $this->iconImage()->service($service) ?>
|
||||
<?= implode(' ', $this->serviceFlags($service)) ?>
|
||||
<?php if ($service->service_icon_image && ! preg_match('/[\'"]/', $service->service_icon_image)): ?>
|
||||
<?= $this->icon($this->resolveMacros($service->service_icon_image, $service)) ?>
|
||||
<?php endif ?>
|
||||
<b>
|
||||
<?= $this->escape($service->getName()); ?>
|
||||
<?= $this->translate('on') ?>
|
||||
|
|
Loading…
Reference in New Issue