iCal-Regelentwuerfe sichtbar speichern und Aktivierungsstand anzeigen
Deploy FeWo mit PipelineManager / deploy (push) Successful in 3m0s
Deploy FeWo mit PipelineManager / deploy (push) Successful in 3m0s
This commit is contained in:
1 parent
e7efb06277
commit
7d998e2b81
5 files changed
+147
-14
No files matched your search
@@ -12,6 +12,7 @@
|
||||
use App\Channels\ICal\ICalParser;
|
||||
use App\Channels\ICal\ICalRuleEngine;
|
||||
use App\Filament\Resources\Channels\ChannelResource;
|
||||
use App\Filament\Resources\PortalOccupations\PortalOccupationResource;
|
||||
use App\Models\BlockedPeriod;
|
||||
use App\Models\Channel;
|
||||
use Filament\Actions\Action;
|
||||
@@ -19,6 +20,7 @@
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Forms\Components\Toggle;
|
||||
use Filament\Infolists\Components\TextEntry;
|
||||
use Filament\Notifications\Notification;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
use Filament\Schemas\Components\Section;
|
||||
@@ -47,9 +49,13 @@ protected function mutateFormDataBeforeFill(array $data): array
|
||||
public function form(Schema $schema): Schema
|
||||
{
|
||||
return $schema->components([
|
||||
TextEntry::make('rule_status')->label('Gespeicherter Regelstand')
|
||||
->state(fn (): string => $this->savedRulesStatus())
|
||||
->helperText('Speichern legt einen Entwurf ab. „Speichern & anwenden“ aktiviert ihn für vorhandene Einträge und die nächsten Importe.')
|
||||
->columnSpanFull(),
|
||||
Section::make('1. Gefundene Kalenderfelder und Originalereignisse')->description('„Kalender analysieren“ liest die hinterlegte Adresse. Die Analyse verändert keine Belegungen.')
|
||||
->schema([View::make('filament.resources.channels.rule-analysis')]),
|
||||
Section::make('2. Erkennungsregeln')->description('Kleinere Prioritätszahlen zuerst. Bei mehreren Treffern gilt die erste passende aktive Regel. Speichern legt einen Entwurf ab; erst „Auf Bestand anwenden“ aktiviert die Regeln für weitere Importe.')
|
||||
Section::make('2. Erkennungsregeln')->description('Kleinere Prioritätszahlen zuerst. Bei mehreren Treffern gilt die erste passende aktive Regel. „Entwurf speichern“ und „Speichern & anwenden“ stehen oben auf dieser Seite.')
|
||||
->schema([
|
||||
Repeater::make('rules')->label('Regeln')->defaultItems(0)->addActionLabel('Regel hinzufügen')->live(debounce: 600)
|
||||
->itemLabel(fn (array $state): string => $state['name'] ?? 'Neue Regel')
|
||||
@@ -67,13 +73,15 @@ public function form(Schema $schema): Schema
|
||||
Select::make('event_type')->label('Dann: Ereignistyp')->options(ICalRuleEngine::TYPES)->default('unknown')->required(),
|
||||
Select::make('origin')->label('Ursprünglicher Buchungskanal')->options(fn (): array => ['unknown' => 'Unbekannt', 'current' => 'Dieser Portalkanal', ...$this->record->property->channels()->get()->mapWithKeys(fn (Channel $channel): array => ['channel:'.$channel->id => $channel->name])->all()])->default('unknown')->required(),
|
||||
Select::make('representation')->label('Fachliche Einordnung')->options(ICalRuleEngine::REPRESENTATIONS)->default('unspecified')->required()->columnSpanFull(),
|
||||
Repeater::make('extractions')->label('Informationen aus Text übernehmen')->defaultItems(0)->addActionLabel('Textextraktion hinzufügen')->columns(2)->schema([
|
||||
Select::make('field')->label('Aus Kalenderfeld')->options(fn (): array => $this->fieldOptions())->required(),
|
||||
Select::make('target')->label('Übernehmen als')->options(ICalRuleEngine::TARGETS)->required(),
|
||||
Select::make('method')->label('Textauswahl')->options(ICalRuleEngine::EXTRACTIONS)->default('whole')->required()->live(),
|
||||
TextInput::make('start')->label('Text nach / Anfangstext')->maxLength(500)->visible(fn (Get $get): bool => in_array($get('method'), ['after', 'between'], true))->live(debounce: 600),
|
||||
TextInput::make('end')->label('Text vor / Endtext')->maxLength(500)->visible(fn (Get $get): bool => in_array($get('method'), ['before', 'between'], true))->live(debounce: 600),
|
||||
])->columnSpanFull(),
|
||||
Repeater::make('extractions')->label('Informationen aus Text übernehmen')
|
||||
->helperText('Ein Name im Original wird erst mit einer Textextraktion angezeigt. Für einen vollständigen Namen das passende Kalenderfeld und „Vollständiger Gastname“ wählen. Die Vorschau prüft das Ergebnis; es wird kein Gast automatisch angelegt.')
|
||||
->defaultItems(0)->addActionLabel('Textextraktion hinzufügen')->columns(2)->schema([
|
||||
Select::make('field')->label('Aus Kalenderfeld')->options(fn (): array => $this->fieldOptions())->required(),
|
||||
Select::make('target')->label('Übernehmen als')->options(ICalRuleEngine::TARGETS)->required(),
|
||||
Select::make('method')->label('Textauswahl')->options(ICalRuleEngine::EXTRACTIONS)->default('whole')->required()->live(),
|
||||
TextInput::make('start')->label('Text nach / Anfangstext')->maxLength(500)->visible(fn (Get $get): bool => in_array($get('method'), ['after', 'between'], true))->live(debounce: 600),
|
||||
TextInput::make('end')->label('Text vor / Endtext')->maxLength(500)->visible(fn (Get $get): bool => in_array($get('method'), ['before', 'between'], true))->live(debounce: 600),
|
||||
])->columnSpanFull(),
|
||||
])->columns(2),
|
||||
]),
|
||||
Section::make('3. Live-Vorschau')->description('Auswertung des gespeicherten echten Kalenderstands mit dem aktuellen Regelentwurf. Identische Termine sind lediglich Zuordnungskandidaten.')
|
||||
@@ -99,7 +107,8 @@ public function preview(): array
|
||||
$counts = array_fill(0, count($rules), 0);
|
||||
$unmatched = 0;
|
||||
$rows = [];
|
||||
$blocks = $this->record->property->blockedPeriods()->occupying()->get();
|
||||
$occupations = $this->record->property->blockedPeriods()->with('channel')->get();
|
||||
$blocks = $occupations->where('is_representation', false);
|
||||
foreach ($this->record->ical_analysis['events'] ?? [] as $event) {
|
||||
$result = $engine->evaluate($this->record, $event['properties'], $rules);
|
||||
if ($result['matched']) {
|
||||
@@ -108,12 +117,31 @@ public function preview(): array
|
||||
$unmatched++;
|
||||
}
|
||||
$candidates = $blocks->filter(fn (BlockedPeriod $block): bool => $block->starts_on->toDateString() === $event['starts_on'] && $block->ends_on->toDateString() === $event['ends_on'] && ! ($block->channel_id === $this->record->id && $block->external_uid === $event['uid']))->sortByDesc('leading_priority');
|
||||
$rows[] = [...$event, 'summary' => $engine->values($event['properties'], 'SUMMARY')[0] ?? '(ohne SUMMARY)', 'result' => $result, 'candidates' => $candidates->map(fn (BlockedPeriod $block): array => ['id' => $block->id, 'reason' => $block->reason, 'priority' => $block->leading_priority])->all()];
|
||||
$occupation = $occupations->first(fn (BlockedPeriod $block): bool => $block->channel_id === $this->record->id && $block->external_uid === $event['uid']);
|
||||
$rows[] = [...$event, 'summary' => $engine->values($event['properties'], 'SUMMARY')[0] ?? '(ohne SUMMARY)', 'result' => $result,
|
||||
'occupation_url' => $occupation ? PortalOccupationResource::getUrl('view', ['record' => $occupation->id]) : null,
|
||||
'candidates' => $candidates->map(fn (BlockedPeriod $block): array => [
|
||||
'id' => $block->id, 'reason' => $block->channel?->name ?? $block->reason,
|
||||
'priority' => $block->leading_priority, 'kind' => $block->occupationKind()->getLabel(),
|
||||
'url' => in_array($block->source, ['channel', 'email'], true) ? PortalOccupationResource::getUrl('view', ['record' => $block->id]) : null,
|
||||
])->all()];
|
||||
}
|
||||
|
||||
return ['rows' => $rows, 'counts' => $counts, 'rules' => $rules, 'unmatched' => $unmatched];
|
||||
}
|
||||
|
||||
public function savedRulesStatus(): string
|
||||
{
|
||||
$draft = $this->record->ical_rules ?? [];
|
||||
$active = $this->record->ical_active_rules ?? [];
|
||||
|
||||
if ($draft !== $active) {
|
||||
return 'Gespeicherte Regeln sind noch nicht aktiv. Entwurf: '.count($draft).' Regeln; aktiv: '.count($active).' Regeln.';
|
||||
}
|
||||
|
||||
return $active === [] ? 'Es sind noch keine Erkennungsregeln aktiviert.' : 'Gespeicherter Entwurf und aktive Regeln stimmen überein. Aktiv: '.count($active).' Regeln.';
|
||||
}
|
||||
|
||||
public function exportPreview(): array
|
||||
{
|
||||
$channel = clone $this->record;
|
||||
@@ -141,6 +169,10 @@ protected function getSavedNotificationTitle(): ?string
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Action::make('saveDraft')->label('Entwurf speichern')->color('gray')
|
||||
->action(function (): void {
|
||||
$this->save(shouldRedirect: false);
|
||||
}),
|
||||
Action::make('analyze')->label('Kalender analysieren')->action(function (AnalyzeChannelCalendar $analyze): void {
|
||||
try {
|
||||
$this->record = $analyze->handle($this->record);
|
||||
@@ -149,7 +181,7 @@ protected function getHeaderActions(): array
|
||||
Notification::make()->title('Analyse nicht möglich')->body($exception->getMessage())->danger()->send();
|
||||
}
|
||||
}),
|
||||
Action::make('applyRules')->label('Auf Bestand anwenden')->requiresConfirmation()
|
||||
Action::make('applyRules')->label('Speichern & anwenden')->requiresConfirmation()
|
||||
->modalDescription('Der Regelentwurf wird aktiviert und der vorhandene Kalenderbestand neu klassifiziert. IDs, Termine und persönliche Zuordnungen bleiben erhalten. Bekannte Herkunft beeinflusst den kanalspezifischen Export. Bei Namensfreigabe werden die gewählten Exportinformationen ebenfalls gespeichert.')
|
||||
->action(function (ApplyChannelRules $apply): void {
|
||||
$counts = DB::transaction(function () use ($apply): array {
|
||||
|
||||
Reference in new issue
Block a user