diff options
Diffstat (limited to 'application/views')
-rw-r--r-- | application/views/helpers/Badges.php | 49 | ||||
-rw-r--r-- | application/views/helpers/Breadcrumb.php | 32 | ||||
-rw-r--r-- | application/views/helpers/Tiles.php | 55 | ||||
-rw-r--r-- | application/views/helpers/Tree.php | 110 | ||||
-rw-r--r-- | application/views/scripts/edit/index.phtml | 36 | ||||
-rw-r--r-- | application/views/scripts/index/index.phtml | 51 | ||||
-rw-r--r-- | application/views/scripts/show/actions.phtml | 43 | ||||
-rw-r--r-- | application/views/scripts/show/index.phtml | 23 | ||||
-rw-r--r-- | application/views/scripts/show/tree.phtml | 22 | ||||
-rw-r--r-- | application/views/scripts/text/index.phtml | 11 |
10 files changed, 432 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; + } +} diff --git a/application/views/scripts/edit/index.phtml b/application/views/scripts/edit/index.phtml new file mode 100644 index 0000000..614e962 --- /dev/null +++ b/application/views/scripts/edit/index.phtml @@ -0,0 +1,36 @@ +<?php if (! $this->compact): ?> +<div class="controls"> + <?= $this->tabs ?> +</div> +<?php endif ?> +<div class="content full-form"> + <h1><?= $title ?></h1> + <?= $form ?> + <h2><?= $this->translate('Editor Help') ?></h2> + <table class="name-value-table"> + <tr> + <th>Ctrl-F / Cmd-F</th> + <td><?= $this->translate('Persistent search (dialog doesn\'t autoclose, enter to find next, Shift-Enter to find previous)') ?></td> + </tr> + <tr> + <th>Ctrl-G / Cmd-G</th> + <td><?= $this->translate('Find next') ?></td> + </tr> + <tr> + <th>Shift-Ctrl-G / Shift-Cmd-G</th> + <td><?= $this->translate('Find previous') ?></td> + </tr> + <tr> + <th>Shift-Ctrl-F / Cmd-Option-F</th> + <td><?= $this->translate('Replace') ?></td> + </tr> + <tr> + <th>Shift-Ctrl-R / Shift-Cmd-Option-F</th> + <td><?= $this->translate('Replace all') ?></td> + </tr> + <tr> + <th>Alt-G</th> + <td><?= $this->translate('Jump to line') ?></td> + </tr> + </table> +</div> diff --git a/application/views/scripts/index/index.phtml b/application/views/scripts/index/index.phtml new file mode 100644 index 0000000..3797583 --- /dev/null +++ b/application/views/scripts/index/index.phtml @@ -0,0 +1,51 @@ +<?php +/** @var array $views */ + +if (! $this->compact): ?> + <div class="controls"> + <?= $this->tabs ?> + </div> +<?php endif ?> +<div class="content"> + <div class="tlv-overview-tiles"> + <div class="action-links"> + <?= $this->qlink( + $this->translate('Add'), + 'toplevelview/edit/add', + array(), + array( + 'class' => 'action-link', + 'icon' => 'plus', + ) + ) ?> + </div> + + <?php + foreach ($views as $name => $view): + /** @var \Icinga\Module\Toplevelview\ViewConfig $view */ + $url = $this->url('toplevelview/show', array('name' => $name)); + ?> + <div class="tlv-overview-tile"> + <div class="tlv-title"><?= $this->qlink($view->getMeta('name'), $url) ?></div> + <div class="tlv-name"><?= $name ?></div> + <?php if ($view->hasBeenLoadedFromSession()): ?> + <div class="unsaved"><?= $this->translate('Unsaved changes!') ?></div> + <?php endif; ?> + + <?php if (! $this->compact && $this->hasPermission('toplevelview/edit')): ?> + <div class="action-links"> + <?= $this->qlink( + $this->translate('Edit'), + 'toplevelview/edit', + array('name' => $view->getName()), + array( + 'class' => 'action-link', + 'icon' => 'edit', + ) + ) ?> + </div> + <?php endif; ?> + </div> + <?php endforeach; ?> + </div> +</div> diff --git a/application/views/scripts/show/actions.phtml b/application/views/scripts/show/actions.phtml new file mode 100644 index 0000000..c72d5a6 --- /dev/null +++ b/application/views/scripts/show/actions.phtml @@ -0,0 +1,43 @@ +<?php +/** @var \Icinga\Module\Toplevelview\ViewConfig $view */ +?> +<div class="action-links"> + <?php + if (! $this->compact) { + if ($this->hasPermission('toplevelview/edit')) { + echo $this->qlink( + $this->translate('Edit'), + 'toplevelview/edit', + array('name' => $view->getName()), + array( + 'class' => 'action-link', + 'icon' => 'edit', + 'data-base-target' => '_next' + ) + ); + echo $this->qlink( + $this->translate('Clone'), + 'toplevelview/edit/clone', + array('name' => $view->getName()), + array( + 'class' => 'action-link', + 'icon' => 'rewind', + 'data-base-target' => '_next' + ) + ); + } else { + echo $this->qlink( + $this->translate('Source'), + 'toplevelview/show/source', + array('name' => $view->getName()) + ); + } + } + ?> + <?php if ($view->hasBeenLoadedFromSession()): ?> + <div class="warning-note"> + <?= $this->translate('This config is only stored in your session!' + . ' Make sure to save it to disk once your work is complete!') ?> + </div> + <?php endif; ?> +</div> diff --git a/application/views/scripts/show/index.phtml b/application/views/scripts/show/index.phtml new file mode 100644 index 0000000..8278ae4 --- /dev/null +++ b/application/views/scripts/show/index.phtml @@ -0,0 +1,23 @@ +<?php +/** @var \Icinga\Web\View $this */ +/** @var \Icinga\Module\Toplevelview\ViewConfig $view */ +$tree = $view->getTree(); +if (! $this->compact): +?> +<div class="controls"> + <?= $this->tabs ?> +</div> +<?php endif ?> +<div class="content tlv-content"> + <div class="tlv-header"> + <?= $this->badges($tree->getStatus(), false, true) ?> + <h1><?= $view->getMeta('name') ?></h1> + <?= $this->partial('show/actions.phtml', $this) ?> + <div class="last-refresh"><?= $this->timeAgo($tree->getFetchTime()) ?></div> + </div> + <div class="tlv-view-tiles"> + <?php foreach ($tree->getChildren() as $topTile): ?> + <?= $this->tiles($topTile) ?> + <?php endforeach; ?> + </div> +</div> diff --git a/application/views/scripts/show/tree.phtml b/application/views/scripts/show/tree.phtml new file mode 100644 index 0000000..52e4f80 --- /dev/null +++ b/application/views/scripts/show/tree.phtml @@ -0,0 +1,22 @@ +<?php +/** @var \Icinga\Module\Toplevelview\ViewConfig $view */ +/** @var \Icinga\Module\Toplevelview\Tree\TLVTreeNode $node */ + +$tree = $view->getTree(); + +if (! $this->compact): +?> +<div class="controls"> + <?= $this->tabs ?> +</div> +<?php endif ?> +<div class="content tlv-view-tree"> + <div class="tlv-header"> + <?= $this->badges($tree->getStatus(), false, true) ?> + <h1><?= $view->getMeta('name') ?></h1> + <?= $this->partial('show/actions.phtml', $this) ?> + <div class="last-refresh"><?= $this->timeAgo($tree->getFetchTime()) ?></div> + </div> + <?= $this->breadcrumb($node->getBreadCrumb(), $view->getName()) ?> + <?= $this->tree($node) ?> +</div> diff --git a/application/views/scripts/text/index.phtml b/application/views/scripts/text/index.phtml new file mode 100644 index 0000000..82b8ee8 --- /dev/null +++ b/application/views/scripts/text/index.phtml @@ -0,0 +1,11 @@ +<?php +/** @var \Icinga\Module\Toplevelview\ViewConfig $view */ +if (! $this->compact): +?> +<div class="controls"> + <?= $this->tabs ?> +</div> +<?php endif ?> +<div class="content"> + <pre><?= $this->text ?></pre> +</div> |