Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add different view modes for resource lists #118

Open
wants to merge 30 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
cee62c4
Add ViewModeSwitcher
jrauh01 Jan 3, 2025
a18492c
Implement abstract function getIgnoredViewModes()
jrauh01 Jan 3, 2025
ab666ab
Return the matching ListItem classes
jrauh01 Jan 3, 2025
91e9c31
Implement the view modes
jrauh01 Jan 3, 2025
75a5199
PHP style fixes
jrauh01 Jan 3, 2025
6a28ed6
Icon titles for namespace list item footer
jrauh01 Jan 7, 2025
bc4320e
Switch between view modes in one file
jrauh01 Jan 14, 2025
8f34413
Add visibility modifiers for constants
jrauh01 Jan 15, 2025
d43b57a
Replace 'else if' with 'elseif'
jrauh01 Jan 15, 2025
eb7b15e
Fix detail view
jrauh01 Jan 15, 2025
74b21fc
Fix referents in event detail view
jrauh01 Jan 15, 2025
4d81daf
Remove redundant line
jrauh01 Jan 16, 2025
90e8e28
Add missing parameter and return type
jrauh01 Jan 16, 2025
3901ff9
Use match expressions instead of if-else
jrauh01 Jan 16, 2025
ced470c
Use ->viewMode instead of ->getViewMode()
jrauh01 Jan 16, 2025
7ccbcb9
Remove superfluous if statement
jrauh01 Jan 16, 2025
bff9e62
Simplify namespace's caption and footer
jrauh01 Jan 16, 2025
96c82e7
Use view mode constants
jrauh01 Jan 16, 2025
587c9d5
Remove tabular view mode from ViewModeSwitcher
jrauh01 Jan 16, 2025
8bb0fa8
Add docs for addIgnoredViewModes()
jrauh01 Jan 16, 2025
99157f3
Hide view mode switcher
jrauh01 Jan 16, 2025
42c3ac8
Format docs
jrauh01 Jan 16, 2025
a867a67
Fix license headers
jrauh01 Jan 16, 2025
1f94596
Pass db via argument
jrauh01 Jan 21, 2025
06debaa
Make getIgnoredViewModes() not abstract anymore
jrauh01 Jan 22, 2025
32ea518
Add function to canonicalize resource kinds
jrauh01 Jan 22, 2025
65f5c07
Add default traits for list item parts
jrauh01 Jan 22, 2025
3d7999c
Adjust function names to canonicalized kind names
jrauh01 Jan 22, 2025
8fb71dc
Use default traits for item list parts
jrauh01 Jan 22, 2025
b4c6932
Add styles for list items
jrauh01 Feb 28, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions application/controllers/ConfigmapsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Icinga\Module\Kubernetes\Model\ConfigMap;
use Icinga\Module\Kubernetes\Web\ConfigMapList;
use Icinga\Module\Kubernetes\Web\ListController;
use Icinga\Module\Kubernetes\Web\ViewModeSwitcher;
use ipl\Orm\Query;

class ConfigmapsController extends ListController
Expand Down Expand Up @@ -41,4 +42,9 @@ protected function getPermission(): string
{
return AUTH::SHOW_CONFIG_MAPS;
}

protected function getIgnoredViewModes(): array
{
return [ViewModeSwitcher::VIEW_MODE_COMMON, ViewModeSwitcher::VIEW_MODE_DETAILED];
}
}
7 changes: 6 additions & 1 deletion application/controllers/DaemonsetController.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Icinga\Module\Kubernetes\Web\Controller;
use Icinga\Module\Kubernetes\Web\DaemonSetDetail;
use Icinga\Module\Kubernetes\Web\DaemonSetList;
use Icinga\Module\Kubernetes\Web\ViewModeSwitcher;
use ipl\Stdlib\Filter;
use Ramsey\Uuid\Uuid;

Expand All @@ -33,7 +34,11 @@ public function indexAction(): void
$this->httpNotFound($this->translate('Daemon Set not found'));
}

$this->addControl((new DaemonSetList([$daemonSet]))->setActionList(false));
$this->addControl(
(new DaemonSetList([$daemonSet]))
->setActionList(false)
->setViewMode(ViewModeSwitcher::VIEW_MODE_DETAILED)
);

$this->addContent(new DaemonSetDetail($daemonSet));
}
Expand Down
7 changes: 6 additions & 1 deletion application/controllers/DeploymentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Icinga\Module\Kubernetes\Web\Controller;
use Icinga\Module\Kubernetes\Web\DeploymentDetail;
use Icinga\Module\Kubernetes\Web\DeploymentList;
use Icinga\Module\Kubernetes\Web\ViewModeSwitcher;
use ipl\Stdlib\Filter;
use Ramsey\Uuid\Uuid;

Expand All @@ -33,7 +34,11 @@ public function indexAction(): void
$this->httpNotFound($this->translate('Deployment not found'));
}

$this->addControl((new DeploymentList([$deployment]))->setActionList(false));
$this->addControl(
(new DeploymentList([$deployment]))
->setActionList(false)
->setViewMode(ViewModeSwitcher::VIEW_MODE_DETAILED)
);

$this->addContent(new DeploymentDetail($deployment));
}
Expand Down
6 changes: 6 additions & 0 deletions application/controllers/EventsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Icinga\Module\Kubernetes\Model\Event;
use Icinga\Module\Kubernetes\Web\EventList;
use Icinga\Module\Kubernetes\Web\ListController;
use Icinga\Module\Kubernetes\Web\ViewModeSwitcher;
use ipl\Orm\Query;
use ipl\Stdlib\Filter;

Expand Down Expand Up @@ -51,4 +52,9 @@ protected function getPermission(): string
{
return Auth::SHOW_EVENTS;
}

protected function getIgnoredViewModes(): array
{
return [ViewModeSwitcher::VIEW_MODE_DETAILED];
}
}
7 changes: 6 additions & 1 deletion application/controllers/JobController.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Icinga\Module\Kubernetes\Web\Controller;
use Icinga\Module\Kubernetes\Web\JobDetail;
use Icinga\Module\Kubernetes\Web\JobList;
use Icinga\Module\Kubernetes\Web\ViewModeSwitcher;
use ipl\Stdlib\Filter;
use Ramsey\Uuid\Uuid;

Expand All @@ -33,7 +34,11 @@ public function indexAction(): void
$this->httpNotFound($this->translate('Job not found'));
}

$this->addControl((new JobList([$job]))->setActionList(false));
$this->addControl(
(new JobList([$job]))
->setActionList(false)
->setViewMode(ViewModeSwitcher::VIEW_MODE_DETAILED)
);

$this->addContent(new JobDetail($job));
}
Expand Down
7 changes: 6 additions & 1 deletion application/controllers/NodeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Icinga\Module\Kubernetes\Web\Controller;
use Icinga\Module\Kubernetes\Web\NodeDetail;
use Icinga\Module\Kubernetes\Web\NodeList;
use Icinga\Module\Kubernetes\Web\ViewModeSwitcher;
use ipl\Stdlib\Filter;
use Ramsey\Uuid\Uuid;

Expand All @@ -33,7 +34,11 @@ public function indexAction(): void
$this->httpNotFound($this->translate('Node not found'));
}

$this->addControl((new NodeList([$node]))->setActionList(false));
$this->addControl(
(new NodeList([$node]))
->setActionList(false)
->setViewMode(ViewModeSwitcher::VIEW_MODE_DETAILED)
);

$this->addContent(new NodeDetail($node));
}
Expand Down
8 changes: 8 additions & 0 deletions application/controllers/PersistentvolumeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
use Icinga\Module\Kubernetes\Model\PersistentVolume;
use Icinga\Module\Kubernetes\Web\Controller;
use Icinga\Module\Kubernetes\Web\PersistentVolumeDetail;
use Icinga\Module\Kubernetes\Web\PersistentVolumeList;
use Icinga\Module\Kubernetes\Web\ViewModeSwitcher;
use ipl\Stdlib\Filter;
use Ramsey\Uuid\Uuid;

Expand All @@ -32,6 +34,12 @@ public function indexAction(): void
$this->httpNotFound($this->translate('Persistent Volume not found'));
}

$this->addControl(
(new PersistentVolumeList([$persistentVolume]))
->setActionList(false)
->setViewMode(ViewModeSwitcher::VIEW_MODE_DETAILED)
);

$this->addContent(new PersistentVolumeDetail($persistentVolume));
}
}
8 changes: 8 additions & 0 deletions application/controllers/PersistentvolumeclaimController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
use Icinga\Module\Kubernetes\Model\PersistentVolumeClaim;
use Icinga\Module\Kubernetes\Web\Controller;
use Icinga\Module\Kubernetes\Web\PersistentVolumeClaimDetail;
use Icinga\Module\Kubernetes\Web\PersistentVolumeClaimList;
use Icinga\Module\Kubernetes\Web\ViewModeSwitcher;
use ipl\Stdlib\Filter;
use Ramsey\Uuid\Uuid;

Expand All @@ -32,6 +34,12 @@ public function indexAction(): void
$this->httpNotFound($this->translate('Persistent Volume Claim not found'));
}

$this->addControl(
(new PersistentVolumeClaimList([$pvc]))
->setActionList(false)
->setViewMode(ViewModeSwitcher::VIEW_MODE_DETAILED)
);

$this->addContent(new PersistentVolumeClaimDetail($pvc));
}
}
7 changes: 6 additions & 1 deletion application/controllers/PodController.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Icinga\Module\Kubernetes\Web\Controller;
use Icinga\Module\Kubernetes\Web\PodDetail;
use Icinga\Module\Kubernetes\Web\PodList;
use Icinga\Module\Kubernetes\Web\ViewModeSwitcher;
use ipl\Stdlib\Filter;
use Ramsey\Uuid\Uuid;

Expand All @@ -33,7 +34,11 @@ public function indexAction(): void
$this->httpNotFound($this->translate('Pod not found'));
}

$this->addControl((new PodList([$pod]))->setActionList(false));
$this->addControl(
(new PodList([$pod]))
->setActionList(false)
->setViewMode(ViewModeSwitcher::VIEW_MODE_DETAILED)
);

$this->addContent(new PodDetail($pod));
}
Expand Down
7 changes: 6 additions & 1 deletion application/controllers/ReplicasetController.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Icinga\Module\Kubernetes\Web\Controller;
use Icinga\Module\Kubernetes\Web\ReplicaSetDetail;
use Icinga\Module\Kubernetes\Web\ReplicaSetList;
use Icinga\Module\Kubernetes\Web\ViewModeSwitcher;
use ipl\Stdlib\Filter;
use Ramsey\Uuid\Uuid;

Expand All @@ -33,7 +34,11 @@ public function indexAction(): void
$this->httpNotFound($this->translate('Replica Set not found'));
}

$this->addControl((new ReplicaSetList([$replicaSet]))->setActionList(false));
$this->addControl(
(new ReplicaSetList([$replicaSet]))
->setActionList(false)
->setViewMode(ViewModeSwitcher::VIEW_MODE_DETAILED)
);

$this->addContent(new ReplicaSetDetail($replicaSet));
}
Expand Down
6 changes: 6 additions & 0 deletions application/controllers/SecretsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Icinga\Module\Kubernetes\Model\Secret;
use Icinga\Module\Kubernetes\Web\ListController;
use Icinga\Module\Kubernetes\Web\SecretList;
use Icinga\Module\Kubernetes\Web\ViewModeSwitcher;
use ipl\Orm\Query;

class SecretsController extends ListController
Expand Down Expand Up @@ -41,4 +42,9 @@ protected function getPermission(): string
{
return Auth::SHOW_SECRETS;
}

protected function getIgnoredViewModes(): array
{
return [ViewModeSwitcher::VIEW_MODE_DETAILED];
}
}
7 changes: 6 additions & 1 deletion application/controllers/StatefulsetController.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Icinga\Module\Kubernetes\Web\Controller;
use Icinga\Module\Kubernetes\Web\StatefulSetDetail;
use Icinga\Module\Kubernetes\Web\StatefulSetList;
use Icinga\Module\Kubernetes\Web\ViewModeSwitcher;
use ipl\Stdlib\Filter;
use Ramsey\Uuid\Uuid;

Expand All @@ -33,7 +34,11 @@ public function indexAction(): void
$this->httpNotFound($this->translate('Stateful Set not found'));
}

$this->addControl((new StatefulSetList([$statefulSet]))->setActionList(false));
$this->addControl(
(new StatefulSetList([$statefulSet]))
->setActionList(false)
->setViewMode(ViewModeSwitcher::VIEW_MODE_DETAILED)
);

$this->addContent(new StatefulSetDetail($statefulSet));
}
Expand Down
2 changes: 1 addition & 1 deletion application/controllers/StatefulsetsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,6 @@ protected function getTitle(): string

protected function getPermission(): string
{
return Auth::SHOW_STATEFUL_SETS;
return Auth::SHOW_STATEFUL_SETS;
}
}
23 changes: 16 additions & 7 deletions library/Kubernetes/Common/BaseItemList.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ abstract class BaseItemList extends BaseHtmlElement
{
use BaseFilter;
use Translation;
use ViewMode;

/**
* Indicates whether the item list should be treated as an action list.
Expand Down Expand Up @@ -47,6 +48,7 @@ public function __construct(iterable $query)
* property.
*
* @param bool $actionList
*
* @return static
*/
public function setActionList(bool $actionList): static
Expand All @@ -70,6 +72,7 @@ protected function assemble(): void
$itemClass = $this->getItemClass();

$this->addAttributes($this->baseAttributes);
$this->addAttributes(['class' => $this->viewMode]);
foreach ($this->query as $item) {
if (! $detailUrlAdded) {
$this->addAttributes(['class' => 'action-list'] + [
Expand All @@ -80,14 +83,20 @@ protected function assemble(): void
$detailUrlAdded = true;
}

$listItem = (new $itemClass($item, $this))
->addAttributes([
'data-action-item' => true,
'data-icinga-detail-filter' => QueryString::render(
Filter::equal('id', Uuid::fromBytes($item->uuid)->toString())
)
]);

if ($this->viewMode !== null) {
$listItem->setViewMode($this->viewMode);
}

$this->addHtml(
(new $itemClass($item, $this))
->addAttributes([
'data-action-item' => true,
'data-icinga-detail-filter' => QueryString::render(
Filter::equal('id', Uuid::fromBytes($item->uuid)->toString())
)
])
$listItem
);
}

Expand Down
4 changes: 3 additions & 1 deletion library/Kubernetes/Common/BaseListItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
*/
abstract class BaseListItem extends BaseHtmlElement
{
use ViewMode;

protected array $baseAttributes = ['class' => 'list-item'];

protected $item;
Expand All @@ -24,7 +26,7 @@ abstract class BaseListItem extends BaseHtmlElement
/**
* Create a new list item
*
* @param object $item
* @param object $item
* @param BaseItemList $list
*/
public function __construct($item, BaseItemList $list)
Expand Down
14 changes: 14 additions & 0 deletions library/Kubernetes/Common/DefaultListItemCaption.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace Icinga\Module\Kubernetes\Common;

use ipl\Html\BaseHtmlElement;
use ipl\Html\Text;

trait DefaultListItemCaption
{
protected function assembleCaption(BaseHtmlElement $caption): void
{
$caption->addHtml(new Text($this->item->icinga_state_reason));
}
}
35 changes: 35 additions & 0 deletions library/Kubernetes/Common/DefaultListItemHeader.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

namespace Icinga\Module\Kubernetes\Common;

use Icinga\Module\Kubernetes\Web\ViewModeSwitcher;
use ipl\Html\Attributes;
use ipl\Html\BaseHtmlElement;
use ipl\Html\Html;
use ipl\Web\Widget\TimeAgo;

trait DefaultListItemHeader
{
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()));
}
}
22 changes: 22 additions & 0 deletions library/Kubernetes/Common/DefaultListItemMain.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace Icinga\Module\Kubernetes\Common;

use Icinga\Module\Kubernetes\Web\ViewModeSwitcher;
use ipl\Html\BaseHtmlElement;

trait DefaultListItemMain
{
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());
}
}
}
Loading