From 0a1ecca96b19426d2089f87dc7c16c40ef4bf273 Mon Sep 17 00:00:00 2001 From: Sukhwinder Dhillon Date: Tue, 3 Dec 2024 10:19:34 +0100 Subject: [PATCH] Host Service group --- .../controllers/HostgroupController.php | 5 +- .../controllers/ServicegroupController.php | 4 +- .../Widget/Detail/HostgroupHeader.php | 49 +++++++++++++++++++ .../Widget/Detail/ServicegroupHeader.php | 19 +++++++ .../Widget/ItemTable/BaseHostGroupItem.php | 40 ++++++--------- .../Widget/ItemTable/BaseServiceGroupItem.php | 36 +++++++------- .../Widget/ItemTable/HostgroupTableRow.php | 4 +- public/css/widget/object-header.less | 30 ++++++++++-- 8 files changed, 134 insertions(+), 53 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..b1a48a691 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,11 @@ 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..5d99eda21 --- /dev/null +++ b/library/Icingadb/Widget/Detail/HostgroupHeader.php @@ -0,0 +1,49 @@ + 'hostgroup-header']; + + protected function assembleTitle(BaseHtmlElement $title): void + { + $title->addHtml($this->createSubject()); + $title->addHtml(new HtmlElement('span', null, Text::create($this->object->name))); + } + + protected function assembleHeader(BaseHtmlElement $header): void + { + $header->addHtml($this->createTitle()); + + $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)); + + $header->addHtml($hostStats, $serviceStats); + } + + protected function assembleMain(BaseHtmlElement $main): void + { + $main->addHtml($this->createHeader()); + } + + 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..6a8905b34 --- /dev/null +++ b/library/Icingadb/Widget/Detail/ServicegroupHeader.php @@ -0,0 +1,19 @@ +addHtml($this->createTitle()); + + $serviceStats = (new ServiceStatistics($this->object)) + ->setBaseFilter(Filter::equal('servicegroup.name', $this->object->name)); + + $header->addHtml($serviceStats); + } +} \ No newline at end of file diff --git a/library/Icingadb/Widget/ItemTable/BaseHostGroupItem.php b/library/Icingadb/Widget/ItemTable/BaseHostGroupItem.php index aa581eed3..6356a2676 100644 --- a/library/Icingadb/Widget/ItemTable/BaseHostGroupItem.php +++ b/library/Icingadb/Widget/ItemTable/BaseHostGroupItem.php @@ -27,37 +27,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..4f7de1424 100644 --- a/library/Icingadb/Widget/ItemTable/BaseServiceGroupItem.php +++ b/library/Icingadb/Widget/ItemTable/BaseServiceGroupItem.php @@ -34,30 +34,28 @@ protected function init(): void 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; - } - return new HtmlElement( 'span', Attributes::create(['class' => 'subject']), Text::create($this->item->display_name) ); + + $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; } 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/public/css/widget/object-header.less b/public/css/widget/object-header.less index 9cd2f9be3..6cd5c7eef 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; @@ -81,6 +81,14 @@ .text-ellipsis(); } + .object-statistics { + margin-left: auto; + + &:not(:last-child) { + margin-right: 1em; + } + } + time { white-space: nowrap; } @@ -96,9 +104,23 @@ color: @default-text-color; } } +} - .object-statistics { - margin-left: auto; - margin-right: 1em; +.hostgroup-header, +.servicegroup-header { + .main { + padding: 0; + } + + .main > header { + justify-content: normal; + + .title { + margin-right: auto; + } + + .object-statistics { + margin-left: 0; + } } }