Zeige Medienfassungen in der Verwaltung und halte Beschreibungen davon getrennt.
Eine Fassung bleibt nummeriert und kann deaktiviert werden. Beschreibung und fachliche Säulen gehören zum Medium und legen keine neue Fassung an. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
12f12117dd
commit
af85a94cd5
28 files changed
+1002
-168
No files matched your search
@@ -3,25 +3,22 @@
|
||||
namespace App\Filament\Resources\ContentElements\Pages;
|
||||
|
||||
use App\Domain\Catalog\ContentElement;
|
||||
use App\Domain\Catalog\ContentElementVersion;
|
||||
use App\Domain\Catalog\ContentService;
|
||||
use App\Domain\Catalog\ContentVersionStatus;
|
||||
use App\Domain\Catalog\DomainRuleException;
|
||||
use App\Domain\Catalog\Pillar;
|
||||
use App\Domain\Catalog\PillarService;
|
||||
use App\Filament\Resources\ContentElements\ContentElementResource;
|
||||
use App\Filament\Support\CatalogReading;
|
||||
use App\Filament\Support\IncomingFile;
|
||||
use App\Filament\Support\ElementRevision;
|
||||
use App\Filament\Support\MediaUploadLimit;
|
||||
use App\Filament\Support\ReportsDomainRules;
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Forms\Components\CheckboxList;
|
||||
use Filament\Forms\Components\FileUpload;
|
||||
use Filament\Forms\Components\Placeholder;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Forms\Components\Textarea;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Forms\Components\Toggle;
|
||||
use Filament\Notifications\Notification;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
use Filament\Schemas\Components\Section;
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Support\Exceptions\Halt;
|
||||
use Illuminate\Contracts\Support\Htmlable;
|
||||
@@ -34,44 +31,27 @@ class EditContentElement extends EditRecord
|
||||
|
||||
protected static string $resource = ContentElementResource::class;
|
||||
|
||||
protected ?string $savedTitle = null;
|
||||
|
||||
public function getSubheading(): string|Htmlable|null
|
||||
{
|
||||
return 'Speichern legt eine neue Fassung an. Die bisherige Fassung bleibt erhalten und kann weiter angesehen werden. Ohne neue Datei bleibt die vorhandene Datei der neuen Fassung zugeordnet.';
|
||||
return 'Arbeitstitel, Beschreibung und Säulen gehören zum Medium. Speichern legt keine neue Fassung an. Text und Datei änderst du über eine neue Fassung; die bisherige bleibt erhalten.';
|
||||
}
|
||||
|
||||
public function form(Schema $schema): Schema
|
||||
{
|
||||
return $schema->columns(1)->components([
|
||||
Placeholder::make('open')->label('Medium')->content(function (): HtmlString {
|
||||
$url = ContentElementResource::getUrl('view', ['record' => $this->getRecord()]);
|
||||
|
||||
return new HtmlString('<a href="'.e($url).'">Medium und Fassungen ansehen</a>');
|
||||
}),
|
||||
TextInput::make('working_title')->label('Arbeitstitel')->required(),
|
||||
Placeholder::make('history')->label('Bisherige Fassungen')->content(function (): HtmlString {
|
||||
/** @var ContentElement $element */
|
||||
$element = $this->getRecord();
|
||||
$lines = app(CatalogReading::class)->elementVersions($element);
|
||||
$html = collect($lines)->map(fn (string $line): string => e($line))->implode('<br>');
|
||||
$links = $element->versions()->orderByDesc('number')->get()->map(function (ContentElementVersion $version): string {
|
||||
return '<a href="'.e(route('content.preview', $version)).'" target="_blank" rel="noopener">Fassung '.$version->number.' ansehen</a>';
|
||||
})->implode(' · ');
|
||||
|
||||
return new HtmlString($html.($links !== '' ? '<br>'.$links : ''));
|
||||
}),
|
||||
Placeholder::make('usage')->label('Verwendung')->content(function (): HtmlString {
|
||||
/** @var ContentElement $element */
|
||||
$element = $this->getRecord();
|
||||
$lines = app(CatalogReading::class)->elementUsage($element);
|
||||
|
||||
return new HtmlString(collect($lines)->map(fn (string $line): string => e($line))->implode('<br>'));
|
||||
}),
|
||||
Section::make('Neue Fassung')->schema([
|
||||
Textarea::make('body')->label('Text')->rows(8),
|
||||
self::uploadField(),
|
||||
Toggle::make('drop_file')
|
||||
->label('Datei in der neuen Fassung nicht mehr verwenden')
|
||||
->visible(fn (): bool => is_string($this->latest()?->metadata['file'] ?? null)),
|
||||
TextInput::make('decision_seconds')->label('Entscheidungsmarke in Sekunden')->numeric()->minValue(0),
|
||||
TextInput::make('change_note')->label('Änderungsnotiz'),
|
||||
]),
|
||||
Textarea::make('description')->label('Beschreibung')->rows(4)
|
||||
->helperText('Gilt für das Medium, nicht für eine einzelne Fassung.'),
|
||||
CheckboxList::make('pillars')
|
||||
->label('Fachliche Säulen')
|
||||
->options(fn (): array => Pillar::query()->orderBy('name')->pluck('name', 'id')->all())
|
||||
->helperText('Ein Medium kann mehreren Säulen zugeordnet sein. Weitere Säulen legst du unter Fachliche Säulen an.')
|
||||
->columns(1),
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -89,32 +69,20 @@ public static function uploadField(): FileUpload
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Action::make('preview')
|
||||
->label('Aktuelle Fassung ansehen')
|
||||
->url(fn (): ?string => ($version = $this->latest()) === null ? null : route('content.preview', $version))
|
||||
->visible(fn (): bool => $this->latest() !== null)
|
||||
->openUrlInNewTab(),
|
||||
Action::make('block')
|
||||
->label('Fassung sperren')
|
||||
->visible(fn (): bool => $this->getRecord()->versions()->where('status', ContentVersionStatus::Bereit)->exists())
|
||||
->schema([
|
||||
Select::make('version')->label('Fassung')->options(function (): array {
|
||||
return $this->getRecord()->versions()
|
||||
->where('status', ContentVersionStatus::Bereit)
|
||||
->orderByDesc('number')
|
||||
->pluck('number', 'id')
|
||||
->map(fn ($number): string => 'Fassung '.$number)
|
||||
->all();
|
||||
})->required(),
|
||||
Textarea::make('reason')->label('Begründung')->required(),
|
||||
])
|
||||
Action::make('view')
|
||||
->label('Ansehen')
|
||||
->url(fn (): string => ContentElementResource::getUrl('view', ['record' => $this->getRecord()])),
|
||||
Action::make('revise')
|
||||
->label('Neue Fassung anlegen')
|
||||
->schema(fn (): array => ElementRevision::fields($this->getRecord()))
|
||||
->action(function (array $data): void {
|
||||
$this->report(function () use ($data): void {
|
||||
$version = ContentElementVersion::query()->findOrFail($data['version']);
|
||||
app(ContentService::class)->block($version, $data['reason']);
|
||||
}, 'Die Fassung ist gesperrt.');
|
||||
$this->report(function () use ($data): string {
|
||||
/** @var ContentElement $element */
|
||||
$element = $this->getRecord();
|
||||
|
||||
return ElementRevision::publish($element, $data);
|
||||
}, 'Die neue Fassung ist angelegt.');
|
||||
$this->getRecord()->unsetRelation('versions');
|
||||
$this->fillForm();
|
||||
}),
|
||||
Action::make('delete')
|
||||
->label('Löschen')
|
||||
@@ -130,12 +98,12 @@ protected function getHeaderActions(): array
|
||||
|
||||
protected function getSaveFormAction(): Action
|
||||
{
|
||||
return parent::getSaveFormAction()->label('Neue Fassung anlegen');
|
||||
return parent::getSaveFormAction()->label('Speichern');
|
||||
}
|
||||
|
||||
protected function getSavedNotificationTitle(): ?string
|
||||
{
|
||||
return $this->savedTitle ?? 'Die neue Fassung ist angelegt.';
|
||||
return 'Gespeichert. Es gibt keine neue Fassung.';
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -144,15 +112,10 @@ protected function getSavedNotificationTitle(): ?string
|
||||
*/
|
||||
protected function mutateFormDataBeforeFill(array $data): array
|
||||
{
|
||||
$latest = $this->latest();
|
||||
$metadata = is_array($latest?->metadata) ? $latest->metadata : [];
|
||||
|
||||
return [
|
||||
'working_title' => $this->getRecord()->working_title,
|
||||
'body' => $latest?->body,
|
||||
'decision_seconds' => $metadata['decision_seconds'] ?? null,
|
||||
'drop_file' => false,
|
||||
'change_note' => null,
|
||||
'description' => $this->getRecord()->description,
|
||||
'pillars' => $this->getRecord()->pillars()->pluck('pillars.id')->all(),
|
||||
];
|
||||
}
|
||||
|
||||
@@ -163,52 +126,8 @@ protected function handleRecordUpdate(Model $record, array $data): Model
|
||||
{
|
||||
/** @var ContentElement $record */
|
||||
try {
|
||||
$record->working_title = trim((string) $data['working_title']);
|
||||
$record->save();
|
||||
|
||||
$latest = $record->versions()->orderByDesc('number')->first();
|
||||
$metadata = [];
|
||||
$incoming = IncomingFile::store($data['incoming'] ?? null);
|
||||
$dropFile = (bool) ($data['drop_file'] ?? false);
|
||||
$previousFile = is_array($latest?->metadata) ? ($latest->metadata['file'] ?? null) : null;
|
||||
|
||||
if (is_string($incoming) && $incoming !== '') {
|
||||
$metadata['incoming'] = $incoming;
|
||||
} elseif (! $dropFile && is_string($previousFile) && $previousFile !== '') {
|
||||
$metadata['file'] = $previousFile;
|
||||
}
|
||||
|
||||
$decision = is_numeric($data['decision_seconds'] ?? null) ? (int) $data['decision_seconds'] : null;
|
||||
|
||||
if ($decision !== null) {
|
||||
$metadata['decision_seconds'] = $decision;
|
||||
}
|
||||
|
||||
$body = is_string($data['body'] ?? null) ? $data['body'] : null;
|
||||
$note = is_string($data['change_note'] ?? null) ? $data['change_note'] : null;
|
||||
$previousDecision = is_array($latest?->metadata) && is_numeric($latest->metadata['decision_seconds'] ?? null)
|
||||
? (int) $latest->metadata['decision_seconds']
|
||||
: null;
|
||||
$changed = $incoming !== null
|
||||
|| $dropFile
|
||||
|| trim((string) $body) !== trim((string) $latest?->body)
|
||||
|| $decision !== $previousDecision
|
||||
|| (is_string($note) && trim($note) !== '');
|
||||
|
||||
if (! $changed) {
|
||||
$this->savedTitle = 'Der Arbeitstitel ist geändert. Text und Datei sind gleich geblieben, deshalb gibt es keine neue Fassung.';
|
||||
|
||||
return $record;
|
||||
}
|
||||
|
||||
if (trim((string) $body) === '' && $metadata === []) {
|
||||
throw new DomainRuleException('Eine neue Fassung braucht einen Text oder eine Datei.');
|
||||
}
|
||||
|
||||
app(ContentService::class)->publishElementVersion($record, $body, $metadata, $note);
|
||||
$this->savedTitle = $incoming !== null
|
||||
? 'Die neue Fassung ist angelegt. Die Datei wird übernommen; die bisherige Fassung bleibt.'
|
||||
: 'Die neue Fassung ist angelegt. Die bisherige Fassung bleibt erhalten.';
|
||||
app(ContentService::class)->describe($record, (string) $data['working_title'], $data['description'] ?? null);
|
||||
app(PillarService::class)->assign($record, array_map(intval(...), $data['pillars'] ?? []));
|
||||
} catch (DomainRuleException $exception) {
|
||||
Notification::make()->title($exception->getMessage())->danger()->send();
|
||||
|
||||
@@ -217,19 +136,4 @@ protected function handleRecordUpdate(Model $record, array $data): Model
|
||||
|
||||
return $record;
|
||||
}
|
||||
|
||||
protected function afterSave(): void
|
||||
{
|
||||
$this->getRecord()->unsetRelation('versions');
|
||||
$this->getRecord()->refresh();
|
||||
$this->fillForm();
|
||||
}
|
||||
|
||||
private function latest(): ?ContentElementVersion
|
||||
{
|
||||
/** @var ContentElement $element */
|
||||
$element = $this->getRecord();
|
||||
|
||||
return $element->versions()->orderByDesc('number')->first();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user