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,6 +3,7 @@
|
||||
namespace App\Domain\Catalog;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
class ContentElement extends Model
|
||||
@@ -11,6 +12,7 @@ class ContentElement extends Model
|
||||
'kind',
|
||||
'output_class',
|
||||
'working_title',
|
||||
'description',
|
||||
'archived_at',
|
||||
];
|
||||
|
||||
@@ -25,4 +27,9 @@ public function versions(): HasMany
|
||||
{
|
||||
return $this->hasMany(ContentElementVersion::class);
|
||||
}
|
||||
|
||||
public function pillars(): BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(Pillar::class)->orderBy('pillars.name');
|
||||
}
|
||||
}
|
||||
@@ -15,6 +15,7 @@ class ContentElementVersion extends Model
|
||||
'body',
|
||||
'metadata',
|
||||
'change_note',
|
||||
'block_reason',
|
||||
];
|
||||
|
||||
protected function casts(): array
|
||||
@@ -37,7 +38,16 @@ protected static function booted(): void
|
||||
return;
|
||||
}
|
||||
|
||||
$dirty = array_diff(array_keys($version->getDirty()), ['status', 'updated_at']);
|
||||
$allowed = ['status', 'updated_at'];
|
||||
|
||||
if (
|
||||
$original === ContentVersionStatus::Bereit->value
|
||||
&& StatusValue::of($version->status) === ContentVersionStatus::Gesperrt->value
|
||||
) {
|
||||
$allowed[] = 'block_reason';
|
||||
}
|
||||
|
||||
$dirty = array_diff(array_keys($version->getDirty()), $allowed);
|
||||
|
||||
if ($dirty !== [] || $original === ContentVersionStatus::Gesperrt->value) {
|
||||
throw new DomainRuleException('Eine bereitgestellte Inhaltsfassung ist unveränderlich.');
|
||||
|
||||
@@ -30,9 +30,22 @@ public function block(ContentElementVersion|CompositionVersion $version, string
|
||||
}
|
||||
|
||||
$version->status = ContentVersionStatus::Gesperrt;
|
||||
|
||||
if ($version instanceof ContentElementVersion) {
|
||||
$version->block_reason = trim($reason);
|
||||
}
|
||||
|
||||
$version->save();
|
||||
}
|
||||
|
||||
public function describe(ContentElement $element, string $workingTitle, ?string $description): void
|
||||
{
|
||||
$element->working_title = $this->required($workingTitle, 'Der Arbeitstitel fehlt.');
|
||||
$description = trim((string) $description);
|
||||
$element->description = $description === '' ? null : $description;
|
||||
$element->save();
|
||||
}
|
||||
|
||||
public function publishElementVersion(
|
||||
ContentElement $element,
|
||||
?string $body = null,
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\Catalog;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
|
||||
class Pillar extends Model
|
||||
{
|
||||
protected $fillable = [
|
||||
'name',
|
||||
];
|
||||
|
||||
public function elements(): BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(ContentElement::class);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\Catalog;
|
||||
|
||||
class PillarService
|
||||
{
|
||||
public function create(string $name): Pillar
|
||||
{
|
||||
$name = $this->name($name);
|
||||
|
||||
if (Pillar::query()->where('name', $name)->exists()) {
|
||||
throw new DomainRuleException('Diese fachliche Säule gibt es schon.');
|
||||
}
|
||||
|
||||
return Pillar::query()->create(['name' => $name]);
|
||||
}
|
||||
|
||||
public function rename(Pillar $pillar, string $name): void
|
||||
{
|
||||
$name = $this->name($name);
|
||||
|
||||
if (Pillar::query()->where('name', $name)->whereKeyNot($pillar->id)->exists()) {
|
||||
throw new DomainRuleException('Diese fachliche Säule gibt es schon.');
|
||||
}
|
||||
|
||||
$pillar->name = $name;
|
||||
$pillar->save();
|
||||
}
|
||||
|
||||
public function delete(Pillar $pillar): void
|
||||
{
|
||||
if ($pillar->elements()->exists()) {
|
||||
throw new DomainRuleException('Eine Säule mit zugeordneten Medien wird nicht gelöscht.');
|
||||
}
|
||||
|
||||
$pillar->delete();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param list<int> $pillarIds
|
||||
*/
|
||||
public function assign(ContentElement $element, array $pillarIds): void
|
||||
{
|
||||
$ids = array_values(array_unique(array_map(intval(...), $pillarIds)));
|
||||
|
||||
if (Pillar::query()->whereIn('id', $ids)->count() !== count($ids)) {
|
||||
throw new DomainRuleException('Eine fachliche Säule fehlt.');
|
||||
}
|
||||
|
||||
$element->pillars()->sync($ids);
|
||||
}
|
||||
|
||||
private function name(string $name): string
|
||||
{
|
||||
$name = trim($name);
|
||||
|
||||
if ($name === '') {
|
||||
throw new DomainRuleException('Der Name der fachlichen Säule fehlt.');
|
||||
}
|
||||
|
||||
return $name;
|
||||
}
|
||||
}
|
||||
@@ -51,6 +51,13 @@ public function form(Schema $schema): Schema
|
||||
|
||||
return new HtmlString(collect($lines)->map(fn (string $line): string => e($line))->implode('<br>'));
|
||||
}),
|
||||
Placeholder::make('pillars')->label('Säulen der Medien')->content(function (): HtmlString {
|
||||
/** @var Composition $composition */
|
||||
$composition = $this->getRecord();
|
||||
$lines = app(CatalogReading::class)->memberPillars($composition);
|
||||
|
||||
return new HtmlString(collect($lines)->map(fn (string $line): string => e($line))->implode('<br>'));
|
||||
}),
|
||||
Repeater::make('members')
|
||||
->label('Bausteine der neuen Fassung')
|
||||
->schema([
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
use App\Domain\Identity\StaffRole;
|
||||
use App\Filament\Resources\ContentElements\Pages\EditContentElement;
|
||||
use App\Filament\Resources\ContentElements\Pages\ListContentElements;
|
||||
use App\Filament\Resources\ContentElements\Pages\ViewContentElement;
|
||||
use App\Models\User;
|
||||
use Filament\Facades\Filament;
|
||||
use Filament\Resources\Resource;
|
||||
@@ -34,7 +35,11 @@ class ContentElementResource extends Resource
|
||||
|
||||
public static function canViewAny(): bool
|
||||
{
|
||||
return self::editor();
|
||||
$user = Filament::auth()->user();
|
||||
|
||||
return $user instanceof User && (
|
||||
$user->hasStaffRole(StaffRole::Redakteur) || $user->hasStaffRole(StaffRole::Katalogverwalter)
|
||||
);
|
||||
}
|
||||
|
||||
public static function editor(): bool
|
||||
@@ -44,6 +49,11 @@ public static function editor(): bool
|
||||
return $user instanceof User && $user->hasStaffRole(StaffRole::Redakteur);
|
||||
}
|
||||
|
||||
public static function getViewAuthorizationResponse(Model $record): Response
|
||||
{
|
||||
return self::canViewAny() ? Response::allow() : Response::deny();
|
||||
}
|
||||
|
||||
public static function getEditAuthorizationResponse(Model $record): Response
|
||||
{
|
||||
return self::editor() ? Response::allow() : Response::deny();
|
||||
@@ -56,9 +66,14 @@ public static function form(Schema $schema): Schema
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return $table->columns([
|
||||
return $table->recordUrl(
|
||||
fn (ContentElement $record): string => static::getUrl('view', ['record' => $record])
|
||||
)->columns([
|
||||
TextColumn::make('working_title')->label('Arbeitstitel')->searchable(),
|
||||
TextColumn::make('kind')->label('Art'),
|
||||
TextColumn::make('pillar_names')->label('Säulen')->state(
|
||||
fn (ContentElement $record): string => $record->pillars->pluck('name')->join(', ') ?: '—'
|
||||
),
|
||||
TextColumn::make('stand')->label('Aktuelle Fassung')->state(function (ContentElement $record): string {
|
||||
$version = $record->versions->sortByDesc('number')->first();
|
||||
|
||||
@@ -75,14 +90,15 @@ public static function table(Table $table): Table
|
||||
|
||||
public static function getEloquentQuery(): Builder
|
||||
{
|
||||
return parent::getEloquentQuery()->with('versions');
|
||||
return parent::getEloquentQuery()->with(['versions', 'pillars']);
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => ListContentElements::route('/'),
|
||||
'edit' => EditContentElement::route('/{record}'),
|
||||
'view' => ViewContentElement::route('/{record}'),
|
||||
'edit' => EditContentElement::route('/{record}/bearbeiten'),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
@@ -76,7 +76,7 @@ protected function getHeaderActions(): array
|
||||
}, 'Das Medium ist angelegt.');
|
||||
|
||||
if ($element !== null) {
|
||||
$this->redirect(ContentElementResource::getUrl('edit', ['record' => $element]));
|
||||
$this->redirect(ContentElementResource::getUrl('view', ['record' => $element]));
|
||||
}
|
||||
}),
|
||||
];
|
||||
|
||||
@@ -0,0 +1,161 @@
|
||||
<?php
|
||||
|
||||
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\Pillar;
|
||||
use App\Domain\Catalog\PillarService;
|
||||
use App\Filament\Resources\ContentElements\ContentElementResource;
|
||||
use App\Filament\Support\CatalogReading;
|
||||
use App\Filament\Support\ElementRevision;
|
||||
use App\Filament\Support\ReportsDomainRules;
|
||||
use App\Http\Controllers\ContentPreviewController;
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Forms\Components\CheckboxList;
|
||||
use Filament\Forms\Components\Textarea;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Resources\Pages\ViewRecord;
|
||||
use Filament\Schemas\Components\View;
|
||||
use Filament\Schemas\Schema;
|
||||
use Illuminate\Contracts\Support\Htmlable;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
class ViewContentElement extends ViewRecord
|
||||
{
|
||||
use ReportsDomainRules;
|
||||
|
||||
protected static string $resource = ContentElementResource::class;
|
||||
|
||||
public ?int $fassung = null;
|
||||
|
||||
public function mount(int|string $record): void
|
||||
{
|
||||
parent::mount($record);
|
||||
|
||||
$requested = request()->integer('fassung');
|
||||
|
||||
if ($requested > 0) {
|
||||
$this->fassung = $requested;
|
||||
}
|
||||
}
|
||||
|
||||
public function getSubheading(): string|Htmlable|null
|
||||
{
|
||||
return 'Jede Fassung hat eine eigene Nummer und bleibt einsehbar. Beschreibung, Arbeitstitel und Säulen gehören zum Medium und ändern keine Fassung. Eine deaktivierte Fassung wird nicht mehr ausgeliefert und lässt sich nicht neu einbauen.';
|
||||
}
|
||||
|
||||
public function infolist(Schema $schema): Schema
|
||||
{
|
||||
return $schema->components([
|
||||
View::make('filament.media.viewer')->viewData(fn (): array => $this->viewerData()),
|
||||
]);
|
||||
}
|
||||
|
||||
public function showVersion(int $version): void
|
||||
{
|
||||
abort_unless($this->ownedVersion($version) instanceof ContentElementVersion, 404);
|
||||
$this->fassung = $version;
|
||||
}
|
||||
|
||||
public function deactivateAction(): Action
|
||||
{
|
||||
return Action::make('deactivate')
|
||||
->label('Deaktivieren')
|
||||
->modalHeading('Fassung deaktivieren')
|
||||
->modalDescription('Die Fassung bleibt hier einsehbar. Sie wird nicht mehr ausgeliefert und kann nicht in eine neue Übung oder einen neuen Kurs übernommen werden.')
|
||||
->modalSubmitActionLabel('Deaktivieren')
|
||||
->visible(fn (): bool => ContentElementResource::editor())
|
||||
->schema([
|
||||
Textarea::make('reason')->label('Begründung')->required(),
|
||||
])
|
||||
->action(function (array $data, array $arguments): void {
|
||||
abort_unless(ContentElementResource::editor(), 403);
|
||||
$this->report(function () use ($data, $arguments): void {
|
||||
$version = $this->ownedVersion((int) ($arguments['version'] ?? 0));
|
||||
abort_unless($version instanceof ContentElementVersion, 404);
|
||||
app(ContentService::class)->block($version, (string) $data['reason']);
|
||||
}, 'Die Fassung ist deaktiviert.');
|
||||
$this->getRecord()->unsetRelation('versions');
|
||||
});
|
||||
}
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Action::make('describe')
|
||||
->label('Beschreibung ändern')
|
||||
->visible(fn (): bool => ContentElementResource::editor())
|
||||
->fillForm(fn (): array => [
|
||||
'working_title' => $this->getRecord()->working_title,
|
||||
'description' => $this->getRecord()->description,
|
||||
'pillars' => $this->getRecord()->pillars()->pluck('pillars.id')->all(),
|
||||
])
|
||||
->schema([
|
||||
TextInput::make('working_title')->label('Arbeitstitel')->required(),
|
||||
Textarea::make('description')->label('Beschreibung')->rows(4)
|
||||
->helperText('Gilt für das Medium. Speichern legt keine neue Fassung an.'),
|
||||
CheckboxList::make('pillars')
|
||||
->label('Fachliche Säulen')
|
||||
->options(fn (): array => Pillar::query()->orderBy('name')->pluck('name', 'id')->all()),
|
||||
])
|
||||
->action(function (array $data): void {
|
||||
$this->report(function () use ($data): void {
|
||||
/** @var ContentElement $element */
|
||||
$element = $this->getRecord();
|
||||
app(ContentService::class)->describe($element, (string) $data['working_title'], $data['description'] ?? null);
|
||||
app(PillarService::class)->assign($element, array_map(intval(...), $data['pillars'] ?? []));
|
||||
}, 'Die Beschreibung ist gespeichert.');
|
||||
$this->getRecord()->refresh();
|
||||
}),
|
||||
Action::make('revise')
|
||||
->label('Neue Fassung anlegen')
|
||||
->visible(fn (): bool => ContentElementResource::editor())
|
||||
->schema(fn (): array => ElementRevision::fields($this->getRecord()))
|
||||
->action(function (array $data): void {
|
||||
$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');
|
||||
}),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array{element: ContentElement, versions: Collection<int, ContentElementVersion>, shown: ?ContentElementVersion, fileUrl: ?string, pending: bool, pillars: list<string>, usage: list<string>, canRevise: bool}
|
||||
*/
|
||||
private function viewerData(): array
|
||||
{
|
||||
/** @var ContentElement $element */
|
||||
$element = $this->getRecord();
|
||||
$versions = $element->versions()->orderByDesc('number')->get();
|
||||
$shown = $versions->firstWhere('id', $this->fassung)
|
||||
?? $versions->first(fn (ContentElementVersion $version): bool => $version->status === ContentVersionStatus::Bereit)
|
||||
?? $versions->first();
|
||||
$preview = app(ContentPreviewController::class);
|
||||
|
||||
return [
|
||||
'element' => $element,
|
||||
'versions' => $versions,
|
||||
'shown' => $shown,
|
||||
'fileUrl' => $shown === null ? null : $preview->fileUrl($shown),
|
||||
'pending' => $shown !== null && $preview->isPending($shown),
|
||||
'pillars' => $element->pillars->pluck('name')->all(),
|
||||
'usage' => app(CatalogReading::class)->elementUsage($element),
|
||||
'canRevise' => ContentElementResource::editor(),
|
||||
];
|
||||
}
|
||||
|
||||
private function ownedVersion(int $id): ?ContentElementVersion
|
||||
{
|
||||
/** @var ContentElement $element */
|
||||
$element = $this->getRecord();
|
||||
|
||||
return $element->versions()->whereKey($id)->first();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Pillars\Pages;
|
||||
|
||||
use App\Domain\Catalog\DomainRuleException;
|
||||
use App\Domain\Catalog\Pillar;
|
||||
use App\Domain\Catalog\PillarService;
|
||||
use App\Filament\Resources\Pillars\PillarResource;
|
||||
use App\Filament\Support\ReportsDomainRules;
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Notifications\Notification;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
use Filament\Support\Exceptions\Halt;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class EditPillar extends EditRecord
|
||||
{
|
||||
use ReportsDomainRules;
|
||||
|
||||
protected static string $resource = PillarResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Action::make('delete')
|
||||
->label('Löschen')
|
||||
->color('danger')
|
||||
->requiresConfirmation()
|
||||
->action(function (): void {
|
||||
/** @var Pillar $pillar */
|
||||
$pillar = $this->getRecord();
|
||||
$deleted = false;
|
||||
$this->report(function () use ($pillar, &$deleted): void {
|
||||
app(PillarService::class)->delete($pillar);
|
||||
$deleted = true;
|
||||
}, 'Die Säule ist gelöscht.');
|
||||
|
||||
if ($deleted) {
|
||||
$this->redirect(PillarResource::getUrl('index'));
|
||||
}
|
||||
}),
|
||||
];
|
||||
}
|
||||
|
||||
protected function handleRecordUpdate(Model $record, array $data): Model
|
||||
{
|
||||
/** @var Pillar $record */
|
||||
try {
|
||||
app(PillarService::class)->rename($record, $data['name']);
|
||||
} catch (DomainRuleException $exception) {
|
||||
Notification::make()->title($exception->getMessage())->danger()->send();
|
||||
|
||||
throw new Halt;
|
||||
}
|
||||
|
||||
return $record;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Pillars\Pages;
|
||||
|
||||
use App\Domain\Catalog\PillarService;
|
||||
use App\Filament\Resources\ContentElements\ContentElementResource;
|
||||
use App\Filament\Resources\Pillars\PillarResource;
|
||||
use App\Filament\Support\ReportsDomainRules;
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
use Illuminate\Contracts\Support\Htmlable;
|
||||
|
||||
class ListPillars extends ListRecords
|
||||
{
|
||||
use ReportsDomainRules;
|
||||
|
||||
protected static string $resource = PillarResource::class;
|
||||
|
||||
public function getSubheading(): string|Htmlable|null
|
||||
{
|
||||
return 'Die fachlichen Säulen des Materials. Es können weitere hinzukommen. Ein Medium kann mehreren Säulen zugeordnet sein.';
|
||||
}
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Action::make('create')
|
||||
->label('Säule anlegen')
|
||||
->visible(fn (): bool => ContentElementResource::editor())
|
||||
->schema([
|
||||
TextInput::make('name')->label('Name')->required(),
|
||||
])
|
||||
->action(function (array $data): void {
|
||||
$pillar = null;
|
||||
$this->report(function () use ($data, &$pillar): void {
|
||||
$pillar = app(PillarService::class)->create($data['name']);
|
||||
}, 'Die Säule ist angelegt.');
|
||||
|
||||
if ($pillar !== null) {
|
||||
$this->redirect(PillarResource::getUrl('edit', ['record' => $pillar]));
|
||||
}
|
||||
}),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Pillars;
|
||||
|
||||
use App\Domain\Catalog\Pillar;
|
||||
use App\Filament\Resources\ContentElements\ContentElementResource;
|
||||
use App\Filament\Resources\Pillars\Pages\EditPillar;
|
||||
use App\Filament\Resources\Pillars\Pages\ListPillars;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Tables\Table;
|
||||
use Illuminate\Auth\Access\Response;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class PillarResource extends Resource
|
||||
{
|
||||
protected static ?string $model = Pillar::class;
|
||||
|
||||
protected static string|\UnitEnum|null $navigationGroup = 'Inhalte';
|
||||
|
||||
protected static ?string $navigationLabel = 'Fachliche Säulen';
|
||||
|
||||
protected static ?string $modelLabel = 'Fachliche Säule';
|
||||
|
||||
protected static ?string $pluralModelLabel = 'Fachliche Säulen';
|
||||
|
||||
protected static ?string $recordTitleAttribute = 'name';
|
||||
|
||||
protected static ?string $slug = 'saeulen';
|
||||
|
||||
protected static ?int $navigationSort = 5;
|
||||
|
||||
public static function canViewAny(): bool
|
||||
{
|
||||
return ContentElementResource::editor();
|
||||
}
|
||||
|
||||
public static function getEditAuthorizationResponse(Model $record): Response
|
||||
{
|
||||
return ContentElementResource::editor() ? Response::allow() : Response::deny();
|
||||
}
|
||||
|
||||
public static function form(Schema $schema): Schema
|
||||
{
|
||||
return $schema->components([
|
||||
TextInput::make('name')->label('Name')->required(),
|
||||
]);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return $table->columns([
|
||||
TextColumn::make('name')->label('Name')->searchable(),
|
||||
TextColumn::make('elements_count')->counts('elements')->label('Medien'),
|
||||
]);
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => ListPillars::route('/'),
|
||||
'edit' => EditPillar::route('/{record}'),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -10,6 +10,8 @@
|
||||
use App\Domain\Catalog\CompositionKind;
|
||||
use App\Domain\Catalog\CompositionMember;
|
||||
use App\Domain\Catalog\ContentElement;
|
||||
use App\Domain\Catalog\ContentElementVersion;
|
||||
use App\Domain\Catalog\ContentResolver;
|
||||
use App\Domain\Catalog\ContentVersionStatus;
|
||||
use App\Domain\Catalog\DomainRuleException;
|
||||
use App\Domain\Catalog\LicenseArticle;
|
||||
@@ -317,6 +319,37 @@ public function compositionMembers(Composition $composition): array
|
||||
return $lines;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return list<string>
|
||||
*/
|
||||
public function memberPillars(Composition $composition): array
|
||||
{
|
||||
$version = $composition->versions()
|
||||
->where('status', ContentVersionStatus::Bereit)
|
||||
->orderByDesc('number')
|
||||
->first();
|
||||
|
||||
if ($version === null) {
|
||||
return ['Noch keine Fassung, deshalb keine Säulen.'];
|
||||
}
|
||||
|
||||
$rows = app(ContentResolver::class)->expand($version);
|
||||
$versions = ContentElementVersion::query()
|
||||
->whereIn('id', array_column($rows, 'version_id'))
|
||||
->with('element.pillars')
|
||||
->get()
|
||||
->keyBy('id');
|
||||
$lines = [];
|
||||
|
||||
foreach ($rows as $row) {
|
||||
$element = $versions[$row['version_id']]->element;
|
||||
$names = $element->pillars->pluck('name');
|
||||
$lines[] = $element->working_title.' — '.($names->isEmpty() ? 'keiner Säule zugeordnet' : $names->join(', '));
|
||||
}
|
||||
|
||||
return $lines === [] ? ['Diese Fassung enthält keine Medien.'] : $lines;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return list<string>
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,103 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Support;
|
||||
|
||||
use App\Domain\Catalog\ContentElement;
|
||||
use App\Domain\Catalog\ContentElementVersion;
|
||||
use App\Domain\Catalog\ContentService;
|
||||
use App\Domain\Catalog\DomainRuleException;
|
||||
use App\Filament\Resources\ContentElements\Pages\EditContentElement;
|
||||
use Filament\Forms\Components\Component;
|
||||
use Filament\Forms\Components\Textarea;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Forms\Components\Toggle;
|
||||
|
||||
class ElementRevision
|
||||
{
|
||||
/**
|
||||
* @param array<string, mixed> $data
|
||||
*/
|
||||
public static function publish(ContentElement $record, array $data): string
|
||||
{
|
||||
$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) {
|
||||
return 'Text und Datei sind gleich geblieben, deshalb gibt es keine neue Fassung.';
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
return $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.';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return list<Component>
|
||||
*/
|
||||
public static function fields(ContentElement $element): array
|
||||
{
|
||||
$latest = $element->versions()->orderByDesc('number')->first();
|
||||
|
||||
return [
|
||||
Textarea::make('body')->label('Text')->rows(8)->default($latest?->body),
|
||||
EditContentElement::uploadField(),
|
||||
Toggle::make('drop_file')
|
||||
->label('Datei in der neuen Fassung nicht mehr verwenden')
|
||||
->visible(fn (): bool => is_string(self::fileOf($element))),
|
||||
TextInput::make('decision_seconds')
|
||||
->label('Entscheidungsmarke in Sekunden')
|
||||
->numeric()
|
||||
->minValue(0)
|
||||
->default(self::decisionOf($latest)),
|
||||
TextInput::make('change_note')->label('Änderungsnotiz'),
|
||||
];
|
||||
}
|
||||
|
||||
private static function fileOf(ContentElement $element): mixed
|
||||
{
|
||||
$latest = $element->versions()->orderByDesc('number')->first();
|
||||
|
||||
return is_array($latest?->metadata) ? ($latest->metadata['file'] ?? null) : null;
|
||||
}
|
||||
|
||||
private static function decisionOf(?ContentElementVersion $version): ?int
|
||||
{
|
||||
if (! is_array($version?->metadata) || ! is_numeric($version->metadata['decision_seconds'] ?? null)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (int) $version->metadata['decision_seconds'];
|
||||
}
|
||||
}
|
||||
@@ -11,25 +11,63 @@
|
||||
|
||||
class ContentPreviewController extends Controller
|
||||
{
|
||||
public function __invoke(ContentElementVersion $version): View|StreamedResponse
|
||||
public function show(ContentElementVersion $version): View
|
||||
{
|
||||
$this->authorizeStaff();
|
||||
$version->loadMissing('element');
|
||||
|
||||
return view('content.preview', [
|
||||
'version' => $version,
|
||||
'fileUrl' => $this->fileUrl($version),
|
||||
'pending' => $this->isPending($version),
|
||||
]);
|
||||
}
|
||||
|
||||
public function file(ContentElementVersion $version): StreamedResponse
|
||||
{
|
||||
$this->authorizeStaff();
|
||||
$path = $this->storedPath($version);
|
||||
abort_unless(is_string($path), 404);
|
||||
|
||||
return Storage::disk('media_derived')->response($path, basename($path), [
|
||||
'Content-Disposition' => 'inline',
|
||||
]);
|
||||
}
|
||||
|
||||
public function fileUrl(ContentElementVersion $version): ?string
|
||||
{
|
||||
return $this->storedPath($version) === null ? null : route('content.file', $version);
|
||||
}
|
||||
|
||||
public function isPending(ContentElementVersion $version): bool
|
||||
{
|
||||
if ($this->storedPath($version) !== null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$metadata = is_array($version->metadata) ? $version->metadata : [];
|
||||
$incoming = $metadata['incoming'] ?? null;
|
||||
|
||||
return (is_string($incoming) && $incoming !== '') || is_array($incoming);
|
||||
}
|
||||
|
||||
private function storedPath(ContentElementVersion $version): ?string
|
||||
{
|
||||
$file = is_array($version->metadata) ? ($version->metadata['file'] ?? null) : null;
|
||||
|
||||
if (! is_string($file) || $file === '' || str_contains($file, '..') || ! str_starts_with($file, 'inhalte/')) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return Storage::disk('media_derived')->exists($file) ? $file : null;
|
||||
}
|
||||
|
||||
private function authorizeStaff(): void
|
||||
{
|
||||
$user = auth('staff')->user();
|
||||
abort_unless(
|
||||
$user instanceof User && ($user->hasStaffRole(StaffRole::Redakteur) || $user->hasStaffRole(StaffRole::Katalogverwalter)),
|
||||
403,
|
||||
);
|
||||
|
||||
$version->loadMissing('element');
|
||||
$file = $version->metadata['file'] ?? null;
|
||||
|
||||
if (is_string($file) && $file !== '' && ! str_contains($file, '..') && Storage::disk('media_derived')->exists($file)) {
|
||||
return Storage::disk('media_derived')->response($file, basename($file), [
|
||||
'Content-Disposition' => 'inline',
|
||||
]);
|
||||
}
|
||||
|
||||
return view('content.preview', [
|
||||
'version' => $version,
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -44,7 +44,7 @@ public function grants(Request $request): View
|
||||
|
||||
public function show(Request $request, LicenseArticle $article): View
|
||||
{
|
||||
$release = $article->currentRelease()->with('contents.elementVersion.element')->first();
|
||||
$release = $article->currentRelease()->with('contents.elementVersion.element.pillars')->first();
|
||||
$entries = [];
|
||||
|
||||
if ($release !== null) {
|
||||
@@ -66,6 +66,7 @@ public function show(Request $request, LicenseArticle $article): View
|
||||
? (int) $metadata['decision_seconds']
|
||||
: null,
|
||||
'playable' => $decision->allowed && is_string($file) && $file !== '' && ($class === 'film' || $class === 'audio'),
|
||||
'pillars' => $version->element->pillars->pluck('name')->all(),
|
||||
'url' => $decision->allowed
|
||||
? SignedLink::temporary('member.media', now()->addMinutes(10), [
|
||||
'article' => $article->id,
|
||||
|
||||
Reference in new issue
Block a user