Ersetze die Builder-Liste des Formular-Editors durch eine Formularansicht mit Ziehen und Ablegen
CI Feature / test (push) Successful in 4m18s
CI Feature / test (push) Successful in 4m18s
Der Aufbau eines Formulars zeigt Bereiche als Karten, Teilbereiche als eingerahmte Einheit darin und Felder als Zeilen (Frage, Art der Antwort, Pflicht). Hilfetext, Auswahlwerte, Bedingung und weitere Einstellungen öffnen als Pop-up. Bereiche, Teilbereiche und Felder lassen sich ziehen (SortableJS aus Filament) oder per Pfeiltasten und über "Verschieben nach" ordnen; Rückgängig nimmt Änderungen bis zum Speichern zurück. Der Browser führt den Baum und übergibt ihn beim Speichern als Text; FormEditor prüft ihn (validateTree) und überführt ihn über fromTree in dieselbe flache Ansicht wie bisher. Entwurf, Katalog und Engine bleiben unverändert, keine Migration. Tests: Die Livewire-Tests des Editors setzen jetzt den Baumtext (editor_json) statt der Builder-Blöcke; neu sind Baumumwandlung ohne Verlust, Teilbereich mit Feldern, Prüfung und Konfiguration. Das ist bewusst: Der Builder entfällt. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
79c4e877ab
commit
380a3013c7
10 files changed
+1860
-225
No files matched your search
@@ -34,7 +34,7 @@ class InquiryTemplateResource extends CommunicationResource
|
||||
|
||||
public static function form(Schema $schema): Schema
|
||||
{
|
||||
return $schema->components(TemplateEditor::schema());
|
||||
return $schema->components(TemplateEditor::schema($schema->getRecord()?->getKey()));
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
|
||||
@@ -140,16 +140,35 @@ protected function archiveBlocked(): ?string
|
||||
|
||||
protected function mutateFormDataBeforeFill(array $data): array
|
||||
{
|
||||
$data['editor'] = app(FormEditor::class)->expand((array) ($data['draft'] ?? []), $this->getRecord()->getKey());
|
||||
$tree = FormEditor::toTree(app(FormEditor::class)->expand((array) ($data['draft'] ?? []), $this->getRecord()->getKey()));
|
||||
|
||||
// Die Formularansicht führt den Baum im Browser und übergibt ihn als Text; die weiteren Regeln bleiben eine Liste.
|
||||
$data['editor'] = ['rules' => $tree['rules']];
|
||||
$data['editor_json'] = json_encode(['areas' => $tree['areas']], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_THROW_ON_ERROR);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
protected function mutateFormDataBeforeSave(array $data): array
|
||||
{
|
||||
$editor = app(FormEditor::class);
|
||||
$tree = json_decode((string) ($data['editor_json'] ?? ''), true);
|
||||
|
||||
if (! is_array($tree)) {
|
||||
$this->failEditor(['Der Aufbau konnte nicht gelesen werden. Bitte lade die Seite neu und versuche es noch einmal.']);
|
||||
}
|
||||
|
||||
$errors = $editor->validateTree($tree);
|
||||
|
||||
if ($errors !== []) {
|
||||
$this->failEditor($errors);
|
||||
}
|
||||
|
||||
// Der Editor schreibt neue und geänderte Felder und Teilbereiche in den Katalog und liefert den Entwurf.
|
||||
$saved = app(FormEditor::class)->persist((array) ($data['editor'] ?? []));
|
||||
unset($data['editor']);
|
||||
$view = FormEditor::fromTree($tree);
|
||||
$view['rules'] = (array) ($data['editor']['rules'] ?? []);
|
||||
$saved = $editor->persist($view);
|
||||
unset($data['editor'], $data['editor_json']);
|
||||
|
||||
$data['draft'] = TemplateDraft::clean([
|
||||
'texts' => (array) ($data['draft']['texts'] ?? []),
|
||||
@@ -161,6 +180,17 @@ protected function mutateFormDataBeforeSave(array $data): array
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param list<string> $messages
|
||||
* @return never
|
||||
*/
|
||||
private function failEditor(array $messages): void
|
||||
{
|
||||
Notification::make()->title('Das Formular ist noch nicht vollständig')->body(implode("\n", array_map(fn (string $line): string => '• '.$line, $messages)))->danger()->persistent()->send();
|
||||
|
||||
throw ValidationException::withMessages(['data.editor_json' => $messages]);
|
||||
}
|
||||
|
||||
protected function afterSave(): void
|
||||
{
|
||||
// Neue Felder und Teilbereiche tragen jetzt ihre festen Kennungen. Ohne neues Laden würde ein zweites Speichern sie doppelt anlegen.
|
||||
|
||||
Reference in new issue
Block a user