diff options
Diffstat (limited to 'application')
-rw-r--r-- | application/controllers/ShowController.php | 94 | ||||
-rw-r--r-- | application/views/scripts/show/map.phtml | 18 |
2 files changed, 112 insertions, 0 deletions
diff --git a/application/controllers/ShowController.php b/application/controllers/ShowController.php new file mode 100644 index 0000000..0a36023 --- /dev/null +++ b/application/controllers/ShowController.php @@ -0,0 +1,94 @@ +<?php + +namespace Icinga\Module\Nagvis\Controllers; + +use Icinga\Module\Nagvis\RestrictionHelper; +use Icinga\Security\SecurityException; +use Icinga\Web\Controller; +use Icinga\Web\Url; +use Icinga\Web\Widget\Tabextension\DashboardAction; +use Icinga\Web\Widget\Tabextension\MenuAction; + +class ShowController extends Controller +{ + public function getTabs() + { + $tabs = parent::getTabs (); + $tabs->add ( + 'index', + array ( + 'title' => 'Nagvis', + 'url' => Url::fromRequest ()->getRelativeUrl () + ) + )->extend( + new DashboardAction() + )->extend( + new MenuAction() + ); + + $menu_param = $this->params->get('showMenu'); + if (isset($menu_param) && $menu_param == 1) { + $menu_text = "Hide NagVis Menu"; + $menu_url = $this->getRequest()->getUrl()->without('showMenu'); + $icon = 'eye-off'; + } else { + $menu_text = "Show NagVis Menu"; + $menu_url = $this->getRequest()->getUrl()->with('showMenu', 1); + $icon = 'eye'; + } + + $tabs->addAsDropdown( + 'nagvis-menu-entry', + array( + 'icon' => $icon, + 'label' => t($menu_text), + 'url' => $menu_url + ) + ); + + return $tabs; + } + + public function mapAction() + { + // TODO: I'd prefer to have mod=Overview as a default, that would also + // work with no enabled map. Unfortunately Overview doesn't seem + // to respect header_menu=0 + $map = $this->params->get( + 'map', + $this->Config()->get( + 'global', + 'default-map', + 'demo-overview' + ) + ); + + $restriction = RestrictionHelper::getRegex(); + if ($restriction !== null && ! preg_match($restriction, $map)) { + throw new SecurityException('You\'re not allowed to view map "%s"', $map); + } + + $baseurl = $this->Config()->get('global', 'baseurl', '/nagvis'); + + $url = $baseurl . '/frontend/nagvis-js/index.php'; + $url .= '?mod=Map&act=view&show=' . urlencode($map); + + if ($this->params->get('showMenu')) { + $url .= '&header_menu=1'; + } else { + $url .= '&header_menu=0'; + } + + $zoom = $this->params->shift('zoom', $this->view->compact ? 47 : null); + if ($zoom) { + $url .= '&zoom=' . (int) $zoom; + } + + if ($height = $this->params->shift('height')) { + $this->view->height = (int) $height; + } + + $this->view->nagvisUrl = $url; + $this->getTabs ()->activate('index'); + } +} diff --git a/application/views/scripts/show/map.phtml b/application/views/scripts/show/map.phtml new file mode 100644 index 0000000..f59aad3 --- /dev/null +++ b/application/views/scripts/show/map.phtml @@ -0,0 +1,18 @@ +<?php if (! $this->compact): ?> +<div class="controls"> + <?= $tabs; ?> +</div> +<?php endif ?> + +<?php + +if ($this->height) { + $attr = sprintf(' height="%d"', $height); +} elseif (! $this->compact) { + $attr = ' height="99%"'; +} else { + $attr = ''; +} + +?> +<iframe id="nagvis-iframe" src="<?= $this->nagvisUrl ?>" width="100%"<?= $attr ?> marginheight=0 marginwidth=0 wspace=0 frameborder=0 ></iframe><!-- onload="nagvis_frame_reload();" -->
\ No newline at end of file |