From f66ab8dae2f3d0418759f81a3a64dc9517a62449 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 14 Apr 2024 15:17:31 +0200 Subject: Adding upstream version 1.10.2. Signed-off-by: Daniel Baumann --- library/Director/Web/Table/ObjectsTableService.php | 219 +++++++++++++++++++++ 1 file changed, 219 insertions(+) create mode 100644 library/Director/Web/Table/ObjectsTableService.php (limited to 'library/Director/Web/Table/ObjectsTableService.php') diff --git a/library/Director/Web/Table/ObjectsTableService.php b/library/Director/Web/Table/ObjectsTableService.php new file mode 100644 index 0000000..2d4ad41 --- /dev/null +++ b/library/Director/Web/Table/ObjectsTableService.php @@ -0,0 +1,219 @@ + 'o.object_name', + 'disabled' => 'o.disabled', + 'host' => 'h.object_name', + 'host_id' => 'h.id', + 'host_object_type' => 'h.object_type', + 'host_disabled' => 'h.disabled', + 'id' => 'o.id', + 'uuid' => 'o.uuid', + 'blacklisted' => "CASE WHEN hsb.service_id IS NULL THEN 'n' ELSE 'y' END", + ]; + + protected $searchColumns = [ + 'o.object_name', + 'h.object_name' + ]; + + public function assemble() + { + $this->enableMultiSelect( + 'director/services/edit', + 'director/services', + ['uuid'] + ); + } + + public function setTitle($title) + { + $this->title = $title; + return $this; + } + + public function setHost(IcingaHost $host) + { + $this->host = $host; + $this->getAttributes()->set('data-base-target', '_self'); + return $this; + } + + public function setInheritedBy(IcingaHost $host) + { + $this->inheritedBy = $host; + return $this; + } + + /** + * Show no related links + * + * @param bool $readonly + * @return $this + */ + public function setReadonly($readonly = true) + { + $this->readonly = (bool) $readonly; + + return $this; + } + + public function highlightService($service) + { + $this->highlightedService = $service; + + return $this; + } + + public function getColumnsToBeRendered() + { + if ($this->title) { + return [$this->title]; + } + if ($this->host) { + return [$this->translate('Servicename')]; + } + return [ + 'host' => $this->translate('Host'), + 'object_name' => $this->translate('Service Name'), + ]; + } + + public function renderRow($row) + { + $caption = $row->host === null + ? Html::tag('span', ['class' => 'error'], '- none -') + : $row->host; + + $hostField = static::td($caption); + if ($row->host === null) { + $hostField->getAttributes()->add('class', 'error'); + } + if ($this->host) { + $tr = static::tr([ + static::td($this->getServiceLink($row)) + ]); + } else { + $tr = static::tr([ + $hostField, + static::td($this->getServiceLink($row)) + ]); + } + + $attributes = $tr->getAttributes(); + $classes = $this->getRowClasses($row); + if ($row->host_disabled === 'y' || $row->disabled === 'y') { + $classes[] = 'disabled'; + } + if ($row->blacklisted === 'y') { + $classes[] = 'strike-links'; + } + $attributes->add('class', $classes); + + return $tr; + } + + protected function getInheritedServiceLink($row, $target) + { + $params = [ + 'name' => $target->object_name, + 'service' => $row->object_name, + 'inheritedFrom' => $row->host, + ]; + + return Link::create( + $row->object_name, + 'director/host/inheritedservice', + $params + ); + } + + protected function getServiceLink($row) + { + if ($this->readonly) { + if ($this->highlightedService === $row->object_name) { + return Html::tag('span', ['class' => 'icon-right-big'], $row->object_name); + } else { + return $row->object_name; + } + } + + $params = [ + 'uuid' => Uuid::fromBytes(DbUtil::binaryResult($row->uuid))->toString(), + ]; + if ($row->host !== null) { + $params['host'] = $row->host; + } + if ($target = $this->inheritedBy) { + return $this->getInheritedServiceLink($row, $target); + } + + return Link::create( + $row->object_name, + 'director/service/edit', + $params + ); + } + + public function prepareQuery() + { + $query = parent::prepareQuery(); + if ($this->branchUuid) { + $queries = [$this->leftSubQuery, $this->rightSubQuery]; + } else { + $queries = [$query]; + } + + foreach ($queries as $subQuery) { + $subQuery->joinLeft( + ['h' => 'icinga_host'], + 'o.host_id = h.id', + [] + )->joinLeft( + ['hsb' => 'icinga_host_service_blacklist'], + 'hsb.service_id = o.id AND hsb.host_id = o.host_id', + [] + )->where('o.service_set_id IS NULL') + ->order('o.object_name')->order('h.object_name'); + + if ($this->host) { + if ($this->branchUuid) { + $subQuery->where('COALESCE(h.object_name, bo.host) = ?', $this->host->getObjectName()); + } else { + $subQuery->where('h.id = ?', $this->host->get('id')); + } + } + } + + return $query; + } +} -- cgit v1.2.3