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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,11 +32,11 @@ class AiModelResource extends Resource
|
||||
->schema([
|
||||
Forms\Components\Section::make()
|
||||
->schema([
|
||||
Select::make('api_provider_id')
|
||||
->label(__('filament.resource.ai_model.form.api_provider'))
|
||||
Select::make('apiProviders')
|
||||
->label(__('filament.resource.ai_model.form.api_providers'))
|
||||
->relationship('apiProviders', 'name')
|
||||
->multiple()
|
||||
->live()
|
||||
->nullable()
|
||||
->afterStateUpdated(function (callable $set) {
|
||||
$set('model_search_result', null);
|
||||
}),
|
||||
@@ -44,20 +44,24 @@ class AiModelResource extends Resource
|
||||
->label(__('filament.resource.ai_model.form.search_model'))
|
||||
->searchable()
|
||||
->live()
|
||||
->hidden(fn (callable $get) => !static::canSearchModels($get('api_provider_id')))
|
||||
->hidden(fn (callable $get) => !static::canSearchModelsWithAnyProvider($get('apiProviders')))
|
||||
->getSearchResultsUsing(function (string $search, callable $get) {
|
||||
$apiProviderId = $get('api_provider_id');
|
||||
if (!$apiProviderId) {
|
||||
$apiProviderIds = $get('apiProviders');
|
||||
if (empty($apiProviderIds)) {
|
||||
return [];
|
||||
}
|
||||
$pluginInstance = static::getPluginInstance($apiProviderId);
|
||||
if ($pluginInstance && method_exists($pluginInstance, 'searchModels')) {
|
||||
$models = $pluginInstance->searchModels($search);
|
||||
$options = [];
|
||||
foreach ($models as $model) {
|
||||
$options[json_encode(['name' => $model['name'], 'id' => $model['id'], 'type' => $model['type'] ?? null])] = $model['name'] . ' (' . $model['id'] . ')';
|
||||
|
||||
// Try each API provider until we find one that works
|
||||
foreach ($apiProviderIds as $apiProviderId) {
|
||||
$pluginInstance = static::getPluginInstance($apiProviderId);
|
||||
if ($pluginInstance && method_exists($pluginInstance, 'searchModels')) {
|
||||
$models = $pluginInstance->searchModels($search);
|
||||
$options = [];
|
||||
foreach ($models as $model) {
|
||||
$options[json_encode(['name' => $model['name'], 'id' => $model['id'], 'type' => $model['type'] ?? null, 'api_provider_id' => $apiProviderId])] = $model['name'] . ' (' . $model['id'] . ')';
|
||||
}
|
||||
return $options;
|
||||
}
|
||||
return $options;
|
||||
}
|
||||
return [];
|
||||
})
|
||||
@@ -103,22 +107,28 @@ class AiModelResource extends Resource
|
||||
]);
|
||||
}
|
||||
|
||||
protected static function canSearchModels(?int $apiProviderId): bool
|
||||
protected static function canSearchModelsWithAnyProvider(?array $apiProviderIds): bool
|
||||
{
|
||||
if (!$apiProviderId) {
|
||||
if (empty($apiProviderIds)) {
|
||||
return false;
|
||||
}
|
||||
$apiProvider = ApiProvider::find($apiProviderId);
|
||||
if (!$apiProvider || !$apiProvider->plugin) {
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
$pluginInstance = PluginLoader::getPlugin($apiProvider->plugin, $apiProvider);
|
||||
return method_exists($pluginInstance, 'searchModels');
|
||||
} catch (\Exception $e) {
|
||||
// Log the exception if needed
|
||||
return false;
|
||||
|
||||
foreach ($apiProviderIds as $apiProviderId) {
|
||||
$apiProvider = ApiProvider::find($apiProviderId);
|
||||
if (!$apiProvider || !$apiProvider->plugin) {
|
||||
continue;
|
||||
}
|
||||
try {
|
||||
$pluginInstance = PluginLoader::getPlugin($apiProvider->plugin, $apiProvider);
|
||||
if (method_exists($pluginInstance, 'searchModels')) {
|
||||
return true;
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
// Log the exception if needed
|
||||
continue;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
protected static function getPluginInstance(?int $apiProviderId): ?ApiPluginInterface
|
||||
@@ -138,6 +148,24 @@ class AiModelResource extends Resource
|
||||
}
|
||||
}
|
||||
|
||||
protected static function canSearchModels(?int $apiProviderId): bool
|
||||
{
|
||||
if (!$apiProviderId) {
|
||||
return false;
|
||||
}
|
||||
$apiProvider = ApiProvider::find($apiProviderId);
|
||||
if (!$apiProvider || !$apiProvider->plugin) {
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
$pluginInstance = PluginLoader::getPlugin($apiProvider->plugin, $apiProvider);
|
||||
return method_exists($pluginInstance, 'searchModels');
|
||||
} catch (\Exception $e) {
|
||||
// Log the exception if needed
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
@@ -148,7 +176,7 @@ class AiModelResource extends Resource
|
||||
Tables\Columns\IconColumn::make('enabled')
|
||||
->label(__('filament.resource.ai_model.table.enabled'))
|
||||
->boolean(),
|
||||
TextColumn::make('apiProviders.name')->label(__('filament.resource.ai_model.table.api_providers'))->searchable()->sortable(),
|
||||
TextColumn::make('apiProviders.name')->label(__('filament.resource.ai_model.table.api_providers'))->searchable()->sortable()->limit(50),
|
||||
])
|
||||
->filters([
|
||||
//
|
||||
|
||||
@@ -54,9 +54,6 @@ class ImageResource extends Resource
|
||||
Tables\Actions\BulkActionGroup::make([
|
||||
Tables\Actions\DeleteBulkAction::make(),
|
||||
]),
|
||||
])
|
||||
->emptyStateActions([
|
||||
Tables\Actions\CreateAction::make(),
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -71,8 +68,7 @@ class ImageResource extends Resource
|
||||
{
|
||||
return [
|
||||
'index' => Pages\ListImages::route('/'),
|
||||
'create' => Pages\CreateImage::route('/create'),
|
||||
'edit' => Pages\EditImage::route('/{record}/edit'),
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\ImageResource\Pages;
|
||||
|
||||
use App\Filament\Resources\ImageResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\CreateRecord;
|
||||
|
||||
class CreateImage extends CreateRecord
|
||||
{
|
||||
protected static string $resource = ImageResource::class;
|
||||
|
||||
protected function getRedirectUrl(): string
|
||||
{
|
||||
return $this->getResource()::getUrl('index');
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,8 @@ use Filament\Actions;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
use Illuminate\Contracts\Pagination\Paginator;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Filament\Notifications\Notification;
|
||||
|
||||
class ListImages extends ListRecords
|
||||
{
|
||||
@@ -15,7 +17,25 @@ class ListImages extends ListRecords
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Actions\CreateAction::make(),
|
||||
Actions\Action::make('delete_all')
|
||||
->label('Delete All Images')
|
||||
->icon('heroicon-o-trash')
|
||||
->color('danger')
|
||||
->requiresConfirmation()
|
||||
->action(function () {
|
||||
// Delete all images from storage
|
||||
Storage::disk('public')->deleteDirectory('images');
|
||||
Storage::disk('public')->makeDirectory('images');
|
||||
|
||||
// Show success notification
|
||||
Notification::make()
|
||||
->title('All images deleted successfully')
|
||||
->success()
|
||||
->send();
|
||||
|
||||
// Refresh the page
|
||||
$this->redirect(static::getUrl());
|
||||
}),
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
@@ -1,105 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources;
|
||||
|
||||
use App\Filament\Resources\SettingResource\Pages;
|
||||
use App\Filament\Resources\SettingResource\RelationManagers;
|
||||
use App\Models\Setting;
|
||||
use Filament\Forms;
|
||||
use Filament\Forms\Form;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Tables;
|
||||
use Filament\Tables\Table;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\SoftDeletingScope;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Forms\Components\Fieldset;
|
||||
|
||||
class SettingResource extends Resource
|
||||
{
|
||||
protected static ?string $model = Setting::class;
|
||||
|
||||
protected static ?string $navigationIcon = 'heroicon-o-cog';
|
||||
|
||||
protected static ?string $navigationGroup = 'Einstellungen';
|
||||
|
||||
public static function form(Form $form): Form
|
||||
{
|
||||
return $form
|
||||
->schema([
|
||||
Forms\Components\TextInput::make('key')
|
||||
->label(__('Key'))
|
||||
->required()
|
||||
->maxLength(255)
|
||||
->hiddenOn('edit'),
|
||||
Forms\Components\Fieldset::make()
|
||||
->label(fn (?Setting $record) => $record ? __('filament.resource.setting.form.' . $record->key) : __('New Setting'))
|
||||
->schema([
|
||||
TextInput::make('value')
|
||||
->label(__('Bitte Wert eingeben'))
|
||||
->disableLabel(fn (?Setting $record) => $record && ($record->key !== 'image_refresh_interval' && $record->key !== 'new_image_timespan_minutes' && $record->key !== 'gallery_heading'))
|
||||
->formatStateUsing(function (?string $state, ?Setting $record) {
|
||||
if ($record && $record->key === 'image_refresh_interval') {
|
||||
return (int)$state / 1000;
|
||||
} else if ($record && $record->key === 'new_image_timespan_minutes') {
|
||||
return (int)$state;
|
||||
}
|
||||
return $state;
|
||||
})
|
||||
->dehydrateStateUsing(function (?string $state, ?Setting $record) {
|
||||
if ($record && $record->key === 'image_refresh_interval') {
|
||||
return (int)$state * 1000;
|
||||
} else if ($record && $record->key === 'new_image_timespan_minutes') {
|
||||
return (int)$state;
|
||||
}
|
||||
return $state;
|
||||
})
|
||||
])
|
||||
]);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->columns([
|
||||
Tables\Columns\TextColumn::make('key')->label(__('Key'))->searchable()->sortable(),
|
||||
Tables\Columns\TextColumn::make('value')->label(__('Value'))->searchable()->sortable(),
|
||||
])
|
||||
->filters([
|
||||
//
|
||||
])
|
||||
->actions([
|
||||
Tables\Actions\EditAction::make(),
|
||||
])
|
||||
|
||||
->bulkActions([
|
||||
Tables\Actions\BulkActionGroup::make([
|
||||
Tables\Actions\DeleteBulkAction::make(),
|
||||
]),
|
||||
])
|
||||
->emptyStateActions([
|
||||
Tables\Actions\CreateAction::make(),
|
||||
]);
|
||||
}
|
||||
|
||||
public static function getRelations(): array
|
||||
{
|
||||
return [
|
||||
//
|
||||
];
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => Pages\ListSettings::route('/'),
|
||||
'create' => Pages\CreateSetting::route('/create'),
|
||||
'edit' => Pages\EditSetting::route('/{record}/edit'),
|
||||
];
|
||||
}
|
||||
|
||||
public static function getNavigationGroup(): ?string
|
||||
{
|
||||
return __('filament.navigation.groups.settings');
|
||||
}
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\SettingResource\Pages;
|
||||
|
||||
use App\Filament\Resources\SettingResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\CreateRecord;
|
||||
|
||||
class CreateSetting extends CreateRecord
|
||||
{
|
||||
protected static string $resource = SettingResource::class;
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\SettingResource\Pages;
|
||||
|
||||
use App\Filament\Resources\SettingResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
|
||||
class EditSetting extends EditRecord
|
||||
{
|
||||
protected static string $resource = SettingResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Actions\DeleteAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\SettingResource\Pages;
|
||||
|
||||
use App\Filament\Resources\SettingResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
|
||||
class ListSettings extends ListRecords
|
||||
{
|
||||
protected static string $resource = SettingResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Actions\CreateAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user