CI Feature / test (push) Successful in 4m17s
Der Editor zeigt Bereiche mit Feldern und Teilbereichen; Felder werden direkt im Bereich angelegt oder aus dem Katalog übernommen und landen im selben Katalog wie bisher. Bedingungen stehen am Feld, Teilbereich oder Bereich und werden zu denselben Regeln wie die Regelliste; alles andere bleibt unter „Weitere Regeln“. Navigation: Anfragen, Formulare & Befragungen, Einstellungen. Anliegen, Feldkatalog, Feldgruppen und Einstiege bleiben erreichbar (Einstellungen). Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
115 lines
5.0 KiB
PHP
115 lines
5.0 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Resources\Communication\Templates\Pages;
|
|
|
|
use App\Domain\Communication\InquiryTemplate;
|
|
use App\Domain\Communication\Keys;
|
|
use App\Filament\Resources\Communication\Templates\InquiryTemplateResource;
|
|
use App\Filament\Support\ListsCatalog;
|
|
use Filament\Actions\Action;
|
|
use Filament\Forms\Components\Textarea;
|
|
use Filament\Forms\Components\TextInput;
|
|
use Filament\Notifications\Notification;
|
|
use Filament\Resources\Pages\ListRecords;
|
|
use Illuminate\Contracts\Support\Htmlable;
|
|
use Illuminate\Support\Str;
|
|
|
|
class ListInquiryTemplates extends ListRecords
|
|
{
|
|
use ListsCatalog;
|
|
|
|
protected static string $resource = InquiryTemplateResource::class;
|
|
|
|
public function getSubheading(): string|Htmlable|null
|
|
{
|
|
return 'Hier entstehen Formulare und Befragungen: Bereiche mit Feldern, Bedingungen und Texte, alles in einem Editor. Änderungen sind zunächst ein Entwurf und gelten erst nach „Veröffentlichen“. Im Widget „Anfrage“ einer Seite wählst du, welches Formular zu welchem Anfragegrund gehört.';
|
|
}
|
|
|
|
protected function getHeaderActions(): array
|
|
{
|
|
return [
|
|
Action::make('create')
|
|
->label('Formular anlegen')
|
|
->modalHeading('Neues Formular')
|
|
->modalDescription('Der Aufbau entsteht danach im Editor des Formulars.')
|
|
->modalSubmitActionLabel('Formular anlegen')
|
|
->schema([
|
|
TextInput::make('name')->label('Name des Formulars')->required()->maxLength(120),
|
|
Textarea::make('description')->label('Beschreibung (nur Verwaltung, optional)')->rows(2)->maxLength(400),
|
|
])
|
|
->action(function (array $data): void {
|
|
$draft = InquiryTemplate::emptyDraft();
|
|
$draft['steps'] = [['key' => 's'.Str::lower(Str::random(6)), 'title' => 'Ihre Angaben', 'intro' => null, 'items' => []]];
|
|
|
|
$template = InquiryTemplate::query()->create([
|
|
'key' => Keys::from($data['name'], InquiryTemplate::query()->pluck('key')->all()),
|
|
'name' => $data['name'],
|
|
'description' => $data['description'] ?? null,
|
|
'draft' => $draft,
|
|
]);
|
|
|
|
Notification::make()->title('Das Formular ist angelegt.')->success()->send();
|
|
$this->redirect(InquiryTemplateResource::getUrl('edit', ['record' => $template]));
|
|
}),
|
|
];
|
|
}
|
|
|
|
protected function catalogRows(): array
|
|
{
|
|
$rows = [];
|
|
|
|
foreach (InquiryTemplate::query()->with('publishedVersion')->withCount('entries')->orderBy('name')->get() as $template) {
|
|
$url = InquiryTemplateResource::getUrl('edit', ['record' => $template]);
|
|
$archived = $template->archived_at !== null;
|
|
$published = $template->isPublished();
|
|
$changes = $published && $template->hasUnpublishedChanges();
|
|
$steps = count((array) ($template->draft['steps'] ?? []));
|
|
|
|
$rows[] = [
|
|
'schluessel' => 't'.$template->id,
|
|
'titel' => $template->name,
|
|
'meta' => 'Formular · '.$steps.' '.($steps === 1 ? 'Bereich' : 'Bereiche').($template->entries_count > 0 ? ' · '.$template->entries_count.' '.($template->entries_count === 1 ? 'Einstieg' : 'Einstiege').' (ältere Seiten)' : ''),
|
|
'text' => (string) ($template->description ?? ''),
|
|
'symbol' => 'modul',
|
|
'url' => $url,
|
|
'chips' => array_values(array_filter([
|
|
$archived ? ['label' => 'Archiviert', 'ton' => 'leise'] : ($published
|
|
? ['label' => 'Fassung '.$template->publishedVersion->version.' gültig', 'ton' => 'gut']
|
|
: ['label' => 'Noch nicht veröffentlicht', 'ton' => 'offen']),
|
|
$changes ? ['label' => 'Änderungen noch nicht veröffentlicht', 'ton' => 'achtung'] : null,
|
|
])),
|
|
'zustand' => [$archived ? 'archiviert' : ($published ? 'veroeffentlicht' : 'entwurf'), ...($changes ? ['aenderungen'] : [])],
|
|
'aktionen' => [['label' => 'Bearbeiten', 'href' => $url, 'icon' => 'stift']],
|
|
];
|
|
}
|
|
|
|
return $rows;
|
|
}
|
|
|
|
protected function zustandOptionen(): array
|
|
{
|
|
return [
|
|
'alle' => 'Jeder Zustand',
|
|
'veroeffentlicht' => 'Veröffentlicht',
|
|
'entwurf' => 'Noch nicht veröffentlicht',
|
|
'aenderungen' => 'Mit unveröffentlichten Änderungen',
|
|
'archiviert' => 'Archiviert',
|
|
];
|
|
}
|
|
|
|
protected function suchPlatzhalter(): string
|
|
{
|
|
return 'Bezeichnung oder Beschreibung';
|
|
}
|
|
|
|
protected function einheit(): array
|
|
{
|
|
return ['Formular', 'Formulare'];
|
|
}
|
|
|
|
protected function leer(): array
|
|
{
|
|
return ['titel' => 'Noch keine Formulare', 'text' => 'Mit „Formular anlegen“ oben entsteht das erste Formular. Auf der Seite „Einstellungen“ lässt sich eine Beispielkonfiguration anlegen.'];
|
|
}
|
|
}
|