Skip to content

Commit

Permalink
Host Service group
Browse files Browse the repository at this point in the history
  • Loading branch information
sukhwinder33445 committed Dec 3, 2024
1 parent 892f40f commit 0a1ecca
Show file tree
Hide file tree
Showing 8 changed files with 134 additions and 53 deletions.
5 changes: 3 additions & 2 deletions application/controllers/HostgroupController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 3 additions & 1 deletion application/controllers/ServicegroupController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
49 changes: 49 additions & 0 deletions library/Icingadb/Widget/Detail/HostgroupHeader.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

/* Icinga DB Web | (c) 2024 Icinga GmbH | GPLv2 */

namespace Icinga\Module\Icingadb\Widget\Detail;

use Icinga\Module\Icingadb\Model\Hostgroupsummary;
use ipl\Html\BaseHtmlElement;
use ipl\Html\HtmlElement;
use ipl\Html\Text;
use ipl\Stdlib\Filter;

/**
* @property Hostgroupsummary $object
*/
class HostgroupHeader extends BaseObjectHeader
{
protected $defaultAttributes = ['class' => '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());
}
}
19 changes: 19 additions & 0 deletions library/Icingadb/Widget/Detail/ServicegroupHeader.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace Icinga\Module\Icingadb\Widget\Detail;

use ipl\Html\BaseHtmlElement;
use ipl\Stdlib\Filter;

class ServicegroupHeader extends HostgroupHeader
{
protected function assembleHeader(BaseHtmlElement $header): void
{
$header->addHtml($this->createTitle());

$serviceStats = (new ServiceStatistics($this->object))
->setBaseFilter(Filter::equal('servicegroup.name', $this->object->name));

$header->addHtml($serviceStats);
}
}
40 changes: 15 additions & 25 deletions library/Icingadb/Widget/ItemTable/BaseHostGroupItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
36 changes: 17 additions & 19 deletions library/Icingadb/Widget/ItemTable/BaseServiceGroupItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions library/Icingadb/Widget/ItemTable/HostgroupTableRow.php
Original file line number Diff line number Diff line change
Expand Up @@ -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())
);
Expand All @@ -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())
);
Expand Down
30 changes: 26 additions & 4 deletions public/css/widget/object-header.less
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
display: flex;
padding: 0.25em 0;
align-items: center;
margin-right: .5em;
}

.icon-image { //todo: center the image
Expand All @@ -21,7 +22,6 @@
flex: 1 1 auto;
padding: 0.25em 0;
width: 0;
margin-left: .5em;

header {
display: flex;
Expand Down Expand Up @@ -81,6 +81,14 @@
.text-ellipsis();
}

.object-statistics {
margin-left: auto;

&:not(:last-child) {
margin-right: 1em;
}
}

time {
white-space: nowrap;
}
Expand All @@ -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;
}
}
}

0 comments on commit 0a1ecca

Please sign in to comment.