fixed migrations, changed settings to global settings, changed image list to have a "delete all" button instead of "create", fixed printing, added imagick for printing.
This commit is contained in:
96
app/Filament/Pages/GlobalSettings.php
Normal file
96
app/Filament/Pages/GlobalSettings.php
Normal file
@@ -0,0 +1,96 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Pages;
|
||||
|
||||
use App\Models\Setting;
|
||||
use App\Services\PrinterService;
|
||||
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 Illuminate\Support\Arr;
|
||||
|
||||
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';
|
||||
|
||||
public ?array $data = [];
|
||||
|
||||
public function mount(): void
|
||||
{
|
||||
$settings = Setting::all()->pluck('value', 'key')->toArray();
|
||||
$this->form->fill($settings);
|
||||
}
|
||||
|
||||
public function form(Form $form): Form
|
||||
{
|
||||
$printerService = new PrinterService();
|
||||
$printers = $printerService->getPrinters();
|
||||
$printerOptions = array_merge($printers, ['__custom__' => __('filament.resource.setting.form.custom_printer')]);
|
||||
|
||||
return $form
|
||||
->schema([
|
||||
TextInput::make('gallery_heading')
|
||||
->label(__('filament.resource.setting.form.gallery_heading'))
|
||||
->required(),
|
||||
TextInput::make('new_image_timespan_minutes')
|
||||
->label(__('filament.resource.setting.form.new_image_timespan_minutes'))
|
||||
->numeric()
|
||||
->required(),
|
||||
TextInput::make('image_refresh_interval')
|
||||
->label(__('filament.resource.setting.form.image_refresh_interval'))
|
||||
->numeric()
|
||||
->required(),
|
||||
TextInput::make('max_number_of_copies')
|
||||
->label(__('filament.resource.setting.form.max_number_of_copies'))
|
||||
->numeric()
|
||||
->required(),
|
||||
Toggle::make('show_print_button')
|
||||
->label(__('filament.resource.setting.form.show_print_button')),
|
||||
Select::make('selected_printer')
|
||||
->label(__('filament.resource.setting.form.printer'))
|
||||
->options($printerOptions)
|
||||
->reactive(),
|
||||
TextInput::make('custom_printer_address')
|
||||
->label(__('filament.resource.setting.form.custom_printer_address'))
|
||||
->visible(fn ($get) => $get('selected_printer') === '__custom__'),
|
||||
])
|
||||
->statePath('data');
|
||||
}
|
||||
|
||||
public function save(): 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'] = '';
|
||||
}
|
||||
|
||||
foreach ($data as $key => $value) {
|
||||
Setting::where('key', $key)->update(['value' => $value]);
|
||||
}
|
||||
|
||||
Notification::make()
|
||||
->title(__('settings.saved_successfully'))
|
||||
->success()
|
||||
->send();
|
||||
}
|
||||
|
||||
protected function getFormActions(): array
|
||||
{
|
||||
return [
|
||||
\Filament\Actions\Action::make('save')
|
||||
->label(__('settings.save_button'))
|
||||
->submit('save'),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -3,21 +3,13 @@
|
||||
namespace App\Filament\Pages;
|
||||
|
||||
use Filament\Pages\Page;
|
||||
use Filament\Tables;
|
||||
use Filament\Tables\Table;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Filament\Forms\Contracts\HasForms;
|
||||
use Filament\Forms\Concerns\InteractsWithForms;
|
||||
use App\Models\Plugin;
|
||||
|
||||
class Plugins extends Page implements Tables\Contracts\HasTable, HasForms
|
||||
class Plugins extends Page
|
||||
{
|
||||
use Tables\Concerns\InteractsWithTable;
|
||||
use InteractsWithForms;
|
||||
|
||||
protected static ?string $navigationIcon = 'heroicon-o-puzzle-piece';
|
||||
|
||||
protected static ?string $navigationGroup = 'Plugins';
|
||||
protected static ?string $navigationGroup = 'Plugins';
|
||||
|
||||
protected static ?string $navigationLabel = 'Plugin List';
|
||||
|
||||
@@ -27,31 +19,7 @@ class Plugins extends Page implements Tables\Contracts\HasTable, HasForms
|
||||
|
||||
protected static ?string $slug = 'list-plugins';
|
||||
|
||||
public function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->query(Plugin::query()) // Use a dummy query
|
||||
->columns([
|
||||
Tables\Columns\TextColumn::make('name')
|
||||
->label('Name')
|
||||
->searchable()
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('identifier')
|
||||
->label('Identifier'),
|
||||
Tables\Columns\IconColumn::make('enabled')
|
||||
->label('Enabled')
|
||||
->boolean(),
|
||||
Tables\Columns\IconColumn::make('configured')
|
||||
->label('Configured')
|
||||
->boolean()
|
||||
->tooltip(fn ($record) => $record->configured ? 'Has ApiProvider record' : 'No ApiProvider record'),
|
||||
Tables\Columns\TextColumn::make('file_path')
|
||||
->label('File Path')
|
||||
->toggleable(isToggledHiddenByDefault: true),
|
||||
]);
|
||||
}
|
||||
|
||||
public $plugins;
|
||||
public $plugins;
|
||||
|
||||
public function mount(): void
|
||||
{
|
||||
@@ -67,9 +35,4 @@ class Plugins extends Page implements Tables\Contracts\HasTable, HasForms
|
||||
{
|
||||
return __('filament.navigation.plugin_list');
|
||||
}
|
||||
|
||||
public function currentlyValidatingForm(\Filament\Forms\ComponentContainer|null $form): void
|
||||
{
|
||||
// No form validation needed for this page
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user