diff --git a/library/Kubernetes/Web/CronJobListItem.php b/library/Kubernetes/Web/CronJobListItem.php index df321c7d..4791d617 100644 --- a/library/Kubernetes/Web/CronJobListItem.php +++ b/library/Kubernetes/Web/CronJobListItem.php @@ -5,11 +5,12 @@ 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; @@ -17,54 +18,19 @@ 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)) { @@ -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)); } } diff --git a/library/Kubernetes/Web/DaemonSetListItem.php b/library/Kubernetes/Web/DaemonSetListItem.php index 8673b50a..cacc5034 100644 --- a/library/Kubernetes/Web/DaemonSetListItem.php +++ b/library/Kubernetes/Web/DaemonSetListItem.php @@ -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 { @@ -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', ' is '), - [ - 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)); - } } diff --git a/library/Kubernetes/Web/DeploymentListItem.php b/library/Kubernetes/Web/DeploymentListItem.php index 8499f6ef..8ddf4b56 100644 --- a/library/Kubernetes/Web/DeploymentListItem.php +++ b/library/Kubernetes/Web/DeploymentListItem.php @@ -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 { @@ -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', ' is '), - [ - 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)); - } } diff --git a/library/Kubernetes/Web/IngressListItem.php b/library/Kubernetes/Web/IngressListItem.php index ba87e330..f829a862 100644 --- a/library/Kubernetes/Web/IngressListItem.php +++ b/library/Kubernetes/Web/IngressListItem.php @@ -5,10 +5,11 @@ 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; @@ -16,54 +17,19 @@ 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 = []; diff --git a/library/Kubernetes/Web/JobListItem.php b/library/Kubernetes/Web/JobListItem.php index 46e4509d..054d99bd 100644 --- a/library/Kubernetes/Web/JobListItem.php +++ b/library/Kubernetes/Web/JobListItem.php @@ -5,65 +5,28 @@ 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 JobListItem 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 { @@ -110,37 +73,4 @@ protected function assembleFooter(BaseHtmlElement $footer): void ) ); } - - protected function assembleTitle(BaseHtmlElement $title): void - { - $title->addHtml(Html::sprintf( - $this->translate('%s is %s', ' is '), - [ - 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-job'])), - new Text($this->item->name) - ), - Links::job($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)); - } } diff --git a/library/Kubernetes/Web/NamespaceListItem.php b/library/Kubernetes/Web/NamespaceListItem.php index e7ac2134..6a55d75d 100644 --- a/library/Kubernetes/Web/NamespaceListItem.php +++ b/library/Kubernetes/Web/NamespaceListItem.php @@ -6,6 +6,8 @@ use Icinga\Module\Kubernetes\Common\BaseListItem; use Icinga\Module\Kubernetes\Common\Database; +use Icinga\Module\Kubernetes\Common\DefaultListItemHeader; +use Icinga\Module\Kubernetes\Common\DefaultListItemMain; use Icinga\Module\Kubernetes\Common\Links; use Icinga\Module\Kubernetes\Model\NamespaceModel; use ipl\Html\Attributes; @@ -19,34 +21,12 @@ use ipl\Web\Widget\HorizontalKeyValue; use ipl\Web\Widget\Link; use ipl\Web\Widget\StateBall; -use ipl\Web\Widget\TimeAgo; class NamespaceListItem 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 { @@ -65,19 +45,6 @@ protected function assembleCaption(BaseHtmlElement $caption): void )); } - 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 { $filter = $this->getResourceFilter(); diff --git a/library/Kubernetes/Web/NodeListItem.php b/library/Kubernetes/Web/NodeListItem.php index 38e26301..c907fe10 100644 --- a/library/Kubernetes/Web/NodeListItem.php +++ b/library/Kubernetes/Web/NodeListItem.php @@ -5,6 +5,10 @@ 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\DefaultListItemVisual; use Icinga\Module\Kubernetes\Common\Links; use Icinga\Util\Format; use ipl\Html\Attributes; @@ -17,50 +21,14 @@ use ipl\Web\Widget\HorizontalKeyValue; use ipl\Web\Widget\Icon; use ipl\Web\Widget\Link; -use ipl\Web\Widget\StateBall; class NodeListItem 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 - }; - } - - 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 DefaultListItemVisual; protected function assembleFooter(BaseHtmlElement $footer): void { @@ -96,9 +64,4 @@ protected function assembleTitle(BaseHtmlElement $title): void ) )); } - - protected function assembleVisual(BaseHtmlElement $visual): void - { - $visual->addHtml(new StateBall($this->item->icinga_state, StateBall::SIZE_MEDIUM)); - } } diff --git a/library/Kubernetes/Web/PersistentVolumeClaimListItem.php b/library/Kubernetes/Web/PersistentVolumeClaimListItem.php index 37f357c5..f68db88c 100644 --- a/library/Kubernetes/Web/PersistentVolumeClaimListItem.php +++ b/library/Kubernetes/Web/PersistentVolumeClaimListItem.php @@ -6,6 +6,8 @@ use Icinga\Module\Kubernetes\Common\AccessModes; 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 Icinga\Module\Kubernetes\Model\PersistentVolumeClaim; @@ -21,11 +23,12 @@ use ipl\Web\Widget\HorizontalKeyValue; use ipl\Web\Widget\Icon; use ipl\Web\Widget\Link; -use ipl\Web\Widget\TimeAgo; class PersistentVolumeClaimListItem extends BaseListItem { use Translation; + use DefaultListItemHeader; + use DefaultListItemMain; protected function getPhaseIcon(): string { @@ -37,47 +40,12 @@ protected function getPhaseIcon(): string }; } - 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 { + // 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 { $footer->addHtml( diff --git a/library/Kubernetes/Web/PersistentVolumeListItem.php b/library/Kubernetes/Web/PersistentVolumeListItem.php index cdec4f1c..041b9d0d 100644 --- a/library/Kubernetes/Web/PersistentVolumeListItem.php +++ b/library/Kubernetes/Web/PersistentVolumeListItem.php @@ -6,6 +6,8 @@ use Icinga\Module\Kubernetes\Common\AccessModes; 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 Icinga\Module\Kubernetes\Model\PersistentVolume; @@ -20,11 +22,12 @@ use ipl\Web\Widget\HorizontalKeyValue; use ipl\Web\Widget\Icon; use ipl\Web\Widget\Link; -use ipl\Web\Widget\TimeAgo; class PersistentVolumeListItem extends BaseListItem { use Translation; + use DefaultListItemHeader; + use DefaultListItemMain; protected function getPhaseIcon(): string { @@ -38,47 +41,12 @@ protected function getPhaseIcon(): string }; } - 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 { + // 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 { $footer->addHtml( diff --git a/library/Kubernetes/Web/PodListItem.php b/library/Kubernetes/Web/PodListItem.php index 35e8be18..d97c9c38 100644 --- a/library/Kubernetes/Web/PodListItem.php +++ b/library/Kubernetes/Web/PodListItem.php @@ -5,26 +5,27 @@ namespace Icinga\Module\Kubernetes\Web; use Icinga\Module\Kubernetes\Common\BaseListItem; -use Icinga\Module\Kubernetes\Common\Links; +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\Model\Container; use Icinga\Module\Kubernetes\Model\InitContainer; use Icinga\Module\Kubernetes\Model\SidecarContainer; -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 PodListItem extends BaseListItem { use Translation; + use DefaultListItemHeader; + use DefaultListItemCaption; + use DefaultListItemMain; + use DefaultListItemTitle; + use DefaultListItemVisual; public const QOS_ICONS = [ 'BestEffort' => 'eraser', @@ -32,47 +33,6 @@ class PodListItem extends BaseListItem 'Guaranteed' => 'heart-pulse' ]; - 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()); - } - } - protected function assembleFooter(BaseHtmlElement $footer): void { $containerRestarts = 0; @@ -132,37 +92,4 @@ protected function assembleFooter(BaseHtmlElement $footer): void new HorizontalKeyValue(new Icon('share-nodes'), $this->item->node_name ?? $this->translate('None')) ); } - - protected function assembleTitle(BaseHtmlElement $title): void - { - $title->addHtml(Html::sprintf( - $this->translate('%s is %s', ' is '), - [ - 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-pod'])), - new Text($this->item->name) - ), - Links::pod($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)); - } } diff --git a/library/Kubernetes/Web/ReplicaSetListItem.php b/library/Kubernetes/Web/ReplicaSetListItem.php index e6f1a963..8cb0c430 100644 --- a/library/Kubernetes/Web/ReplicaSetListItem.php +++ b/library/Kubernetes/Web/ReplicaSetListItem.php @@ -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 ReplicaSetListItem 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 { @@ -94,37 +56,4 @@ protected function assembleFooter(BaseHtmlElement $footer): void ), ); } - - protected function assembleTitle(BaseHtmlElement $title): void - { - $title->addHtml(Html::sprintf( - $this->translate('%s is %s', ' is '), - [ - 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-replica-set'])), - new Text($this->item->name) - ), - Links::replicaset($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)); - } } diff --git a/library/Kubernetes/Web/ServiceListItem.php b/library/Kubernetes/Web/ServiceListItem.php index d885a70a..d88f1c01 100644 --- a/library/Kubernetes/Web/ServiceListItem.php +++ b/library/Kubernetes/Web/ServiceListItem.php @@ -5,10 +5,11 @@ 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; @@ -16,54 +17,19 @@ use ipl\Web\Widget\HorizontalKeyValue; use ipl\Web\Widget\Link; use ipl\Web\Widget\StateBall; -use ipl\Web\Widget\TimeAgo; class ServiceListItem 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 { $footer->addHtml( diff --git a/library/Kubernetes/Web/StatefulSetListItem.php b/library/Kubernetes/Web/StatefulSetListItem.php index 6a406ff0..b493f250 100644 --- a/library/Kubernetes/Web/StatefulSetListItem.php +++ b/library/Kubernetes/Web/StatefulSetListItem.php @@ -5,24 +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 StatefulSetListItem extends BaseListItem { use Translation; + use DefaultListItemHeader; + use DefaultListItemCaption; + use DefaultListItemMain; + use DefaultListItemTitle; + use DefaultListItemVisual; public const UPDATE_STRATEGY_ICONS = [ 'RollingUpdate' => 'repeat', @@ -34,47 +37,6 @@ class StatefulSetListItem extends BaseListItem 'Parallel' => 'grip-lines' ]; - 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()); - } - } - protected function assembleFooter(BaseHtmlElement $footer): void { $pods = (new ItemCountIndicator()) @@ -120,37 +82,4 @@ protected function assembleFooter(BaseHtmlElement $footer): void ]) ); } - - protected function assembleTitle(BaseHtmlElement $title): void - { - $title->addHtml(Html::sprintf( - $this->translate('%s is %s', ' is '), - [ - 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-stateful-set'])), - new Text($this->item->name) - ), - Links::statefulset($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)); - } }