summaryrefslogtreecommitdiffstats
path: root/application/views/helpers
diff options
context:
space:
mode:
Diffstat (limited to 'application/views/helpers')
-rw-r--r--application/views/helpers/Badges.php49
-rw-r--r--application/views/helpers/Breadcrumb.php32
-rw-r--r--application/views/helpers/Tiles.php55
-rw-r--r--application/views/helpers/Tree.php110
4 files changed, 246 insertions, 0 deletions
diff --git a/application/views/helpers/Badges.php b/application/views/helpers/Badges.php
new file mode 100644
index 0000000..6066a72
--- /dev/null
+++ b/application/views/helpers/Badges.php
@@ -0,0 +1,49 @@
+<?php
+/* Icinga Web 2 Top Level View | (c) 2017 Icinga Development Team | GPLv2+ */
+
+use Icinga\Module\Toplevelview\Tree\TLVStatus;
+use Icinga\Web\Url;
+
+class Zend_View_Helper_Badges extends Zend_View_Helper_Abstract
+{
+ /** @var \Icinga\Web\View */
+ public $view;
+
+ protected function prettyTitle($identifier)
+ {
+ $s = '';
+ foreach (preg_split('/[\.\-_\s]+/', $identifier) as $p) {
+ $s .= ' ' . ucfirst($p);
+ }
+ return trim($s);
+ }
+
+ public function badges(TLVStatus $status, $problemsOnly = true, $showTotal = false)
+ {
+ $htm = '';
+
+ $values = false;
+ $htm .= '<div class="badges">';
+ foreach ($status->getProperties() as $key => $value) {
+ if ($problemsOnly === true && ($key === 'ok' || $key === 'downtime_active')
+ || ($key === 'total' && $showTotal !== true)
+ ) {
+ continue;
+ }
+ if ($value !== null && $value > 0) {
+ $values = true;
+ $title = $value . ' ' . $this->prettyTitle($key);
+ $class = 'tlv-status-tile ' . str_replace('_', ' ', $key);
+ $htm .= sprintf(
+ '<div class="badge status-badge %s" title="%s">%s</div>',
+ $class,
+ $title,
+ $value
+ );
+ }
+ }
+ $htm .= '</div>';
+
+ return $values ? $htm : '';
+ }
+}
diff --git a/application/views/helpers/Breadcrumb.php b/application/views/helpers/Breadcrumb.php
new file mode 100644
index 0000000..3263712
--- /dev/null
+++ b/application/views/helpers/Breadcrumb.php
@@ -0,0 +1,32 @@
+<?php
+/* Icinga Web 2 | (c) 2016 Icinga Development Team | GPLv2+ */
+
+use Icinga\Module\Toplevelview\Tree\TLVTreeNode;
+
+class Zend_View_Helper_Breadcrumb extends Zend_View_Helper_Abstract
+{
+ /** @var \Icinga\Web\View */
+ public $view;
+
+ /**
+ * @param TLVTreeNode[] $breadcrumb
+ *
+ * @return string
+ */
+ public function breadcrumb($breadcrumb, $config_name)
+ {
+ $htm = '<ul class="breadcrumb">';
+ foreach ($breadcrumb as $crumb) {
+ $htm .= '<li>' . $this->view->qlink(
+ $crumb->getTitle(),
+ 'toplevelview/show/tree',
+ array(
+ 'name' => $config_name,
+ 'id' => $crumb->getFullId()
+ )
+ ) . '</li>';
+ }
+ $htm .= '</ul>';
+ return $htm;
+ }
+}
diff --git a/application/views/helpers/Tiles.php b/application/views/helpers/Tiles.php
new file mode 100644
index 0000000..dcefbfe
--- /dev/null
+++ b/application/views/helpers/Tiles.php
@@ -0,0 +1,55 @@
+<?php
+/* Icinga Web 2 Top Level View | (c) 2017 Icinga Development Team | GPLv2+ */
+
+use Icinga\Module\Toplevelview\Tree\TLVTreeNode;
+
+class Zend_View_Helper_Tiles extends Zend_View_Helper_Abstract
+{
+ /** @var \Icinga\Web\View */
+ public $view;
+
+ public function tiles(TLVTreeNode $node, $levels = 2, $classes = array())
+ {
+ $htm = '';
+ $title = $this->view->escape($node->getTitle());
+
+ $status = $node->getStatus();
+ if ($levels > 1) {
+ $statusClass = 'tlv-status-section';
+ } else {
+ $statusClass = 'tlv-status-tile';
+ }
+ $statusClasses = array($statusClass, $status->getOverall());
+
+ $htm .= sprintf(
+ '<div class="tlv-tile %s" title="%s" data-base-target="_next">' . "\n",
+ join(' ', $classes + $statusClasses),
+ $title
+ );
+ $badges = $this->view->badges($status);
+
+ $htm .= $this->view->qlink(
+ $title . $badges,
+ 'toplevelview/show/tree',
+ array(
+ 'name' => $node->getRoot()->getConfig()->getName(),
+ 'id' => $node->getFullId()
+ ),
+ array(
+ 'class' => 'tlv-tile-title'
+ ),
+ false
+ );
+
+ if ($levels > 1 && $node->hasChildren()) {
+ $htm .= '<div class="tlv-tiles">';
+ foreach ($node->getChildren() as $child) {
+ $htm .= $this->tiles($child, $levels - 1, $classes);
+ }
+ $htm .= '</div>';
+ }
+
+ $htm .= "</div>\n";
+ return $htm;
+ }
+}
diff --git a/application/views/helpers/Tree.php b/application/views/helpers/Tree.php
new file mode 100644
index 0000000..a016b68
--- /dev/null
+++ b/application/views/helpers/Tree.php
@@ -0,0 +1,110 @@
+<?php
+/* Icinga Web 2 Top Level View | (c) 2017 Icinga Development Team | GPLv2+ */
+
+use Icinga\Module\Toplevelview\Tree\TLVTreeNode;
+use Icinga\Web\Url;
+
+class Zend_View_Helper_Tree extends Zend_View_Helper_Abstract
+{
+ /** @var \Icinga\Web\View */
+ public $view;
+
+ public function tree(TLVTreeNode $node, $classes = array(), $level = 0)
+ {
+ $htm = '';
+ $htmExtra = '';
+ $title = $node->getTitle();
+ $type = $node->getType();
+
+ $cssClasses = join(' ', $classes);
+
+ $status = $node->getStatus();
+ $statusClass = $status->getOverall();
+
+ if ($type === 'host') {
+ $icon = 'host';
+ $url = Url::fromPath(
+ 'monitoring/host/show',
+ array(
+ 'host' => $node->get('host')
+ )
+ );
+ } elseif ($type === 'service') {
+ $icon = 'service';
+ $url = Url::fromPath(
+ 'monitoring/service/show',
+ array(
+ 'host' => $node->get('host'),
+ 'service' => $node->get('service')
+ )
+ );
+ } elseif ($type === 'hostgroup') {
+ $icon = 'cubes';
+ $url = Url::fromPath(
+ 'monitoring/list/services',
+ array(
+ 'hostgroup' => $node->get('hostgroup'),
+ 'sort' => 'service_severity',
+ 'dir' => 'desc',
+ )
+ );
+
+ if (($h = $status->getMeta('hosts_unhandled')) > 0) {
+ $hostTitle = '(<strong>'
+ . sprintf($this->view->translatePlural('%s unhandled host', '%s unhandled hosts', $h), $h)
+ . '</strong>)';
+ } else {
+ $h = $status->getMeta('hosts_total');
+ $hostTitle = '(' . sprintf($this->view->translatePlural('%s host', '%s hosts', $h), $h) . ')';
+ }
+
+ $htmExtra .= ' ' . $this->view->qlink(
+ $hostTitle,
+ 'monitoring/list/hosts',
+ array(
+ 'hostgroup' => $node->get('hostgroup'),
+ 'sort' => 'host_severity',
+ 'dir' => 'desc',
+ ),
+ null,
+ false
+ );
+ } else {
+ $icon = null;
+ $url = Url::fromPath(
+ 'toplevelview/show/tree',
+ array(
+ 'name' => $node->getRoot()->getConfig()->getName(),
+ 'id' => $node->getFullId()
+ )
+ );
+ }
+
+ if ($type !== 'node') {
+ $htm .= "<div class=\"tlv-node-icinga tlv-node-\$type tlv-status-tile action $statusClass $cssClasses\""
+ . " data-base-target=\"_next\" href=\"$url\">";
+ $htm .= $this->view->icon($icon) . ' ';
+ $htm .= $this->view->qlink($title, $url);
+ $htm .= $htmExtra;
+ $htm .= ' ' . $this->view->badges($status, false);
+ $htm .= '</div>';
+ } else {
+ $htm .= "<div class=\"tlv-tree-node tlv-status-section tlv-collapsible $statusClass $cssClasses\"";
+ $htm .= " title=\"$title\">";
+ $htm .= '<div class="tlv-tree-title">';
+ $htm .= $this->view->badges($status, false, $level === 0 ? true : false);
+ $htm .= '<i class="icon icon-bycss tlv-collapse-handle"></i> ';
+ $htm .= $this->view->qlink($title, $url);
+ $htm .= $htmExtra;
+ $htm .= '</div>';
+ if ($node->hasChildren()) {
+ foreach ($node->getChildren() as $child) {
+ $htm .= $this->tree($child, $classes, $level + 1);
+ }
+ }
+ $htm .= '</div>';
+ }
+
+ return $htm;
+ }
+}