-
Notifications
You must be signed in to change notification settings - Fork 0
Favorites feature #125
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
Merged
Merged
Favorites feature #125
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
de73db1
Implement abstract function getIgnoredViewModes()
jrauh01 498b63b
Switch between view modes in one file
jrauh01 907a09a
Fix detail view
jrauh01 b878797
Use DetailState in resource details
jrauh01 1e7b98d
Use own action list
jrauh01 576c19a
Add model for favorites
jrauh01 e1f48d6
Add QuickActions
jrauh01 f20d36c
Add quick actions to toggle favorites
jrauh01 b292acf
Show favorite icon in action list
jrauh01 e265faf
Remove multi select feature from action list
jrauh01 4b8e50a
Remove load more feature from action list
jrauh01 143b662
Add priority column to favorites
jrauh01 1c42d35
Add toggle to show only favorites
jrauh01 c411830
Add reordering via drag & drop
jrauh01 fcee920
Dashboard to show all favorites
jrauh01 867fa56
Disable auto refresh while dragging
jrauh01 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
<?php | ||
|
||
/* Icinga for Kubernetes Web | (c) 2025 Icinga GmbH | AGPLv3 */ | ||
|
||
namespace Icinga\Module\Kubernetes\Controllers; | ||
|
||
use Icinga\Application\Logger; | ||
use Icinga\Module\Kubernetes\Common\Auth; | ||
use Icinga\Module\Kubernetes\Common\Database; | ||
use Icinga\Module\Kubernetes\Forms\FavorForm; | ||
use Icinga\Module\Kubernetes\Forms\UnfavorForm; | ||
use Icinga\Module\Kubernetes\Model\Favorite; | ||
use Icinga\Module\Kubernetes\Web\Controller; | ||
use ipl\Sql\Expression; | ||
use ipl\Stdlib\Filter; | ||
use Throwable; | ||
|
||
class FavoriteController extends Controller | ||
{ | ||
/** | ||
* Favors a resource by adding it into the database. Throws an exception if the database operation fails. | ||
* | ||
* @return void | ||
*/ | ||
public function favorAction(): void | ||
{ | ||
(new FavorForm()) | ||
->on(FavorForm::ON_SUCCESS, function () { | ||
$db = Database::connection(); | ||
$uuid = $this->params->get('uuid'); | ||
$kind = $this->params->get('kind'); | ||
$username = Auth::getInstance()->getUser()->getUsername(); | ||
|
||
try { | ||
$highestPriorityFavorite = Favorite::on($db) | ||
->columns('priority') | ||
->filter( | ||
Filter::all( | ||
Filter::equal('kind', $kind), | ||
Filter::equal('username', $username) | ||
) | ||
) | ||
->orderBy('priority', SORT_DESC) | ||
->first(); | ||
|
||
$db->insert( | ||
'favorite', | ||
[ | ||
'resource_uuid' => $uuid, | ||
'kind' => $kind, | ||
'username' => $username, | ||
'priority' => ($highestPriorityFavorite?->priority ?? -1) + 1, | ||
] | ||
); | ||
} catch (Throwable $e) { | ||
Logger::error($e); | ||
Logger::error($e->getTraceAsString()); | ||
|
||
throw $e; | ||
} | ||
}) | ||
->handleRequest($this->getServerRequest()); | ||
|
||
$this->closeModalAndRefreshRemainingViews('__REFRESH__'); | ||
} | ||
|
||
/** | ||
* Unfavors a resource by removing it from the database. Throws an exception if the database operation fails. | ||
* | ||
* @return void | ||
*/ | ||
public function unfavorAction(): void | ||
{ | ||
(new UnfavorForm()) | ||
->on(FavorForm::ON_SUCCESS, function () { | ||
$db = Database::connection(); | ||
$uuid = $this->params->get('uuid'); | ||
$username = Auth::getInstance()->getUser()->getUsername(); | ||
try { | ||
$transactionStarted = false; | ||
if (! $db->inTransaction()) { | ||
$transactionStarted = true; | ||
$db->beginTransaction(); | ||
} | ||
|
||
$favoriteToDelete = Favorite::on($db) | ||
->filter(Filter::all( | ||
Filter::equal('resource_uuid', $uuid), | ||
Filter::equal('username', $username) | ||
)) | ||
->first(); | ||
|
||
$db->delete( | ||
'favorite', | ||
[ | ||
'resource_uuid = ?' => $uuid, | ||
'username = ?' => $username, | ||
] | ||
); | ||
|
||
$affectedFavorites = Favorite::on($db) | ||
->columns(['resource_uuid', 'username']) | ||
->filter( | ||
Filter::all( | ||
Filter::equal('kind', $favoriteToDelete->kind), | ||
Filter::equal('username', $username), | ||
Filter::greaterThan('priority', $favoriteToDelete->priority) | ||
) | ||
) | ||
->orderBy('priority', SORT_ASC); | ||
|
||
foreach ($affectedFavorites as $favorite) { | ||
$db->update( | ||
'favorite', | ||
['priority' => new Expression('priority - 1')], | ||
['resource_uuid = ?' => $favorite->resource_uuid, 'username = ?' => $favorite->username] | ||
); | ||
} | ||
|
||
if ($transactionStarted) { | ||
$db->commitTransaction(); | ||
} | ||
} catch (Throwable $e) { | ||
Logger::error($e); | ||
Logger::error($e->getTraceAsString()); | ||
|
||
$db->rollBackTransaction(); | ||
|
||
throw $e; | ||
} | ||
}) | ||
->handleRequest($this->getServerRequest()); | ||
|
||
$this->closeModalAndRefreshRemainingViews('__REFRESH__'); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
<?php | ||
|
||
/* Icinga for Kubernetes Web | (c) 2025 Icinga GmbH | AGPLv3 */ | ||
|
||
namespace Icinga\Module\Kubernetes\Controllers; | ||
|
||
use Icinga\Module\Kubernetes\Common\Auth; | ||
use Icinga\Module\Kubernetes\Common\Database; | ||
use Icinga\Module\Kubernetes\Model\Favorite; | ||
use Icinga\Module\Kubernetes\Web\Controller; | ||
use Icinga\Module\Kubernetes\Web\Factory; | ||
use Icinga\Module\Kubernetes\Web\FavoriteDashboard; | ||
use Icinga\Web\Widget\Dashboard; | ||
use Icinga\Web\Widget\Dashboard\Dashlet; | ||
use Icinga\Web\Widget\Dashboard\Pane; | ||
use ipl\Stdlib\Filter; | ||
|
||
class FavoritesController extends Controller | ||
{ | ||
/** @var array */ | ||
protected const FAVORABLE_KINDS = [ | ||
'cronjob', | ||
'daemonset', | ||
'deployment', | ||
'ingress', | ||
'job', | ||
'namespace', | ||
'node', | ||
'persistentvolumeclaim', | ||
'persistentvolume', | ||
'pod', | ||
'replicaset', | ||
'service', | ||
'statefulset' | ||
]; | ||
|
||
public function indexAction(): void | ||
{ | ||
$this->addTitleTab('Favorites'); | ||
$dashboard = new Dashboard(); | ||
$pane = (new Pane('favorites'))->setTitle('Favorites'); | ||
$dashboard->addPane($pane); | ||
|
||
foreach (static::FAVORABLE_KINDS as $kind) { | ||
$hasFavorites = Favorite::on(Database::connection()) | ||
->filter(Filter::all( | ||
Filter::equal('kind', $kind), | ||
Filter::equal('username', Auth::getInstance()->getUser()->getUsername()) | ||
))->first(); | ||
|
||
if ($hasFavorites) { | ||
$dashlet = new Dashlet( | ||
Factory::createTitle($kind), | ||
Factory::createListUrl($kind) . '?view=minimal&show-favorites=y&sort=favorite.priority desc', | ||
$pane | ||
); | ||
$pane->addDashlet($dashlet); | ||
} | ||
} | ||
|
||
$dashboard->activate('favorites'); | ||
$this->addContent(new FavoriteDashboard($dashboard)); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is that necessary?