Baue die Verwaltung Kommunikation, die öffentliche Anfrageschnittstelle und das CMS-Widget Anfrage
Anliegen, Feldkatalog, Feldgruppen, Anfragevorlagen mit Fassungen, Anfrage-Einstiege, Posteingang mit Status und Notizen, Einstellungen mit Empfängern. Das Widget speichert nur die Kennung eines veröffentlichten Einstiegs; Formular, Bedingungen und Annahme kommen zur Laufzeit vom Server (Kompaktformular und mehrstufiger Dialog aus derselben Beschreibung). Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
2ee1fc9866
commit
c6a8167601
45 files changed
+5415
No files matched your search
@@ -0,0 +1,139 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Communication\Groups\Pages;
|
||||
|
||||
use App\Domain\Communication\InquiryField;
|
||||
use App\Domain\Communication\InquiryFieldGroup;
|
||||
use App\Domain\Communication\InquiryTemplate;
|
||||
use App\Domain\Communication\Keys;
|
||||
use App\Filament\Resources\Communication\Groups\InquiryFieldGroupResource;
|
||||
use App\Filament\Support\ListsCatalog;
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Notifications\Notification;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
use Illuminate\Contracts\Support\Htmlable;
|
||||
|
||||
class ListInquiryFieldGroups extends ListRecords
|
||||
{
|
||||
use ListsCatalog;
|
||||
|
||||
protected static string $resource = InquiryFieldGroupResource::class;
|
||||
|
||||
public function getSubheading(): string|Htmlable|null
|
||||
{
|
||||
return 'Feldgruppen fassen Felder fachlich zusammen, zum Beispiel „Kontaktinformationen“ oder „Kindergruppe“. Eine Gruppe wird in beliebig vielen Anfragevorlagen verwendet; Reihenfolge und Pflichtangaben pflegst du hier einmal.';
|
||||
}
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Action::make('create')
|
||||
->label('Feldgruppe anlegen')
|
||||
->modalHeading('Neue Feldgruppe')
|
||||
->modalDescription('Die Felder legst du danach auf der Seite der Gruppe fest.')
|
||||
->modalSubmitActionLabel('Feldgruppe anlegen')
|
||||
->schema([TextInput::make('name')->label('Fachliche Bezeichnung')->required()->maxLength(120)])
|
||||
->action(function (array $data): void {
|
||||
$group = InquiryFieldGroup::query()->create([
|
||||
'key' => Keys::from($data['name'], InquiryFieldGroup::query()->pluck('key')->all()),
|
||||
'name' => $data['name'],
|
||||
'items' => [],
|
||||
'sort_order' => ((int) InquiryFieldGroup::query()->max('sort_order')) + 10,
|
||||
]);
|
||||
|
||||
Notification::make()->title('Die Feldgruppe ist angelegt.')->success()->send();
|
||||
$this->redirect(InquiryFieldGroupResource::getUrl('edit', ['record' => $group]));
|
||||
}),
|
||||
];
|
||||
}
|
||||
|
||||
public function moveGroup(int $id, string $direction): void
|
||||
{
|
||||
$group = InquiryFieldGroup::query()->findOrFail($id);
|
||||
$all = InquiryFieldGroup::query()->orderBy('sort_order')->orderBy('id')->get()->values();
|
||||
$index = $all->search(fn (InquiryFieldGroup $item): bool => $item->id === $group->id);
|
||||
$target = $direction === 'up' ? $index - 1 : $index + 1;
|
||||
|
||||
if ($index === false || $target < 0 || $target >= $all->count()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$order = $all->all();
|
||||
[$order[$index], $order[$target]] = [$order[$target], $order[$index]];
|
||||
|
||||
foreach ($order as $position => $item) {
|
||||
$item->forceFill(['sort_order' => ($position + 1) * 10])->save();
|
||||
}
|
||||
}
|
||||
|
||||
protected function catalogRows(): array
|
||||
{
|
||||
$templates = InquiryTemplate::query()->get(['id', 'draft']);
|
||||
$names = InquiryField::query()->pluck('name', 'key');
|
||||
$groups = InquiryFieldGroup::query()->orderBy('sort_order')->orderBy('id')->get();
|
||||
$rows = [];
|
||||
|
||||
foreach ($groups as $i => $group) {
|
||||
$url = InquiryFieldGroupResource::getUrl('edit', ['record' => $group]);
|
||||
$state = $group->archived_at !== null ? 'archiviert' : ($group->active ? 'aktiv' : 'inaktiv');
|
||||
$used = $templates->filter(function (InquiryTemplate $template) use ($group): bool {
|
||||
foreach ((array) ($template->draft['steps'] ?? []) as $step) {
|
||||
foreach ((array) ($step['items'] ?? []) as $item) {
|
||||
if (($item['group'] ?? null) === $group->key) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
})->count();
|
||||
$fieldNames = array_map(fn (array $item): string => (string) ($names[$item['field']] ?? $item['field']), $group->itemList());
|
||||
|
||||
$rows[] = [
|
||||
'schluessel' => 'g'.$group->id,
|
||||
'titel' => $group->name,
|
||||
'meta' => 'Feldgruppe · '.count($fieldNames).' '.(count($fieldNames) === 1 ? 'Feld' : 'Felder'),
|
||||
'text' => implode(', ', $fieldNames),
|
||||
'symbol' => 'modul',
|
||||
'url' => $url,
|
||||
'chips' => [
|
||||
match ($state) {
|
||||
'aktiv' => ['label' => 'Wird angeboten', 'ton' => 'gut'],
|
||||
'inaktiv' => ['label' => 'Deaktiviert', 'ton' => 'leise'],
|
||||
default => ['label' => 'Archiviert', 'ton' => 'leise'],
|
||||
},
|
||||
['label' => $used === 0 ? 'In keiner Vorlage' : ($used === 1 ? 'In 1 Vorlage' : "In $used Vorlagen"), 'ton' => 'neutral'],
|
||||
],
|
||||
'zustand' => [$state],
|
||||
'aktionen' => [
|
||||
['label' => 'Bearbeiten', 'href' => $url, 'icon' => 'stift'],
|
||||
...($i > 0 ? [['label' => 'Nach oben', 'wire' => "moveGroup({$group->id}, 'up')"]] : []),
|
||||
...($i < $groups->count() - 1 ? [['label' => 'Nach unten', 'wire' => "moveGroup({$group->id}, 'down')"]] : []),
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
return $rows;
|
||||
}
|
||||
|
||||
protected function zustandOptionen(): array
|
||||
{
|
||||
return ['alle' => 'Jeder Zustand', 'aktiv' => 'Wird angeboten', 'inaktiv' => 'Deaktiviert', 'archiviert' => 'Archiviert'];
|
||||
}
|
||||
|
||||
protected function suchPlatzhalter(): string
|
||||
{
|
||||
return 'Bezeichnung oder Feldname';
|
||||
}
|
||||
|
||||
protected function einheit(): array
|
||||
{
|
||||
return ['Feldgruppe', 'Feldgruppen'];
|
||||
}
|
||||
|
||||
protected function leer(): array
|
||||
{
|
||||
return ['titel' => 'Noch keine Feldgruppen', 'text' => 'Mit „Feldgruppe anlegen“ oben entsteht die erste Gruppe, zum Beispiel „Kontaktinformationen“.'];
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user