added a sparkbooth section to gallery form, connection details reside there now.
This commit is contained in:
@@ -4,9 +4,9 @@ namespace App\Filament\Pages;
|
||||
|
||||
use App\Models\Gallery;
|
||||
use BackedEnum;
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Notifications\Notification;
|
||||
use Filament\Pages\Page;
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Tables\Concerns\InteractsWithTable;
|
||||
use Filament\Tables\Contracts\HasTable;
|
||||
@@ -88,11 +88,24 @@ class SparkboothConnections extends Page implements HasTable
|
||||
|
||||
return view('filament.pages.partials.sparkbooth-token', $data);
|
||||
}),
|
||||
Action::make('deleteConnection')
|
||||
->label('Verbindung loeschen')
|
||||
->icon('heroicon-o-trash')
|
||||
->color('danger')
|
||||
->requiresConfirmation()
|
||||
->modalHeading('Sparkbooth-Verbindung entfernen')
|
||||
->modalDescription('Die Galerie bleibt erhalten, aber Upload-Token und Zugangsdaten werden geloescht.')
|
||||
->action(function (Gallery $record): void {
|
||||
$record->clearSparkboothConnection();
|
||||
|
||||
Notification::make()
|
||||
->title('Sparkbooth-Verbindung entfernt.')
|
||||
->body('Der Upload-Token und die Zugangsdaten wurden geloescht.')
|
||||
->success()
|
||||
->send();
|
||||
}),
|
||||
])
|
||||
->emptyStateHeading('Keine Sparkbooth-Verbindungen')
|
||||
->emptyStateDescription('Lege eine neue Verbindung an oder aktiviere Uploads fuer eine Galerie.');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -59,6 +59,7 @@ class GalleryResource extends Resource
|
||||
public static function mutateFormDataBeforeCreate(array $data): array
|
||||
{
|
||||
$data = self::mutatePassword($data);
|
||||
$data = self::mutateSparkbooth($data, true);
|
||||
$data['slug'] = $data['slug'] ?: Str::uuid()->toString();
|
||||
|
||||
return $data;
|
||||
@@ -67,6 +68,7 @@ class GalleryResource extends Resource
|
||||
public static function mutateFormDataBeforeSave(array $data): array
|
||||
{
|
||||
$data = self::mutatePassword($data);
|
||||
$data = self::mutateSparkbooth($data);
|
||||
$data['slug'] = $data['slug'] ?: Str::uuid()->toString();
|
||||
|
||||
return $data;
|
||||
@@ -83,4 +85,24 @@ class GalleryResource extends Resource
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
private static function mutateSparkbooth(array $data, bool $isCreate = false): array
|
||||
{
|
||||
if (array_key_exists('sparkbooth_username', $data)) {
|
||||
$data['sparkbooth_username'] = $data['sparkbooth_username']
|
||||
? Str::of($data['sparkbooth_username'])->lower()->trim()->value()
|
||||
: null;
|
||||
}
|
||||
|
||||
$password = $data['sparkbooth_password'] ?? null;
|
||||
unset($data['sparkbooth_password']);
|
||||
|
||||
if (! empty($password)) {
|
||||
$data['sparkbooth_password'] = $password;
|
||||
} elseif ($isCreate && empty($password)) {
|
||||
$data['sparkbooth_password'] = Str::random(24);
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,71 +3,125 @@
|
||||
namespace App\Filament\Resources\Galleries\Schemas;
|
||||
|
||||
use Filament\Forms\Components\DateTimePicker;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Forms\Components\Toggle;
|
||||
use Filament\Schemas\Components\Section;
|
||||
use Filament\Schemas\Components\Tabs;
|
||||
use Filament\Schemas\Components\Tabs\Tab;
|
||||
use Filament\Schemas\Components\View;
|
||||
use Filament\Schemas\Schema;
|
||||
use Illuminate\Support\Facades\URL;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class GalleryForm
|
||||
{
|
||||
public static function configure(Schema $schema): Schema
|
||||
{
|
||||
return $schema
|
||||
->columns(1)
|
||||
->components([
|
||||
Section::make('Details')
|
||||
->columns(2)
|
||||
->schema([
|
||||
TextInput::make('name')
|
||||
->label('Name')
|
||||
->required(),
|
||||
TextInput::make('slug')
|
||||
->label('Slug')
|
||||
->disabled()
|
||||
->dehydrated(true)
|
||||
->helperText('Wird automatisch erzeugt'),
|
||||
TextInput::make('title')
|
||||
->label('Titel')
|
||||
->required(),
|
||||
TextInput::make('images_path')
|
||||
->label('Bilder-Pfad')
|
||||
->helperText('Relativer Pfad unter public/storage')
|
||||
->required(),
|
||||
Toggle::make('is_public')
|
||||
->label('Öffentlich')
|
||||
->default(true),
|
||||
Toggle::make('allow_ai_styles')
|
||||
->label('AI-Stile erlauben')
|
||||
->default(true),
|
||||
Toggle::make('allow_print')
|
||||
->label('Drucken erlauben')
|
||||
->default(true),
|
||||
Toggle::make('require_password')
|
||||
->label('Passwortschutz aktiv')
|
||||
->default(false),
|
||||
TextInput::make('password')
|
||||
->label('Neues Passwort')
|
||||
->password()
|
||||
->revealable()
|
||||
->dehydrated(false)
|
||||
->helperText('Leer lassen, um das bestehende Passwort zu behalten.'),
|
||||
DateTimePicker::make('expires_at')
|
||||
->label('Ablaufdatum')
|
||||
->native(false)
|
||||
->seconds(false),
|
||||
TextInput::make('access_duration_minutes')
|
||||
->label('Zugriffsdauer (Minuten)')
|
||||
->numeric()
|
||||
->minValue(1)
|
||||
->nullable()
|
||||
->helperText('Optional: Zeitfenster nach dem ersten Unlock.'),
|
||||
]),
|
||||
View::make('filament.components.gallery-link')
|
||||
->columnSpanFull()
|
||||
->visible(fn (?object $record) => (bool) $record?->id)
|
||||
->viewData(fn (?object $record) => [
|
||||
'url' => $record ? URL::route('gallery.show', $record) : null,
|
||||
Tabs::make('gallery_tabs')
|
||||
->tabs([
|
||||
Tab::make('Galerie')
|
||||
->schema([
|
||||
Section::make('Details')
|
||||
->columns(2)
|
||||
->schema([
|
||||
TextInput::make('name')
|
||||
->label('Name')
|
||||
->required(),
|
||||
TextInput::make('slug')
|
||||
->label('Slug')
|
||||
->disabled()
|
||||
->dehydrated(true)
|
||||
->helperText('Wird automatisch erzeugt'),
|
||||
TextInput::make('title')
|
||||
->label('Titel')
|
||||
->required(),
|
||||
TextInput::make('images_path')
|
||||
->label('Bilder-Pfad')
|
||||
->helperText('Relativer Pfad unter public/storage')
|
||||
->required(),
|
||||
Toggle::make('is_public')
|
||||
->label('Öffentlich')
|
||||
->default(true),
|
||||
Toggle::make('allow_ai_styles')
|
||||
->label('AI-Stile erlauben')
|
||||
->default(true),
|
||||
Toggle::make('allow_print')
|
||||
->label('Drucken erlauben')
|
||||
->default(true),
|
||||
Toggle::make('require_password')
|
||||
->label('Passwortschutz aktiv')
|
||||
->default(false),
|
||||
TextInput::make('password')
|
||||
->label('Neues Passwort')
|
||||
->password()
|
||||
->revealable()
|
||||
->dehydrated(false)
|
||||
->helperText('Leer lassen, um das bestehende Passwort zu behalten.'),
|
||||
DateTimePicker::make('expires_at')
|
||||
->label('Ablaufdatum')
|
||||
->native(false)
|
||||
->seconds(false),
|
||||
TextInput::make('access_duration_minutes')
|
||||
->label('Zugriffsdauer (Minuten)')
|
||||
->numeric()
|
||||
->minValue(1)
|
||||
->nullable()
|
||||
->helperText('Optional: Zeitfenster nach dem ersten Unlock.'),
|
||||
]),
|
||||
View::make('filament.components.gallery-link')
|
||||
->columnSpanFull()
|
||||
->visible(fn (?object $record) => (bool) $record?->id)
|
||||
->viewData(fn (?object $record) => [
|
||||
'url' => $record ? URL::route('gallery.show', $record) : null,
|
||||
]),
|
||||
]),
|
||||
Tab::make('Sparkbooth')
|
||||
->schema([
|
||||
Section::make('Sparkbooth Upload')
|
||||
->columns(2)
|
||||
->schema([
|
||||
Toggle::make('upload_enabled')
|
||||
->label('Uploads aktivieren')
|
||||
->helperText('Steuert, ob Sparkbooth-Uploads erlaubt sind.')
|
||||
->default(false),
|
||||
Select::make('sparkbooth_response_format')
|
||||
->label('Standard-Antwortformat')
|
||||
->options([
|
||||
'json' => 'JSON',
|
||||
'xml' => 'XML',
|
||||
])
|
||||
->default('json'),
|
||||
TextInput::make('sparkbooth_username')
|
||||
->label('Sparkbooth Benutzername')
|
||||
->helperText('Wird in Sparkbooth unter „Username“ eingetragen. Erlaubt sind Buchstaben, Zahlen sowie ._-')
|
||||
->maxLength(64)
|
||||
->rule('regex:/^[A-Za-z0-9._-]+$/')
|
||||
->unique(table: \App\Models\Gallery::class, column: 'sparkbooth_username', ignoreRecord: true)
|
||||
->dehydrateStateUsing(fn (?string $state): ?string => $state ? Str::of($state)->lower()->trim()->value() : null),
|
||||
TextInput::make('sparkbooth_password')
|
||||
->label('Sparkbooth Passwort (neu)')
|
||||
->password()
|
||||
->revealable()
|
||||
->dehydrated(false)
|
||||
->afterStateHydrated(fn (callable $set) => $set('sparkbooth_password', null))
|
||||
->helperText('Leer lassen, um das bestehende Passwort zu behalten.'),
|
||||
]),
|
||||
View::make('filament.pages.partials.sparkbooth-token')
|
||||
->columnSpanFull()
|
||||
->visible(fn (?object $record) => (bool) $record?->id)
|
||||
->viewData(fn (?object $record) => [
|
||||
'upload_url' => URL::route('api.sparkbooth.upload'),
|
||||
'gallery_url' => $record ? URL::route('gallery.show', $record) : null,
|
||||
'sparkbooth_username' => $record?->sparkbooth_username,
|
||||
'sparkbooth_password' => $record?->sparkbooth_password,
|
||||
'response_format' => $record?->sparkbooth_response_format,
|
||||
'gallery' => $record ? $record->only(['slug', 'images_path']) : null,
|
||||
]),
|
||||
]),
|
||||
]),
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -74,4 +74,15 @@ class Gallery extends Model
|
||||
|
||||
return $password;
|
||||
}
|
||||
|
||||
public function clearSparkboothConnection(): void
|
||||
{
|
||||
$this->forceFill([
|
||||
'upload_token_hash' => null,
|
||||
'upload_token_expires_at' => null,
|
||||
'sparkbooth_username' => null,
|
||||
'sparkbooth_password' => null,
|
||||
'upload_enabled' => false,
|
||||
])->save();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user