add enum for plugin category and add tabs to list

This commit is contained in:
Boy132 2025-08-05 14:43:16 +02:00
parent 736d9be9e3
commit 793d264f72
6 changed files with 74 additions and 12 deletions

View File

@ -2,6 +2,7 @@
namespace App\Console\Commands\Plugin;
use App\Enums\PluginCategory;
use App\Enums\PluginStatus;
use Illuminate\Console\Command;
use Illuminate\Filesystem\Filesystem;
@ -51,11 +52,15 @@ class MakePluginCommand extends Command
$this->info('Creating Plugin "' . $name . '" (' . $id . ') by ' . $author);
$description = $this->option('description') ?? $this->ask('Description');
$category = $this->option('category') ?? $this->choice('Category', [
'plugin' => 'Plugin',
'theme' => 'Theme',
'language' => 'Language Pack',
], 'plugin');
$category = $this->option('category') ?? $this->choice('Category', collect(PluginCategory::cases())->mapWithKeys(fn (PluginCategory $category) => [$category->value => $category->getLabel()])->toArray(), PluginCategory::Plugin->value);
if (!PluginCategory::tryFrom($category)) {
$this->error('Unknown plugin category!');
return;
}
$url = $this->option('url') ?? $this->ask('URL', 'https://github.com/' . $author . '/' . $id);
$updateUrl = $this->option('updateUrl') ?? $this->ask('Update URL');
$panels = $this->option('panels') ?? $this->choice('Panels', [

View 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);
}
}

View File

@ -68,7 +68,8 @@ class PluginResource extends Resource
TextColumn::make('category')
->label(trans('admin/plugin.category'))
->badge()
->sortable(),
->sortable()
->visible(fn ($livewire) => $livewire->activeTab === 'all'),
TextColumn::make('status')
->label(trans('admin/plugin.status'))
->badge()

View File

@ -2,8 +2,11 @@
namespace App\Filament\Admin\Resources\PluginResource\Pages;
use App\Enums\PluginCategory;
use App\Facades\Plugins;
use App\Filament\Admin\Resources\PluginResource;
use App\Models\Plugin;
use Filament\Resources\Components\Tab;
use Filament\Resources\Pages\ListRecords;
class ListPlugins extends ListRecords
@ -14,4 +17,21 @@ class ListPlugins extends ListRecords
{
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;
}
}

View File

@ -3,6 +3,7 @@
namespace App\Models;
use App\Contracts\Plugins\HasPluginSettings;
use App\Enums\PluginCategory;
use App\Enums\PluginStatus;
use Exception;
use Filament\Forms\Components\Component;
@ -19,7 +20,7 @@ use Sushi\Sushi;
* @property string $author
* @property string $version
* @property string|null $description
* @property string $category
* @property PluginCategory $category
* @property string|null $url
* @property string|null $update_url
* @property string $namespace
@ -73,7 +74,7 @@ class Plugin extends Model implements HasPluginSettings
* author: string,
* version: string,
* description: ?string,
* category: ?string,
* category: string,
* url: ?string,
* update_url: ?string,
* namespace: string,
@ -120,7 +121,7 @@ class Plugin extends Model implements HasPluginSettings
'author' => $data['author'],
'version' => Arr::get($data, 'version', '1.0.0'),
'description' => Arr::get($data, 'description', null),
'category' => Arr::get($data, 'category', null),
'category' => $data['category'],
'url' => Arr::get($data, 'url', null),
'update_url' => Arr::get($data, 'update_url', null),
'namespace' => $data['namespace'],
@ -145,7 +146,7 @@ class Plugin extends Model implements HasPluginSettings
'author' => $data['author'] ?? 'Unknown',
'version' => '0.0.0',
'description' => 'Plugin.json is invalid!',
'category' => 'invalid',
'category' => PluginCategory::Plugin->value,
'url' => null,
'update_url' => null,
'namespace' => 'Error',
@ -174,6 +175,7 @@ class Plugin extends Model implements HasPluginSettings
{
return [
'status' => PluginStatus::class,
'category' => PluginCategory::class,
];
}
@ -245,12 +247,12 @@ class Plugin extends Model implements HasPluginSettings
public function isTheme(): bool
{
return $this->category === 'theme';
return $this->category === PluginCategory::Theme;
}
public function isLanguage(): bool
{
return $this->category === 'language';
return $this->category === PluginCategory::Language;
}
/** @return null|array<string, array{version: string, download_url: string}> */

View File

@ -20,6 +20,7 @@ return [
'no_plugins' => 'No Plugins',
'from_file' => 'From File',
'from_url' => 'From URL',
'all' => 'All',
'status_enum' => [
'not_installed' => 'Not Installed',
@ -29,6 +30,12 @@ return [
'incompatible' => 'Incompatible',
],
'category_enum' => [
'plugin' => 'Plugin',
'theme' => 'Theme',
'language' => 'Language Pack',
],
'notifications' => [
'installed' => 'Plugin installed',
'updated' => 'Plugin updated',