[icinga-checkins] icinga.org: icingaweb2/bugfix/correct-duration-formatting-6778: Deduplicate hostgroups list view's logic

git at icinga.org git at icinga.org
Thu Nov 27 18:29:29 CET 2014


Module: icingaweb2
Branch: bugfix/correct-duration-formatting-6778
Commit: 7d7663a9af8fdfd8755ff1dba5d9ef8f07835084
URL:    https://git.icinga.org/?p=icingaweb2.git;a=commit;h=7d7663a9af8fdfd8755ff1dba5d9ef8f07835084

Author: Alexander Klimov <alexander.klimov at netways.de>
Date:   Thu Nov 27 13:28:34 2014 +0100

Deduplicate hostgroups list view's logic

refs #6778

---

 .../views/scripts/list/hostgroups.phtml            |   70 ++++++--------------
 1 file changed, 22 insertions(+), 48 deletions(-)

diff --git a/modules/monitoring/application/views/scripts/list/hostgroups.phtml b/modules/monitoring/application/views/scripts/list/hostgroups.phtml
index 2b8ad6c..6a8eb15 100644
--- a/modules/monitoring/application/views/scripts/list/hostgroups.phtml
+++ b/modules/monitoring/application/views/scripts/list/hostgroups.phtml
@@ -29,55 +29,29 @@
     <tbody>
     <?php foreach ($hostgroups as $h): ?>
       <tr href="<?= $this->href('monitoring/list/services', array('hostgroup' => $h->hostgroup)); ?>">
-       <?php if ($h->services_critical_last_state_change_unhandled): ?>
-        <td class="state change critical unhandled">
-          <strong><?= $this->translate('CRITICAL'); ?></strong>
+       <?php
+       foreach (array(
+           array('critical', '_handled',   '',           $this->translate('CRITICAL')),
+           array('critical', '_unhandled', ' unhandled', $this->translate('CRITICAL')),
+           array('warning',  '_handled',   '',           $this->translate('WARNING')),
+           array('warning',  '_unhandled', ' unhandled', $this->translate('WARNING')),
+           array('unknown',  '_handled',   '',           $this->translate('UNKNOWN')),
+           array('unknown',  '_unhandled', ' unhandled', $this->translate('UNKNOWN')),
+           array('ok',       '',           '',           $this->translate('OK')),
+           array('pending',  '',           '',           $this->translate('PENDING'))
+       ) as $combinations):
+           $state = $combinations[0];
+           $time = $h->{'services_' . $state . '_last_state_change' . $combinations[1]};
+           if ($time): ?>
+        <td class="state change <?= $state . $combinations[2] ?>">
+          <strong><?= $combinations[3] ?></strong>
           <br>
-          <?= $this->prefixedTimeSince($h->services_critical_last_state_change_unhandled); ?>
+          <?= $this->prefixedTimeSince($time) ?>
         </td>
-       <?php elseif ($h->services_unknown_last_state_change_unhandled): ?>
-        <td class="state change unknown unhandled">
-          <strong><?= $this->translate('UNKNOWN'); ?></strong>
-          <br>
-          <?= $this->prefixedTimeSince($h->services_unknown_last_state_change_unhandled); ?>
-        </td>
-       <?php elseif ($h->services_warning_last_state_change_unhandled): ?>
-        <td class="state change warning unhandled">
-          <strong><?= $this->translate('WARNING'); ?></strong>
-          <br>
-          <?= $this->prefixedTimeSince($h->services_warning_last_state_change_unhandled); ?>
-        </td>
-       <?php elseif ($h->services_critical_last_state_change_handled): ?>
-        <td class="state change critical">
-          <strong><?= $this->translate('CRITICAL'); ?></strong>
-          <br>
-          <?= $this->prefixedTimeSince($h->services_critical_last_state_change_handled); ?>
-        </td>
-       <?php elseif ($h->services_unknown_last_state_change_handled): ?>
-        <td class="state change unknown">
-          <strong><?= $this->translate('UNKNOWN'); ?></strong>
-          <br>
-          <?= $this->prefixedTimeSince($h->services_unknown_last_state_change_handled); ?>
-        </td>
-       <?php elseif ($h->services_warning_last_state_change_handled): ?>
-        <td class="state change warning">
-          <strong><?= $this->translate('WARNING'); ?></strong>
-          <br>
-          <?= $this->prefixedTimeSince($h->services_warning_last_state_change_handled); ?>
-        </td>
-       <?php elseif ($h->services_ok_last_state_change): ?>
-        <td class="state change ok">
-          <strong><?= $this->translate('OK'); ?></strong>
-          <br>
-          <?= $this->prefixedTimeSince($h->services_ok_last_state_change); ?>
-        </td>
-       <?php else: ?>
-        <td class="state change pending">
-          <strong><?= $this->translate('PENDING'); ?></strong>
-          <br>
-          <?= $this->prefixedTimeSince($h->services_pending_last_state_change); ?>
-        </td>
-       <?php endif ?>
+               <?php
+               break;
+           endif;
+       endforeach; ?>
         <td class="groupname">
           <a href="<?= $this->href('monitoring/list/services', array('hostgroup' => $h->hostgroup)); ?>">
             <?= $h->hostgroup; ?>
@@ -222,4 +196,4 @@
     <?php endforeach ?>
     </tbody>
   </table>
-</div>
\ No newline at end of file
+</div>



More information about the icinga-checkins mailing list