finished the upgrade to filament 4. completely revamped the frontend with codex, now it looks great!
This commit is contained in:
@@ -2,41 +2,44 @@
|
||||
|
||||
namespace App\Filament\Pages;
|
||||
|
||||
use App\Models\Setting;
|
||||
use App\Services\PrinterService;
|
||||
use App\Settings\GeneralSettings;
|
||||
use BackedEnum;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Forms\Components\Toggle;
|
||||
use Filament\Forms\Concerns\InteractsWithForms;
|
||||
use Filament\Forms\Contracts\HasForms;
|
||||
use Filament\Forms\Form;
|
||||
use Filament\Notifications\Notification;
|
||||
use Filament\Pages\Page;
|
||||
use Filament\Schemas\Schema;
|
||||
use Illuminate\Support\Arr;
|
||||
use UnitEnum;
|
||||
|
||||
class GlobalSettings extends Page implements HasForms
|
||||
{
|
||||
use InteractsWithForms;
|
||||
|
||||
protected static ?string $navigationIcon = 'heroicon-o-cog';
|
||||
protected static string $view = 'filament.pages.global-settings';
|
||||
protected static ?string $navigationGroup = 'Admin';
|
||||
protected static string|BackedEnum|null $navigationIcon = 'heroicon-o-cog';
|
||||
|
||||
protected string $view = 'filament.pages.global-settings';
|
||||
|
||||
protected static string|UnitEnum|null $navigationGroup = 'Admin';
|
||||
|
||||
public ?array $data = [];
|
||||
|
||||
public function mount(): void
|
||||
public function mount(GeneralSettings $settings): void
|
||||
{
|
||||
$settings = Setting::all()->pluck('value', 'key')->toArray();
|
||||
$this->form->fill($settings);
|
||||
$this->form->fill($settings->toArray());
|
||||
}
|
||||
|
||||
public function form(Form $form): Form
|
||||
public function form(Schema $schema): Schema
|
||||
{
|
||||
$printerService = new PrinterService();
|
||||
$printerService = new PrinterService;
|
||||
$printers = $printerService->getPrinters();
|
||||
$printerOptions = array_merge($printers, ['__custom__' => __('filament.resource.setting.form.custom_printer')]);
|
||||
|
||||
return $form
|
||||
return $schema
|
||||
->schema([
|
||||
TextInput::make('gallery_heading')
|
||||
->label(__('filament.resource.setting.form.gallery_heading'))
|
||||
@@ -66,18 +69,21 @@ class GlobalSettings extends Page implements HasForms
|
||||
->statePath('data');
|
||||
}
|
||||
|
||||
public function save(): void
|
||||
public function save(GeneralSettings $settings): void
|
||||
{
|
||||
$data = $this->form->getState();
|
||||
|
||||
// if a non-custom printer is selected, clear the custom address
|
||||
if (Arr::get($data, 'selected_printer') !== '__custom__') {
|
||||
$data['custom_printer_address'] = '';
|
||||
$data['custom_printer_address'] = null;
|
||||
}
|
||||
|
||||
foreach ($data as $key => $value) {
|
||||
Setting::where('key', $key)->update(['value' => $value]);
|
||||
}
|
||||
$data['new_image_timespan_minutes'] = (int) Arr::get($data, 'new_image_timespan_minutes', 0);
|
||||
$data['image_refresh_interval'] = (int) Arr::get($data, 'image_refresh_interval', 0);
|
||||
$data['max_number_of_copies'] = (int) Arr::get($data, 'max_number_of_copies', 0);
|
||||
$data['show_print_button'] = (bool) Arr::get($data, 'show_print_button', false);
|
||||
$data['custom_printer_address'] = $data['custom_printer_address'] ?: null;
|
||||
|
||||
$settings->fill($data)->save();
|
||||
|
||||
Notification::make()
|
||||
->title(__('settings.saved_successfully'))
|
||||
|
||||
@@ -2,23 +2,25 @@
|
||||
|
||||
namespace App\Filament\Pages;
|
||||
|
||||
use BackedEnum;
|
||||
use Filament\Forms\Components\FileUpload;
|
||||
use Filament\Forms\Concerns\InteractsWithForms;
|
||||
use Filament\Forms\Contracts\HasForms;
|
||||
use Filament\Forms\Form;
|
||||
use Filament\Notifications\Notification;
|
||||
use Filament\Pages\Page;
|
||||
use Filament\Schemas\Schema;
|
||||
use Illuminate\Support\Facades\File;
|
||||
use UnitEnum;
|
||||
|
||||
class InstallPluginPage extends Page implements HasForms
|
||||
{
|
||||
use InteractsWithForms;
|
||||
|
||||
protected static ?string $navigationIcon = 'heroicon-o-cloud-arrow-up';
|
||||
protected static string|BackedEnum|null $navigationIcon = 'heroicon-o-cloud-arrow-up';
|
||||
|
||||
protected static string $view = 'filament.pages.install-plugin-page';
|
||||
protected string $view = 'filament.pages.install-plugin-page';
|
||||
|
||||
protected static ?string $navigationGroup = 'Plugins';
|
||||
protected static string|UnitEnum|null $navigationGroup = 'Plugins';
|
||||
|
||||
protected static ?string $title = 'Install Plugin';
|
||||
|
||||
@@ -29,9 +31,9 @@ class InstallPluginPage extends Page implements HasForms
|
||||
$this->form->fill();
|
||||
}
|
||||
|
||||
public function form(Form $form): Form
|
||||
public function form(Schema $schema): Schema
|
||||
{
|
||||
return $form
|
||||
return $schema
|
||||
->schema([
|
||||
FileUpload::make('plugin_file')
|
||||
->label('Plugin File (.php)')
|
||||
@@ -59,10 +61,10 @@ class InstallPluginPage extends Page implements HasForms
|
||||
|
||||
$uploadedFile = $data['plugin_file'];
|
||||
$filename = File::basename($uploadedFile);
|
||||
$destinationPath = app_path('Api/Plugins/' . $filename);
|
||||
$destinationPath = app_path('Api/Plugins/'.$filename);
|
||||
|
||||
try {
|
||||
File::move(storage_path('app/temp_plugins/' . $filename), $destinationPath);
|
||||
File::move(storage_path('app/temp_plugins/'.$filename), $destinationPath);
|
||||
|
||||
Notification::make()
|
||||
->title('Plugin installed successfully')
|
||||
|
||||
@@ -2,30 +2,31 @@
|
||||
|
||||
namespace App\Filament\Pages;
|
||||
|
||||
use Filament\Pages\Page;
|
||||
use App\Models\Plugin;
|
||||
use BackedEnum;
|
||||
use Filament\Pages\Page;
|
||||
use Filament\Tables;
|
||||
use Filament\Tables\Columns\IconColumn;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Tables\Table;
|
||||
use UnitEnum;
|
||||
|
||||
class Plugins extends Page
|
||||
class Plugins extends Page implements Tables\Contracts\HasTable
|
||||
{
|
||||
protected static ?string $navigationIcon = 'heroicon-o-puzzle-piece';
|
||||
use Tables\Concerns\InteractsWithTable;
|
||||
|
||||
protected static ?string $navigationGroup = 'Plugins';
|
||||
protected static string|BackedEnum|null $navigationIcon = 'heroicon-o-puzzle-piece';
|
||||
|
||||
protected static string|UnitEnum|null $navigationGroup = 'Plugins';
|
||||
|
||||
protected static ?string $navigationLabel = 'Plugin List';
|
||||
|
||||
protected static ?string $title = 'Plugins';
|
||||
|
||||
protected static string $view = 'filament.pages.plugins';
|
||||
protected string $view = 'filament.pages.plugins';
|
||||
|
||||
protected static ?string $slug = 'list-plugins';
|
||||
|
||||
public $plugins;
|
||||
|
||||
public function mount(): void
|
||||
{
|
||||
$this->plugins = Plugin::getAllPlugins();
|
||||
}
|
||||
|
||||
public static function getNavigationGroup(): ?string
|
||||
{
|
||||
return __('filament.navigation.groups.plugins');
|
||||
@@ -35,4 +36,29 @@ class Plugins extends Page
|
||||
{
|
||||
return __('filament.navigation.plugin_list');
|
||||
}
|
||||
|
||||
public function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->columns([
|
||||
TextColumn::make('name')
|
||||
->label(__('Name'))
|
||||
->searchable()
|
||||
->sortable(),
|
||||
TextColumn::make('identifier')
|
||||
->label(__('Identifier'))
|
||||
->searchable()
|
||||
->sortable(),
|
||||
IconColumn::make('enabled')
|
||||
->label(__('Enabled'))
|
||||
->boolean(),
|
||||
IconColumn::make('configured')
|
||||
->label(__('Configured'))
|
||||
->boolean(),
|
||||
])
|
||||
->records(fn () => Plugin::getAllPlugins())
|
||||
->paginated(false)
|
||||
->emptyStateHeading(__('No plugins found'))
|
||||
->emptyStateDescription(__('Drop PHP plugin files into app/Api/Plugins (excluding ApiPluginInterface.php).'));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user