mirror of
https://github.com/pelican-dev/panel.git
synced 2025-11-09 16:19:35 +01:00
add enum for plugin category and add tabs to list
This commit is contained in:
parent
736d9be9e3
commit
793d264f72
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace App\Console\Commands\Plugin;
|
namespace App\Console\Commands\Plugin;
|
||||||
|
|
||||||
|
use App\Enums\PluginCategory;
|
||||||
use App\Enums\PluginStatus;
|
use App\Enums\PluginStatus;
|
||||||
use Illuminate\Console\Command;
|
use Illuminate\Console\Command;
|
||||||
use Illuminate\Filesystem\Filesystem;
|
use Illuminate\Filesystem\Filesystem;
|
||||||
@ -51,11 +52,15 @@ class MakePluginCommand extends Command
|
|||||||
$this->info('Creating Plugin "' . $name . '" (' . $id . ') by ' . $author);
|
$this->info('Creating Plugin "' . $name . '" (' . $id . ') by ' . $author);
|
||||||
|
|
||||||
$description = $this->option('description') ?? $this->ask('Description');
|
$description = $this->option('description') ?? $this->ask('Description');
|
||||||
$category = $this->option('category') ?? $this->choice('Category', [
|
|
||||||
'plugin' => 'Plugin',
|
$category = $this->option('category') ?? $this->choice('Category', collect(PluginCategory::cases())->mapWithKeys(fn (PluginCategory $category) => [$category->value => $category->getLabel()])->toArray(), PluginCategory::Plugin->value);
|
||||||
'theme' => 'Theme',
|
|
||||||
'language' => 'Language Pack',
|
if (!PluginCategory::tryFrom($category)) {
|
||||||
], 'plugin');
|
$this->error('Unknown plugin category!');
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
$url = $this->option('url') ?? $this->ask('URL', 'https://github.com/' . $author . '/' . $id);
|
$url = $this->option('url') ?? $this->ask('URL', 'https://github.com/' . $author . '/' . $id);
|
||||||
$updateUrl = $this->option('updateUrl') ?? $this->ask('Update URL');
|
$updateUrl = $this->option('updateUrl') ?? $this->ask('Update URL');
|
||||||
$panels = $this->option('panels') ?? $this->choice('Panels', [
|
$panels = $this->option('panels') ?? $this->choice('Panels', [
|
||||||
|
|||||||
27
app/Enums/PluginCategory.php
Normal file
27
app/Enums/PluginCategory.php
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Enums;
|
||||||
|
|
||||||
|
use Filament\Support\Contracts\HasIcon;
|
||||||
|
use Filament\Support\Contracts\HasLabel;
|
||||||
|
|
||||||
|
enum PluginCategory: string implements HasIcon, HasLabel
|
||||||
|
{
|
||||||
|
case Plugin = 'plugin';
|
||||||
|
case Theme = 'theme';
|
||||||
|
case Language = 'language';
|
||||||
|
|
||||||
|
public function getIcon(): string
|
||||||
|
{
|
||||||
|
return match ($this) {
|
||||||
|
self::Plugin => 'tabler-package',
|
||||||
|
self::Theme => 'tabler-palette',
|
||||||
|
self::Language => 'tabler-language',
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getLabel(): string
|
||||||
|
{
|
||||||
|
return trans('admin/plugin.category_enum.' . $this->value);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -68,7 +68,8 @@ class PluginResource extends Resource
|
|||||||
TextColumn::make('category')
|
TextColumn::make('category')
|
||||||
->label(trans('admin/plugin.category'))
|
->label(trans('admin/plugin.category'))
|
||||||
->badge()
|
->badge()
|
||||||
->sortable(),
|
->sortable()
|
||||||
|
->visible(fn ($livewire) => $livewire->activeTab === 'all'),
|
||||||
TextColumn::make('status')
|
TextColumn::make('status')
|
||||||
->label(trans('admin/plugin.status'))
|
->label(trans('admin/plugin.status'))
|
||||||
->badge()
|
->badge()
|
||||||
|
|||||||
@ -2,8 +2,11 @@
|
|||||||
|
|
||||||
namespace App\Filament\Admin\Resources\PluginResource\Pages;
|
namespace App\Filament\Admin\Resources\PluginResource\Pages;
|
||||||
|
|
||||||
|
use App\Enums\PluginCategory;
|
||||||
use App\Facades\Plugins;
|
use App\Facades\Plugins;
|
||||||
use App\Filament\Admin\Resources\PluginResource;
|
use App\Filament\Admin\Resources\PluginResource;
|
||||||
|
use App\Models\Plugin;
|
||||||
|
use Filament\Resources\Components\Tab;
|
||||||
use Filament\Resources\Pages\ListRecords;
|
use Filament\Resources\Pages\ListRecords;
|
||||||
|
|
||||||
class ListPlugins extends ListRecords
|
class ListPlugins extends ListRecords
|
||||||
@ -14,4 +17,21 @@ class ListPlugins extends ListRecords
|
|||||||
{
|
{
|
||||||
Plugins::updateLoadOrder($order);
|
Plugins::updateLoadOrder($order);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getTabs(): array
|
||||||
|
{
|
||||||
|
$tabs = [];
|
||||||
|
|
||||||
|
foreach (PluginCategory::cases() as $category) {
|
||||||
|
$tabs[$category->value] = Tab::make($category->getLabel())
|
||||||
|
->icon($category->getIcon())
|
||||||
|
->badge(Plugin::whereCategory($category->value)->count())
|
||||||
|
->modifyQueryUsing(fn ($query) => $query->whereCategory($category->value));
|
||||||
|
}
|
||||||
|
|
||||||
|
$tabs['all'] = Tab::make(trans('admin/plugin.all'))
|
||||||
|
->badge(Plugin::count());
|
||||||
|
|
||||||
|
return $tabs;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,6 +3,7 @@
|
|||||||
namespace App\Models;
|
namespace App\Models;
|
||||||
|
|
||||||
use App\Contracts\Plugins\HasPluginSettings;
|
use App\Contracts\Plugins\HasPluginSettings;
|
||||||
|
use App\Enums\PluginCategory;
|
||||||
use App\Enums\PluginStatus;
|
use App\Enums\PluginStatus;
|
||||||
use Exception;
|
use Exception;
|
||||||
use Filament\Forms\Components\Component;
|
use Filament\Forms\Components\Component;
|
||||||
@ -19,7 +20,7 @@ use Sushi\Sushi;
|
|||||||
* @property string $author
|
* @property string $author
|
||||||
* @property string $version
|
* @property string $version
|
||||||
* @property string|null $description
|
* @property string|null $description
|
||||||
* @property string $category
|
* @property PluginCategory $category
|
||||||
* @property string|null $url
|
* @property string|null $url
|
||||||
* @property string|null $update_url
|
* @property string|null $update_url
|
||||||
* @property string $namespace
|
* @property string $namespace
|
||||||
@ -73,7 +74,7 @@ class Plugin extends Model implements HasPluginSettings
|
|||||||
* author: string,
|
* author: string,
|
||||||
* version: string,
|
* version: string,
|
||||||
* description: ?string,
|
* description: ?string,
|
||||||
* category: ?string,
|
* category: string,
|
||||||
* url: ?string,
|
* url: ?string,
|
||||||
* update_url: ?string,
|
* update_url: ?string,
|
||||||
* namespace: string,
|
* namespace: string,
|
||||||
@ -120,7 +121,7 @@ class Plugin extends Model implements HasPluginSettings
|
|||||||
'author' => $data['author'],
|
'author' => $data['author'],
|
||||||
'version' => Arr::get($data, 'version', '1.0.0'),
|
'version' => Arr::get($data, 'version', '1.0.0'),
|
||||||
'description' => Arr::get($data, 'description', null),
|
'description' => Arr::get($data, 'description', null),
|
||||||
'category' => Arr::get($data, 'category', null),
|
'category' => $data['category'],
|
||||||
'url' => Arr::get($data, 'url', null),
|
'url' => Arr::get($data, 'url', null),
|
||||||
'update_url' => Arr::get($data, 'update_url', null),
|
'update_url' => Arr::get($data, 'update_url', null),
|
||||||
'namespace' => $data['namespace'],
|
'namespace' => $data['namespace'],
|
||||||
@ -145,7 +146,7 @@ class Plugin extends Model implements HasPluginSettings
|
|||||||
'author' => $data['author'] ?? 'Unknown',
|
'author' => $data['author'] ?? 'Unknown',
|
||||||
'version' => '0.0.0',
|
'version' => '0.0.0',
|
||||||
'description' => 'Plugin.json is invalid!',
|
'description' => 'Plugin.json is invalid!',
|
||||||
'category' => 'invalid',
|
'category' => PluginCategory::Plugin->value,
|
||||||
'url' => null,
|
'url' => null,
|
||||||
'update_url' => null,
|
'update_url' => null,
|
||||||
'namespace' => 'Error',
|
'namespace' => 'Error',
|
||||||
@ -174,6 +175,7 @@ class Plugin extends Model implements HasPluginSettings
|
|||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'status' => PluginStatus::class,
|
'status' => PluginStatus::class,
|
||||||
|
'category' => PluginCategory::class,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -245,12 +247,12 @@ class Plugin extends Model implements HasPluginSettings
|
|||||||
|
|
||||||
public function isTheme(): bool
|
public function isTheme(): bool
|
||||||
{
|
{
|
||||||
return $this->category === 'theme';
|
return $this->category === PluginCategory::Theme;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function isLanguage(): bool
|
public function isLanguage(): bool
|
||||||
{
|
{
|
||||||
return $this->category === 'language';
|
return $this->category === PluginCategory::Language;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @return null|array<string, array{version: string, download_url: string}> */
|
/** @return null|array<string, array{version: string, download_url: string}> */
|
||||||
|
|||||||
@ -20,6 +20,7 @@ return [
|
|||||||
'no_plugins' => 'No Plugins',
|
'no_plugins' => 'No Plugins',
|
||||||
'from_file' => 'From File',
|
'from_file' => 'From File',
|
||||||
'from_url' => 'From URL',
|
'from_url' => 'From URL',
|
||||||
|
'all' => 'All',
|
||||||
|
|
||||||
'status_enum' => [
|
'status_enum' => [
|
||||||
'not_installed' => 'Not Installed',
|
'not_installed' => 'Not Installed',
|
||||||
@ -29,6 +30,12 @@ return [
|
|||||||
'incompatible' => 'Incompatible',
|
'incompatible' => 'Incompatible',
|
||||||
],
|
],
|
||||||
|
|
||||||
|
'category_enum' => [
|
||||||
|
'plugin' => 'Plugin',
|
||||||
|
'theme' => 'Theme',
|
||||||
|
'language' => 'Language Pack',
|
||||||
|
],
|
||||||
|
|
||||||
'notifications' => [
|
'notifications' => [
|
||||||
'installed' => 'Plugin installed',
|
'installed' => 'Plugin installed',
|
||||||
'updated' => 'Plugin updated',
|
'updated' => 'Plugin updated',
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user