From 1e2bd37ae829f1dd7ccd7f519f65b689f0784bd3 Mon Sep 17 00:00:00 2001 From: Gianluca Piccolo Date: Wed, 2 Oct 2019 13:42:42 +0200 Subject: [PATCH] Add custom tab hook --- .../views/scripts/object/detail-tabhook.phtml | 21 +++++++ .../Monitoring/Hook/ObjectDetailsTabHook.php | 60 +++++++++++++++++++ .../Controller/MonitoredObjectController.php | 38 ++++++++++++ 3 files changed, 119 insertions(+) create mode 100644 modules/monitoring/application/views/scripts/object/detail-tabhook.phtml create mode 100644 modules/monitoring/library/Monitoring/Hook/ObjectDetailsTabHook.php diff --git a/modules/monitoring/application/views/scripts/object/detail-tabhook.phtml b/modules/monitoring/application/views/scripts/object/detail-tabhook.phtml new file mode 100644 index 000000000..abcfcc131 --- /dev/null +++ b/modules/monitoring/application/views/scripts/object/detail-tabhook.phtml @@ -0,0 +1,21 @@ +compact): ?> +
+ tabs ?> +header === true) { + if ($object->type === 'service') { + echo $this->render('partials/object/service-header.phtml'); + } else { + echo $this->render('partials/object/host-header.phtml'); + } +} elseif ($this->header !== false) { + echo $this->header; +} +?> +
+ +
+ content ?> +
\ No newline at end of file diff --git a/modules/monitoring/library/Monitoring/Hook/ObjectDetailsTabHook.php b/modules/monitoring/library/Monitoring/Hook/ObjectDetailsTabHook.php new file mode 100644 index 000000000..15fa9bb60 --- /dev/null +++ b/modules/monitoring/library/Monitoring/Hook/ObjectDetailsTabHook.php @@ -0,0 +1,60 @@ +render('object/detail-history', null, true); } + /** + * Show the content of a custom tab + */ + public function tabhookAction() + { + $hookName = $this->params->get('hook'); + $this->getTabs()->activate($hookName); + + $hook = $this->tabHooks[$hookName]; + + $this->view->header = $hook->getHeader($this->object, $this->getRequest()); + $this->view->content = $hook->getContent($this->object, $this->getRequest()); + $this->view->object = $this->object; + $this->render('object/detail-tabhook', null, true); + } + /** * Handle a command form * @@ -262,6 +286,20 @@ abstract class MonitoredObjectController extends Controller ) ); } + + /** @var ObjectDetailsTabHook $hook */ + foreach (Hook::all('Monitoring\\ObjectDetailsTab') as $hook) { + $hookName = $hook->getName(); + if ($hook->shouldBeShown($object, $this->Auth())) { + $this->tabHooks[$hookName] = $hook; + $tabs->add($hookName, [ + 'label' => $hook->getLabel(), + 'url' => $isService ? 'monitoring/service/tabhook' : 'monitoring/host/tabhook', + 'urlParams' => $params + [ 'hook' => $hookName ] + ]); + } + } + $tabs->extend(new DashboardAction())->extend(new MenuAction()); }