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
+78
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Communication\Templates\RelationManagers;
|
||||
|
||||
use App\Domain\Communication\Inquiry;
|
||||
use App\Domain\Communication\InquiryTemplate;
|
||||
use App\Domain\Communication\InquiryTemplateVersion;
|
||||
use App\Domain\Communication\Publisher;
|
||||
use App\Filament\Resources\Communication\Templates\InquiryTemplateResource;
|
||||
use App\Models\User;
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Notifications\Notification;
|
||||
use Filament\Resources\RelationManagers\RelationManager;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Tables\Table;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
|
||||
/**
|
||||
* Fassungen einer Anfragevorlage: unveränderlich, jederzeit nachvollziehbar. Eine frühere Fassung lässt sich wieder in
|
||||
* Kraft setzen oder als Entwurf laden.
|
||||
*/
|
||||
class VersionsRelationManager extends RelationManager
|
||||
{
|
||||
protected static string $relationship = 'versions';
|
||||
|
||||
protected static ?string $title = 'Fassungen';
|
||||
|
||||
protected static ?bool $isLazyLoaded = false;
|
||||
|
||||
public function table(Table $table): Table
|
||||
{
|
||||
/** @var InquiryTemplate $template */
|
||||
$template = $this->getOwnerRecord();
|
||||
|
||||
return $table
|
||||
->columns([
|
||||
TextColumn::make('version')->label('Fassung')->prefix('Nr. '),
|
||||
TextColumn::make('published_at')->label('Veröffentlicht')->dateTime('d.m.Y H:i'),
|
||||
TextColumn::make('published_by')->label('Von')->state(fn (InquiryTemplateVersion $record): string => (string) User::query()->whereKey($record->published_by)->value('name')),
|
||||
TextColumn::make('note')->label('Bemerkung')->placeholder('–'),
|
||||
TextColumn::make('state')->label('Zustand')->badge()
|
||||
->color(fn (string $state): string => $state === 'Gültig' ? 'success' : 'gray')
|
||||
->state(fn (InquiryTemplateVersion $record): string => $record->id === $this->getOwnerRecord()->published_version_id ? 'Gültig' : 'Früher'),
|
||||
TextColumn::make('inquiries')->label('Anfragen')->state(fn (InquiryTemplateVersion $record): int => Inquiry::query()->where('template_version_id', $record->id)->count()),
|
||||
])
|
||||
->recordActions([
|
||||
Action::make('restore')
|
||||
->label('Wieder in Kraft setzen')
|
||||
->visible(fn (InquiryTemplateVersion $record): bool => $record->id !== $template->fresh()->published_version_id)
|
||||
->requiresConfirmation()
|
||||
->modalDescription('Besucher sehen danach wieder diese Fassung. Der Entwurf bleibt unverändert. Eingegangene Anfragen bleiben ihrer damaligen Fassung zugeordnet.')
|
||||
->action(function (InquiryTemplateVersion $record): void {
|
||||
try {
|
||||
app(Publisher::class)->restoreVersion($this->getOwnerRecord(), $record);
|
||||
} catch (ValidationException $e) {
|
||||
Notification::make()->title('Nicht möglich')->body(implode(' ', $e->errors()['draft'] ?? []))->danger()->send();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
Notification::make()->title('Fassung '.$record->version.' ist wieder gültig.')->success()->send();
|
||||
$this->redirect(InquiryTemplateResource::getUrl('edit', ['record' => $this->getOwnerRecord()]));
|
||||
}),
|
||||
Action::make('load')
|
||||
->label('Als Entwurf laden')
|
||||
->color('gray')
|
||||
->requiresConfirmation()
|
||||
->modalDescription('Der aktuelle Entwurf wird durch den Stand dieser Fassung ersetzt. Veröffentlicht wird dadurch nichts.')
|
||||
->action(function (InquiryTemplateVersion $record): void {
|
||||
$this->getOwnerRecord()->forceFill(['draft' => $record->source])->save();
|
||||
Notification::make()->title('Der Entwurf entspricht jetzt Fassung '.$record->version.'.')->success()->send();
|
||||
$this->redirect(InquiryTemplateResource::getUrl('edit', ['record' => $this->getOwnerRecord()]));
|
||||
}),
|
||||
])
|
||||
->defaultSort('version', 'desc')
|
||||
->paginated(false);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user