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 4, 2024
1 parent b0c0994 commit 179b48a
Show file tree
Hide file tree
Showing 9 changed files with 141 additions and 60 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
5 changes: 3 additions & 2 deletions 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,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);
Expand Down
51 changes: 51 additions & 0 deletions library/Icingadb/Widget/Detail/HostgroupHeader.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

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

namespace Icinga\Module\Icingadb\Widget\Detail;

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

/**
* @property Hostgroupsummary $object
*/
class HostgroupHeader extends BaseObjectHeader
{
use ListItemMinimalLayout;

protected $defaultAttributes = ['class' => '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());
}
}
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 $defaultAttributes = ['class' => 'servicegroup-header'];

protected function assembleCaption(BaseHtmlElement $caption): void
{
$caption->addHtml(
(new ServiceStatistics($this->object))
->setBaseFilter(Filter::equal('servicegroup.name', $this->object->name))
);
}
}
41 changes: 15 additions & 26 deletions library/Icingadb/Widget/ItemTable/BaseHostGroupItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down
41 changes: 15 additions & 26 deletions library/Icingadb/Widget/ItemTable/BaseServiceGroupItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
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
2 changes: 1 addition & 1 deletion library/Icingadb/Widget/ItemTable/ServicegroupTableRow.php
Original file line number Diff line number Diff line change
Expand Up @@ -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())
);
Expand Down
33 changes: 32 additions & 1 deletion 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 @@ -62,6 +62,10 @@
margin-right: 1em;
width: 0;

> *:not(:last-child) {
margin-right: .5em;
}

.line-clamp("reset");

font-size: 11/12em;
Expand Down Expand Up @@ -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;
}
}
}
}
}

0 comments on commit 179b48a

Please sign in to comment.