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,80 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Communication\Groups;
|
||||
|
||||
use App\Domain\Communication\InquiryField;
|
||||
use App\Domain\Communication\InquiryFieldGroup;
|
||||
use App\Filament\Resources\Communication\CommunicationResource;
|
||||
use App\Filament\Resources\Communication\Groups\Pages\EditInquiryFieldGroup;
|
||||
use App\Filament\Resources\Communication\Groups\Pages\ListInquiryFieldGroups;
|
||||
use Filament\Forms\Components\Placeholder;
|
||||
use Filament\Forms\Components\Repeater;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Forms\Components\Textarea;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Forms\Components\Toggle;
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Tables\Table;
|
||||
|
||||
/**
|
||||
* Feldgruppen: fachliche Zusammenstellung von Feldern in fester Reihenfolge, die mehrere Anfragevorlagen verwenden.
|
||||
*/
|
||||
class InquiryFieldGroupResource extends CommunicationResource
|
||||
{
|
||||
protected static ?string $model = InquiryFieldGroup::class;
|
||||
|
||||
protected static ?string $navigationLabel = 'Feldgruppen';
|
||||
|
||||
protected static ?string $modelLabel = 'Feldgruppe';
|
||||
|
||||
protected static ?string $pluralModelLabel = 'Feldgruppen';
|
||||
|
||||
protected static ?string $recordTitleAttribute = 'name';
|
||||
|
||||
protected static ?string $slug = 'kommunikation/feldgruppen';
|
||||
|
||||
protected static ?int $navigationSort = 4;
|
||||
|
||||
public static function form(Schema $schema): Schema
|
||||
{
|
||||
return $schema->components([
|
||||
TextInput::make('name')->label('Fachliche Bezeichnung')->required()->maxLength(120)
|
||||
->helperText('Nur für die Verwaltung, zum Beispiel „Kindergruppe“.'),
|
||||
TextInput::make('label')->label('Überschrift im Formular (optional)')->maxLength(200)
|
||||
->helperText('Leer: die fachliche Bezeichnung.'),
|
||||
Textarea::make('description')->label('Erläuterung im Formular (optional)')->rows(2)->maxLength(600),
|
||||
Repeater::make('items')
|
||||
->label('Felder der Gruppe')
|
||||
->schema([
|
||||
Select::make('field')->label('Feld')->required()->searchable()->distinct()
|
||||
->options(fn (): array => InquiryField::query()->offered()->orderBy('name')->get()->mapWithKeys(
|
||||
fn (InquiryField $field): array => [$field->key => $field->name.' ('.$field->type->label().')']
|
||||
)->all()),
|
||||
Toggle::make('required')->label('Pflichtfeld')->default(false)
|
||||
->helperText('Eine Vorlage kann ein Feld zusätzlich unter einer Bedingung zur Pflicht machen.'),
|
||||
])
|
||||
->minItems(1)
|
||||
->reorderableWithButtons()
|
||||
->addActionLabel('Feld hinzufügen')
|
||||
->itemLabel(fn (array $state): ?string => InquiryField::query()->where('key', $state['field'] ?? '')->value('name'))
|
||||
->helperText('Die Reihenfolge hier ist die Reihenfolge im Formular.'),
|
||||
Placeholder::make('key_info')->label('Interne Kennung')->content(fn (?InquiryFieldGroup $record): string => (string) $record?->key)
|
||||
->visible(fn (?InquiryFieldGroup $record): bool => $record !== null),
|
||||
Toggle::make('active')->label('Zur Verwendung anbieten'),
|
||||
]);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return $table->columns([TextColumn::make('name')->label('Bezeichnung')]);
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => ListInquiryFieldGroups::route('/'),
|
||||
'edit' => EditInquiryFieldGroup::route('/{record}'),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Communication\Groups\Pages;
|
||||
|
||||
use App\Filament\Resources\Communication\Groups\InquiryFieldGroupResource;
|
||||
use App\Filament\Support\ArchivesCommunicationRecords;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
|
||||
class EditInquiryFieldGroup extends EditRecord
|
||||
{
|
||||
use ArchivesCommunicationRecords;
|
||||
|
||||
protected static string $resource = InquiryFieldGroupResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return $this->archiveActions();
|
||||
}
|
||||
|
||||
protected function archiveNote(): string
|
||||
{
|
||||
return 'Die Gruppe kann in keiner neuen Fassung einer Vorlage mehr verwendet werden. Veröffentlichte Fassungen und eingegangene Anfragen bleiben unverändert.';
|
||||
}
|
||||
|
||||
protected function indexUrl(): string
|
||||
{
|
||||
return InquiryFieldGroupResource::getUrl('index');
|
||||
}
|
||||
|
||||
protected function getRedirectUrl(): ?string
|
||||
{
|
||||
return InquiryFieldGroupResource::getUrl('index');
|
||||
}
|
||||
}
|
||||
@@ -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