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 24 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
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
5 changes: 5 additions & 0 deletions application/controllers/ConfigmapsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,9 @@ protected function getPermission(): string
{
return AUTH::SHOW_CONFIG_MAPS;
}

protected function getIgnoredViewModes(): array
{
return ['common', 'detailed'];
}
}
5 changes: 5 additions & 0 deletions application/controllers/CronjobsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,9 @@ protected function getPermission(): string
{
return Auth::SHOW_CRON_JOBS;
}

protected function getIgnoredViewModes(): array
{
return [];
}
}
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
5 changes: 5 additions & 0 deletions application/controllers/DaemonsetsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,9 @@ protected function getPermission(): string
{
return Auth::SHOW_DAEMON_SETS;
}

protected function getIgnoredViewModes(): array
{
return [];
}
}
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
5 changes: 5 additions & 0 deletions application/controllers/DeploymentsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,9 @@ protected function getPermission(): string
{
return Auth::SHOW_DEPLOYMENTS;
}

protected function getIgnoredViewModes(): array
{
return [];
}
}
5 changes: 5 additions & 0 deletions application/controllers/EventsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,9 @@ protected function getPermission(): string
{
return Auth::SHOW_EVENTS;
}

protected function getIgnoredViewModes(): array
{
return ['detailed'];
}
}
5 changes: 5 additions & 0 deletions application/controllers/IngressesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,9 @@ protected function getPermission(): string
{
return Auth::SHOW_INGRESSES;
}

protected function getIgnoredViewModes(): array
{
return [];
}
}
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
5 changes: 5 additions & 0 deletions application/controllers/JobsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,9 @@ protected function getPermission(): string
{
return Auth::SHOW_JOBS;
}

protected function getIgnoredViewModes(): array
{
return [];
}
}
5 changes: 5 additions & 0 deletions application/controllers/NamespacesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,9 @@ protected function getPermission(): string
{
return Auth::SHOW_NAMESPACES;
}

protected function getIgnoredViewModes(): array
{
return [];
}
}
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
5 changes: 5 additions & 0 deletions application/controllers/NodesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,9 @@ protected function getPermission(): string
{
return Auth::SHOW_NODES;
}

protected function getIgnoredViewModes(): array
{
return [];
}
}
5 changes: 5 additions & 0 deletions application/controllers/PersistentvolumeclaimsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,9 @@ protected function getPermission(): string
{
return Auth::SHOW_PERSISTENT_VOLUME_CLAIMS;
}

protected function getIgnoredViewModes(): array
{
return [];
}
}
5 changes: 5 additions & 0 deletions application/controllers/PersistentvolumesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,9 @@ protected function getPermission(): string
{
return Auth::SHOW_PERSISTENT_VOLUMES;
}

protected function getIgnoredViewModes(): array
{
return [];
}
}
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
5 changes: 5 additions & 0 deletions application/controllers/PodsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,9 @@ protected function getPermission(): string
{
return Auth::SHOW_PODS;
}

protected function getIgnoredViewModes(): array
{
return [];
}
}
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
5 changes: 5 additions & 0 deletions application/controllers/ReplicasetsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,9 @@ protected function getPermission(): string
{
return Auth::SHOW_REPLICA_SETS;
}

protected function getIgnoredViewModes(): array
{
return [];
}
}
5 changes: 5 additions & 0 deletions application/controllers/SecretsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,9 @@ protected function getPermission(): string
{
return Auth::SHOW_SECRETS;
}

protected function getIgnoredViewModes(): array
{
return ['detailed'];
}
}
5 changes: 5 additions & 0 deletions application/controllers/ServicesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,9 @@ protected function getPermission(): string
{
return Auth::SHOW_SERVICES;
}

protected function getIgnoredViewModes(): array
{
return [];
}
}
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
7 changes: 6 additions & 1 deletion application/controllers/StatefulsetsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ protected function getTitle(): string

protected function getPermission(): string
{
return Auth::SHOW_STATEFUL_SETS;
return Auth::SHOW_STATEFUL_SETS;
}

protected function getIgnoredViewModes(): array
{
return [];
}
}
22 changes: 15 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 Down Expand Up @@ -80,14 +82,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
Loading
Loading