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,
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('pillars', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('name')->unique();
|
||||
$table->timestamps();
|
||||
});
|
||||
|
||||
Schema::create('content_element_pillar', function (Blueprint $table) {
|
||||
$table->foreignId('content_element_id')->constrained()->cascadeOnDelete();
|
||||
$table->foreignId('pillar_id')->constrained()->restrictOnDelete();
|
||||
$table->primary(['content_element_id', 'pillar_id']);
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('content_element_pillar');
|
||||
Schema::dropIfExists('pillars');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('content_elements', function (Blueprint $table) {
|
||||
$table->text('description')->nullable();
|
||||
});
|
||||
|
||||
Schema::table('content_element_versions', function (Blueprint $table) {
|
||||
$table->text('block_reason')->nullable();
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('content_elements', function (Blueprint $table) {
|
||||
$table->dropColumn('description');
|
||||
});
|
||||
|
||||
Schema::table('content_element_versions', function (Blueprint $table) {
|
||||
$table->dropColumn('block_reason');
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -9,7 +9,7 @@ ## Bedienbar
|
||||
- Lizenzartikel, verschachtelte Pakete, Rechteprofile und Angebote als Katalogverwalter. Die jeweilige Seite zeigt den Stand, die Bestandteile, die aufgelösten Artikel und die daraus entstehenden Berechtigungen. Ein neuer Stand zeigt Inhaber, Angebote und Inhaltszahl; ein Rückzug stellt den vorherigen Stand wieder her und nennt die Betroffenen.
|
||||
- Manuelle Vergabe als Kundenbetreuung, am Benutzer in der Verwaltung.
|
||||
- Registrierung, Anmeldung, kostenloser Abruf, Testkauf, Ablehnung und Widerruf im Mitgliederbereich. Die Verwaltung fragt den Authenticator-Code auf demselben Browser 30 Tage lang nicht erneut ab. In der Authenticator-App heißt der Eintrag „Lara&Felix“, außerhalb der Produktion „Lara&Felix (dev)“. Ein bestehender Eintrag übernimmt den Namen erst bei erneuter Einrichtung.
|
||||
- Medien werden in der Verwaltung angelegt, mit Datei oder Text versehen und als neue Fassung fortgeschrieben. Eine Datei darf bis 2 GB groß sein. Die bisherige Fassung bleibt. Übungen, Kurse und fachliche Kombinationen sind getrennte Zusammenstellungen; ihre Bausteine lassen sich hinzufügen, tauschen und aus der neuen Fassung nehmen.
|
||||
- Medien werden in der Verwaltung angelegt und geöffnet: die Datei oder der Text der gewählten Fassung ist dort sichtbar. Jede Fassung hat eine eigene Nummer. Beschreibung, Arbeitstitel und Säulen gehören zum Medium und ändern keine Fassung. Eine deaktivierte Fassung bleibt einsehbar, wird nicht mehr ausgeliefert und lässt sich nicht neu einbauen. Eine Datei darf bis 2 GB groß sein. Ein Medium kann mehreren fachlichen Säulen zugeordnet sein; weitere Säulen lassen sich anlegen. Übungen, Kurse und fachliche Kombinationen sind getrennte Zusammenstellungen; ihre Bausteine lassen sich hinzufügen, tauschen und aus der neuen Fassung nehmen.
|
||||
- Kurse im Mitgliederbereich zeigen den Namen der Übung, die Bausteine in Reihenfolge und einen Player. Ein Film mit Entscheidungsmarke lässt sich an dieser Stelle pausieren und von vorn starten. Die Verwaltung zeigt den Text einer Fassung und, sobald die Datei übernommen ist, die Datei selbst.
|
||||
- Bibliothek entscheidet je Abruf erneut. Filme mit Datei werden im Player geladen, Texte und PDF über einen kurz signierten Abruf.
|
||||
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
@php
|
||||
$metadata = is_array($version->metadata) ? $version->metadata : [];
|
||||
$class = $version->element->output_class;
|
||||
@endphp
|
||||
|
||||
@if ($fileUrl)
|
||||
@if ($class === 'film')
|
||||
<video controls preload="metadata" playsinline src="{{ $fileUrl }}" style="width: 100%; max-height: 70vh; background: #111;"></video>
|
||||
@elseif ($class === 'audio')
|
||||
<audio controls preload="metadata" src="{{ $fileUrl }}" style="width: 100%;"></audio>
|
||||
@elseif ($class === 'bild')
|
||||
<img src="{{ $fileUrl }}" alt="{{ $version->element->working_title }}" style="max-width: 100%; height: auto;">
|
||||
@else
|
||||
<iframe src="{{ $fileUrl }}" title="Fassung {{ $version->number }}" style="width: 100%; height: 70vh; border: 0;"></iframe>
|
||||
@endif
|
||||
<p><a href="{{ $fileUrl }}">Datei öffnen</a></p>
|
||||
@elseif ($pending)
|
||||
<p>Die Datei wird noch übernommen.</p>
|
||||
@elseif (is_string($metadata['file'] ?? null))
|
||||
<p>Für Fassung {{ $version->number }} ist eine Datei vorgemerkt, sie liegt aber nicht vor.</p>
|
||||
@endif
|
||||
|
||||
@if (filled($version->body))
|
||||
<article class="prose">
|
||||
{!! nl2br(e($version->body)) !!}
|
||||
</article>
|
||||
@endif
|
||||
@@ -4,12 +4,9 @@
|
||||
|
||||
@section('content')
|
||||
<h1>{{ $version->element->working_title }}</h1>
|
||||
<p class="lede">Fassung {{ $version->number }}, nur für die Redaktion.</p>
|
||||
@if (filled($version->body))
|
||||
<article class="prose">
|
||||
{!! nl2br(e($version->body)) !!}
|
||||
</article>
|
||||
@else
|
||||
<p class="lede">Fassung {{ $version->number }}, nur für die Verwaltung.</p>
|
||||
@include('content.player', ['version' => $version, 'fileUrl' => $fileUrl, 'pending' => $pending])
|
||||
@if (! $fileUrl && ! $pending && blank($version->body))
|
||||
<div class="empty">
|
||||
<p>Für diese Fassung liegt noch kein lesbarer Text und keine übernommene Datei vor.</p>
|
||||
</div>
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
@php
|
||||
use App\Domain\Catalog\ContentVersionStatus;
|
||||
@endphp
|
||||
|
||||
<div style="display: grid; gap: 1.5rem;">
|
||||
<section style="display: grid; gap: 0.75rem;">
|
||||
<h2 style="font-size: 1.125rem; font-weight: 600;">{{ $element->working_title }}</h2>
|
||||
@if (filled($element->description))
|
||||
<p>{{ $element->description }}</p>
|
||||
@else
|
||||
<p>Noch keine Beschreibung. Beschreibung, Arbeitstitel und Säulen lassen sich ändern, ohne eine neue Fassung anzulegen.</p>
|
||||
@endif
|
||||
<p>{{ $pillars === [] ? 'Keiner Säule zugeordnet.' : implode(' · ', $pillars) }}</p>
|
||||
</section>
|
||||
|
||||
<section style="display: grid; gap: 0.75rem;">
|
||||
@if ($shown === null)
|
||||
<p>Noch keine Fassung.</p>
|
||||
@else
|
||||
<h2 style="font-size: 1.125rem; font-weight: 600;">Fassung {{ $shown->number }}</h2>
|
||||
@include('content.player', ['version' => $shown, 'fileUrl' => $fileUrl, 'pending' => $pending])
|
||||
@if (! $fileUrl && ! $pending && blank($shown->body) && ! is_string((is_array($shown->metadata) ? $shown->metadata : [])['file'] ?? null))
|
||||
<p>Für diese Fassung liegt noch kein Text und keine Datei vor.</p>
|
||||
@endif
|
||||
@endif
|
||||
</section>
|
||||
|
||||
<section style="display: grid; gap: 0.75rem;">
|
||||
<h2 style="font-size: 1.125rem; font-weight: 600;">Fassungen</h2>
|
||||
@if ($versions->isEmpty())
|
||||
<p>Noch keine Fassung.</p>
|
||||
@else
|
||||
<ul style="display: grid; gap: 0.75rem; list-style: none; padding: 0; margin: 0;">
|
||||
@foreach ($versions as $version)
|
||||
@php
|
||||
$status = match ($version->status) {
|
||||
ContentVersionStatus::Gesperrt => 'deaktiviert',
|
||||
ContentVersionStatus::Entwurf => 'Entwurf',
|
||||
default => 'bereit',
|
||||
};
|
||||
@endphp
|
||||
<li style="display: grid; gap: 0.35rem; padding: 0.75rem 0; border-top: 1px solid rgba(0,0,0,0.12);">
|
||||
<strong>Fassung {{ $version->number }}</strong>
|
||||
<span>{{ $status }}@if (filled($version->change_note)) · {{ $version->change_note }}@endif</span>
|
||||
@if (filled($version->block_reason))
|
||||
<span>Begründung: {{ $version->block_reason }}</span>
|
||||
@endif
|
||||
<span style="display: flex; flex-wrap: wrap; gap: 0.75rem;">
|
||||
<button type="button" wire:click="showVersion({{ $version->id }})">Fassung {{ $version->number }} ansehen</button>
|
||||
<a href="{{ route('content.preview', $version) }}" target="_blank" rel="noopener">Im eigenen Tab</a>
|
||||
@if ($canRevise && $version->status === ContentVersionStatus::Bereit)
|
||||
<button type="button" wire:click="mountAction('deactivate', { version: {{ $version->id }} })">Deaktivieren</button>
|
||||
@endif
|
||||
</span>
|
||||
</li>
|
||||
@endforeach
|
||||
</ul>
|
||||
@endif
|
||||
</section>
|
||||
|
||||
@if ($usage !== [])
|
||||
<section style="display: grid; gap: 0.35rem;">
|
||||
<h2 style="font-size: 1.125rem; font-weight: 600;">Verwendung</h2>
|
||||
@foreach ($usage as $line)
|
||||
<p>{{ $line }}</p>
|
||||
@endforeach
|
||||
</section>
|
||||
@endif
|
||||
</div>
|
||||
@@ -20,6 +20,12 @@
|
||||
@foreach ($entries as $entry)
|
||||
<li>
|
||||
<h2>{{ $entry['role'] }}: {{ $entry['version']->element->working_title }}</h2>
|
||||
@if (filled($entry['version']->element->description))
|
||||
<p>{{ $entry['version']->element->description }}</p>
|
||||
@endif
|
||||
@if ($entry['pillars'] !== [])
|
||||
<p>{{ implode(' · ', $entry['pillars']) }}</p>
|
||||
@endif
|
||||
@if ($entry['playable'])
|
||||
<video controls preload="metadata" playsinline src="{{ $entry['url'] }}" @if ($entry['decision'] !== null) data-decision="{{ $entry['decision'] }}" @endif></video>
|
||||
<p class="course-actions">
|
||||
|
||||
+4
-1
@@ -29,9 +29,12 @@
|
||||
|
||||
Route::post('/abmelden', [SessionController::class, 'destroy'])->middleware('auth')->name('logout');
|
||||
|
||||
Route::get('/redaktion/inhalt/{version}', ContentPreviewController::class)
|
||||
Route::get('/redaktion/inhalt/{version}', [ContentPreviewController::class, 'show'])
|
||||
->middleware('auth:staff')
|
||||
->name('content.preview');
|
||||
Route::get('/redaktion/inhalt/{version}/datei', [ContentPreviewController::class, 'file'])
|
||||
->middleware('auth:staff')
|
||||
->name('content.file');
|
||||
|
||||
Route::middleware('auth')->group(function () {
|
||||
Route::get('/email/bestaetigen', [EmailVerificationController::class, 'notice'])->name('verification.notice');
|
||||
|
||||
@@ -96,8 +96,10 @@ public function test_catalog_pages_show_contents_packages_and_resolved_rights():
|
||||
$sheet->load('element');
|
||||
|
||||
$this->actingAs($editor, 'staff')
|
||||
->get(ContentElementResource::getUrl('edit', ['record' => $sheet->element]))
|
||||
->get(ContentElementResource::getUrl('view', ['record' => $sheet->element]))
|
||||
->assertOk()
|
||||
->assertSee('Hinweis für die Prüfung.')
|
||||
->assertSee('Fassung 1')
|
||||
->assertSee('Übung: Übung Alltag')
|
||||
->assertSee('Lizenzartikel demo-merkblatt')
|
||||
->assertSee('Neue Fassung anlegen');
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
use App\Filament\Resources\Combinations\CombinationResource;
|
||||
use App\Filament\Resources\ContentElements\ContentElementResource;
|
||||
use App\Filament\Resources\ContentElements\Pages\EditContentElement;
|
||||
use App\Filament\Resources\ContentElements\Pages\ViewContentElement;
|
||||
use App\Filament\Resources\Courses\CourseResource;
|
||||
use App\Filament\Resources\Exercises\ExerciseResource;
|
||||
use App\Filament\Resources\Exercises\Pages\EditExercise;
|
||||
@@ -39,15 +40,14 @@ public function test_a_medium_keeps_the_old_version_when_a_new_one_is_saved(): v
|
||||
$editor->saveAppAuthenticationSecret('JBSWY3DPEHPK3PXP');
|
||||
$this->actingAs($editor, 'staff');
|
||||
|
||||
Livewire::test(EditContentElement::class, ['record' => $element->getKey()])
|
||||
Livewire::test(ViewContentElement::class, ['record' => $element->getKey()])
|
||||
->assertOk()
|
||||
->assertSee('Erste Fassung')
|
||||
->fillForm([
|
||||
'working_title' => 'Merkblatt',
|
||||
->assertSee('Fassung 1')
|
||||
->callAction('revise', [
|
||||
'body' => 'Zweite Fassung',
|
||||
'change_note' => 'Korrektur',
|
||||
])
|
||||
->call('save')
|
||||
->assertHasNoFormErrors();
|
||||
|
||||
$versions = $element->versions()->orderBy('number')->get();
|
||||
@@ -69,14 +69,13 @@ public function test_an_uploaded_file_becomes_a_ready_version(): void
|
||||
$editor->saveAppAuthenticationSecret('JBSWY3DPEHPK3PXP');
|
||||
$this->actingAs($editor, 'staff');
|
||||
|
||||
Livewire::test(EditContentElement::class, ['record' => $element->getKey()])
|
||||
->fillForm([
|
||||
Livewire::test(ViewContentElement::class, ['record' => $element->getKey()])
|
||||
->callAction('revise', [
|
||||
'working_title' => 'Übungsfilm',
|
||||
'body' => 'Anleitung zum Film',
|
||||
'incoming' => ['inhalte/film.mp4'],
|
||||
'decision_seconds' => 12,
|
||||
])
|
||||
->call('save')
|
||||
->assertHasNoFormErrors();
|
||||
|
||||
$version = $element->versions()->first();
|
||||
@@ -150,5 +149,58 @@ public function test_a_catalog_keeper_cannot_edit_media(): void
|
||||
$this->actingAs($keeper, 'staff')
|
||||
->get(ContentElementResource::getUrl('edit', ['record' => $element]))
|
||||
->assertForbidden();
|
||||
|
||||
$version = app(ContentService::class)->publishElementVersion($element, 'Sichtbarer Text');
|
||||
|
||||
$this->actingAs($keeper, 'staff')
|
||||
->get(ContentElementResource::getUrl('view', ['record' => $element]))
|
||||
->assertOk()
|
||||
->assertSee('Fassung 1')
|
||||
->assertSee('Sichtbarer Text')
|
||||
->assertDontSee('Beschreibung ändern');
|
||||
}
|
||||
|
||||
public function test_a_description_does_not_create_a_version_and_an_older_version_can_be_deactivated(): void
|
||||
{
|
||||
Storage::fake('media_derived');
|
||||
Storage::disk('media_derived')->put('inhalte/film.mp4', 'filmbytes');
|
||||
$content = app(ContentService::class);
|
||||
$element = $content->createElement('film', 'film', 'Übungsfilm');
|
||||
$first = $content->publishElementVersion($element, 'Erste Fassung', ['file' => 'inhalte/film.mp4']);
|
||||
$second = $content->publishElementVersion($element, 'Zweite Fassung', ['file' => 'inhalte/film.mp4']);
|
||||
$editor = User::factory()->redakteur()->create();
|
||||
$editor->saveAppAuthenticationSecret('JBSWY3DPEHPK3PXP');
|
||||
$this->actingAs($editor, 'staff');
|
||||
|
||||
Livewire::test(EditContentElement::class, ['record' => $element->getKey()])
|
||||
->fillForm([
|
||||
'working_title' => 'Übungsfilm',
|
||||
'description' => 'Für die Gruppe',
|
||||
'pillars' => [],
|
||||
])
|
||||
->call('save')
|
||||
->assertHasNoFormErrors();
|
||||
|
||||
$this->assertSame(2, $element->versions()->count());
|
||||
$this->assertSame('Für die Gruppe', $element->fresh()->description);
|
||||
|
||||
Livewire::test(ViewContentElement::class, ['record' => $element->getKey()])
|
||||
->assertSee('Fassung 1')
|
||||
->assertSee('Fassung 2')
|
||||
->assertSee('<video', false)
|
||||
->assertSee(route('content.file', $second), false)
|
||||
->callAction('deactivate', ['reason' => 'Veraltet'], ['version' => $first->id])
|
||||
->assertHasNoFormErrors()
|
||||
->assertSee('deaktiviert');
|
||||
|
||||
$first->refresh();
|
||||
|
||||
$this->assertSame(ContentVersionStatus::Gesperrt, $first->status);
|
||||
$this->assertSame('Veraltet', $first->block_reason);
|
||||
$this->assertSame(ContentVersionStatus::Bereit, $element->versions()->where('number', 2)->first()->status);
|
||||
|
||||
$this->actingAs($editor, 'staff')
|
||||
->get(route('content.file', $first))
|
||||
->assertOk();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Domain\Catalog\CompositionKind;
|
||||
use App\Domain\Catalog\ContentService;
|
||||
use App\Domain\Catalog\DomainRuleException;
|
||||
use App\Domain\Catalog\PillarService;
|
||||
use App\Filament\Resources\Pillars\PillarResource;
|
||||
use App\Filament\Support\CatalogReading;
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Tests\TestCase;
|
||||
|
||||
class PillarAssignmentTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_a_medium_can_belong_to_several_pillars_and_a_course_keeps_them(): void
|
||||
{
|
||||
$pillars = app(PillarService::class);
|
||||
$grenzen = $pillars->create('Grenzen');
|
||||
$hilfe = $pillars->create('Hilfe holen');
|
||||
$pillars->create('Alltag');
|
||||
$content = app(ContentService::class);
|
||||
$filmElement = $content->createElement('film', 'film', 'Film');
|
||||
$film = $content->publishElementVersion($filmElement, 'Text');
|
||||
$sheet = $content->publishElementVersion($content->createElement('pdf', 'pdf', 'Blatt'), 'Hinweis');
|
||||
$pillars->assign($filmElement, [$hilfe->id, $grenzen->id]);
|
||||
$pillars->assign($sheet->element, [$grenzen->id]);
|
||||
|
||||
$this->assertSame(1, $filmElement->versions()->count());
|
||||
$this->assertSame(['Grenzen', 'Hilfe holen'], $filmElement->pillars()->pluck('name')->all());
|
||||
|
||||
$exercise = $content->publishComposition(
|
||||
$content->createComposition('Übung Grenzen', CompositionKind::Uebung),
|
||||
[
|
||||
['role' => 'Film', 'target' => $film],
|
||||
['role' => 'Blatt', 'target' => $sheet],
|
||||
],
|
||||
);
|
||||
$course = $content->publishComposition(
|
||||
$content->createComposition('Kurs Alltag', CompositionKind::Kurs),
|
||||
[['role' => 'Übung', 'target' => $exercise]],
|
||||
);
|
||||
|
||||
$this->assertSame([
|
||||
'Film — Grenzen, Hilfe holen',
|
||||
'Blatt — Grenzen',
|
||||
], app(CatalogReading::class)->memberPillars($course->composition));
|
||||
|
||||
$editor = User::factory()->redakteur()->create();
|
||||
$editor->saveAppAuthenticationSecret('JBSWY3DPEHPK3PXP');
|
||||
|
||||
$this->actingAs($editor, 'staff')
|
||||
->get(PillarResource::getUrl('index'))
|
||||
->assertOk()
|
||||
->assertSee('Grenzen')
|
||||
->assertSee('Alltag')
|
||||
->assertSee('weitere hinzukommen');
|
||||
}
|
||||
|
||||
public function test_a_pillar_with_media_cannot_be_deleted(): void
|
||||
{
|
||||
$pillars = app(PillarService::class);
|
||||
$pillar = $pillars->create('Grenzen');
|
||||
$element = app(ContentService::class)->createElement('text', 'text', 'Hinweis');
|
||||
$pillars->assign($element, [$pillar->id]);
|
||||
|
||||
$this->expectException(DomainRuleException::class);
|
||||
|
||||
$pillars->delete($pillar);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user