Skip to content

Commit

Permalink
Introduce (Host|Service)Header class
Browse files Browse the repository at this point in the history
- Use this class to create object header for host and service
- Remove previous implementation
- Add required changes to `object-header.less`
- StateList: Remove now unused NoSubjectLink

wip
  • Loading branch information
sukhwinder33445 committed Dec 3, 2024
1 parent d8c6735 commit 892f40f
Show file tree
Hide file tree
Showing 18 changed files with 435 additions and 310 deletions.
22 changes: 4 additions & 18 deletions application/controllers/HostController.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
use Icinga\Module\Icingadb\Redis\VolatileStateResults;
use Icinga\Module\Icingadb\Web\Controller;
use Icinga\Module\Icingadb\Widget\Detail\HostDetail;
use Icinga\Module\Icingadb\Widget\Detail\HostHeader;
use Icinga\Module\Icingadb\Widget\Detail\HostInspectionDetail;
use Icinga\Module\Icingadb\Widget\Detail\HostMetaInfo;
use Icinga\Module\Icingadb\Widget\Detail\QuickActions;
use Icinga\Module\Icingadb\Widget\ItemList\HostList;
use Icinga\Module\Icingadb\Widget\ItemList\HistoryList;
use Icinga\Module\Icingadb\Widget\ItemList\ServiceList;
use ipl\Stdlib\Filter;
Expand Down Expand Up @@ -57,6 +57,8 @@ public function init()
$this->host = $host;
$this->loadTabsForObject($host);

$this->addControl(new HostHeader($this->host));

$this->setTitleTab($this->getRequest()->getActionName());
$this->setTitle($host->display_name);
}
Expand All @@ -72,10 +74,6 @@ public function indexAction()
$this->controls->addAttributes(['class' => 'overdue']);
}

$this->addControl((new HostList([$this->host]))
->setViewMode('objectHeader')
->setDetailActionsDisabled()
->setNoSubjectLink());
$this->addControl(new HostMetaInfo($this->host));
$this->addControl(new QuickActions($this->host));

Expand All @@ -97,10 +95,6 @@ public function sourceAction()
$this->controls->addAttributes(['class' => 'overdue']);
}

$this->addControl((new HostList([$this->host]))
->setViewMode('objectHeader')
->setDetailActionsDisabled()
->setNoSubjectLink());
$this->addContent(new HostInspectionDetail(
$this->host,
reset($apiResult)
Expand Down Expand Up @@ -158,10 +152,6 @@ public function historyAction()

yield $this->export($history);

$this->addControl((new HostList([$this->host]))
->setViewMode('objectHeader')
->setDetailActionsDisabled()
->setNoSubjectLink());
$this->addControl($sortControl);
$this->addControl($limitControl);
$this->addControl($viewModeSwitcher);
Expand Down Expand Up @@ -221,10 +211,6 @@ public function servicesAction()
$serviceList = (new ServiceList($services))
->setViewMode($viewModeSwitcher->getViewMode());

$this->addControl((new HostList([$this->host]))
->setViewMode('objectHeader')
->setDetailActionsDisabled()
->setNoSubjectLink());
$this->addControl($paginationControl);
$this->addControl($sortControl);
$this->addControl($limitControl);
Expand Down Expand Up @@ -288,6 +274,6 @@ protected function getCommandTargetsUrl(): Url

protected function getDefaultTabControls(): array
{
return [(new HostList([$this->host]))->setDetailActionsDisabled()->setNoSubjectLink()];
return [(new HostHeader($this->host))];
}
}
18 changes: 4 additions & 14 deletions application/controllers/ServiceController.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
use Icinga\Module\Icingadb\Web\Controller;
use Icinga\Module\Icingadb\Widget\Detail\QuickActions;
use Icinga\Module\Icingadb\Widget\Detail\ServiceDetail;
use Icinga\Module\Icingadb\Widget\Detail\ServiceHeader;
use Icinga\Module\Icingadb\Widget\Detail\ServiceInspectionDetail;
use Icinga\Module\Icingadb\Widget\Detail\ServiceMetaInfo;
use Icinga\Module\Icingadb\Widget\ItemList\HistoryList;
use Icinga\Module\Icingadb\Widget\ItemList\ServiceList;
use ipl\Stdlib\Filter;
use ipl\Web\Url;

Expand Down Expand Up @@ -65,6 +65,8 @@ public function init()
$this->service = $service;
$this->loadTabsForObject($service);

$this->addControl(new ServiceHeader($this->service));

$this->setTitleTab($this->getRequest()->getActionName());
$this->setTitle(
t('%s on %s', '<service> on <host>'),
Expand All @@ -79,10 +81,6 @@ public function indexAction()
$this->controls->addAttributes(['class' => 'overdue']);
}

$this->addControl((new ServiceList([$this->service]))
->setViewMode('objectHeader')
->setDetailActionsDisabled()
->setNoSubjectLink());
$this->addControl(new ServiceMetaInfo($this->service));
$this->addControl(new QuickActions($this->service));

Expand All @@ -104,10 +102,6 @@ public function sourceAction()
$this->controls->addAttributes(['class' => 'overdue']);
}

$this->addControl((new ServiceList([$this->service]))
->setViewMode('objectHeader')
->setDetailActionsDisabled()
->setNoSubjectLink());
$this->addContent(new ServiceInspectionDetail(
$this->service,
reset($apiResult)
Expand Down Expand Up @@ -166,10 +160,6 @@ public function historyAction()

yield $this->export($history);

$this->addControl((new ServiceList([$this->service]))
->setViewMode('objectHeader')
->setDetailActionsDisabled()
->setNoSubjectLink());
$this->addControl($sortControl);
$this->addControl($limitControl);
$this->addControl($viewModeSwitcher);
Expand Down Expand Up @@ -242,6 +232,6 @@ protected function getCommandTargetsUrl(): Url

protected function getDefaultTabControls(): array
{
return [(new ServiceList([$this->service]))->setDetailActionsDisabled()->setNoSubjectLink()];
return [new ServiceHeader($this->service)];
}
}
51 changes: 51 additions & 0 deletions library/Icingadb/Widget/Detail/BaseHostAndServiceHeader.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 ipl\Html\Attributes;
use ipl\Html\HtmlElement;
use ipl\Html\Text;
use ipl\Html\ValidHtml;
use ipl\Orm\Model;

class BaseHostAndServiceHeader extends BaseObjectHeader
{
use HostAndServiceHeaderUtils;
use ListItemMinimalLayout;

protected function getObject(): Model
{
return $this->object;
}

protected function getSubject(): ValidHtml
{
return new HtmlElement(
'span',
Attributes::create(['class' => 'subject']),
Text::create($this->object->display_name)
);
}

protected function getStateBallSize(): string
{
return ''; // not required because the parent class overrides the assembleVisual method
}

protected function wantIconImage(): bool
{
return isset($this->object->icon_image->icon_image);
}

protected function assemble(): void
{
$this->add([
$this->createVisual(),
$this->createIconImage(),
$this->createMain()
]);
}
}
23 changes: 0 additions & 23 deletions library/Icingadb/Widget/Detail/BaseObjectHeader.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,8 @@
use ipl\Html\Attributes;
use ipl\Html\BaseHtmlElement;
use ipl\Html\HtmlElement;
use ipl\Html\Text;
use ipl\I18n\Translation;
use ipl\Orm\Model;
use ipl\Web\Widget\StateBall;
use ipl\Web\Widget\TimeSince;

abstract class BaseObjectHeader extends BaseHtmlElement
{
Expand Down Expand Up @@ -55,11 +52,6 @@ protected function assembleVisual(BaseHtmlElement $visual): void
{
}

protected function getStateBallSize(): string
{
return StateBall::SIZE_BIG;
}

protected function createCaption(): BaseHtmlElement
{
$caption = new HtmlElement('section', Attributes::create(['class' => 'caption']));
Expand Down Expand Up @@ -87,21 +79,6 @@ protected function createMain(): BaseHtmlElement
return $main;
}

protected function createTimestamp(): ?BaseHtmlElement
{
//TODO: add support for host/service
return new TimeSince($this->object->state->last_state_change->getTimestamp());
}

protected function createSubject(): BaseHtmlElement
{
return new HtmlElement(
'span',
Attributes::create(['class' => 'subject']),
Text::create($this->object->display_name)
);
}

protected function createTitle(): BaseHtmlElement
{
$title = new HtmlElement('div', Attributes::create(['class' => 'title']));
Expand Down
Loading

0 comments on commit 892f40f

Please sign in to comment.