Skip to content

Commit b340f9b

Browse files
committed
Add toggle to show only favorites
1 parent 1dfb03d commit b340f9b

20 files changed

+211
-8
lines changed

application/controllers/ConfigmapsController.php

+5
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,9 @@ protected function getIgnoredViewModes(): array
4747
{
4848
return [ViewModeSwitcher::VIEW_MODE_COMMON, ViewModeSwitcher::VIEW_MODE_DETAILED];
4949
}
50+
51+
protected function getFavorable(): bool
52+
{
53+
return false;
54+
}
5055
}

application/controllers/CronjobsController.php

+5
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,9 @@ protected function getPermission(): string
4141
{
4242
return Auth::SHOW_CRON_JOBS;
4343
}
44+
45+
protected function getFavorable(): bool
46+
{
47+
return true;
48+
}
4449
}

application/controllers/DaemonsetsController.php

+5
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,9 @@ protected function getPermission(): string
4141
{
4242
return Auth::SHOW_DAEMON_SETS;
4343
}
44+
45+
protected function getFavorable(): bool
46+
{
47+
return true;
48+
}
4449
}

application/controllers/DeploymentsController.php

+5
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,9 @@ protected function getPermission(): string
4141
{
4242
return Auth::SHOW_DEPLOYMENTS;
4343
}
44+
45+
protected function getFavorable(): bool
46+
{
47+
return true;
48+
}
4449
}

application/controllers/EventsController.php

+5
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,9 @@ protected function getIgnoredViewModes(): array
5757
{
5858
return [ViewModeSwitcher::VIEW_MODE_DETAILED];
5959
}
60+
61+
protected function getFavorable(): bool
62+
{
63+
return false;
64+
}
6065
}

application/controllers/IngressesController.php

+5
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,9 @@ protected function getPermission(): string
4141
{
4242
return Auth::SHOW_INGRESSES;
4343
}
44+
45+
protected function getFavorable(): bool
46+
{
47+
return true;
48+
}
4449
}

application/controllers/JobsController.php

+5
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,9 @@ protected function getPermission(): string
4141
{
4242
return Auth::SHOW_JOBS;
4343
}
44+
45+
protected function getFavorable(): bool
46+
{
47+
return true;
48+
}
4449
}

application/controllers/NamespacesController.php

+5
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,9 @@ protected function getPermission(): string
4040
{
4141
return Auth::SHOW_NAMESPACES;
4242
}
43+
44+
protected function getFavorable(): bool
45+
{
46+
return true;
47+
}
4348
}

application/controllers/NodesController.php

+5
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,9 @@ protected function getPermission(): string
4040
{
4141
return Auth::SHOW_NODES;
4242
}
43+
44+
protected function getFavorable(): bool
45+
{
46+
return true;
47+
}
4348
}

application/controllers/PersistentvolumeclaimsController.php

+5
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,9 @@ protected function getPermission(): string
4141
{
4242
return Auth::SHOW_PERSISTENT_VOLUME_CLAIMS;
4343
}
44+
45+
protected function getFavorable(): bool
46+
{
47+
return true;
48+
}
4449
}

application/controllers/PersistentvolumesController.php

+5
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,9 @@ protected function getPermission(): string
4141
{
4242
return Auth::SHOW_PERSISTENT_VOLUMES;
4343
}
44+
45+
protected function getFavorable(): bool
46+
{
47+
return true;
48+
}
4449
}

application/controllers/PodsController.php

+5
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,9 @@ protected function getPermission(): string
4343
{
4444
return Auth::SHOW_PODS;
4545
}
46+
47+
protected function getFavorable(): bool
48+
{
49+
return true;
50+
}
4651
}

application/controllers/ReplicasetsController.php

+5
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,9 @@ protected function getPermission(): string
4141
{
4242
return Auth::SHOW_REPLICA_SETS;
4343
}
44+
45+
protected function getFavorable(): bool
46+
{
47+
return true;
48+
}
4449
}

application/controllers/SecretsController.php

+5
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,9 @@ protected function getIgnoredViewModes(): array
4747
{
4848
return [ViewModeSwitcher::VIEW_MODE_DETAILED];
4949
}
50+
51+
protected function getFavorable(): bool
52+
{
53+
return false;
54+
}
5055
}

application/controllers/ServicesController.php

+5
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,9 @@ protected function getPermission(): string
4141
{
4242
return Auth::SHOW_SERVICES;
4343
}
44+
45+
protected function getFavorable(): bool
46+
{
47+
return true;
48+
}
4449
}

application/controllers/StatefulsetsController.php

+5
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,9 @@ protected function getPermission(): string
4141
{
4242
return Auth::SHOW_STATEFUL_SETS;
4343
}
44+
45+
protected function getFavorable(): bool
46+
{
47+
return true;
48+
}
4449
}
+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<?php
2+
3+
/* Icinga for Kubernetes Web | (c) 2025 Icinga GmbH | AGPLv3 */
4+
5+
namespace Icinga\Module\Kubernetes\Web;
6+
7+
use ipl\Web\Compat\CompatForm;
8+
9+
class FavoriteToggle extends CompatForm
10+
{
11+
/** @var string Default favorite param */
12+
const string DEFAULT_FAVORITE_PARAM = 'show-favorites';
13+
14+
/** @var string The URL parameter which stores whether to show the favorites */
15+
protected string $favoriteParam = self::DEFAULT_FAVORITE_PARAM;
16+
17+
/** @var string */
18+
protected $method = 'POST';
19+
20+
/**
21+
* Get the name of the URL parameter which stores whether to show the favorites
22+
*
23+
* @return string
24+
*/
25+
public function getFavoriteParam(): string
26+
{
27+
return $this->favoriteParam;
28+
}
29+
30+
/**
31+
* Set the name of the URL parameter which stores whether to show the favorites
32+
*
33+
* @param string $favoriteParam
34+
*
35+
* @return $this
36+
*/
37+
public function setFavoriteParam($favoriteParam): self
38+
{
39+
$this->favoriteParam = $favoriteParam;
40+
41+
return $this;
42+
}
43+
44+
protected function assemble(): void
45+
{
46+
$this->addAttributes(['class' => 'favorite-toggle inline']);
47+
48+
$this->addElement(
49+
'checkbox',
50+
self::DEFAULT_FAVORITE_PARAM,
51+
[
52+
'label' => 'Favorites Only',
53+
'class' => 'autosubmit',
54+
]
55+
);
56+
}
57+
}

library/Kubernetes/Web/ListController.php

+64-3
Original file line numberDiff line numberDiff line change
@@ -60,17 +60,25 @@ public function indexAction(): void
6060
$q->filter(Filter::equal('cluster_uuid', Uuid::fromString($clusterUuid)->getBytes()));
6161
}
6262

63+
if ($this->getFavorable()) {
64+
$favoriteToggle = $this->createFavoriteToggle($q);
65+
}
66+
6367
$limitControl = $this->createLimitControl();
64-
$sortControl = $this->createSortControl($q, $this->getSortColumns());
68+
$sortControl = $this->createSortControl(
69+
$q,
70+
$this->getSortColumns()
71+
+ ($favoriteToggleActive ? ['favorite.priority desc' => 'Custom Order'] : [])
72+
);
6573
$paginationControl = $this->createPaginationControl($q);
66-
6774
$viewModeSwitcher = $this->createViewModeSwitcher($paginationControl, $limitControl);
6875

6976
$searchBar = $this->createSearchBar($q, [
7077
$limitControl->getLimitParam(),
7178
$sortControl->getSortParam(),
7279
$viewModeSwitcher->getViewModeParam(),
73-
'columns'
80+
(isset($favoriteToggle) ? $favoriteToggle->getFavoriteParam() : ''),
81+
'columns',
7482
]);
7583

7684
if ($searchBar->hasBeenSent() && ! $searchBar->isValid()) {
@@ -92,6 +100,9 @@ public function indexAction(): void
92100
$this->addControl($sortControl);
93101
$this->addControl($limitControl);
94102
$this->addControl($viewModeSwitcher);
103+
if ($this->getFavorable()) {
104+
$this->addControl($favoriteToggle);
105+
}
95106
$this->addControl($searchBar);
96107

97108
$contentClass = $this->getContentClass();
@@ -110,6 +121,8 @@ abstract protected function getContentClass(): string;
110121

111122
abstract protected function getPermission(): string;
112123

124+
abstract protected function getFavorable(): bool;
125+
113126
protected function getIgnoredViewModes(): array
114127
{
115128
return [];
@@ -285,4 +298,52 @@ function (ViewModeSwitcher $viewModeSwitcher) use (
285298

286299
return $viewModeSwitcher;
287300
}
301+
302+
/**
303+
* Create and return the FavoriteToggle
304+
*
305+
* This automatically shifts the favorite URL parameter from {@link $params}.
306+
*
307+
* @param Query $query
308+
*
309+
* @return FavoriteToggle
310+
*/
311+
public function createFavoriteToggle(
312+
Query $query
313+
): FavoriteToggle {
314+
$favoriteToggle = new FavoriteToggle();
315+
$defaultFavoriteParam = $favoriteToggle->getFavoriteParam();
316+
$favoriteParam = $this->params->shift($defaultFavoriteParam);
317+
$favoriteToggle->populate([
318+
$defaultFavoriteParam => $favoriteParam
319+
]);
320+
321+
$favoriteToggle->on(FavoriteToggle::ON_SUCCESS, function (FavoriteToggle $favoriteToggle) use (
322+
$query,
323+
$defaultFavoriteParam
324+
) {
325+
$favoriteParam = $favoriteToggle->getValue($defaultFavoriteParam);
326+
327+
$requestUrl = Url::fromRequest();
328+
329+
// Redirect if favorite param has changed to update the URL
330+
if (isset($favoriteParam) && $requestUrl->getParam($defaultFavoriteParam) !== $favoriteParam) {
331+
$requestUrl->setParam($defaultFavoriteParam, $favoriteParam);
332+
if (
333+
$favoriteParam === 'n'
334+
&& $requestUrl->getParam(SortControl::DEFAULT_SORT_PARAM) === 'favorite.priority desc'
335+
) {
336+
$requestUrl->remove(SortControl::DEFAULT_SORT_PARAM);
337+
}
338+
339+
$this->redirectNow($requestUrl);
340+
}
341+
})->handleRequest($this->getServerRequest());
342+
343+
if ($favoriteToggle->getValue($defaultFavoriteParam) === 'y') {
344+
$query->with('favorite')->filter(Filter::equal('favorite.username', Auth::getInstance()->getUser()->getUsername()));
345+
}
346+
347+
return $favoriteToggle;
348+
}
288349
}

public/css/common.less

+10-4
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,6 @@ pre {
4848
}
4949

5050
.favorite-toggle {
51-
margin-right: 1em;
52-
float: right;
5351
width: auto;
5452

5553
.control-group {
@@ -59,17 +57,25 @@ pre {
5957

6058
label {
6159
text-align: right;
60+
margin-right: 0;
6261
}
6362
}
6463
}
6564

6665
.limit-control,
6766
.view-mode-switcher,
68-
.sort-control {
69-
margin-left: .5em;
67+
.sort-control,
68+
.favorite-toggle {
69+
margin-left: 1em;
7070
float: right;
7171
}
7272

73+
.limit-control,
74+
.view-mode-switcher,
75+
.favorite-toggle {
76+
margin-right: 0;
77+
}
78+
7379
.item-list .list-item {
7480
.main {
7581
padding: 3px 0;

public/css/widgets.less

-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,6 @@
100100

101101
.view-mode-switcher {
102102
list-style-type: none;
103-
margin: 0 0 0.25em 0;
104103
padding: 0;
105104
display: flex;
106105

0 commit comments

Comments
 (0)