From ee6c669441ce8a8d34a269a8f7c7dfc76efaafda Mon Sep 17 00:00:00 2001 From: Matthias Jentsch Date: Thu, 21 May 2015 11:40:08 +0200 Subject: [PATCH] Deduplicate code and fix layout Move icon rendering code into a separate for better maintainabillity. refs #8665 --- .../controllers/ServicesController.php | 2 + .../application/views/helpers/IconImage.php | 46 +++++++++++++++++++ .../views/scripts/list/hosts.phtml | 6 +-- .../views/scripts/list/services.phtml | 6 +-- .../scripts/partials/host/object-header.phtml | 6 +-- .../partials/host/objects-header.phtml | 4 +- .../partials/service/object-header.phtml | 8 +--- .../partials/service/objects-header.phtml | 4 +- 8 files changed, 57 insertions(+), 25 deletions(-) create mode 100644 modules/monitoring/application/views/helpers/IconImage.php diff --git a/modules/monitoring/application/controllers/ServicesController.php b/modules/monitoring/application/controllers/ServicesController.php index ca9788ff2..6877aca02 100644 --- a/modules/monitoring/application/controllers/ServicesController.php +++ b/modules/monitoring/application/controllers/ServicesController.php @@ -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', diff --git a/modules/monitoring/application/views/helpers/IconImage.php b/modules/monitoring/application/views/helpers/IconImage.php new file mode 100644 index 000000000..2ed3b1d25 --- /dev/null +++ b/modules/monitoring/application/views/helpers/IconImage.php @@ -0,0 +1,46 @@ +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 ''; + } +} diff --git a/modules/monitoring/application/views/scripts/list/hosts.phtml b/modules/monitoring/application/views/scripts/list/hosts.phtml index 89c2e7d26..a83f3bb8a 100644 --- a/modules/monitoring/application/views/scripts/list/hosts.phtml +++ b/modules/monitoring/application/views/scripts/list/hosts.phtml @@ -52,9 +52,7 @@ if (count($hosts) === 0) { - host_icon_image && ! preg_match('/[\'"]/', $host->host_icon_image)): ?> - icon($this->resolveMacros($host->host_icon_image, $host)) ?> - + iconImage()->host($host) ?> hostFlags($host)) ?> 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( diff --git a/modules/monitoring/application/views/scripts/list/services.phtml b/modules/monitoring/application/views/scripts/list/services.phtml index 12ba232cc..964a0e982 100644 --- a/modules/monitoring/application/views/scripts/list/services.phtml +++ b/modules/monitoring/application/views/scripts/list/services.phtml @@ -58,12 +58,8 @@ if (count($services) === 0) {
perfdata($service->service_perfdata, true, 8) ?>
- + iconImage()->service($service) ?> serviceFlags($service)); ?> - - service_icon_image && ! preg_match('/[\'"]/', $service->service_icon_image)): ?> - icon($this->resolveMacros($service->service_icon_image, $service)) ?> - qlink( $service->service_display_name, $serviceLink, diff --git a/modules/monitoring/application/views/scripts/partials/host/object-header.phtml b/modules/monitoring/application/views/scripts/partials/host/object-header.phtml index 127f492e6..ed7edae79 100644 --- a/modules/monitoring/application/views/scripts/partials/host/object-header.phtml +++ b/modules/monitoring/application/views/scripts/partials/host/object-header.phtml @@ -9,9 +9,7 @@ use Icinga\Module\Monitoring\Object\Host; prefixedTimeSince($object->host_last_state_change, true); ?> - host_icon_image && ! preg_match('/[\'"]/', $object->host_icon_image)): ?> - icon($this->resolveMacros($object->host_icon_image, $object)) ?> - + iconImage()->host($object) ?> escape($object->host_display_name); ?> host_display_name !== $object->host_name): ?> (escape($object->host_name); ?>) @@ -23,4 +21,4 @@ use Icinga\Module\Monitoring\Object\Host; render('partials/host/statusicons.phtml'); ?> - \ No newline at end of file + diff --git a/modules/monitoring/application/views/scripts/partials/host/objects-header.phtml b/modules/monitoring/application/views/scripts/partials/host/objects-header.phtml index b6856609c..bce62db6b 100644 --- a/modules/monitoring/application/views/scripts/partials/host/objects-header.phtml +++ b/modules/monitoring/application/views/scripts/partials/host/objects-header.phtml @@ -17,10 +17,8 @@ $i = 0; host_state, true); ?>
+ iconImage()->host($host) ?> hostFlags($host)) ?> - host_icon_image && ! preg_match('/[\'"]/', $host->host_icon_image)): ?> - icon($this->resolveMacros($host->host_icon_image, $host)) ?> - escape($host->getName()); ?>
escape($host->host_output) ?> diff --git a/modules/monitoring/application/views/scripts/partials/service/object-header.phtml b/modules/monitoring/application/views/scripts/partials/service/object-header.phtml index b50aff9bc..c6dbb4730 100644 --- a/modules/monitoring/application/views/scripts/partials/service/object-header.phtml +++ b/modules/monitoring/application/views/scripts/partials/service/object-header.phtml @@ -10,9 +10,7 @@ use Icinga\Module\Monitoring\Object\Service; prefixedTimeSince($object->host_last_state_change, true); ?> - host_icon_image && ! preg_match('/[\'"]/', $object->host_icon_image)): ?> - icon($this->resolveMacros($object->host_icon_image, $object)) ?> - + iconImage()->service($object) ?> escape($object->host_display_name); ?> host_display_name !== $object->host_name): ?> (escape($object->host_name); ?>) @@ -30,9 +28,7 @@ use Icinga\Module\Monitoring\Object\Service; prefixedTimeSince($object->service_last_state_change, true); ?> - service_icon_image && ! preg_match('/[\'"]/', $object->service_icon_image)): ?> - icon($this->resolveMacros($object->service_icon_image, $object)) ?> - + iconImage()->host($object) ?> translate('Service'); ?>: escape($object->service_display_name); ?> service_display_name !== $object->service_description): ?> (escape($object->service_description); ?>) diff --git a/modules/monitoring/application/views/scripts/partials/service/objects-header.phtml b/modules/monitoring/application/views/scripts/partials/service/objects-header.phtml index fe1e4b16a..176c43d92 100644 --- a/modules/monitoring/application/views/scripts/partials/service/objects-header.phtml +++ b/modules/monitoring/application/views/scripts/partials/service/objects-header.phtml @@ -15,10 +15,8 @@ $i = 0; service_state, true); ?>
+ iconImage()->service($service) ?> serviceFlags($service)) ?> - service_icon_image && ! preg_match('/[\'"]/', $service->service_icon_image)): ?> - icon($this->resolveMacros($service->service_icon_image, $service)) ?> - escape($service->getName()); ?> translate('on') ?>