From a7feef2cd22154fce6add4b4eee3630175d26718 Mon Sep 17 00:00:00 2001 From: Lars Date: Mon, 16 Nov 2026 14:03:22 +0100 Subject: [PATCH] Mache den Aufbau von Modulen und Programmen im Arbeitsplatz bedienbar. Co-authored-by: Cursor --- app/Filament/Pages/EditorialDesk.php | 132 +++ .../Compositions/CompositionKindResource.php | 12 +- .../Compositions/Pages/EditComposition.php | 1021 ++++++++++++----- .../Pages/ListCompositionKind.php | 6 +- app/Filament/Support/EditorialCatalog.php | 355 ++++++ .../EditorialPreviewController.php | 92 ++ .../filament/editorial/desk-page.blade.php | 55 + .../views/filament/editorial/edit.blade.php | 4 + .../views/filament/editorial/editor.blade.php | 251 ++++ .../editorial/preview-nodes.blade.php | 15 + .../filament/editorial/preview.blade.php | 47 + .../views/filament/editorial/styles.blade.php | 137 +++ routes/web.php | 4 + tests/Feature/EditorialEditorTest.php | 215 ++++ tests/Feature/MediaAdministrationTest.php | 50 +- 15 files changed, 2068 insertions(+), 328 deletions(-) create mode 100644 app/Filament/Pages/EditorialDesk.php create mode 100644 app/Filament/Support/EditorialCatalog.php create mode 100644 app/Http/Controllers/EditorialPreviewController.php create mode 100644 resources/views/filament/editorial/desk-page.blade.php create mode 100644 resources/views/filament/editorial/edit.blade.php create mode 100644 resources/views/filament/editorial/editor.blade.php create mode 100644 resources/views/filament/editorial/preview-nodes.blade.php create mode 100644 resources/views/filament/editorial/preview.blade.php create mode 100644 resources/views/filament/editorial/styles.blade.php create mode 100644 tests/Feature/EditorialEditorTest.php diff --git a/app/Filament/Pages/EditorialDesk.php b/app/Filament/Pages/EditorialDesk.php new file mode 100644 index 0000000..2e161ac --- /dev/null +++ b/app/Filament/Pages/EditorialDesk.php @@ -0,0 +1,132 @@ + + */ + public function entries(): array + { + $query = trim($this->query); + $needle = mb_strtolower($query); + $catalog = app(EditorialCatalog::class); + $rows = []; + + $compositions = Composition::query() + ->whereIn('kind', [CompositionKind::Kurs, CompositionKind::Uebung]) + ->with(['editorialContentKind', 'versions']) + ->orderBy('designation') + ->get(); + + foreach ($compositions as $composition) { + $kind = $composition->kind instanceof CompositionKind + ? $composition->kind + : CompositionKind::from((string) $composition->kind); + $label = $kind->deskLabel(); + + if ($this->kindFilter === 'programm' && $kind !== CompositionKind::Kurs) { + continue; + } + + if ($this->kindFilter === 'modul' && $kind !== CompositionKind::Uebung) { + continue; + } + + $title = $catalog->compositionTitle($composition); + $haystack = mb_strtolower($title.' '.$composition->designation.' '.(string) $composition->summary); + + if ($needle !== '' && ! str_contains($haystack, $needle)) { + continue; + } + + $rows[] = [ + 'title' => $title, + 'kind' => $label, + 'stand' => $catalog->stand($composition)['text'], + 'url' => EditorialCatalog::editUrl($composition), + 'summary' => (string) ($composition->summary ?? ''), + ]; + } + + return $rows; + } + + public function createProgram(): void + { + $this->create(CompositionKind::Kurs, $this->programName); + } + + public function createModule(): void + { + $this->create(CompositionKind::Uebung, $this->moduleName); + } + + private function create(CompositionKind $kind, string $name): void + { + $name = trim($name); + + if ($name === '') { + $this->feedback = 'Der Name fehlt.'; + + return; + } + + $composition = app(EditorialCatalog::class)->create($name, $kind); + $this->redirect(EditorialCatalog::editUrl($composition), navigate: false); + } +} diff --git a/app/Filament/Resources/Compositions/CompositionKindResource.php b/app/Filament/Resources/Compositions/CompositionKindResource.php index b8c0a87..2ea1fb4 100644 --- a/app/Filament/Resources/Compositions/CompositionKindResource.php +++ b/app/Filament/Resources/Compositions/CompositionKindResource.php @@ -5,6 +5,7 @@ use App\Domain\Catalog\Composition; use App\Domain\Catalog\CompositionKind; use App\Filament\Resources\ContentElements\ContentElementResource; +use App\Filament\Support\EditorialCatalog; use Filament\Resources\Resource; use Filament\Schemas\Schema; use Filament\Tables\Columns\TextColumn; @@ -41,13 +42,20 @@ public static function form(Schema $schema): Schema public static function table(Table $table): Table { return $table->columns([ - TextColumn::make('designation')->label('Bezeichnung')->searchable(), + TextColumn::make('designation') + ->label('Name') + ->formatStateUsing(fn (Composition $record): string => app(EditorialCatalog::class)->compositionTitle($record)) + ->description(fn (Composition $record): ?string => filled($record->display_title) && $record->display_title !== $record->designation ? $record->designation : null) + ->searchable(['designation', 'display_title', 'summary']), + TextColumn::make('stand') + ->label('Stand') + ->state(fn (Composition $record): string => app(EditorialCatalog::class)->stand($record)['text']), TextColumn::make('versions_count')->counts('versions')->label('Fassungen'), ]); } public static function getEloquentQuery(): Builder { - return parent::getEloquentQuery()->where('kind', static::kind()); + return parent::getEloquentQuery()->where('kind', static::kind())->with('versions'); } } diff --git a/app/Filament/Resources/Compositions/Pages/EditComposition.php b/app/Filament/Resources/Compositions/Pages/EditComposition.php index cf28593..1fda0f0 100644 --- a/app/Filament/Resources/Compositions/Pages/EditComposition.php +++ b/app/Filament/Resources/Compositions/Pages/EditComposition.php @@ -2,157 +2,154 @@ namespace App\Filament\Resources\Compositions\Pages; -use App\Domain\Catalog\ArticleRelease; use App\Domain\Catalog\Composition; use App\Domain\Catalog\CompositionDisplayRelease; use App\Domain\Catalog\CompositionKind; -use App\Domain\Catalog\CompositionMember; use App\Domain\Catalog\CompositionStructureReader; use App\Domain\Catalog\CompositionVersion; use App\Domain\Catalog\ContentElementVersion; use App\Domain\Catalog\ContentService; use App\Domain\Catalog\ContentVersionStatus; use App\Domain\Catalog\DomainRuleException; -use App\Domain\Catalog\EditorialContentKind; use App\Domain\Catalog\EditorialDimension; use App\Domain\Catalog\EditorialDimensionValue; use App\Domain\Catalog\IdentityDimension; use App\Domain\Catalog\IdentityDimensionValue; use App\Domain\Catalog\IdentityProfile; use App\Domain\Catalog\StructureNode; -use App\Filament\Resources\Combinations\CombinationResource; -use App\Filament\Resources\Courses\CourseResource; -use App\Filament\Resources\Exercises\ExerciseResource; -use App\Filament\Support\CatalogOptions; -use App\Filament\Support\CatalogReading; +use App\Filament\Support\EditorialCatalog; use App\Jobs\DeriveThumbnail; use App\Models\User; use Filament\Actions\Action; use Filament\Facades\Filament; -use Filament\Forms\Components\CheckboxList; -use Filament\Forms\Components\FileUpload; -use Filament\Forms\Components\Placeholder; -use Filament\Forms\Components\Repeater; -use Filament\Forms\Components\Select; -use Filament\Forms\Components\Textarea; -use Filament\Forms\Components\TextInput; -use Filament\Notifications\Notification; use Filament\Resources\Pages\EditRecord; -use Filament\Schemas\Schema; -use Filament\Support\Exceptions\Halt; +use Filament\Support\Enums\Width; use Illuminate\Contracts\Support\Htmlable; use Illuminate\Database\Eloquent\Model; -use Illuminate\Support\HtmlString; +use Livewire\Features\SupportFileUploads\TemporaryUploadedFile; +use Livewire\WithFileUploads; abstract class EditComposition extends EditRecord { - protected ?string $savedTitle = null; + use WithFileUploads; + + protected string $view = 'filament.editorial.edit'; + + public string $designation = ''; + + public string $displayTitle = ''; + + public string $summary = ''; + + public string $learningGoal = ''; + + public string $durationMinutes = ''; + + public string $materialNote = ''; + + public string $revisionNote = ''; + + public string $search = ''; + + public string $catalogScope = 'medien'; + + public bool $listCatalog = false; + + public ?int $selected = null; + + public string $panel = 'angaben'; + + public string $returnUrl = ''; + + public ?int $templateNumber = null; + + public string $feedback = ''; + + public string $newTextTitle = ''; + + public string $newTextBody = ''; + + public string $newModuleName = ''; + + public mixed $previewUpload = null; + + public ?string $thumbnailPath = null; + + public ?string $thumbnailError = null; + + /** @var list> */ + public array $members = []; + + /** @var list */ + public array $dimensionIds = []; + + public function mount(int|string $record): void + { + parent::mount($record); + + $this->loadEditor(); + $this->returnUrl = $this->safeReturn(request()->query('zurueck')); + $adopt = request()->query('uebernehmen'); + + if (is_string($adopt)) { + $this->addPart($adopt); + } + + $flashed = session('redaktion'); + + if (is_string($flashed) && $flashed !== '' && $this->feedback === '') { + $this->feedback = $flashed; + } + } + + public function getHeading(): string|Htmlable|null + { + $title = trim($this->displayTitle) !== '' ? trim($this->displayTitle) : trim($this->designation); + + return $title !== '' ? $title : parent::getHeading(); + } public function getSubheading(): string|Htmlable|null { - return 'Bausteine hinzufügen, gegen eine neuere Medienfassung tauschen oder aus der Liste nehmen. Speichern legt dafür eine neue Fassung an. Die bisherige Fassung bleibt und wird nicht nachträglich verändert.'; + return $this->hostKind()->deskExplanation().' '.$this->statusSentence(); } - public function form(Schema $schema): Schema + public function getMaxContentWidth(): Width|string|null { - return $schema->columns(1)->components([ - TextInput::make('designation')->label('Bezeichnung')->required(), - TextInput::make('display_title')->label('Anzeigetitel') - ->helperText('Erscheint in der Bibliothek. Leer lässt die Bezeichnung stehen.'), - Textarea::make('summary')->label('Kurzbeschreibung')->rows(3), - Textarea::make('learning_goal')->label('Lernziel')->rows(2) - ->helperText('Gehört zur Fassung. Eine Änderung legt eine neue Fassung an.'), - TextInput::make('duration_minutes')->label('Zeitbedarf in Minuten')->numeric()->minValue(1), - Textarea::make('material_note')->label('Materialbedarf')->rows(2), - Placeholder::make('status')->label('Stand')->content(fn (): HtmlString => new HtmlString(e($this->statusText()))), - Placeholder::make('outline')->label('Gliederung der aktuellen Fassung')->content(fn (): HtmlString => new HtmlString($this->outlineHtml())), - Select::make('kind')->label('Zusammenstellung')->options(CompositionKind::deskOptions())->required() - ->helperText('Programm, Modul oder fachliche Kombination. Die Inhaltsart steuert die Bibliothek. Die gespeicherte Herkunft bleibt bestehen.'), - Select::make('editorial_content_kind_id') - ->label('Inhaltsart') - ->options(fn (): array => EditorialContentKind::selectOptions()) - ->nullable() - ->helperText('Optional für Bibliothek und Website. Ändert weder die technische Art noch eine Fassung.'), - Placeholder::make('usage')->label('Verwendung')->content(function (): HtmlString { - $version = $this->currentReadyVersion(); - if ($version === null) { - return new HtmlString('Noch keine Fassung.'); - } - $lines = CompositionMember::query() - ->where('nested_composition_version_id', $version->id) - ->with('compositionVersion.composition') - ->get() - ->map(fn (CompositionMember $member): string => ($member->compositionVersion->composition->designation ?? 'Programm').', Rolle '.$member->role) - ->all(); - $articles = ArticleRelease::query() - ->where('root_composition_version_id', $version->id) - ->with('article') - ->get() - ->map(fn (ArticleRelease $release): string => 'Lizenzartikel '.$release->article->code.', Stand '.$release->number) - ->all(); - $lines = [...$lines, ...$articles]; + return Width::Full; + } - return new HtmlString($lines === [] ? 'In keinem anderen Programm und in keinem Lizenzartikel.' : implode('
', array_map(e(...), $lines))); - }), - CheckboxList::make('dimension_ids')->label('Fachliche Einordnung') - ->options(fn (): array => self::dimensionOptions()) - ->columns(1) - ->helperText('Wirkt auf die Suche in der Bibliothek und legt keine neue Fassung an.'), - FileUpload::make('thumbnail_upload')->label('Vorschaubild') - ->disk('cms_incoming')->directory('vorschau')->visibility('private')->image() - ->helperText('Ersetzt nur das Bild der Karte. Die Fassung und die Dateien bleiben unverändert.'), - Placeholder::make('history')->label('Aktuelle Fassung')->content(function (): HtmlString { - /** @var Composition $composition */ - $composition = $this->getRecord(); - $lines = app(CatalogReading::class)->compositionMembers($composition); - - return new HtmlString(collect($lines)->map(fn (string $line): string => e($line))->implode('
')); - }), - 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('
')); - }), - Repeater::make('members') - ->label('Bausteine der neuen Fassung') - ->schema([ - TextInput::make('role')->label('Rolle')->placeholder('Film, Merkblatt, Übung')->required(), - Select::make('target')->label('Vorhandener Inhalt')->required()->searchable() - ->options(fn (): array => CatalogOptions::assignmentTargets($this->getRecord()->getKey())) - ->helperText('Titel, Inhaltsart und Fassungsnummer. Es wird genau diese Fassung verwendet.'), - ]) - ->minItems(1) - ->reorderable() - ->addActionLabel('Baustein hinzufügen') - ->helperText('Eine Zeile entfernen nimmt den Baustein nur aus der neuen Fassung. Eine neuere Medienfassung gilt erst, wenn du sie hier auswählst.'), - TextInput::make('note')->label('Notiz zur neuen Fassung'), - ]); + protected function mutateFormDataBeforeFill(array $data): array + { + return []; } protected function getHeaderActions(): array { return [ + Action::make('preview') + ->label('Vorschau für Trainer') + ->url(fn (): ?string => $this->previewUrl()) + ->openUrlInNewTab() + ->visible(fn (): bool => $this->previewUrl() !== null), Action::make('displayRelease') ->label('Zur Anzeige freigeben') ->requiresConfirmation() + ->modalHeading('Diese Fassung zur Anzeige freigeben') + ->modalDescription('Freigegeben wird die zuletzt übernommene Fassung. Eine frühere Fassung bleibt unverändert. Ungespeicherte Änderungen am Aufbau sind nicht Teil dieser Freigabe.') ->visible(function (): bool { $version = $this->currentReadyVersion(); return $version !== null && ! app(CompositionDisplayRelease::class)->isReleased($version); }) ->action(function (): void { - $version = $this->currentReadyVersion(); - $actor = Filament::auth()->user(); - abort_unless($version !== null && $actor instanceof User, 403); - app(CompositionDisplayRelease::class)->release($version, $actor); - Notification::make()->title('Die aktuelle Fassung ist zur Anzeige freigegeben.')->success()->send(); + $this->releaseDisplay(); }), Action::make('displayRevoke') - ->label('Anzeigefreigabe zurücknehmen') + ->label('Anzeige zurücknehmen') ->color('danger') ->requiresConfirmation() + ->modalDescription('Nur die Anzeige dieser Fassung wird zurückgenommen. Der Inhalt der Fassung bleibt gespeichert.') ->visible(function (): bool { $version = $this->currentReadyVersion(); @@ -160,170 +157,590 @@ protected function getHeaderActions(): array }) ->action(function (): void { $version = $this->currentReadyVersion(); - $actor = Filament::auth()->user(); + $actor = $this->actor(); abort_unless($version !== null && $actor instanceof User, 403); app(CompositionDisplayRelease::class)->revoke($version, $actor); - Notification::make()->title('Die Anzeigefreigabe dieser Fassung ist zurückgenommen.')->success()->send(); + $this->feedback = 'Die Anzeige dieser Fassung ist zurückgenommen. Der Inhalt bleibt gespeichert.'; }), ]; } - protected function getSaveFormAction(): Action - { - return parent::getSaveFormAction()->label('Neue Fassung veröffentlichen'); - } - - protected function getSavedNotificationTitle(): ?string - { - return $this->savedTitle ?? 'Die neue Fassung ist veröffentlicht.'; - } - - /** - * @param array $data - * @return array - */ - protected function mutateFormDataBeforeFill(array $data): array + public function hostKind(): CompositionKind { /** @var Composition $composition */ $composition = $this->getRecord(); - $version = $composition->versions() - ->where('status', ContentVersionStatus::Bereit) - ->orderByDesc('number') - ->with('members') - ->first(); - $members = []; - - foreach ($version?->members ?? [] as $member) { - $target = $member->content_element_version_id - ? 'element:'.$member->content_element_version_id - : 'composition:'.$member->nested_composition_version_id; - $members[] = ['role' => $member->role, 'target' => $target]; - } - $kind = $composition->kind; - return [ - 'designation' => $composition->designation, - 'display_title' => $composition->display_title, - 'summary' => $composition->summary, - 'kind' => $kind instanceof CompositionKind ? $kind->value : $kind, - 'editorial_content_kind_id' => $composition->editorial_content_kind_id, - 'learning_goal' => $version?->learning_goal, - 'duration_minutes' => $version?->duration_minutes, - 'material_note' => $version?->material_note, - 'dimension_ids' => IdentityDimensionValue::query() - ->where('subject_type', $composition->getMorphClass()) - ->where('subject_id', $composition->id) - ->where('origin', 'direkt') - ->pluck('editorial_dimension_value_id') - ->all(), - 'members' => $members, - 'note' => null, - ]; + return $kind instanceof CompositionKind ? $kind : CompositionKind::from((string) $kind); + } + + public function hostLabel(): string + { + return $this->hostKind()->deskLabel(); + } + + public function isProgram(): bool + { + return $this->hostKind() === CompositionKind::Kurs; + } + + public function selfUrl(): string + { + return static::getResource()::getUrl('edit', ['record' => $this->getRecord()]); + } + + public function previewUrl(): ?string + { + $version = $this->currentReadyVersion(); + + if ($version === null) { + return null; + } + + return route('editorial.preview', ['composition' => $this->getRecord(), 'version' => $version]); + } + + public function previewUrlFor(int $versionId): ?string + { + $version = $this->ownedVersion($versionId); + + if ($version === null || $version->status !== ContentVersionStatus::Bereit) { + return null; + } + + return route('editorial.preview', ['composition' => $this->getRecord(), 'version' => $version]); } /** - * @param array $data + * @return list> */ - protected function handleRecordUpdate(Model $record, array $data): Model + public function hits(): array { - /** @var Composition $record */ - try { - $kind = CompositionKind::from($data['kind']); - $record->designation = trim((string) $data['designation']); - app(IdentityProfile::class)->fill($record, [ - 'display_title' => $data['display_title'] ?? null, - 'summary' => $data['summary'] ?? null, - ], auth()->user()); - $record->kind = $kind; - if (array_key_exists('editorial_content_kind_id', $data)) { - $record->editorial_content_kind_id = filled($data['editorial_content_kind_id'] ?? null) - ? (int) $data['editorial_content_kind_id'] - : null; - } - $thumbnail = is_string($data['thumbnail_upload'] ?? null) ? $data['thumbnail_upload'] : ''; - $record->save(); - if (array_key_exists('dimension_ids', $data)) { - $this->syncDimensions($record, array_map(intval(...), $data['dimension_ids'] ?? [])); - } - - $members = []; - - foreach ($data['members'] as $member) { - if (! is_string($member['target'] ?? null) || ! str_contains($member['target'], ':')) { - throw new DomainRuleException('Jeder Baustein braucht eine Fassung.'); - } - - [$type, $id] = explode(':', $member['target'], 2); - $target = $type === 'composition' - ? CompositionVersion::query()->findOrFail($id) - : ContentElementVersion::query()->findOrFail($id); - $members[] = ['role' => $member['role'], 'target' => $target]; - } - - $note = is_string($data['note'] ?? null) ? trim($data['note']) : ''; - $current = $this->currentReadyVersion(); - $didactic = [ - 'learning_goal' => $this->blankToNull(array_key_exists('learning_goal', $data) ? $data['learning_goal'] : $current?->learning_goal), - 'duration_minutes' => $this->minutes(array_key_exists('duration_minutes', $data) ? $data['duration_minutes'] : $current?->duration_minutes), - 'material_note' => $this->blankToNull(array_key_exists('material_note', $data) ? $data['material_note'] : $current?->material_note), - ]; - - if ($note !== '' || ! $this->sameMembers($record, $members) || $this->didacticChanged($current, $didactic)) { - $actor = Filament::auth()->user(); - app(ContentService::class)->publishComposition( - $record, - $members, - $actor instanceof User ? $actor : null, - $note !== '' ? $note : null, - $didactic, - ); - $this->savedTitle = 'Die neue Fassung ist veröffentlicht. Die bisherige Fassung bleibt erhalten.'; - } else { - $this->savedTitle = 'Bezeichnung und Art sind gespeichert. Die Bausteine sind unverändert, deshalb gibt es keine neue Fassung.'; - } - - if ($thumbnail !== '') { - DeriveThumbnail::dispatch('komposition', $record->id, $thumbnail); - } - } catch (DomainRuleException $exception) { - Notification::make()->title($exception->getMessage())->danger()->send(); - - throw new Halt; + if (trim($this->search) === '' && ! $this->listCatalog) { + return []; } - return $record; + return app(EditorialCatalog::class)->search( + $this->search, + $this->catalogScope, + (int) $this->getRecord()->getKey(), + ); } - protected function afterSave(): void + /** + * @return list + */ + public function versionChoices(): array { - $this->getRecord()->unsetRelations(); - $this->getRecord()->refresh(); - $this->fillForm(); + /** @var Composition $composition */ + $composition = $this->getRecord(); + $release = app(CompositionDisplayRelease::class); + $latest = $this->currentReadyVersion(); + $rows = []; + + foreach ($composition->versions()->orderByDesc('number')->get() as $version) { + $released = $version->status === ContentVersionStatus::Bereit && $release->isReleased($version); + $rows[] = [ + 'id' => $version->id, + 'number' => $version->number, + 'text' => 'Fassung '.$version->number + .($version->status === ContentVersionStatus::Bereit ? '' : ', nicht bereit') + .($released ? ', zur Anzeige freigegeben' : ''), + 'current' => $latest !== null && $latest->id === $version->id, + ]; + } + + return $rows; } - protected function getRedirectUrl(): ?string + /** + * @return list + */ + public function usageLines(): array + { + $version = $this->currentReadyVersion(); + + if ($version === null) { + return []; + } + + return app(EditorialCatalog::class)->usage($version); + } + + /** + * @return list}> + */ + public function dimensionGroups(): array + { + $groups = []; + + foreach (EditorialDimension::query()->with('values')->orderBy('label')->get() as $dimension) { + $values = []; + + foreach ($dimension->values as $value) { + $values[] = ['id' => $value->id, 'label' => $value->label]; + } + + if ($values !== []) { + $groups[] = ['label' => $dimension->label, 'values' => $values]; + } + } + + return $groups; + } + + /** + * @return list + */ + public function selectedAlternatives(): array + { + $member = $this->selectedMember(); + + if ($member === null) { + return []; + } + + return app(EditorialCatalog::class)->alternatives( + (string) ($member['identity'] ?? ''), + (int) $this->getRecord()->getKey(), + ); + } + + public function childrenOf(string $target): string + { + if (preg_match('/^composition:(\d+)$/', $target, $match) !== 1) { + return ''; + } + + $version = CompositionVersion::query()->find($match[1]); + + if (! $version instanceof CompositionVersion) { + return ''; + } + + $lines = []; + $this->childLines(app(CompositionStructureReader::class)->tree($version), $lines); + + return implode(' · ', $lines); + } + + /** + * @param list $nodes + * @param list $lines + */ + protected function childLines(array $nodes, array &$lines): void + { + foreach ($nodes as $node) { + $lines[] = $node->role.': '.$node->title; + $this->childLines($node->children, $lines); + } + } + + public function publishHint(): string + { + if ($this->members === []) { + return 'Eine Fassung braucht mindestens einen Bestandteil. Anzeige und Kurzbeschreibung kannst du schon speichern. Ein Film ist dafür nicht nötig.'; + } + + if (! $this->needsRevision()) { + return 'Lernziel, Zeit, Material und Aufbau sind unverändert. Es entsteht keine neue Fassung.'; + } + + return 'Übernehmen legt eine neue Fassung an. Die bisherige Fassung bleibt und wird nicht überschrieben.'; + } + + public function selectPart(int $index): void + { + if (! isset($this->members[$index])) { + return; + } + + $this->selected = $index; + $this->panel = 'bestandteil'; + } + + public function addPart(string $target): void + { + if (preg_match('/^(element|composition):\d+$/', $target) !== 1) { + $this->feedback = 'Dieser Bestandteil ist nicht verfügbar.'; + + return; + } + + foreach ($this->members as $index => $member) { + if (($member['target'] ?? '') === $target) { + $this->selected = $index; + $this->panel = 'bestandteil'; + $this->feedback = 'Diese Fassung ist schon enthalten.'; + + return; + } + } + + $row = app(EditorialCatalog::class)->rowForTarget($target, (int) $this->getRecord()->getKey()); + + if ($row === null) { + $this->feedback = 'Diese Fassung ist nicht bereit oder gehört zu diesem Eintrag.'; + + return; + } + + $row['role'] = app(EditorialCatalog::class)->defaultRole((string) $row['kind']); + $this->members[] = $row; + $this->members = array_values($this->members); + $this->selected = array_key_last($this->members); + $this->panel = 'bestandteil'; + $this->search = ''; + $this->feedback = $row['title'].' ist in den Aufbau übernommen. Die neue Fassung entsteht erst mit „Neue Fassung übernehmen“.'; + } + + public function removePart(int $index): void + { + if (! isset($this->members[$index])) { + return; + } + + unset($this->members[$index]); + $this->members = array_values($this->members); + $this->selected = null; + $this->panel = 'angaben'; + $this->feedback = 'Der Bestandteil ist aus dem Arbeitsstand genommen. Gespeichert ist das erst mit einer neuen Fassung.'; + } + + public function movePart(int $index, int $direction): void + { + $target = $index + $direction; + + if (! isset($this->members[$index], $this->members[$target])) { + return; + } + + $current = $this->members[$index]; + $this->members[$index] = $this->members[$target]; + $this->members[$target] = $current; + $this->members = array_values($this->members); + $this->selected = $target; + } + + public function useVersion(int $index, string $target): void + { + if (! isset($this->members[$index])) { + return; + } + + $row = app(EditorialCatalog::class)->rowForTarget($target, (int) $this->getRecord()->getKey(), allowSelf: true); + + if ($row === null || ($row['identity'] ?? '') !== ($this->members[$index]['identity'] ?? '')) { + $this->feedback = 'Diese Fassung passt nicht zu dem ausgewählten Bestandteil.'; + + return; + } + + $row['role'] = $this->members[$index]['role'] ?? $row['kind']; + $this->members[$index] = $row; + $this->feedback = $row['version_label'].' ist für diese Stelle ausgewählt. Übernehmen legt dafür eine neue Fassung an.'; + } + + public function loadTemplate(int $versionId): void + { + $version = $this->ownedVersion($versionId); + + if ($version === null || $version->status !== ContentVersionStatus::Bereit) { + $this->feedback = 'Diese Fassung kann nicht als Vorlage geladen werden.'; + + return; + } + + $this->applyVersion($version); + $this->templateNumber = $version->number; + $this->feedback = 'Fassung '.$version->number.' ist als Arbeitsstand geladen. Übernehmen legt eine neue Fassung an und lässt die geladene Fassung unverändert.'; + } + + public function addText(): void + { + $title = trim($this->newTextTitle); + $body = trim($this->newTextBody); + + if ($title === '' || $body === '') { + $this->feedback = 'Der Text braucht einen Titel und einen Inhalt.'; + + return; + } + + try { + $service = app(ContentService::class); + $element = $service->createElement('text', 'text', $title); + $version = $service->publishElementVersion($element, $body); + } catch (DomainRuleException $exception) { + $this->feedback = $exception->getMessage(); + + return; + } + + $this->newTextTitle = ''; + $this->newTextBody = ''; + $this->addPart('element:'.$version->id); + } + + public function startModule(): void + { + $name = trim($this->newModuleName); + + if ($name === '') { + $this->feedback = 'Das neue Modul braucht einen Namen.'; + + return; + } + + $composition = app(EditorialCatalog::class)->create($name, CompositionKind::Uebung); + $this->newModuleName = ''; + $url = EditorialCatalog::editUrl($composition).'?zurueck='.urlencode($this->selfUrl()); + $this->redirect($url, navigate: false); + } + + public function saveDisplay(): void { /** @var Composition $record */ $record = $this->getRecord(); - $kind = $record->kind instanceof CompositionKind ? $record->kind : CompositionKind::from((string) $record->kind); - $resource = match ($kind) { - CompositionKind::Kurs => CourseResource::class, - CompositionKind::Kombination => CombinationResource::class, - CompositionKind::Uebung => ExerciseResource::class, - }; + $name = trim($this->designation); - if ($resource !== static::getResource()) { - return $resource::getUrl('edit', ['record' => $record]); + if ($name === '') { + $this->feedback = 'Der Name fehlt.'; + + return; } - return null; + $record->designation = $name; + app(IdentityProfile::class)->fill($record, [ + 'display_title' => $this->displayTitle, + 'summary' => $this->summary, + ], $this->actor()); + $this->syncDimensions($record, array_map(intval(...), $this->dimensionIds)); + $record->refresh(); + $this->getRecord()->setRawAttributes($record->getAttributes()); + $this->feedback = 'Die Anzeige ist gespeichert. Die Fassung bleibt unverändert.'; + } + + public function savePreview(): void + { + if (! $this->previewUpload instanceof TemporaryUploadedFile) { + $this->feedback = 'Wähle zuerst eine Bilddatei.'; + + return; + } + + $extension = strtolower($this->previewUpload->getClientOriginalExtension()); + + if (! in_array($extension, ['png', 'jpg', 'jpeg', 'webp'], true)) { + $this->feedback = 'Das Vorschaubild muss eine Bilddatei sein.'; + + return; + } + + $path = $this->previewUpload->storeAs( + 'vorschau', + 'karte-'.bin2hex(random_bytes(4)).'.'.$extension, + 'cms_incoming', + ); + $this->previewUpload = null; + + if (! is_string($path)) { + $this->feedback = 'Das Vorschaubild wurde nicht übernommen.'; + + return; + } + + $this->storePreview($path); + } + + public function savePreviewImage(string $storedPath): void + { + $this->storePreview($storedPath); + } + + public function publishRevision(): bool + { + if ($this->members === []) { + $this->feedback = 'Eine Fassung braucht mindestens einen Bestandteil. Anzeige und Kurzbeschreibung kannst du schon speichern.'; + + return false; + } + + if (! $this->needsRevision()) { + $this->feedback = 'Die Fassung ist unverändert.'; + + return false; + } + + $minutes = $this->minutes($this->durationMinutes); + + if ($minutes === false) { + $this->feedback = 'Der Zeitbedarf ist eine Zahl von Minuten oder bleibt leer.'; + + return false; + } + + $payload = []; + + foreach (array_values($this->members) as $member) { + $role = trim((string) ($member['role'] ?? '')); + $target = (string) ($member['target'] ?? ''); + + if ($role === '' || preg_match('/^(element|composition):(\d+)$/', $target, $match) !== 1) { + $this->feedback = 'Jeder Bestandteil braucht eine Rolle und eine vorhandene Fassung.'; + + return false; + } + + $model = $match[1] === 'composition' + ? CompositionVersion::query()->find($match[2]) + : ContentElementVersion::query()->find($match[2]); + + if ($model === null) { + $this->feedback = 'Ein Bestandteil ist nicht mehr vorhanden.'; + + return false; + } + + $payload[] = ['role' => $role, 'target' => $model]; + } + + /** @var Composition $record */ + $record = $this->getRecord(); + $note = trim($this->revisionNote); + + try { + app(ContentService::class)->publishComposition( + $record, + $payload, + $this->actor(), + $note !== '' ? $note : null, + [ + 'learning_goal' => $this->blank($this->learningGoal), + 'duration_minutes' => $minutes, + 'material_note' => $this->blank($this->materialNote), + ], + ); + } catch (DomainRuleException $exception) { + $this->feedback = $exception->getMessage(); + + return false; + } + + $this->revisionNote = ''; + $this->templateNumber = null; + $this->loadEditor(); + $this->feedback = 'Die neue Fassung ist übernommen. Die bisherige Fassung bleibt erhalten.'; + + return true; + } + + public function returnAndInclude(): void + { + if ($this->returnUrl === '') { + return; + } + + if ($this->needsRevision()) { + if (! $this->publishRevision()) { + return; + } + } + + $version = $this->currentReadyVersion(); + $url = $this->returnUrl; + + if ($version === null) { + session()->flash('redaktion', 'Es gibt noch keine Fassung, deshalb wurde nichts eingebunden.'); + $this->redirect($url, navigate: false); + + return; + } + + $join = str_contains($url, '?') ? '&' : '?'; + $this->redirect($url.$join.'uebernehmen=composition:'.$version->id, navigate: false); } /** - * @param list $members + * @return array|null */ - private function currentReadyVersion(): ?CompositionVersion + public function selectedMember(): ?array + { + if ($this->selected === null) { + return null; + } + + return $this->members[$this->selected] ?? null; + } + + protected function loadEditor(): void + { + /** @var Composition $composition */ + $composition = $this->getRecord(); + $composition->refresh(); + $version = $this->currentReadyVersion(); + $this->designation = $composition->designation; + $this->displayTitle = (string) ($composition->display_title ?? ''); + $this->summary = (string) ($composition->summary ?? ''); + $this->thumbnailPath = $composition->thumbnail_path; + $this->thumbnailError = $composition->thumbnail_error; + $this->dimensionIds = IdentityDimensionValue::query() + ->where('subject_type', $composition->getMorphClass()) + ->where('subject_id', $composition->id) + ->where('origin', 'direkt') + ->pluck('editorial_dimension_value_id') + ->map(fn (mixed $id): string => (string) (int) $id) + ->all(); + $this->catalogScope = match ($this->hostKind()) { + CompositionKind::Kurs => 'module', + CompositionKind::Uebung => 'medien', + default => 'alles', + }; + + if ($version === null) { + $this->members = []; + $this->learningGoal = ''; + $this->durationMinutes = ''; + $this->materialNote = ''; + + return; + } + + $this->applyVersion($version); + } + + protected function applyVersion(CompositionVersion $version): void + { + $this->members = app(EditorialCatalog::class)->rows($version, (int) $this->getRecord()->getKey()); + $this->learningGoal = (string) ($version->learning_goal ?? ''); + $this->durationMinutes = $version->duration_minutes === null ? '' : (string) $version->duration_minutes; + $this->materialNote = (string) ($version->material_note ?? ''); + $this->selected = null; + $this->panel = 'angaben'; + } + + public function releaseDisplay(): void + { + $this->releaseCurrent(); + } + + protected function releaseCurrent(): void + { + $version = $this->currentReadyVersion(); + $actor = $this->actor(); + abort_unless($version !== null && $actor instanceof User, 403); + + if ($this->needsRevision()) { + $this->feedback = 'Übernimm zuerst die Änderungen. Freigegeben wird nur eine bereits übernommene Fassung.'; + + return; + } + + app(CompositionDisplayRelease::class)->release($version, $actor); + $this->feedback = 'Fassung '.$version->number.' ist zur Anzeige freigegeben. Frühere Fassungen bleiben erhalten.'; + } + + protected function currentReadyVersion(): ?CompositionVersion { /** @var Composition $composition */ $composition = $this->getRecord(); @@ -334,18 +751,28 @@ private function currentReadyVersion(): ?CompositionVersion ->first(); } - private function sameMembers(Composition $composition, array $members): bool + protected function ownedVersion(int $versionId): ?CompositionVersion { - $version = $composition->versions() - ->where('status', ContentVersionStatus::Bereit) - ->orderByDesc('number') - ->with('members') - ->first(); + /** @var Composition $composition */ + $composition = $this->getRecord(); - if ($version === null) { - return false; + return $composition->versions()->whereKey($versionId)->first(); + } + + protected function needsRevision(): bool + { + $current = $this->currentReadyVersion(); + + if ($current === null) { + return $this->members !== []; } + return ! $this->sameMembers($current) || $this->didacticChanged($current); + } + + protected function sameMembers(CompositionVersion $version): bool + { + $version->loadMissing('members'); $current = $version->members->map(function ($member): string { $target = $member->content_element_version_id ? 'element:'.$member->content_element_version_id @@ -354,44 +781,47 @@ private function sameMembers(Composition $composition, array $members): bool return $member->role.'|'.$target; })->all(); $next = array_values(array_map( - fn (array $member): string => $member['role'].'|'.($member['target'] instanceof ContentElementVersion ? 'element:' : 'composition:').$member['target']->id, - $members, + fn (array $member): string => trim((string) ($member['role'] ?? '')).'|'.($member['target'] ?? ''), + $this->members, )); return $current === $next; } - /** - * @param array{learning_goal: mixed, duration_minutes: mixed, material_note: mixed} $didactic - */ - private function didacticChanged(?CompositionVersion $version, array $didactic): bool + protected function didacticChanged(CompositionVersion $version): bool { - if ($version === null) { + $minutes = $this->minutes($this->durationMinutes); + + if ($minutes === false) { return true; } $storedMinutes = $version->duration_minutes === null ? null : (int) $version->duration_minutes; - return $version->learning_goal !== $didactic['learning_goal'] - || $version->material_note !== $didactic['material_note'] - || $storedMinutes !== $didactic['duration_minutes']; + return $version->learning_goal !== $this->blank($this->learningGoal) + || $version->material_note !== $this->blank($this->materialNote) + || $storedMinutes !== $minutes; } - private function minutes(mixed $value): ?int + protected function minutes(string $value): int|false|null { - if ($value === null || $value === '') { + $value = trim($value); + + if ($value === '') { return null; } - return (int) $value; - } - - private function blankToNull(mixed $value): ?string - { - if (! is_string($value)) { - return null; + if (preg_match('/^\d+$/', $value) !== 1) { + return false; } + $minutes = (int) $value; + + return $minutes > 0 ? $minutes : false; + } + + protected function blank(string $value): ?string + { $value = trim($value); return $value === '' ? null : $value; @@ -400,7 +830,7 @@ private function blankToNull(mixed $value): ?string /** * @param list $ids */ - private function syncDimensions(Composition $composition, array $ids): void + protected function syncDimensions(Composition $composition, array $ids): void { IdentityDimensionValue::query() ->where('subject_type', $composition->getMorphClass()) @@ -414,64 +844,69 @@ private function syncDimensions(Composition $composition, array $ids): void } } - /** - * @return array - */ - private static function dimensionOptions(): array + protected function storePreview(string $path): void { - $options = []; + if (! str_starts_with($path, 'vorschau/') || str_contains($path, '..')) { + $this->feedback = 'Das Vorschaubild wurde nicht übernommen.'; - foreach (EditorialDimension::query()->with('values')->orderBy('label')->get() as $dimension) { - foreach ($dimension->values as $value) { - $options[$value->id] = $dimension->label.': '.$value->label; - } + return; } - return $options; + /** @var Composition $record */ + $record = $this->getRecord(); + $before = $record->versions()->count(); + DeriveThumbnail::dispatch('komposition', $record->id, $path); + $record->refresh(); + $this->thumbnailPath = $record->thumbnail_path; + $this->thumbnailError = $record->thumbnail_error; + $this->feedback = $record->versions()->count() === $before && filled($record->thumbnail_path) + ? 'Das Vorschaubild ist gespeichert. Die Fassung bleibt unverändert.' + : ($record->thumbnail_error ?: 'Das Vorschaubild wurde nicht übernommen.'); } - private function statusText(): string + protected function statusSentence(): string { - /** @var Composition $composition */ - $composition = $this->getRecord(); $version = $this->currentReadyVersion(); if ($version === null) { - return 'Noch keine technisch bereite Fassung. Speichern legt die erste Fassung an.'; + return 'Noch keine Fassung.'; } $released = app(CompositionDisplayRelease::class)->isReleased($version); - $older = $composition->versions()->where('number', '<', $version->number)->orderBy('number')->pluck('number')->all(); - $history = $older === [] ? 'Es gibt keine ältere Fassung.' : 'Ältere Fassungen: '.implode(', ', $older).'.'; - return 'Fassung '.$version->number.' ist technisch bereit. ' - .($released ? 'Sie ist zur Anzeige freigegeben. ' : 'Sie ist noch nicht zur Anzeige freigegeben. ') - .$history; + return 'Zuletzt übernommen: Fassung '.$version->number.'. ' + .($released ? 'Sie ist zur Anzeige freigegeben.' : 'Sie ist noch nicht zur Anzeige freigegeben.'); } - private function outlineHtml(): string + protected function actor(): ?User { - $version = $this->currentReadyVersion(); + $actor = Filament::auth()->user(); - if ($version === null) { - return 'Die Gliederung erscheint, sobald eine Fassung bereit ist.'; + return $actor instanceof User ? $actor : null; + } + + protected function safeReturn(mixed $url): string + { + if (! is_string($url) || $url === '' || parse_url($url, PHP_URL_HOST)) { + return ''; } - $lines = []; - $this->outlineLines(app(CompositionStructureReader::class)->tree($version), 0, $lines); + $path = parse_url($url, PHP_URL_PATH); - return $lines === [] ? 'Diese Fassung hat noch keine Bestandteile.' : implode('
', array_map(e(...), $lines)); + if (! is_string($path) || ! str_starts_with($path, '/verwaltung/') || str_contains($path, '..')) { + return ''; + } + + $query = parse_url($url, PHP_URL_QUERY); + + return $path.(is_string($query) && $query !== '' ? '?'.$query : ''); } /** - * @param list $nodes - * @param list $lines + * @param array $data */ - private function outlineLines(array $nodes, int $depth, array &$lines): void + protected function handleRecordUpdate(Model $record, array $data): Model { - foreach ($nodes as $node) { - $lines[] = str_repeat('– ', $depth).$node->role.': '.$node->title; - $this->outlineLines($node->children, $depth + 1, $lines); - } + return $record; } } diff --git a/app/Filament/Resources/Compositions/Pages/ListCompositionKind.php b/app/Filament/Resources/Compositions/Pages/ListCompositionKind.php index 9a531ae..222a441 100644 --- a/app/Filament/Resources/Compositions/Pages/ListCompositionKind.php +++ b/app/Filament/Resources/Compositions/Pages/ListCompositionKind.php @@ -20,7 +20,11 @@ abstract protected function kind(): CompositionKind; public function getSubheading(): string|Htmlable|null { - return $this->kind()->deskExplanation(); + $desk = in_array($this->kind(), [CompositionKind::Kurs, CompositionKind::Uebung], true) + ? ' Programme und Module liegen gemeinsam auf dem Arbeitsplatz.' + : ''; + + return $this->kind()->deskExplanation().$desk; } protected function getHeaderActions(): array diff --git a/app/Filament/Support/EditorialCatalog.php b/app/Filament/Support/EditorialCatalog.php new file mode 100644 index 0000000..0ca593d --- /dev/null +++ b/app/Filament/Support/EditorialCatalog.php @@ -0,0 +1,355 @@ +> + */ + public function rows(CompositionVersion $version, int $exceptCompositionId): array + { + $version->loadMissing([ + 'members.contentElementVersion.element.editorialContentKind', + 'members.nestedCompositionVersion.composition.editorialContentKind', + ]); + $rows = []; + + foreach ($version->members as $member) { + $target = $member->content_element_version_id + ? 'element:'.$member->content_element_version_id + : 'composition:'.$member->nested_composition_version_id; + $row = $this->rowForTarget($target, $exceptCompositionId, allowSelf: true); + + if ($row === null) { + continue; + } + + $row['role'] = $member->role; + $rows[] = $row; + } + + return $rows; + } + + /** + * @return array|null + */ + public function rowForTarget(string $target, int $exceptCompositionId, bool $allowSelf = false): ?array + { + if (preg_match('/^(element|composition):(\d+)$/', $target, $match) !== 1) { + return null; + } + + if ($match[1] === 'element') { + $version = ContentElementVersion::query() + ->with('element.editorialContentKind') + ->find($match[2]); + + if (! $version instanceof ContentElementVersion || $version->status !== ContentVersionStatus::Bereit) { + return null; + } + + $element = $version->element; + $kind = $element->editorialContentKind?->label ?: $this->outputLabel((string) $element->output_class); + $title = filled($element->display_title) ? $element->display_title : $element->working_title; + + return [ + 'target' => 'element:'.$version->id, + 'title' => $title, + 'kind' => $kind, + 'version_label' => 'Fassung '.$version->number, + 'identity' => 'medium:'.$element->id, + 'open_url' => route('content.preview', $version), + 'open_label' => 'Medium ansehen', + 'edit_url' => null, + ]; + } + + $version = CompositionVersion::query() + ->with('composition.editorialContentKind') + ->find($match[2]); + + if (! $version instanceof CompositionVersion || $version->status !== ContentVersionStatus::Bereit) { + return null; + } + + if (! $allowSelf && (int) $version->composition_id === $exceptCompositionId) { + return null; + } + + $composition = $version->composition; + $kind = $composition->editorialContentKind?->label + ?: ($composition->kind instanceof CompositionKind ? $composition->kind->deskLabel() : 'Zusammenstellung'); + + return [ + 'target' => 'composition:'.$version->id, + 'title' => $this->compositionTitle($composition), + 'kind' => $kind, + 'version_label' => 'Fassung '.$version->number, + 'identity' => 'zusammenstellung:'.$composition->id, + 'open_url' => null, + 'open_label' => null, + 'edit_url' => self::editUrl($composition), + ]; + } + + /** + * @return list> + */ + public function search(string $query, string $scope, int $exceptCompositionId): array + { + $query = trim($query); + $like = '%'.str_replace(['%', '_'], ['', ''], $query).'%'; + $limit = $scope === 'alles' ? 20 : 40; + $rows = []; + + if ($scope !== 'module') { + $elements = ContentElementVersion::query() + ->where('status', ContentVersionStatus::Bereit) + ->with('element.editorialContentKind') + ->whereHas('element', function ($builder) use ($query, $like): void { + if ($query === '') { + return; + } + + $builder->where('working_title', 'like', $like) + ->orWhere('display_title', 'like', $like) + ->orWhere('summary', 'like', $like); + }) + ->orderByDesc('id') + ->limit($limit) + ->get(); + + foreach ($elements as $version) { + $row = $this->rowForTarget('element:'.$version->id, $exceptCompositionId); + + if ($row !== null) { + $rows[] = $row; + } + } + } + + if ($scope !== 'medien') { + $versions = CompositionVersion::query() + ->where('status', ContentVersionStatus::Bereit) + ->where('composition_id', '!=', $exceptCompositionId) + ->with('composition.editorialContentKind') + ->whereHas('composition', function ($builder) use ($scope, $query, $like): void { + if ($scope === 'module') { + $builder->where('kind', CompositionKind::Uebung); + } + + if ($query === '') { + return; + } + + $builder->where(function ($inner) use ($like): void { + $inner->where('designation', 'like', $like) + ->orWhere('display_title', 'like', $like) + ->orWhere('summary', 'like', $like); + }); + }) + ->orderByDesc('id') + ->limit($limit) + ->get(); + + foreach ($versions as $version) { + $row = $this->rowForTarget('composition:'.$version->id, $exceptCompositionId); + + if ($row !== null) { + $rows[] = $row; + } + } + } + + return array_slice($rows, 0, 40); + } + + /** + * @return list + */ + public function alternatives(string $identity, int $exceptCompositionId): array + { + if (preg_match('/^(medium|zusammenstellung):(\d+)$/', $identity, $match) !== 1) { + return []; + } + + $options = []; + + if ($match[1] === 'medium') { + $versions = ContentElementVersion::query() + ->where('content_element_id', $match[2]) + ->where('status', ContentVersionStatus::Bereit) + ->orderBy('number') + ->get(); + + foreach ($versions as $version) { + $options[] = [ + 'target' => 'element:'.$version->id, + 'label' => 'Fassung '.$version->number, + ]; + } + + return $options; + } + + if ((int) $match[2] === $exceptCompositionId) { + return []; + } + + $versions = CompositionVersion::query() + ->where('composition_id', $match[2]) + ->where('status', ContentVersionStatus::Bereit) + ->orderBy('number') + ->get(); + + foreach ($versions as $version) { + $options[] = [ + 'target' => 'composition:'.$version->id, + 'label' => 'Fassung '.$version->number, + ]; + } + + return $options; + } + + public function defaultRole(string $kind): string + { + $kind = mb_strtolower($kind); + + return match (true) { + str_contains($kind, 'film') => 'Film', + str_contains($kind, 'hör') || str_contains($kind, 'audio') => 'Hörstück', + str_contains($kind, 'modul') => 'Modul', + str_contains($kind, 'programm') => 'Programm', + str_contains($kind, 'text'), str_contains($kind, 'dokument'), str_contains($kind, 'merkblatt'), str_contains($kind, 'unterlage') => 'Unterlage', + default => 'Bestandteil', + }; + } + + /** + * @return list + */ + public function usage(CompositionVersion $version): array + { + $lines = []; + $parents = CompositionMember::query() + ->where('nested_composition_version_id', $version->id) + ->with('compositionVersion.composition') + ->get(); + + foreach ($parents as $member) { + $parent = $member->compositionVersion?->composition; + $name = $parent instanceof Composition ? $this->compositionTitle($parent) : 'Zusammenstellung'; + $lines[] = $name.', Rolle '.$member->role; + } + + $articles = ArticleRelease::query() + ->where('root_composition_version_id', $version->id) + ->with('article') + ->get(); + + foreach ($articles as $release) { + $lines[] = 'Lizenzartikel '.$release->article->code.', Stand '.$release->number; + } + + return $lines; + } + + /** + * @return array{text: string, number: int|null, released_number: int|null} + */ + public function stand(Composition $composition): array + { + $ready = $composition->versions + ->filter(fn (CompositionVersion $version): bool => $version->status === ContentVersionStatus::Bereit) + ->sortByDesc('number') + ->values(); + $latest = $ready->first(); + $release = app(CompositionDisplayRelease::class); + $released = $ready->first(fn (CompositionVersion $version): bool => $release->isReleased($version)); + + if (! $latest instanceof CompositionVersion) { + return [ + 'text' => 'Noch ohne Fassung', + 'number' => null, + 'released_number' => $released instanceof CompositionVersion ? $released->number : null, + ]; + } + + $text = 'Fassung '.$latest->number.($release->isReleased($latest) ? ', zur Anzeige freigegeben' : ', noch nicht freigegeben'); + + if ($released instanceof CompositionVersion && $released->number !== $latest->number) { + $text .= '. Angezeigt wird Fassung '.$released->number; + } + + return [ + 'text' => $text, + 'number' => $latest->number, + 'released_number' => $released instanceof CompositionVersion ? $released->number : null, + ]; + } + + public function create(string $designation, CompositionKind $kind): Composition + { + $composition = app(ContentService::class)->createComposition($designation, $kind); + $slug = match ($kind) { + CompositionKind::Kurs => 'programm', + CompositionKind::Uebung => 'modul', + default => null, + }; + $editorial = $slug === null ? null : EditorialContentKind::query()->where('slug', $slug)->first(); + + if ($editorial !== null) { + $composition->editorial_content_kind_id = $editorial->id; + $composition->save(); + } + + return $composition; + } + + public static function editUrl(Composition $composition): string + { + $kind = $composition->kind instanceof CompositionKind + ? $composition->kind + : CompositionKind::from((string) $composition->kind); + $resource = match ($kind) { + CompositionKind::Kurs => CourseResource::class, + CompositionKind::Kombination => CombinationResource::class, + CompositionKind::Uebung => ExerciseResource::class, + }; + + return $resource::getUrl('edit', ['record' => $composition]); + } + + public function compositionTitle(Composition $composition): string + { + return filled($composition->display_title) ? $composition->display_title : $composition->designation; + } + + public function outputLabel(string $outputClass): string + { + return match ($outputClass) { + 'film' => 'Film', + 'audio' => 'Hörstück', + 'bild' => 'Bild', + 'document', 'pdf' => 'Dokument', + default => 'Text', + }; + } +} diff --git a/app/Http/Controllers/EditorialPreviewController.php b/app/Http/Controllers/EditorialPreviewController.php new file mode 100644 index 0000000..390d019 --- /dev/null +++ b/app/Http/Controllers/EditorialPreviewController.php @@ -0,0 +1,92 @@ +authorizeStaff(); + + if ($version === null) { + $version = $composition->versions() + ->where('status', ContentVersionStatus::Bereit) + ->orderByDesc('number') + ->first(); + } + + abort_unless($version instanceof CompositionVersion, 404); + abort_unless((int) $version->composition_id === (int) $composition->id, 404); + abort_unless($version->status === ContentVersionStatus::Bereit, 404); + + $catalog = app(EditorialCatalog::class); + + return view('filament.editorial.preview', [ + 'title' => $catalog->compositionTitle($composition), + 'summary' => $composition->summary, + 'kind' => $composition->editorialContentKind?->label + ?? ($composition->kind?->deskLabel()), + 'learningGoal' => $version->learning_goal, + 'durationMinutes' => $version->duration_minutes, + 'materialNote' => $version->material_note, + 'number' => $version->number, + 'backUrl' => $catalog->editUrl($composition), + 'nodes' => array_map( + fn (StructureNode $node): array => $this->present($node, $catalog), + app(CompositionStructureReader::class)->tree($version), + ), + ]); + } + + /** + * @return array + */ + private function present(StructureNode $node, EditorialCatalog $catalog): array + { + $versionLabel = null; + $openUrl = null; + + if ($node->contentElementVersionId !== null) { + $version = ContentElementVersion::query()->find($node->contentElementVersionId); + $versionLabel = $version instanceof ContentElementVersion ? 'Fassung '.$version->number : null; + $openUrl = $version instanceof ContentElementVersion ? route('content.preview', $version) : null; + } + + if ($node->compositionVersionId !== null) { + $version = CompositionVersion::query()->find($node->compositionVersionId); + $versionLabel = $version instanceof CompositionVersion ? 'Fassung '.$version->number : $versionLabel; + } + + return [ + 'role' => $node->role, + 'title' => $node->title, + 'kind' => $node->editorialKindLabel ?: ($node->outputClass !== null ? $catalog->outputLabel($node->outputClass) : $node->technicalKindLabel), + 'version' => $versionLabel, + 'open_url' => $openUrl, + 'children' => array_map( + fn (StructureNode $child): array => $this->present($child, $catalog), + $node->children, + ), + ]; + } + + private function authorizeStaff(): void + { + $user = auth('staff')->user(); + abort_unless( + $user instanceof User && ($user->hasStaffRole(StaffRole::Redakteur) || $user->hasStaffRole(StaffRole::Katalogverwalter)), + 403, + ); + } +} diff --git a/resources/views/filament/editorial/desk-page.blade.php b/resources/views/filament/editorial/desk-page.blade.php new file mode 100644 index 0000000..77784bb --- /dev/null +++ b/resources/views/filament/editorial/desk-page.blade.php @@ -0,0 +1,55 @@ + + @include('filament.editorial.styles') +
+ @if ($this->feedback !== '') +

{{ $this->feedback }}

+ @endif +
+ + +
+
+ + + +
+ @if ($this->entries() === []) +

{{ trim($this->query) === '' ? 'Noch keine Programme oder Module.' : 'Nichts gefunden. Prüfe die Schreibweise oder lege einen neuen Eintrag an.' }}

+ @else + + @endif +
+
+

Neues Programm

+
+ + +
+ +
+
+

Neues Modul

+
+ + +
+ +
+
+
+
diff --git a/resources/views/filament/editorial/edit.blade.php b/resources/views/filament/editorial/edit.blade.php new file mode 100644 index 0000000..30de769 --- /dev/null +++ b/resources/views/filament/editorial/edit.blade.php @@ -0,0 +1,4 @@ + + @include('filament.editorial.styles') + @include('filament.editorial.editor') + diff --git a/resources/views/filament/editorial/editor.blade.php b/resources/views/filament/editorial/editor.blade.php new file mode 100644 index 0000000..09c9aa5 --- /dev/null +++ b/resources/views/filament/editorial/editor.blade.php @@ -0,0 +1,251 @@ +
+

Zum Arbeitsplatz

+ @if ($this->returnUrl !== '') +

+ Dieser Eintrag wurde aus einem anderen Aufbau geöffnet. + +

+ @endif + @if ($this->feedback !== '') +

{{ $this->feedback }}

+ @endif + @if ($this->templateNumber) +

Arbeitsstand nach Fassung {{ $this->templateNumber }}. Die gespeicherte Fassung bleibt, bis du eine neue übernimmst.

+ @endif + +
+
+

Aufbau

+ @if ($this->members === []) +

+ @if ($this->isProgram()) + Dieses Programm hat noch keinen Bestandteil. Suche ein Modul oder ein Medium und übernimm es. Die Datei wird nicht kopiert. + @else + Dieses Modul hat noch keinen Bestandteil. Suche ein vorhandenes Medium oder lege einen Text an. Ein Film ist nicht nötig. + @endif +

+ @else +
    + @foreach ($this->members as $index => $member) +
  1. + +
    + + +
    +
  2. + @endforeach +
+ @endif + +

Bestandteil suchen

+
+ + +
+
+ + + + +
+ @if ($this->hits() === [] && (trim($this->search) !== '' || $this->listCatalog)) +

Nichts gefunden.

+ @endif +
    + @foreach ($this->hits() as $hit) +
  • +
    + + {{ $hit['title'] }} + {{ $hit['kind'] }} · {{ $hit['version_label'] }} + +
    + +
  • + @endforeach +
+ +
+

Text anlegen und übernehmen

+

Der Text wird einmal angelegt und hier verwendet. Dieselbe Fassung kann später woanders wiederverwendet werden.

+
+ + +
+
+ + +
+ +
+ + @if ($this->isProgram()) +
+

Neues Modul

+

Du wechselst in das Modul und kehrst danach in dieses Programm zurück.

+
+ + +
+ +
+ @endif +
+ +
+
+ + + +
+ + @if ($this->panel === 'bestandteil' && $this->selectedMember()) + @php($member = $this->selectedMember()) +

{{ $member['title'] }}

+

{{ $member['kind'] }} · {{ $member['version_label'] }}

+
+ + +
+

Die Rolle gilt nur hier. Dasselbe Medium kann woanders eine andere Rolle haben.

+ @if (count($this->selectedAlternatives()) > 1) +

Fassung

+
+ @foreach ($this->selectedAlternatives() as $alternative) + + @endforeach +
+ @endif +
+ @if ($member['open_url']) + Medium ansehen + @endif + @if ($member['edit_url']) + Bestandteil bearbeiten + @endif + +
+ @elseif ($this->panel === 'fassungen') +

Fassungen

+ @if ($this->versionChoices() === []) +

Noch keine Fassung. Sie entsteht, sobald der Aufbau übernommen wird.

+ @else +
    + @foreach ($this->versionChoices() as $version) +
  • +
    + + {{ $version['text'] }} + @if ($version['current']) + Zuletzt übernommen + @endif + +
    +
    + + @if ($url = $this->previewUrlFor($version['id'])) + Vorschau + @endif +
    +
  • + @endforeach +
+ @endif +

Eine übernommene Fassung wird nicht überschrieben. Als Vorlage laden ändert nur den Arbeitsstand.

+ @else +

Angaben

+

Name, Anzeigetitel, Kurzbeschreibung, Einordnung und Vorschaubild gelten sofort und legen keine neue Fassung an.

+
+ + +
+
+ + +
+
+ + +
+ @foreach ($this->dimensionGroups() as $group) +
+ {{ $group['label'] }} + @foreach ($group['values'] as $value) + + @endforeach +
+ @endforeach +

+ @if ($this->thumbnailError) + {{ $this->thumbnailError }} + @elseif (filled($this->thumbnailPath)) + Ein Vorschaubild ist hinterlegt. Es gehört zur Anzeige, nicht zur Fassung. + @else + Noch kein Vorschaubild. + @endif +

+
+ + +
+
+ + +
+ +

Zur Fassung

+

Lernziel, Zeit und Material gehören zur Fassung. Eine Änderung legt eine neue Fassung an.

+
+ + +
+
+ + +
+
+ + +
+
+ + +
+

{{ $this->publishHint() }}

+ + @endif + + @if ($this->usageLines() !== []) +

Verwendung der letzten Fassung

+
    + @foreach ($this->usageLines() as $line) +
  • {{ $line }}
  • + @endforeach +
+ @endif + +
+ Was beim Speichern passiert +

Anzeigetitel, Kurzbeschreibung, Einordnung und Vorschaubild ändern die sichtbare Karte sofort. Sie erzeugen keine neue Inhaltsfassung.

+

Lernziel, Zeit, Material, Rollen und die Reihenfolge erzeugen eine neue Fassung. Die bisherige bleibt für ältere Verweise erhalten.

+

Eine freigegebene Fassung wird nicht überschrieben. Die Freigabe gilt nur für die Fassung, die du ausdrücklich freigibst.

+

Ein Medium oder Modul, das auch woanders steckt, bleibt dort bei seiner bisherigen Fassung. Hier wird nur auf eine vorhandene Fassung verwiesen, nichts wird kopiert.

+

Die Vorschau zeigt den Aufbau der gespeicherten Fassung, wie ein Trainer ihn sieht. Die Datei selbst bleibt an die Lizenz gebunden.

+
+
+
+
diff --git a/resources/views/filament/editorial/preview-nodes.blade.php b/resources/views/filament/editorial/preview-nodes.blade.php new file mode 100644 index 0000000..0b5678f --- /dev/null +++ b/resources/views/filament/editorial/preview-nodes.blade.php @@ -0,0 +1,15 @@ +
    $nested ?? false])> + @foreach ($nodes as $node) +
  1. +

    {{ $node['role'] }}

    +

    {{ $node['title'] }}

    +

    {{ $node['kind'] }}@if ($node['version']) · {{ $node['version'] }}@endif

    + @if ($node['open_url']) +

    Medium ansehen

    + @endif + @if ($node['children'] !== []) + @include('filament.editorial.preview-nodes', ['nodes' => $node['children'], 'nested' => true]) + @endif +
  2. + @endforeach +
diff --git a/resources/views/filament/editorial/preview.blade.php b/resources/views/filament/editorial/preview.blade.php new file mode 100644 index 0000000..12a2ed1 --- /dev/null +++ b/resources/views/filament/editorial/preview.blade.php @@ -0,0 +1,47 @@ + + + + + + Vorschau: {{ $title }} + + + +
+ +

Zurück zur Bearbeitung

+ @if ($kind) +

{{ $kind }}

+ @endif +

{{ $title }}

+ @if (filled($summary)) +

{{ $summary }}

+ @endif + @if (filled($learningGoal)) +

Lernziel

+

{{ $learningGoal }}

+ @endif + @if ($durationMinutes) +

Zeit: {{ $durationMinutes }} Minuten

+ @endif + @if (filled($materialNote)) +

Material

+

{{ $materialNote }}

+ @endif +

Aufbau

+ @include('filament.editorial.preview-nodes', ['nodes' => $nodes]) +
+ + diff --git a/resources/views/filament/editorial/styles.blade.php b/resources/views/filament/editorial/styles.blade.php new file mode 100644 index 0000000..906f13b --- /dev/null +++ b/resources/views/filament/editorial/styles.blade.php @@ -0,0 +1,137 @@ + diff --git a/routes/web.php b/routes/web.php index ac02aa6..228a686 100644 --- a/routes/web.php +++ b/routes/web.php @@ -5,6 +5,7 @@ use App\Http\Controllers\Auth\RegistrationController; use App\Http\Controllers\Auth\SessionController; use App\Http\Controllers\ContentPreviewController; +use App\Http\Controllers\EditorialPreviewController; use App\Http\Controllers\Member\CheckoutController; use App\Http\Controllers\Member\LibraryController; use App\Http\Controllers\Member\MemberController; @@ -35,6 +36,9 @@ Route::post('/abmelden', [SessionController::class, 'destroy'])->middleware('auth')->name('logout'); +Route::get('/redaktion/aufbau/{composition}/{version?}', [EditorialPreviewController::class, 'show']) + ->middleware('auth:staff') + ->name('editorial.preview'); Route::get('/redaktion/inhalt/{version}', [ContentPreviewController::class, 'show']) ->middleware('auth:staff') ->name('content.preview'); diff --git a/tests/Feature/EditorialEditorTest.php b/tests/Feature/EditorialEditorTest.php new file mode 100644 index 0000000..7d63b10 --- /dev/null +++ b/tests/Feature/EditorialEditorTest.php @@ -0,0 +1,215 @@ +publishElementVersion($content->createElement('text', 'text', 'Blatt'), 'Hinweis'); + $module = $content->publishComposition( + $content->createComposition('Modul Abstand', CompositionKind::Uebung), + [['role' => 'Unterlage', 'target' => $sheet]], + ); + $content->publishComposition( + $content->createComposition('Programm Abstand', CompositionKind::Kurs), + [['role' => 'Modul', 'target' => $module]], + ); + $editor = $this->editor(); + + Livewire::actingAs($editor, 'staff') + ->test(EditorialDesk::class) + ->assertSee('Programm Abstand') + ->assertSee('Modul Abstand') + ->set('query', 'Programm') + ->assertSee('Programm Abstand') + ->assertDontSee('Modul Abstand') + ->set('query', 'kein-treffer') + ->assertSee('Nichts gefunden'); + } + + public function test_display_data_does_not_create_a_version_and_a_module_works_without_a_film(): void + { + $editor = $this->editor(); + $module = app(ContentService::class)->createComposition('Ohne Film', CompositionKind::Uebung); + + Livewire::actingAs($editor, 'staff') + ->test(EditExercise::class, ['record' => $module->id]) + ->assertSee('Ein Film ist nicht nötig') + ->set('displayTitle', 'Sichtbar ohne Film') + ->set('summary', 'Nur eine Beschreibung') + ->call('saveDisplay') + ->assertSet('feedback', 'Die Anzeige ist gespeichert. Die Fassung bleibt unverändert.') + ->set('learningGoal', 'Den Abstand erklären') + ->call('publishRevision') + ->assertSet('feedback', 'Eine Fassung braucht mindestens einen Bestandteil. Anzeige und Kurzbeschreibung kannst du schon speichern.') + ->set('newTextTitle', 'Hinweis ohne Film') + ->set('newTextBody', 'Zuerst den Abstand ansprechen.') + ->call('addText') + ->call('publishRevision'); + + $module->refresh(); + + $this->assertSame('Sichtbar ohne Film', $module->display_title); + $this->assertSame(1, $module->versions()->count()); + $this->assertSame('Den Abstand erklären', $module->versions()->first()->learning_goal); + $this->assertSame(1, $module->versions()->first()->members()->count()); + } + + public function test_reordering_reuses_a_medium_and_keeps_the_released_version(): void + { + $content = app(ContentService::class); + $sheet = $content->publishElementVersion( + $content->createElement('text', 'text', 'Trainerunterlage Abstand'), + 'Im Kurs zuerst den Abstand ansprechen.', + ); + $film = $content->publishElementVersion( + $content->createElement('film', 'film', 'Lara im Park'), + 'Film', + ); + $firstModule = $content->publishComposition( + $content->createComposition('Modul Abstand', CompositionKind::Uebung), + [ + ['role' => 'Unterlage', 'target' => $sheet], + ['role' => 'Film', 'target' => $film], + ], + null, + null, + ['learning_goal' => 'Abstand halten', 'duration_minutes' => 15], + ); + $secondModule = $content->publishComposition( + $content->createComposition('Modul Hilfe', CompositionKind::Uebung), + [['role' => 'Unterlage', 'target' => $sheet]], + ); + $programVersion = $content->publishComposition( + $content->createComposition('Programm Abstand', CompositionKind::Kurs), + [ + ['role' => 'Modul', 'target' => $firstModule], + ['role' => 'Modul', 'target' => $secondModule], + ], + ); + $editor = $this->editor(); + app(CompositionDisplayRelease::class)->release($programVersion, $editor); + app(CompositionDisplayRelease::class)->release($firstModule, $editor); + + $component = Livewire::actingAs($editor, 'staff') + ->test(EditCourse::class, ['record' => $programVersion->composition_id]) + ->assertSee('Modul Abstand') + ->assertSee('Modul Hilfe'); + $members = $component->get('members'); + $component->set('members', array_reverse($members)) + ->call('publishRevision') + ->assertSet('feedback', 'Die neue Fassung ist übernommen. Die bisherige Fassung bleibt erhalten.'); + + $versions = $programVersion->composition->versions()->with('members')->orderBy('number')->get(); + + $this->assertCount(2, $versions); + $this->assertSame($firstModule->id, $versions[0]->members[0]->nested_composition_version_id); + $this->assertSame($secondModule->id, $versions[1]->members[0]->nested_composition_version_id); + $this->assertTrue(app(CompositionDisplayRelease::class)->isReleased($versions[0])); + $this->assertFalse(app(CompositionDisplayRelease::class)->isReleased($versions[1])); + $this->assertSame($sheet->id, $firstModule->members()->first()->content_element_version_id); + $this->assertSame('Im Kurs zuerst den Abstand ansprechen.', $sheet->fresh()->body); + + Livewire::actingAs($editor, 'staff') + ->test(EditCourse::class, ['record' => $programVersion->composition_id]) + ->call('releaseDisplay'); + + $this->assertTrue(app(CompositionDisplayRelease::class)->isReleased($versions[0]->fresh())); + $this->assertTrue(app(CompositionDisplayRelease::class)->isReleased($versions[1]->fresh())); + $this->assertSame(1, $film->element->versions()->count()); + + $this->actingAs($editor, 'staff') + ->get(route('editorial.preview', ['composition' => $programVersion->composition, 'version' => $versions[1]])) + ->assertOk() + ->assertSee('Vorschau für die Redaktion') + ->assertSee('Modul Hilfe') + ->assertSee('Lara im Park') + ->assertSee('Trainerunterlage Abstand'); + } + + public function test_a_new_module_returns_into_the_program(): void + { + $content = app(ContentService::class); + $sheet = $content->publishElementVersion($content->createElement('text', 'text', 'Blatt'), 'Hinweis'); + $program = $content->publishComposition( + $content->createComposition('Programm Abstand', CompositionKind::Kurs), + [['role' => 'Unterlage', 'target' => $sheet]], + ); + $editor = $this->editor(); + $programUrl = CourseResource::getUrl('edit', ['record' => $program->composition]); + + $created = Livewire::actingAs($editor, 'staff') + ->test(EditCourse::class, ['record' => $program->composition_id]) + ->set('newModuleName', 'UX-Prüfung Modul') + ->call('startModule'); + $module = Composition::query()->where('designation', 'UX-Prüfung Modul')->firstOrFail(); + + $this->assertSame(CompositionKind::Uebung, $module->kind); + + Livewire::actingAs($editor, 'staff') + ->test(EditExercise::class, ['record' => $module->id]) + ->set('returnUrl', $programUrl) + ->set('newTextTitle', 'UX-Prüfung Text') + ->set('newTextBody', 'Nur für die Bedienprüfung.') + ->call('addText') + ->call('returnAndInclude') + ->assertRedirect(); + + $version = $module->versions()->firstOrFail(); + + $this->actingAs($editor, 'staff') + ->get($programUrl.'?uebernehmen=composition:'.$version->id) + ->assertOk() + ->assertSee('UX-Prüfung Modul') + ->assertSee('ist in den Aufbau übernommen'); + + $this->assertSame(1, $program->composition->versions()->count()); + $this->assertSame($sheet->id, $program->fresh()->members()->first()->content_element_version_id); + } + + public function test_guests_cannot_open_the_trainer_preview(): void + { + $content = app(ContentService::class); + $sheet = $content->publishElementVersion($content->createElement('text', 'text', 'Blatt'), 'Hinweis'); + $version = $content->publishComposition( + $content->createComposition('Programm Abstand', CompositionKind::Kurs), + [['role' => 'Unterlage', 'target' => $sheet]], + ); + + $this->get(route('editorial.preview', ['composition' => $version->composition, 'version' => $version])) + ->assertRedirect(); + } + + private function editor(): User + { + $editor = User::factory()->redakteur()->create(); + $editor->saveAppAuthenticationSecret('JBSWY3DPEHPK3PXP'); + + return $editor; + } +} diff --git a/tests/Feature/MediaAdministrationTest.php b/tests/Feature/MediaAdministrationTest.php index 20ddfff..ef7c5b1 100644 --- a/tests/Feature/MediaAdministrationTest.php +++ b/tests/Feature/MediaAdministrationTest.php @@ -113,8 +113,8 @@ public function test_an_exercise_can_gain_and_drop_a_medium_without_losing_the_o $this->get(ExerciseResource::getUrl('edit', ['record' => $exercise->composition])) ->assertOk() ->assertSee('Merkblatt') - ->assertSee('Baustein hinzufügen') - ->assertSee('Neue Fassung veröffentlichen'); + ->assertSee('Bestandteil suchen') + ->assertSee('Neue Fassung übernehmen'); $this->get(CourseResource::getUrl('index'))->assertOk()->assertSee('Ein Programm aus Modulen'); $this->assertStringContainsString('Ein Kurs ist keine Übung', CompositionKind::Kurs->explanation()); @@ -122,16 +122,17 @@ public function test_an_exercise_can_gain_and_drop_a_medium_without_losing_the_o $this->get(ContentElementResource::getUrl('index'))->assertOk()->assertSee('Übungsfilm'); Livewire::test(EditExercise::class, ['record' => $exercise->composition_id]) - ->fillForm([ - 'designation' => 'Alltag üben', - 'kind' => 'uebung', - 'members' => [ - ['role' => 'Film', 'target' => 'element:'.$film->id], - ], - 'note' => 'Film statt Merkblatt', - ]) - ->call('save') - ->assertHasNoFormErrors(); + ->set('members', [[ + 'role' => 'Film', + 'target' => 'element:'.$film->id, + 'title' => 'Übungsfilm', + 'kind' => 'Film', + 'version_label' => 'Fassung 1', + 'identity' => 'medium:'.$film->content_element_id, + ]]) + ->set('revisionNote', 'Film statt Merkblatt') + ->call('publishRevision') + ->assertSet('feedback', 'Die neue Fassung ist übernommen. Die bisherige Fassung bleibt erhalten.'); $versions = $exercise->composition->versions()->with('members')->orderBy('number')->get(); @@ -141,16 +142,9 @@ public function test_an_exercise_can_gain_and_drop_a_medium_without_losing_the_o $this->assertSame('Film', $versions[1]->members->first()->role); Livewire::test(EditExercise::class, ['record' => $exercise->composition_id]) - ->fillForm([ - 'designation' => 'Alltag üben', - 'kind' => 'uebung', - 'learning_goal' => 'Den Abstand üben', - 'members' => [ - ['role' => 'Film', 'target' => 'element:'.$film->id], - ], - ]) - ->call('save') - ->assertHasNoFormErrors(); + ->set('learningGoal', 'Den Abstand üben') + ->call('publishRevision') + ->assertSet('feedback', 'Die neue Fassung ist übernommen. Die bisherige Fassung bleibt erhalten.'); $this->assertSame('Den Abstand üben', $exercise->composition->versions()->orderByDesc('number')->first()->learning_goal); $this->assertSame(3, $exercise->composition->versions()->count()); @@ -181,16 +175,8 @@ public function test_a_composition_preview_is_derived_without_a_new_version(): v $this->actingAs($editor, 'staff'); Livewire::test(EditExercise::class, ['record' => $exercise->composition_id]) - ->fillForm([ - 'designation' => 'Alltag üben', - 'kind' => 'uebung', - 'members' => [ - ['role' => 'Blatt', 'target' => 'element:'.$sheet->id], - ], - 'thumbnail_upload' => ['vorschau/karte.png'], - ]) - ->call('save') - ->assertHasNoFormErrors(); + ->call('savePreviewImage', 'vorschau/karte.png') + ->assertSet('feedback', 'Das Vorschaubild ist gespeichert. Die Fassung bleibt unverändert.'); $composition = $exercise->composition->fresh();