48 lines
1.6 KiB
PHP
48 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Resources\Channels\Pages;
|
|
|
|
use App\Actions\AnalyzeChannelCalendar;
|
|
use App\Actions\ConfigureChannel;
|
|
use App\Channels\ChannelSyncException;
|
|
use App\Filament\Resources\Channels\ChannelResource;
|
|
use Filament\Actions\Action;
|
|
use Filament\Notifications\Notification;
|
|
use Filament\Resources\Pages\EditRecord;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
class EditChannel extends EditRecord
|
|
{
|
|
protected static string $resource = ChannelResource::class;
|
|
|
|
protected function getHeaderActions(): array
|
|
{
|
|
return [
|
|
Action::make('rules')->label('Regeln & Exportfelder')->url(fn (): string => ChannelResource::getUrl('rules', ['record' => $this->record])),
|
|
Action::make('analyze')->label('Kalender analysieren')->action(function (AnalyzeChannelCalendar $analyze): void {
|
|
try {
|
|
$analyze->handle($this->record);
|
|
$this->redirect(ChannelResource::getUrl('rules', ['record' => $this->record]));
|
|
} catch (ChannelSyncException $exception) {
|
|
Notification::make()->title('Analyse nicht möglich')->body($exception->getMessage())->danger()->send();
|
|
}
|
|
}),
|
|
];
|
|
}
|
|
|
|
protected function mutateFormDataBeforeFill(array $data): array
|
|
{
|
|
return [...$data, 'settings' => $this->record->settings];
|
|
}
|
|
|
|
protected function handleRecordUpdate(Model $record, array $data): Model
|
|
{
|
|
return app(ConfigureChannel::class)->handle($record->property, $data, $record);
|
|
}
|
|
|
|
protected function getRedirectUrl(): string
|
|
{
|
|
return ChannelResource::getUrl('index');
|
|
}
|
|
}
|