Skip to content

Commit d41c6cd

Browse files
committed
Use default traits for item list parts
1 parent 7bdc420 commit d41c6cd

13 files changed

+98
-760
lines changed

library/Kubernetes/Web/CronJobListItem.php

+6-39
Original file line numberDiff line numberDiff line change
@@ -5,66 +5,32 @@
55
namespace Icinga\Module\Kubernetes\Web;
66

77
use Icinga\Module\Kubernetes\Common\BaseListItem;
8+
use Icinga\Module\Kubernetes\Common\DefaultListItemHeader;
9+
use Icinga\Module\Kubernetes\Common\DefaultListItemMain;
810
use Icinga\Module\Kubernetes\Common\Icons;
911
use Icinga\Module\Kubernetes\Common\Links;
1012
use ipl\Html\Attributes;
1113
use ipl\Html\BaseHtmlElement;
12-
use ipl\Html\Html;
1314
use ipl\Html\HtmlDocument;
1415
use ipl\Html\HtmlElement;
1516
use ipl\Html\Text;
1617
use ipl\I18n\Translation;
1718
use ipl\Web\Widget\HorizontalKeyValue;
1819
use ipl\Web\Widget\Link;
1920
use ipl\Web\Widget\StateBall;
20-
use ipl\Web\Widget\TimeAgo;
2121

2222
class CronJobListItem extends BaseListItem
2323
{
2424
use Translation;
25-
26-
protected function assembleHeader(BaseHtmlElement $header): void
27-
{
28-
match ($this->viewMode) {
29-
ViewModeSwitcher::VIEW_MODE_MINIMAL,
30-
ViewModeSwitcher::VIEW_MODE_COMMON =>
31-
$header->addHtml(
32-
Html::tag(
33-
'span',
34-
Attributes::create(['class' => 'header-minimal']),
35-
[
36-
$this->createTitle(),
37-
$this->createCaption()
38-
]
39-
)
40-
),
41-
ViewModeSwitcher::VIEW_MODE_DETAILED =>
42-
$header->addHtml($this->createTitle()),
43-
default => null
44-
};
45-
46-
$header->addHtml(new TimeAgo($this->item->created->getTimestamp()));
47-
}
25+
use DefaultListItemHeader;
26+
use DefaultListItemMain;
4827

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

55-
protected function assembleMain(BaseHtmlElement $main): void
56-
{
57-
$main->addHtml($this->createHeader());
58-
59-
if ($this->viewMode === ViewModeSwitcher::VIEW_MODE_DETAILED) {
60-
$main->addHtml($this->createCaption());
61-
}
62-
63-
if ($this->viewMode !== ViewModeSwitcher::VIEW_MODE_MINIMAL) {
64-
$main->addHtml($this->createFooter());
65-
}
66-
}
67-
6834
protected function assembleFooter(BaseHtmlElement $footer): void
6935
{
7036
if (isset($this->item->last_schedule_time)) {
@@ -110,6 +76,7 @@ protected function assembleTitle(BaseHtmlElement $title): void
11076

11177
protected function assembleVisual(BaseHtmlElement $visual): void
11278
{
79+
// TODO add icinga state then replace function by DefaultListItemVisual trait
11380
$visual->addHtml(new StateBall('none', StateBall::SIZE_MEDIUM));
11481
}
11582
}

library/Kubernetes/Web/DaemonSetListItem.php

+10-81
Original file line numberDiff line numberDiff line change
@@ -5,65 +5,27 @@
55
namespace Icinga\Module\Kubernetes\Web;
66

77
use Icinga\Module\Kubernetes\Common\BaseListItem;
8+
use Icinga\Module\Kubernetes\Common\DefaultListItemCaption;
9+
use Icinga\Module\Kubernetes\Common\DefaultListItemHeader;
10+
use Icinga\Module\Kubernetes\Common\DefaultListItemMain;
11+
use Icinga\Module\Kubernetes\Common\DefaultListItemTitle;
12+
use Icinga\Module\Kubernetes\Common\DefaultListItemVisual;
813
use Icinga\Module\Kubernetes\Common\Format;
9-
use Icinga\Module\Kubernetes\Common\Links;
1014
use ipl\Html\Attributes;
1115
use ipl\Html\BaseHtmlElement;
12-
use ipl\Html\Html;
13-
use ipl\Html\HtmlDocument;
1416
use ipl\Html\HtmlElement;
15-
use ipl\Html\Text;
1617
use ipl\I18n\Translation;
1718
use ipl\Web\Widget\HorizontalKeyValue;
1819
use ipl\Web\Widget\Icon;
19-
use ipl\Web\Widget\Link;
20-
use ipl\Web\Widget\StateBall;
21-
use ipl\Web\Widget\TimeAgo;
2220

2321
class DaemonSetListItem extends BaseListItem
2422
{
2523
use Translation;
26-
27-
protected function assembleHeader(BaseHtmlElement $header): void
28-
{
29-
match ($this->viewMode) {
30-
ViewModeSwitcher::VIEW_MODE_MINIMAL,
31-
ViewModeSwitcher::VIEW_MODE_COMMON =>
32-
$header->addHtml(
33-
Html::tag(
34-
'span',
35-
Attributes::create(['class' => 'header-minimal']),
36-
[
37-
$this->createTitle(),
38-
$this->createCaption()
39-
]
40-
)
41-
),
42-
ViewModeSwitcher::VIEW_MODE_DETAILED =>
43-
$header->addHtml($this->createTitle()),
44-
default => null
45-
};
46-
47-
$header->addHtml(new TimeAgo($this->item->created->getTimestamp()));
48-
}
49-
50-
protected function assembleCaption(BaseHtmlElement $caption): void
51-
{
52-
$caption->addHtml(new Text($this->item->icinga_state_reason));
53-
}
54-
55-
protected function assembleMain(BaseHtmlElement $main): void
56-
{
57-
$main->addHtml($this->createHeader());
58-
59-
if ($this->viewMode === ViewModeSwitcher::VIEW_MODE_DETAILED) {
60-
$main->addHtml($this->createCaption());
61-
}
62-
63-
if ($this->viewMode !== ViewModeSwitcher::VIEW_MODE_MINIMAL) {
64-
$main->addHtml($this->createFooter());
65-
}
66-
}
24+
use DefaultListItemHeader;
25+
use DefaultListItemCaption;
26+
use DefaultListItemMain;
27+
use DefaultListItemTitle;
28+
use DefaultListItemVisual;
6729

6830
protected function assembleFooter(BaseHtmlElement $footer): void
6931
{
@@ -99,37 +61,4 @@ protected function assembleFooter(BaseHtmlElement $footer): void
9961
)
10062
);
10163
}
102-
103-
protected function assembleTitle(BaseHtmlElement $title): void
104-
{
105-
$title->addHtml(Html::sprintf(
106-
$this->translate('%s is %s', '<daemon_set> is <icinga_state>'),
107-
[
108-
new HtmlElement(
109-
'span',
110-
new Attributes(['class' => 'namespace-badge']),
111-
new HtmlElement('i', new Attributes(['class' => 'icon kicon-namespace'])),
112-
new Text($this->item->namespace)
113-
),
114-
new Link(
115-
(new HtmlDocument())->addHtml(
116-
new HtmlElement('i', new Attributes(['class' => 'icon kicon-daemon-set'])),
117-
new Text($this->item->name)
118-
),
119-
Links::daemonset($this->item),
120-
new Attributes(['class' => 'subject'])
121-
)
122-
],
123-
new HtmlElement(
124-
'span',
125-
new Attributes(['class' => 'icinga-state-text']),
126-
new Text($this->item->icinga_state)
127-
)
128-
));
129-
}
130-
131-
protected function assembleVisual(BaseHtmlElement $visual): void
132-
{
133-
$visual->addHtml(new StateBall($this->item->icinga_state, StateBall::SIZE_MEDIUM));
134-
}
13564
}

library/Kubernetes/Web/DeploymentListItem.php

+10-81
Original file line numberDiff line numberDiff line change
@@ -5,65 +5,27 @@
55
namespace Icinga\Module\Kubernetes\Web;
66

77
use Icinga\Module\Kubernetes\Common\BaseListItem;
8+
use Icinga\Module\Kubernetes\Common\DefaultListItemCaption;
9+
use Icinga\Module\Kubernetes\Common\DefaultListItemHeader;
10+
use Icinga\Module\Kubernetes\Common\DefaultListItemMain;
11+
use Icinga\Module\Kubernetes\Common\DefaultListItemTitle;
12+
use Icinga\Module\Kubernetes\Common\DefaultListItemVisual;
813
use Icinga\Module\Kubernetes\Common\Format;
9-
use Icinga\Module\Kubernetes\Common\Links;
1014
use ipl\Html\Attributes;
1115
use ipl\Html\BaseHtmlElement;
12-
use ipl\Html\Html;
13-
use ipl\Html\HtmlDocument;
1416
use ipl\Html\HtmlElement;
15-
use ipl\Html\Text;
1617
use ipl\I18n\Translation;
1718
use ipl\Web\Widget\HorizontalKeyValue;
1819
use ipl\Web\Widget\Icon;
19-
use ipl\Web\Widget\Link;
20-
use ipl\Web\Widget\StateBall;
21-
use ipl\Web\Widget\TimeAgo;
2220

2321
class DeploymentListItem extends BaseListItem
2422
{
2523
use Translation;
26-
27-
protected function assembleHeader(BaseHtmlElement $header): void
28-
{
29-
match ($this->viewMode) {
30-
ViewModeSwitcher::VIEW_MODE_MINIMAL,
31-
ViewModeSwitcher::VIEW_MODE_COMMON =>
32-
$header->addHtml(
33-
Html::tag(
34-
'span',
35-
Attributes::create(['class' => 'header-minimal']),
36-
[
37-
$this->createTitle(),
38-
$this->createCaption()
39-
]
40-
)
41-
),
42-
ViewModeSwitcher::VIEW_MODE_DETAILED =>
43-
$header->addHtml($this->createTitle()),
44-
default => null
45-
};
46-
47-
$header->addHtml(new TimeAgo($this->item->created->getTimestamp()));
48-
}
49-
50-
protected function assembleCaption(BaseHtmlElement $caption): void
51-
{
52-
$caption->addHtml(new Text($this->item->icinga_state_reason));
53-
}
54-
55-
protected function assembleMain(BaseHtmlElement $main): void
56-
{
57-
$main->addHtml($this->createHeader());
58-
59-
if ($this->viewMode === ViewModeSwitcher::VIEW_MODE_DETAILED) {
60-
$main->addHtml($this->createCaption());
61-
}
62-
63-
if ($this->viewMode !== ViewModeSwitcher::VIEW_MODE_MINIMAL) {
64-
$main->addHtml($this->createFooter());
65-
}
66-
}
24+
use DefaultListItemHeader;
25+
use DefaultListItemCaption;
26+
use DefaultListItemMain;
27+
use DefaultListItemTitle;
28+
use DefaultListItemVisual;
6729

6830
protected function assembleFooter(BaseHtmlElement $footer): void
6931
{
@@ -103,37 +65,4 @@ protected function assembleFooter(BaseHtmlElement $footer): void
10365
)
10466
);
10567
}
106-
107-
protected function assembleTitle(BaseHtmlElement $title): void
108-
{
109-
$title->addHtml(Html::sprintf(
110-
$this->translate('%s is %s', '<deployment> is <icinga_state>'),
111-
[
112-
new HtmlElement(
113-
'span',
114-
new Attributes(['class' => 'namespace-badge']),
115-
new HtmlElement('i', new Attributes(['class' => 'icon kicon-namespace'])),
116-
new Text($this->item->namespace)
117-
),
118-
new Link(
119-
(new HtmlDocument())->addHtml(
120-
new HtmlElement('i', new Attributes(['class' => 'icon kicon-deployment'])),
121-
new Text($this->item->name)
122-
),
123-
Links::deployment($this->item),
124-
new Attributes(['class' => 'subject'])
125-
)
126-
],
127-
new HtmlElement(
128-
'span',
129-
new Attributes(['class' => 'icinga-state-text']),
130-
new Text($this->item->icinga_state)
131-
)
132-
));
133-
}
134-
135-
protected function assembleVisual(BaseHtmlElement $visual): void
136-
{
137-
$visual->addHtml(new StateBall($this->item->icinga_state, StateBall::SIZE_MEDIUM));
138-
}
13968
}

library/Kubernetes/Web/IngressListItem.php

+5-39
Original file line numberDiff line numberDiff line change
@@ -5,65 +5,31 @@
55
namespace Icinga\Module\Kubernetes\Web;
66

77
use Icinga\Module\Kubernetes\Common\BaseListItem;
8+
use Icinga\Module\Kubernetes\Common\DefaultListItemHeader;
9+
use Icinga\Module\Kubernetes\Common\DefaultListItemMain;
810
use Icinga\Module\Kubernetes\Common\Links;
911
use ipl\Html\Attributes;
1012
use ipl\Html\BaseHtmlElement;
11-
use ipl\Html\Html;
1213
use ipl\Html\HtmlDocument;
1314
use ipl\Html\HtmlElement;
1415
use ipl\Html\Text;
1516
use ipl\I18n\Translation;
1617
use ipl\Web\Widget\HorizontalKeyValue;
1718
use ipl\Web\Widget\Link;
1819
use ipl\Web\Widget\StateBall;
19-
use ipl\Web\Widget\TimeAgo;
2020

2121
class IngressListItem extends BaseListItem
2222
{
2323
use Translation;
24-
25-
protected function assembleHeader(BaseHtmlElement $header): void
26-
{
27-
match ($this->viewMode) {
28-
ViewModeSwitcher::VIEW_MODE_MINIMAL,
29-
ViewModeSwitcher::VIEW_MODE_COMMON =>
30-
$header->addHtml(
31-
Html::tag(
32-
'span',
33-
Attributes::create(['class' => 'header-minimal']),
34-
[
35-
$this->createTitle(),
36-
$this->createCaption()
37-
]
38-
)
39-
),
40-
ViewModeSwitcher::VIEW_MODE_DETAILED =>
41-
$header->addHtml($this->createTitle()),
42-
default => null
43-
};
44-
45-
$header->addHtml(new TimeAgo($this->item->created->getTimestamp()));
46-
}
24+
use DefaultListItemHeader;
25+
use DefaultListItemMain;
4726

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

54-
protected function assembleMain(BaseHtmlElement $main): void
55-
{
56-
$main->addHtml($this->createHeader());
57-
58-
if ($this->viewMode === ViewModeSwitcher::VIEW_MODE_DETAILED) {
59-
$main->addHtml($this->createCaption());
60-
}
61-
62-
if ($this->viewMode !== ViewModeSwitcher::VIEW_MODE_MINIMAL) {
63-
$main->addHtml($this->createFooter());
64-
}
65-
}
66-
6733
protected function assembleFooter(BaseHtmlElement $footer): void
6834
{
6935
$hosts = [];

0 commit comments

Comments
 (0)