Skip to content

Commit 30f8e55

Browse files
committed
Switch between view modes in one file
1 parent 0f57b36 commit 30f8e55

File tree

64 files changed

+411
-3165
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+411
-3165
lines changed

library/Kubernetes/Common/BaseItemList.php

+11-7
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ abstract class BaseItemList extends BaseHtmlElement
1717
{
1818
use BaseFilter;
1919
use Translation;
20+
use ViewMode;
2021

2122
protected array $baseAttributes = [
2223
'class' => 'item-list action-list',
@@ -58,14 +59,17 @@ protected function assemble(): void
5859
$detailUrlAdded = true;
5960
}
6061

62+
$listItem = (new $itemClass($item, $this))
63+
->addAttributes([
64+
'data-action-item' => true,
65+
'data-icinga-detail-filter' => QueryString::render(
66+
Filter::equal('id', Uuid::fromBytes($item->uuid)->toString())
67+
)
68+
]);
69+
$listItem->setViewMode($this->getViewMode());
70+
6171
$this->addHtml(
62-
(new $itemClass($item, $this))
63-
->addAttributes([
64-
'data-action-item' => true,
65-
'data-icinga-detail-filter' => QueryString::render(
66-
Filter::equal('id', Uuid::fromBytes($item->uuid)->toString())
67-
)
68-
])
72+
$listItem
6973
);
7074
}
7175

library/Kubernetes/Common/BaseListItem.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
*/
1414
abstract class BaseListItem extends BaseHtmlElement
1515
{
16+
use ViewMode;
17+
1618
protected array $baseAttributes = ['class' => 'list-item'];
1719

1820
protected $item;
@@ -24,7 +26,7 @@ abstract class BaseListItem extends BaseHtmlElement
2426
/**
2527
* Create a new list item
2628
*
27-
* @param object $item
29+
* @param object $item
2830
* @param BaseItemList $list
2931
*/
3032
public function __construct($item, BaseItemList $list)

library/Kubernetes/Web/ConfigMapList.php

+1-4
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,13 @@
55
namespace Icinga\Module\Kubernetes\Web;
66

77
use Icinga\Module\Kubernetes\Common\BaseItemList;
8-
use Icinga\Module\Kubernetes\Common\ViewMode;
98

109
class ConfigMapList extends BaseItemList
1110
{
12-
use ViewMode;
13-
1411
protected $defaultAttributes = ['class' => 'config-map-list'];
1512

1613
protected function getItemClass(): string
1714
{
18-
return ConfigMapListItemMinimal::class;
15+
return ConfigMapListItem::class;
1916
}
2017
}

library/Kubernetes/Web/ConfigMapListItemMinimal.php library/Kubernetes/Web/ConfigMapListItem.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
use ipl\Web\Widget\Link;
1515
use ipl\Web\Widget\TimeAgo;
1616

17-
class ConfigMapListItemMinimal extends BaseListItem
17+
class ConfigMapListItem extends BaseListItem
1818
{
1919
protected function assembleHeader(BaseHtmlElement $header): void
2020
{

library/Kubernetes/Web/CronJobList.php

+1-8
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,13 @@
55
namespace Icinga\Module\Kubernetes\Web;
66

77
use Icinga\Module\Kubernetes\Common\BaseItemList;
8-
use Icinga\Module\Kubernetes\Common\ViewMode;
98

109
class CronJobList extends BaseItemList
1110
{
12-
use ViewMode;
13-
1411
protected $defaultAttributes = ['class' => 'cronjob-list'];
1512

1613
protected function getItemClass(): string
1714
{
18-
return match ($this->getViewMode()) {
19-
'minimal' => CronJobListItemMinimal::class,
20-
'detailed' => CronJobListItemDetailed::class,
21-
default => CronJobListItem::class,
22-
};
15+
return CronJobListItem::class;
2316
}
2417
}

library/Kubernetes/Web/CronJobListItem.php

+25-15
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,22 @@ class CronJobListItem extends BaseListItem
2525

2626
protected function assembleHeader(BaseHtmlElement $header): void
2727
{
28-
$header->addHtml(
29-
Html::tag(
30-
'span',
31-
Attributes::create(['class' => 'header-minimal']),
32-
[
33-
$this->createTitle(),
34-
$this->createCaption()
35-
]
36-
),
37-
new TimeAgo($this->item->created->getTimestamp())
38-
);
28+
if (in_array($this->getViewMode(), [ViewModeSwitcher::VIEW_MODE_MINIMAL, ViewModeSwitcher::VIEW_MODE_COMMON])) {
29+
$header->addHtml(
30+
Html::tag(
31+
'span',
32+
Attributes::create(['class' => 'header-minimal']),
33+
[
34+
$this->createTitle(),
35+
$this->createCaption()
36+
]
37+
)
38+
);
39+
} else if ($this->getViewMode() === ViewModeSwitcher::VIEW_MODE_DETAILED) {
40+
$header->addHtml($this->createTitle());
41+
}
42+
43+
$header->addHtml(new TimeAgo($this->item->created->getTimestamp()));
3944
}
4045

4146
protected function assembleCaption(BaseHtmlElement $caption): void
@@ -46,10 +51,15 @@ protected function assembleCaption(BaseHtmlElement $caption): void
4651

4752
protected function assembleMain(BaseHtmlElement $main): void
4853
{
49-
$main->addHtml(
50-
$this->createHeader(),
51-
$this->createFooter()
52-
);
54+
$main->addHtml($this->createHeader());
55+
56+
if ($this->getViewMode() === ViewModeSwitcher::VIEW_MODE_DETAILED) {
57+
$main->addHtml($this->createCaption());
58+
}
59+
60+
if ($this->getViewMode() !== ViewModeSwitcher::VIEW_MODE_MINIMAL) {
61+
$main->addHtml($this->createFooter());
62+
}
5363
}
5464

5565
protected function assembleFooter(BaseHtmlElement $footer): void

library/Kubernetes/Web/CronJobListItemDetailed.php

-95
This file was deleted.

library/Kubernetes/Web/CronJobListItemMinimal.php

-76
This file was deleted.

library/Kubernetes/Web/DaemonSetList.php

+1-8
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,13 @@
55
namespace Icinga\Module\Kubernetes\Web;
66

77
use Icinga\Module\Kubernetes\Common\BaseItemList;
8-
use Icinga\Module\Kubernetes\Common\ViewMode;
98

109
class DaemonSetList extends BaseItemList
1110
{
12-
use ViewMode;
13-
1411
protected $defaultAttributes = ['class' => 'daemon-set-list'];
1512

1613
protected function getItemClass(): string
1714
{
18-
return match ($this->getViewMode()) {
19-
'minimal' => DaemonSetListItemMinimal::class,
20-
'detailed' => DaemonSetListItemDetailed::class,
21-
default => DaemonSetListItem::class,
22-
};
15+
return DaemonSetListItem::class;
2316
}
2417
}

0 commit comments

Comments
 (0)