From a0901c4b7f2db488cb4fb3be2dd921a0308f4659 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 28 Apr 2024 14:36:40 +0200 Subject: Adding upstream version 1.0.2. Signed-off-by: Daniel Baumann --- application/controllers/HostgroupController.php | 89 +++++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 application/controllers/HostgroupController.php (limited to 'application/controllers/HostgroupController.php') diff --git a/application/controllers/HostgroupController.php b/application/controllers/HostgroupController.php new file mode 100644 index 0000000..978489d --- /dev/null +++ b/application/controllers/HostgroupController.php @@ -0,0 +1,89 @@ +assertRouteAccess('hostgroups'); + + $this->addTitleTab(t('Host Group')); + + $name = $this->params->getRequired('name'); + + $query = Hostgroupsummary::on($this->getDb()); + + foreach ($query->getUnions() as $unionPart) { + $unionPart->filter(Filter::equal('hostgroup.name', $name)); + } + + $this->applyRestrictions($query); + + $hostgroup = $query->first(); + if ($hostgroup === null) { + throw new NotFoundError(t('Host group not found')); + } + + $this->hostgroup = $hostgroup; + $this->setTitle($hostgroup->display_name); + } + + public function indexAction() + { + $db = $this->getDb(); + + $hosts = Host::on($db)->with(['state', 'state.last_comment', 'icon_image']); + $hosts + ->setResultSetClass(VolatileStateResults::class) + ->filter(Filter::equal('hostgroup.id', $this->hostgroup->id)); + $this->applyRestrictions($hosts); + + $limitControl = $this->createLimitControl(); + $paginationControl = $this->createPaginationControl($hosts); + $viewModeSwitcher = $this->createViewModeSwitcher($paginationControl, $limitControl); + + $hostList = (new HostList($hosts->execute())) + ->setViewMode($viewModeSwitcher->getViewMode()); + + yield $this->export($hosts); + + // ICINGAWEB_EXPORT_FORMAT is not set yet and $this->format is inaccessible, yeah... + if ($this->getRequest()->getParam('format') === 'pdf') { + $this->addContent((new HostgroupList([$this->hostgroup])) + ->setViewMode('minimal') + ->setDetailActionsDisabled() + ->setNoSubjectLink()); + $this->addContent(Html::tag('h2', null, t('Hosts'))); + } else { + $this->addControl((new HostgroupList([$this->hostgroup])) + ->setViewMode('minimal') + ->setDetailActionsDisabled() + ->setNoSubjectLink()); + } + + $this->addControl($paginationControl); + $this->addControl($viewModeSwitcher); + $this->addControl($limitControl); + + $this->addContent($hostList); + + $this->setAutorefreshInterval(10); + } +} -- cgit v1.2.3