Halte die Rolle an dem Bestandteil, der gerade ausgewählt ist.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
42415dff51
commit
7eb50c8a8d
3 files changed
+69
-1
No files matched your search
@@ -57,6 +57,8 @@ abstract class EditComposition extends EditRecord
|
||||
|
||||
public ?int $selected = null;
|
||||
|
||||
public string $roleDraft = '';
|
||||
|
||||
public string $panel = 'angaben';
|
||||
|
||||
public string $returnUrl = '';
|
||||
@@ -355,8 +357,10 @@ public function selectPart(int $index): void
|
||||
return;
|
||||
}
|
||||
|
||||
$this->commitRoleDraft();
|
||||
$this->selected = $index;
|
||||
$this->panel = 'bestandteil';
|
||||
$this->syncRoleDraft();
|
||||
}
|
||||
|
||||
public function addPart(string $target): void
|
||||
@@ -390,6 +394,7 @@ public function addPart(string $target): void
|
||||
$this->members = array_values($this->members);
|
||||
$this->selected = array_key_last($this->members);
|
||||
$this->panel = 'bestandteil';
|
||||
$this->syncRoleDraft();
|
||||
$this->search = '';
|
||||
$this->feedback = $row['title'].' ist in den Aufbau übernommen. Die neue Fassung entsteht erst mit „Neue Fassung übernehmen“.';
|
||||
}
|
||||
@@ -403,12 +408,14 @@ public function removePart(int $index): void
|
||||
unset($this->members[$index]);
|
||||
$this->members = array_values($this->members);
|
||||
$this->selected = null;
|
||||
$this->roleDraft = '';
|
||||
$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
|
||||
{
|
||||
$this->commitRoleDraft();
|
||||
$target = $index + $direction;
|
||||
|
||||
if (! isset($this->members[$index], $this->members[$target])) {
|
||||
@@ -420,6 +427,7 @@ public function movePart(int $index, int $direction): void
|
||||
$this->members[$target] = $current;
|
||||
$this->members = array_values($this->members);
|
||||
$this->selected = $target;
|
||||
$this->syncRoleDraft();
|
||||
}
|
||||
|
||||
public function useVersion(int $index, string $target): void
|
||||
@@ -436,8 +444,10 @@ public function useVersion(int $index, string $target): void
|
||||
return;
|
||||
}
|
||||
|
||||
$this->commitRoleDraft();
|
||||
$row['role'] = $this->members[$index]['role'] ?? $row['kind'];
|
||||
$this->members[$index] = $row;
|
||||
$this->syncRoleDraft();
|
||||
$this->feedback = $row['version_label'].' ist für diese Stelle ausgewählt. Übernehmen legt dafür eine neue Fassung an.';
|
||||
}
|
||||
|
||||
@@ -560,6 +570,8 @@ public function savePreviewImage(string $storedPath): void
|
||||
|
||||
public function publishRevision(): bool
|
||||
{
|
||||
$this->commitRoleDraft();
|
||||
|
||||
if ($this->members === []) {
|
||||
$this->feedback = 'Eine Fassung braucht mindestens einen Bestandteil. Anzeige und Kurzbeschreibung kannst du schon speichern.';
|
||||
|
||||
@@ -716,9 +728,31 @@ protected function applyVersion(CompositionVersion $version): void
|
||||
$this->durationMinutes = $version->duration_minutes === null ? '' : (string) $version->duration_minutes;
|
||||
$this->materialNote = (string) ($version->material_note ?? '');
|
||||
$this->selected = null;
|
||||
$this->roleDraft = '';
|
||||
$this->panel = 'angaben';
|
||||
}
|
||||
|
||||
public function updatedRoleDraft(string $value): void
|
||||
{
|
||||
$this->commitRoleDraft($value);
|
||||
}
|
||||
|
||||
protected function commitRoleDraft(?string $value = null): void
|
||||
{
|
||||
if ($this->selected === null || ! isset($this->members[$this->selected])) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->members[$this->selected]['role'] = trim($value ?? $this->roleDraft);
|
||||
}
|
||||
|
||||
protected function syncRoleDraft(): void
|
||||
{
|
||||
$this->roleDraft = $this->selected !== null && isset($this->members[$this->selected])
|
||||
? (string) ($this->members[$this->selected]['role'] ?? '')
|
||||
: '';
|
||||
}
|
||||
|
||||
public function releaseDisplay(): void
|
||||
{
|
||||
$this->releaseCurrent();
|
||||
|
||||
@@ -116,7 +116,7 @@
|
||||
<p class="luf-meta">{{ $member['kind'] }} · {{ $member['version_label'] }}</p>
|
||||
<div class="luf-field">
|
||||
<label for="rolle">Rolle an dieser Stelle</label>
|
||||
<input id="rolle" type="text" wire:model="members.{{ $this->selected }}.role">
|
||||
<input id="rolle" type="text" wire:key="rolle-{{ $member['target'] }}" wire:model.blur="roleDraft">
|
||||
</div>
|
||||
<p class="luf-note">Die Rolle gilt nur hier. Dasselbe Medium kann woanders eine andere Rolle haben.</p>
|
||||
@if (count($this->selectedAlternatives()) > 1)
|
||||
|
||||
@@ -198,6 +198,40 @@ public function test_a_new_module_returns_into_the_program(): void
|
||||
$this->assertSame($sheet->id, $program->fresh()->members()->first()->content_element_version_id);
|
||||
}
|
||||
|
||||
public function test_a_role_change_stays_on_the_selected_part_when_the_order_changes(): void
|
||||
{
|
||||
$content = app(ContentService::class);
|
||||
$sheet = $content->publishElementVersion($content->createElement('text', 'text', 'Blatt'), 'Hinweis');
|
||||
$film = $content->publishElementVersion($content->createElement('film', 'film', 'Lara im Park'), 'Film');
|
||||
$program = $content->publishComposition(
|
||||
$content->createComposition('Programm Abstand', CompositionKind::Kurs),
|
||||
[
|
||||
['role' => 'Unterlage', 'target' => $sheet],
|
||||
['role' => 'Film', 'target' => $film],
|
||||
],
|
||||
);
|
||||
|
||||
Livewire::actingAs($this->editor(), 'staff')
|
||||
->test(EditCourse::class, ['record' => $program->composition_id])
|
||||
->call('selectPart', 1)
|
||||
->set('roleDraft', 'Film zum Einstieg')
|
||||
->assertSet('members.0.role', 'Unterlage')
|
||||
->assertSet('members.1.role', 'Film zum Einstieg')
|
||||
->call('movePart', 1, -1)
|
||||
->call('publishRevision')
|
||||
->assertSet('feedback', 'Die neue Fassung ist übernommen. Die bisherige Fassung bleibt erhalten.');
|
||||
|
||||
$versions = $program->composition->versions()->with('members')->orderBy('number')->get();
|
||||
|
||||
$this->assertCount(2, $versions);
|
||||
$this->assertSame('Unterlage', $versions[0]->members[0]->role);
|
||||
$this->assertSame('Film', $versions[0]->members[1]->role);
|
||||
$this->assertSame('Film zum Einstieg', $versions[1]->members[0]->role);
|
||||
$this->assertSame($film->id, $versions[1]->members[0]->content_element_version_id);
|
||||
$this->assertSame('Unterlage', $versions[1]->members[1]->role);
|
||||
$this->assertSame($sheet->id, $versions[1]->members[1]->content_element_version_id);
|
||||
}
|
||||
|
||||
public function test_guests_cannot_open_the_trainer_preview(): void
|
||||
{
|
||||
$content = app(ContentService::class);
|
||||
|
||||
Reference in new issue
Block a user