Skip to content

Commit

Permalink
Use default traits for item list parts
Browse files Browse the repository at this point in the history
  • Loading branch information
jrauh01 committed Jan 22, 2025
1 parent 7bdc420 commit d41c6cd
Show file tree
Hide file tree
Showing 13 changed files with 98 additions and 760 deletions.
45 changes: 6 additions & 39 deletions library/Kubernetes/Web/CronJobListItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,66 +5,32 @@
namespace Icinga\Module\Kubernetes\Web;

use Icinga\Module\Kubernetes\Common\BaseListItem;
use Icinga\Module\Kubernetes\Common\DefaultListItemHeader;
use Icinga\Module\Kubernetes\Common\DefaultListItemMain;
use Icinga\Module\Kubernetes\Common\Icons;
use Icinga\Module\Kubernetes\Common\Links;
use ipl\Html\Attributes;
use ipl\Html\BaseHtmlElement;
use ipl\Html\Html;
use ipl\Html\HtmlDocument;
use ipl\Html\HtmlElement;
use ipl\Html\Text;
use ipl\I18n\Translation;
use ipl\Web\Widget\HorizontalKeyValue;
use ipl\Web\Widget\Link;
use ipl\Web\Widget\StateBall;
use ipl\Web\Widget\TimeAgo;

class CronJobListItem extends BaseListItem
{
use Translation;

protected function assembleHeader(BaseHtmlElement $header): void
{
match ($this->viewMode) {
ViewModeSwitcher::VIEW_MODE_MINIMAL,
ViewModeSwitcher::VIEW_MODE_COMMON =>
$header->addHtml(
Html::tag(
'span',
Attributes::create(['class' => 'header-minimal']),
[
$this->createTitle(),
$this->createCaption()
]
)
),
ViewModeSwitcher::VIEW_MODE_DETAILED =>
$header->addHtml($this->createTitle()),
default => null
};

$header->addHtml(new TimeAgo($this->item->created->getTimestamp()));
}
use DefaultListItemHeader;
use DefaultListItemMain;

protected function assembleCaption(BaseHtmlElement $caption): void
{
// TODO add state reason
// TODO add state reason then replace function by DefaultListItemCaption trait
$caption->addHtml(new Text('Placeholder for Icinga State Reason'));
}

protected function assembleMain(BaseHtmlElement $main): void
{
$main->addHtml($this->createHeader());

if ($this->viewMode === ViewModeSwitcher::VIEW_MODE_DETAILED) {
$main->addHtml($this->createCaption());
}

if ($this->viewMode !== ViewModeSwitcher::VIEW_MODE_MINIMAL) {
$main->addHtml($this->createFooter());
}
}

protected function assembleFooter(BaseHtmlElement $footer): void
{
if (isset($this->item->last_schedule_time)) {
Expand Down Expand Up @@ -110,6 +76,7 @@ protected function assembleTitle(BaseHtmlElement $title): void

protected function assembleVisual(BaseHtmlElement $visual): void
{
// TODO add icinga state then replace function by DefaultListItemVisual trait
$visual->addHtml(new StateBall('none', StateBall::SIZE_MEDIUM));
}
}
91 changes: 10 additions & 81 deletions library/Kubernetes/Web/DaemonSetListItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,65 +5,27 @@
namespace Icinga\Module\Kubernetes\Web;

use Icinga\Module\Kubernetes\Common\BaseListItem;
use Icinga\Module\Kubernetes\Common\DefaultListItemCaption;
use Icinga\Module\Kubernetes\Common\DefaultListItemHeader;
use Icinga\Module\Kubernetes\Common\DefaultListItemMain;
use Icinga\Module\Kubernetes\Common\DefaultListItemTitle;
use Icinga\Module\Kubernetes\Common\DefaultListItemVisual;
use Icinga\Module\Kubernetes\Common\Format;
use Icinga\Module\Kubernetes\Common\Links;
use ipl\Html\Attributes;
use ipl\Html\BaseHtmlElement;
use ipl\Html\Html;
use ipl\Html\HtmlDocument;
use ipl\Html\HtmlElement;
use ipl\Html\Text;
use ipl\I18n\Translation;
use ipl\Web\Widget\HorizontalKeyValue;
use ipl\Web\Widget\Icon;
use ipl\Web\Widget\Link;
use ipl\Web\Widget\StateBall;
use ipl\Web\Widget\TimeAgo;

class DaemonSetListItem extends BaseListItem
{
use Translation;

protected function assembleHeader(BaseHtmlElement $header): void
{
match ($this->viewMode) {
ViewModeSwitcher::VIEW_MODE_MINIMAL,
ViewModeSwitcher::VIEW_MODE_COMMON =>
$header->addHtml(
Html::tag(
'span',
Attributes::create(['class' => 'header-minimal']),
[
$this->createTitle(),
$this->createCaption()
]
)
),
ViewModeSwitcher::VIEW_MODE_DETAILED =>
$header->addHtml($this->createTitle()),
default => null
};

$header->addHtml(new TimeAgo($this->item->created->getTimestamp()));
}

protected function assembleCaption(BaseHtmlElement $caption): void
{
$caption->addHtml(new Text($this->item->icinga_state_reason));
}

protected function assembleMain(BaseHtmlElement $main): void
{
$main->addHtml($this->createHeader());

if ($this->viewMode === ViewModeSwitcher::VIEW_MODE_DETAILED) {
$main->addHtml($this->createCaption());
}

if ($this->viewMode !== ViewModeSwitcher::VIEW_MODE_MINIMAL) {
$main->addHtml($this->createFooter());
}
}
use DefaultListItemHeader;
use DefaultListItemCaption;
use DefaultListItemMain;
use DefaultListItemTitle;
use DefaultListItemVisual;

protected function assembleFooter(BaseHtmlElement $footer): void
{
Expand Down Expand Up @@ -99,37 +61,4 @@ protected function assembleFooter(BaseHtmlElement $footer): void
)
);
}

protected function assembleTitle(BaseHtmlElement $title): void
{
$title->addHtml(Html::sprintf(
$this->translate('%s is %s', '<daemon_set> is <icinga_state>'),
[
new HtmlElement(
'span',
new Attributes(['class' => 'namespace-badge']),
new HtmlElement('i', new Attributes(['class' => 'icon kicon-namespace'])),
new Text($this->item->namespace)
),
new Link(
(new HtmlDocument())->addHtml(
new HtmlElement('i', new Attributes(['class' => 'icon kicon-daemon-set'])),
new Text($this->item->name)
),
Links::daemonset($this->item),
new Attributes(['class' => 'subject'])
)
],
new HtmlElement(
'span',
new Attributes(['class' => 'icinga-state-text']),
new Text($this->item->icinga_state)
)
));
}

protected function assembleVisual(BaseHtmlElement $visual): void
{
$visual->addHtml(new StateBall($this->item->icinga_state, StateBall::SIZE_MEDIUM));
}
}
91 changes: 10 additions & 81 deletions library/Kubernetes/Web/DeploymentListItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,65 +5,27 @@
namespace Icinga\Module\Kubernetes\Web;

use Icinga\Module\Kubernetes\Common\BaseListItem;
use Icinga\Module\Kubernetes\Common\DefaultListItemCaption;
use Icinga\Module\Kubernetes\Common\DefaultListItemHeader;
use Icinga\Module\Kubernetes\Common\DefaultListItemMain;
use Icinga\Module\Kubernetes\Common\DefaultListItemTitle;
use Icinga\Module\Kubernetes\Common\DefaultListItemVisual;
use Icinga\Module\Kubernetes\Common\Format;
use Icinga\Module\Kubernetes\Common\Links;
use ipl\Html\Attributes;
use ipl\Html\BaseHtmlElement;
use ipl\Html\Html;
use ipl\Html\HtmlDocument;
use ipl\Html\HtmlElement;
use ipl\Html\Text;
use ipl\I18n\Translation;
use ipl\Web\Widget\HorizontalKeyValue;
use ipl\Web\Widget\Icon;
use ipl\Web\Widget\Link;
use ipl\Web\Widget\StateBall;
use ipl\Web\Widget\TimeAgo;

class DeploymentListItem extends BaseListItem
{
use Translation;

protected function assembleHeader(BaseHtmlElement $header): void
{
match ($this->viewMode) {
ViewModeSwitcher::VIEW_MODE_MINIMAL,
ViewModeSwitcher::VIEW_MODE_COMMON =>
$header->addHtml(
Html::tag(
'span',
Attributes::create(['class' => 'header-minimal']),
[
$this->createTitle(),
$this->createCaption()
]
)
),
ViewModeSwitcher::VIEW_MODE_DETAILED =>
$header->addHtml($this->createTitle()),
default => null
};

$header->addHtml(new TimeAgo($this->item->created->getTimestamp()));
}

protected function assembleCaption(BaseHtmlElement $caption): void
{
$caption->addHtml(new Text($this->item->icinga_state_reason));
}

protected function assembleMain(BaseHtmlElement $main): void
{
$main->addHtml($this->createHeader());

if ($this->viewMode === ViewModeSwitcher::VIEW_MODE_DETAILED) {
$main->addHtml($this->createCaption());
}

if ($this->viewMode !== ViewModeSwitcher::VIEW_MODE_MINIMAL) {
$main->addHtml($this->createFooter());
}
}
use DefaultListItemHeader;
use DefaultListItemCaption;
use DefaultListItemMain;
use DefaultListItemTitle;
use DefaultListItemVisual;

protected function assembleFooter(BaseHtmlElement $footer): void
{
Expand Down Expand Up @@ -103,37 +65,4 @@ protected function assembleFooter(BaseHtmlElement $footer): void
)
);
}

protected function assembleTitle(BaseHtmlElement $title): void
{
$title->addHtml(Html::sprintf(
$this->translate('%s is %s', '<deployment> is <icinga_state>'),
[
new HtmlElement(
'span',
new Attributes(['class' => 'namespace-badge']),
new HtmlElement('i', new Attributes(['class' => 'icon kicon-namespace'])),
new Text($this->item->namespace)
),
new Link(
(new HtmlDocument())->addHtml(
new HtmlElement('i', new Attributes(['class' => 'icon kicon-deployment'])),
new Text($this->item->name)
),
Links::deployment($this->item),
new Attributes(['class' => 'subject'])
)
],
new HtmlElement(
'span',
new Attributes(['class' => 'icinga-state-text']),
new Text($this->item->icinga_state)
)
));
}

protected function assembleVisual(BaseHtmlElement $visual): void
{
$visual->addHtml(new StateBall($this->item->icinga_state, StateBall::SIZE_MEDIUM));
}
}
44 changes: 5 additions & 39 deletions library/Kubernetes/Web/IngressListItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,65 +5,31 @@
namespace Icinga\Module\Kubernetes\Web;

use Icinga\Module\Kubernetes\Common\BaseListItem;
use Icinga\Module\Kubernetes\Common\DefaultListItemHeader;
use Icinga\Module\Kubernetes\Common\DefaultListItemMain;
use Icinga\Module\Kubernetes\Common\Links;
use ipl\Html\Attributes;
use ipl\Html\BaseHtmlElement;
use ipl\Html\Html;
use ipl\Html\HtmlDocument;
use ipl\Html\HtmlElement;
use ipl\Html\Text;
use ipl\I18n\Translation;
use ipl\Web\Widget\HorizontalKeyValue;
use ipl\Web\Widget\Link;
use ipl\Web\Widget\StateBall;
use ipl\Web\Widget\TimeAgo;

class IngressListItem extends BaseListItem
{
use Translation;

protected function assembleHeader(BaseHtmlElement $header): void
{
match ($this->viewMode) {
ViewModeSwitcher::VIEW_MODE_MINIMAL,
ViewModeSwitcher::VIEW_MODE_COMMON =>
$header->addHtml(
Html::tag(
'span',
Attributes::create(['class' => 'header-minimal']),
[
$this->createTitle(),
$this->createCaption()
]
)
),
ViewModeSwitcher::VIEW_MODE_DETAILED =>
$header->addHtml($this->createTitle()),
default => null
};

$header->addHtml(new TimeAgo($this->item->created->getTimestamp()));
}
use DefaultListItemHeader;
use DefaultListItemMain;

protected function assembleCaption(BaseHtmlElement $caption): void
{
// TODO add state reason
// TODO add state reason then replace function by DefaultListItemCaption trait
$caption->addHtml(new Text('Placeholder for Icinga State Reason'));
}

protected function assembleMain(BaseHtmlElement $main): void
{
$main->addHtml($this->createHeader());

if ($this->viewMode === ViewModeSwitcher::VIEW_MODE_DETAILED) {
$main->addHtml($this->createCaption());
}

if ($this->viewMode !== ViewModeSwitcher::VIEW_MODE_MINIMAL) {
$main->addHtml($this->createFooter());
}
}

protected function assembleFooter(BaseHtmlElement $footer): void
{
$hosts = [];
Expand Down
Loading

0 comments on commit d41c6cd

Please sign in to comment.