mirror of
https://github.com/pelican-dev/panel.git
synced 2025-12-08 18:30:15 +01:00
Better Role icons (#1936)
Fix `Role` class path for `::getNavigationIcon()` Allow to register custom model icons Co-authored-by: Boy132 <mail@boy132.de>
This commit is contained in:
parent
897b95ec13
commit
d16e7dd876
@ -160,23 +160,11 @@ class RoleResource extends Resource
|
|||||||
*/
|
*/
|
||||||
private static function makeSection(string $model, array $options): Section
|
private static function makeSection(string $model, array $options): Section
|
||||||
{
|
{
|
||||||
$model = ucwords($model);
|
|
||||||
|
|
||||||
$icon = null;
|
|
||||||
|
|
||||||
if (class_exists('\App\Filament\Admin\Resources\\' . $model . 'Resource')) {
|
|
||||||
$icon = ('\App\Filament\Admin\Resources\\' . $model . 'Resource')::getNavigationIcon();
|
|
||||||
} elseif (class_exists('\App\Filament\Admin\Pages\\' . $model)) {
|
|
||||||
$icon = ('\App\Filament\Admin\Pages\\' . $model)::getNavigationIcon();
|
|
||||||
} elseif (class_exists('\App\Filament\Server\Resources\\' . $model . 'Resource')) {
|
|
||||||
$icon = ('\App\Filament\Server\Resources\\' . $model . 'Resource')::getNavigationIcon();
|
|
||||||
}
|
|
||||||
|
|
||||||
return Section::make(Str::headline($model))
|
return Section::make(Str::headline($model))
|
||||||
->columnSpan(1)
|
->columnSpan(1)
|
||||||
->collapsible()
|
->collapsible()
|
||||||
->collapsed()
|
->collapsed()
|
||||||
->icon($icon)
|
->icon(Role::getModelIcon($model))
|
||||||
->headerActions([
|
->headerActions([
|
||||||
Action::make('count')
|
Action::make('count')
|
||||||
->label(fn (Get $get) => count($get(strtolower($model) . '_list')))
|
->label(fn (Get $get) => count($get(strtolower($model) . '_list')))
|
||||||
|
|||||||
@ -54,6 +54,12 @@ class Role extends BaseRole
|
|||||||
],
|
],
|
||||||
];
|
];
|
||||||
|
|
||||||
|
public const MODEL_ICONS = [
|
||||||
|
'health' => 'tabler-heart',
|
||||||
|
'activityLog' => 'tabler-stack',
|
||||||
|
'panelLog' => 'tabler-file-info',
|
||||||
|
];
|
||||||
|
|
||||||
/** @var array<string, array<string>> */
|
/** @var array<string, array<string>> */
|
||||||
protected static array $customPermissions = [];
|
protected static array $customPermissions = [];
|
||||||
|
|
||||||
@ -79,6 +85,14 @@ class Role extends BaseRole
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @var array<string, string> */
|
||||||
|
protected static array $customModelIcons = [];
|
||||||
|
|
||||||
|
public static function registerCustomModelIcon(string $model, string $icon): void
|
||||||
|
{
|
||||||
|
static::$customModelIcons[$model] = $icon;
|
||||||
|
}
|
||||||
|
|
||||||
/** @return array<string, array<string>> */
|
/** @return array<string, array<string>> */
|
||||||
public static function getPermissionList(): array
|
public static function getPermissionList(): array
|
||||||
{
|
{
|
||||||
@ -124,6 +138,31 @@ class Role extends BaseRole
|
|||||||
return $allPermissions;
|
return $allPermissions;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function getModelIcon(string $model): ?string
|
||||||
|
{
|
||||||
|
$customModels = array_merge(static::MODEL_ICONS, static::$customModelIcons);
|
||||||
|
|
||||||
|
if (array_key_exists($model, $customModels)) {
|
||||||
|
return $customModels[$model];
|
||||||
|
}
|
||||||
|
|
||||||
|
$model = ucwords($model);
|
||||||
|
|
||||||
|
if (class_exists($class = '\\App\\Filament\\Admin\\Resources\\' . $model . 's\\' . $model . 'Resource')) {
|
||||||
|
return $class::getNavigationIcon();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (class_exists($class = '\\App\\Filament\\Admin\\Pages\\' . $model)) {
|
||||||
|
return $class::getNavigationIcon();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (class_exists($class = '\\App\\Filament\\Server\\Resources\\' . $model . 's\\' . $model . 'Resource')) {
|
||||||
|
return $class::getNavigationIcon();
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
public function isRootAdmin(): bool
|
public function isRootAdmin(): bool
|
||||||
{
|
{
|
||||||
return $this->name === self::ROOT_ADMIN;
|
return $this->name === self::ROOT_ADMIN;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user