From 179b48abe0204fb7f2508147c449f976fb44fec0 Mon Sep 17 00:00:00 2001 From: Sukhwinder Dhillon Date: Wed, 4 Dec 2024 14:24:04 +0100 Subject: [PATCH] host/service group --- .../controllers/HostgroupController.php | 5 +- .../controllers/ServicegroupController.php | 5 +- .../Widget/Detail/HostgroupHeader.php | 51 +++++++++++++++++++ .../Widget/Detail/ServicegroupHeader.php | 19 +++++++ .../Widget/ItemTable/BaseHostGroupItem.php | 41 ++++++--------- .../Widget/ItemTable/BaseServiceGroupItem.php | 41 ++++++--------- .../Widget/ItemTable/HostgroupTableRow.php | 4 +- .../Widget/ItemTable/ServicegroupTableRow.php | 2 +- public/css/widget/object-header.less | 33 +++++++++++- 9 files changed, 141 insertions(+), 60 deletions(-) create mode 100644 library/Icingadb/Widget/Detail/HostgroupHeader.php create mode 100644 library/Icingadb/Widget/Detail/ServicegroupHeader.php diff --git a/application/controllers/HostgroupController.php b/application/controllers/HostgroupController.php index e48adca20..96cb2265c 100644 --- a/application/controllers/HostgroupController.php +++ b/application/controllers/HostgroupController.php @@ -12,6 +12,7 @@ use Icinga\Module\Icingadb\Web\Control\SearchBar\ObjectSuggestions; use Icinga\Module\Icingadb\Web\Control\ViewModeSwitcher; use Icinga\Module\Icingadb\Web\Controller; +use Icinga\Module\Icingadb\Widget\Detail\HostgroupHeader; use Icinga\Module\Icingadb\Widget\ItemList\HostList; use Icinga\Module\Icingadb\Widget\ItemTable\HostgroupTableRow; use ipl\Html\Html; @@ -114,10 +115,10 @@ public function indexAction(): Generator // ICINGAWEB_EXPORT_FORMAT is not set yet and $this->format is inaccessible, yeah... if ($this->getRequest()->getParam('format') === 'pdf') { - $this->addContent(new HostgroupTableRow($hostgroup)); + $this->addContent(new HostgroupHeader($hostgroup)); $this->addContent(Html::tag('h2', null, t('Hosts'))); } else { - $this->addControl(new HostgroupTableRow($hostgroup)); + $this->addControl(new HostgroupHeader($hostgroup)); } $this->addControl($paginationControl); diff --git a/application/controllers/ServicegroupController.php b/application/controllers/ServicegroupController.php index c3dea15bc..2dd4f210e 100644 --- a/application/controllers/ServicegroupController.php +++ b/application/controllers/ServicegroupController.php @@ -12,6 +12,7 @@ use Icinga\Module\Icingadb\Web\Control\SearchBar\ObjectSuggestions; use Icinga\Module\Icingadb\Web\Control\ViewModeSwitcher; use Icinga\Module\Icingadb\Web\Controller; +use Icinga\Module\Icingadb\Widget\Detail\ServicegroupHeader; use Icinga\Module\Icingadb\Widget\ItemList\ServiceList; use Icinga\Module\Icingadb\Widget\ItemTable\ServicegroupTableRow; use ipl\Html\Html; @@ -122,10 +123,10 @@ public function indexAction(): Generator // ICINGAWEB_EXPORT_FORMAT is not set yet and $this->format is inaccessible, yeah... if ($this->getRequest()->getParam('format') === 'pdf') { - $this->addContent(new ServicegroupTableRow($servicegroup)); + $this->addContent(new ServicegroupHeader($servicegroup)); $this->addContent(Html::tag('h2', null, t('Services'))); } else { - $this->addControl(new ServicegroupTableRow($servicegroup)); + $this->addControl(new ServicegroupHeader($servicegroup)); } $this->addControl($paginationControl); diff --git a/library/Icingadb/Widget/Detail/HostgroupHeader.php b/library/Icingadb/Widget/Detail/HostgroupHeader.php new file mode 100644 index 000000000..5058c145f --- /dev/null +++ b/library/Icingadb/Widget/Detail/HostgroupHeader.php @@ -0,0 +1,51 @@ + 'hostgroup-header']; + + protected function assembleTitle(BaseHtmlElement $title): void + { + $title->addHtml(new HtmlElement( + 'span', + Attributes::create(['class' => 'subject']), + Text::create($this->object->display_name) + )); + + $title->addHtml(new HtmlElement('span', null, Text::create($this->object->name))); + } + + protected function assembleCaption(BaseHtmlElement $caption): void + { + $hostStats = (new HostStatistics($this->object)) + ->setBaseFilter(Filter::equal('hostgroup.name', $this->object->name)); + + + $serviceStats = (new ServiceStatistics($this->object)) + ->setBaseFilter(Filter::equal('hostgroup.name', $this->object->name)); + + $caption->addHtml($hostStats, $serviceStats); + } + + protected function assemble(): void + { + $this->addHtml($this->createMain()); + } +} diff --git a/library/Icingadb/Widget/Detail/ServicegroupHeader.php b/library/Icingadb/Widget/Detail/ServicegroupHeader.php new file mode 100644 index 000000000..bcadd5c1f --- /dev/null +++ b/library/Icingadb/Widget/Detail/ServicegroupHeader.php @@ -0,0 +1,19 @@ + 'servicegroup-header']; + + protected function assembleCaption(BaseHtmlElement $caption): void + { + $caption->addHtml( + (new ServiceStatistics($this->object)) + ->setBaseFilter(Filter::equal('servicegroup.name', $this->object->name)) + ); + } +} \ No newline at end of file diff --git a/library/Icingadb/Widget/ItemTable/BaseHostGroupItem.php b/library/Icingadb/Widget/ItemTable/BaseHostGroupItem.php index aa581eed3..7a352746a 100644 --- a/library/Icingadb/Widget/ItemTable/BaseHostGroupItem.php +++ b/library/Icingadb/Widget/ItemTable/BaseHostGroupItem.php @@ -6,7 +6,6 @@ use Icinga\Module\Icingadb\Common\Links; use Icinga\Module\Icingadb\Model\Hostgroupsummary; -use ipl\Html\Attributes; use ipl\Html\BaseHtmlElement; use ipl\Html\HtmlElement; use ipl\Html\Text; @@ -27,37 +26,27 @@ abstract class BaseHostGroupItem extends BaseTableRowItem protected function init(): void { - if (isset($this->table)) { - $this->table->addDetailFilterAttribute($this, Filter::equal('name', $this->item->name)); - } + $this->table->addDetailFilterAttribute($this, Filter::equal('name', $this->item->name)); } protected function createSubject(): BaseHtmlElement { - if (isset($this->table)) { - $link = new Link( - $this->item->display_name, - Links::hostgroup($this->item), - [ - 'class' => 'subject', - 'title' => sprintf( - $this->translate('List all hosts in the group "%s"'), - $this->item->display_name - ) - ] - ); - if ($this->table->hasBaseFilter()) { - $link->getUrl()->setFilter($this->table->getBaseFilter()); - } - - return $link; + $link = new Link( + $this->item->display_name, + Links::hostgroup($this->item), + [ + 'class' => 'subject', + 'title' => sprintf( + $this->translate('List all hosts in the group "%s"'), + $this->item->display_name + ) + ] + ); + if ($this->table->hasBaseFilter()) { + $link->getUrl()->setFilter($this->table->getBaseFilter()); } - return new HtmlElement( - 'span', - Attributes::create(['class' => 'subject']), - Text::create($this->item->display_name) - ); + return $link; } protected function createCaption(): BaseHtmlElement diff --git a/library/Icingadb/Widget/ItemTable/BaseServiceGroupItem.php b/library/Icingadb/Widget/ItemTable/BaseServiceGroupItem.php index 4719bb9e5..f8a50cb2e 100644 --- a/library/Icingadb/Widget/ItemTable/BaseServiceGroupItem.php +++ b/library/Icingadb/Widget/ItemTable/BaseServiceGroupItem.php @@ -6,7 +6,6 @@ use Icinga\Module\Icingadb\Common\Links; use Icinga\Module\Icingadb\Model\ServicegroupSummary; -use ipl\Html\Attributes; use ipl\Html\BaseHtmlElement; use ipl\Html\HtmlElement; use ipl\Html\Text; @@ -27,37 +26,27 @@ abstract class BaseServiceGroupItem extends BaseTableRowItem protected function init(): void { - if (isset($this->table)) { - $this->table->addDetailFilterAttribute($this, Filter::equal('name', $this->item->name)); - } + $this->table->addDetailFilterAttribute($this, Filter::equal('name', $this->item->name)); } protected function createSubject(): BaseHtmlElement { - if (isset($this->table)) { - $link = new Link( - $this->item->display_name, - Links::servicegroup($this->item), - [ - 'class' => 'subject', - 'title' => sprintf( - $this->translate('List all services in the group "%s"'), - $this->item->display_name - ) - ] - ); - if ($this->table->hasBaseFilter()) { - $link->getUrl()->setFilter($this->table->getBaseFilter()); - } - - return $link; + $link = new Link( + $this->item->display_name, + Links::servicegroup($this->item), + [ + 'class' => 'subject', + 'title' => sprintf( + $this->translate('List all services in the group "%s"'), + $this->item->display_name + ) + ] + ); + if ($this->table->hasBaseFilter()) { + $link->getUrl()->setFilter($this->table->getBaseFilter()); } - return new HtmlElement( - 'span', - Attributes::create(['class' => 'subject']), - Text::create($this->item->display_name) - ); + return $link; } protected function createCaption(): BaseHtmlElement diff --git a/library/Icingadb/Widget/ItemTable/HostgroupTableRow.php b/library/Icingadb/Widget/ItemTable/HostgroupTableRow.php index cb3f06a9a..5094f132f 100644 --- a/library/Icingadb/Widget/ItemTable/HostgroupTableRow.php +++ b/library/Icingadb/Widget/ItemTable/HostgroupTableRow.php @@ -32,7 +32,7 @@ protected function createStatistics(): array $hostStats = new HostStatistics($this->item); $hostStats->setBaseFilter(Filter::equal('hostgroup.name', $this->item->name)); - if (isset($this->table) && $this->table->hasBaseFilter()) { + if ($this->table->hasBaseFilter()) { $hostStats->setBaseFilter( Filter::all($hostStats->getBaseFilter(), $this->table->getBaseFilter()) ); @@ -41,7 +41,7 @@ protected function createStatistics(): array $serviceStats = new ServiceStatistics($this->item); $serviceStats->setBaseFilter(Filter::equal('hostgroup.name', $this->item->name)); - if (isset($this->table) && $this->table->hasBaseFilter()) { + if ($this->table->hasBaseFilter()) { $serviceStats->setBaseFilter( Filter::all($serviceStats->getBaseFilter(), $this->table->getBaseFilter()) ); diff --git a/library/Icingadb/Widget/ItemTable/ServicegroupTableRow.php b/library/Icingadb/Widget/ItemTable/ServicegroupTableRow.php index e34c029ff..24abf7ec6 100644 --- a/library/Icingadb/Widget/ItemTable/ServicegroupTableRow.php +++ b/library/Icingadb/Widget/ItemTable/ServicegroupTableRow.php @@ -31,7 +31,7 @@ protected function createStatistics(): array $serviceStats = new ServiceStatistics($this->item); $serviceStats->setBaseFilter(Filter::equal('servicegroup.name', $this->item->name)); - if (isset($this->table) && $this->table->hasBaseFilter()) { + if ($this->table->hasBaseFilter()) { $serviceStats->setBaseFilter( Filter::all($serviceStats->getBaseFilter(), $this->table->getBaseFilter()) ); diff --git a/public/css/widget/object-header.less b/public/css/widget/object-header.less index d4379eade..e894b0f1a 100644 --- a/public/css/widget/object-header.less +++ b/public/css/widget/object-header.less @@ -6,6 +6,7 @@ display: flex; padding: 0.25em 0; align-items: center; + margin-right: .5em; } .icon-image { //todo: center the image @@ -21,7 +22,6 @@ flex: 1 1 auto; padding: 0.25em 0; width: 0; - margin-left: .5em; header { display: flex; @@ -62,6 +62,10 @@ margin-right: 1em; width: 0; + > *:not(:last-child) { + margin-right: .5em; + } + .line-clamp("reset"); font-size: 11/12em; @@ -108,3 +112,30 @@ } } } + +.hostgroup-header, +.servicegroup-header { + .main > header { + .caption { + height: unset; //TODO; fix this, this must be removed + } + + .object-statistics { + display: inline-flex; + + .vertical-key-value { + br { + display: none; + } + + .key { + padding-left: .417em; + } + + .value { + vertical-align: middle; + } + } + } + } +}