Compare commits
6
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8ffcf0fa33 | ||
|
|
f9b665d706 | ||
|
|
a7b1daefa2 | ||
|
|
3c809b6cc8 | ||
|
|
c30883472f | ||
|
|
e91c7f7ebb |
No files matched your search
@@ -28,6 +28,7 @@ class ContentElement extends Model
|
|||||||
'thumbnail_alt',
|
'thumbnail_alt',
|
||||||
'thumbnail_source',
|
'thumbnail_source',
|
||||||
'thumbnail_error',
|
'thumbnail_error',
|
||||||
|
'marker_draft',
|
||||||
'preview_path',
|
'preview_path',
|
||||||
'editorial_content_kind_id',
|
'editorial_content_kind_id',
|
||||||
'archived_at',
|
'archived_at',
|
||||||
@@ -40,6 +41,7 @@ protected function casts(): array
|
|||||||
return [
|
return [
|
||||||
'archived_at' => 'datetime',
|
'archived_at' => 'datetime',
|
||||||
'website_released_at' => 'datetime',
|
'website_released_at' => 'datetime',
|
||||||
|
'marker_draft' => 'array',
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace App\Domain\Catalog;
|
namespace App\Domain\Catalog;
|
||||||
|
|
||||||
|
use App\Domain\Media\FilmMarkers;
|
||||||
use App\Domain\Media\MediaRendition;
|
use App\Domain\Media\MediaRendition;
|
||||||
use App\Jobs\StoreContentFile;
|
use App\Jobs\StoreContentFile;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
@@ -58,6 +59,7 @@ public function publishElementVersion(
|
|||||||
}
|
}
|
||||||
|
|
||||||
$number = ((int) $element->versions()->max('number')) + 1;
|
$number = ((int) $element->versions()->max('number')) + 1;
|
||||||
|
$metadata = $this->withCarriedMarkers($element, $metadata);
|
||||||
$incoming = $metadata['incoming'] ?? null;
|
$incoming = $metadata['incoming'] ?? null;
|
||||||
$version = $element->versions()->create([
|
$version = $element->versions()->create([
|
||||||
'number' => $number,
|
'number' => $number,
|
||||||
@@ -82,6 +84,35 @@ public function publishElementVersion(
|
|||||||
return $version;
|
return $version;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Eine Fassung mit Datei übernimmt die Marken der bisherigen neuesten Fassung, wenn der Aufrufer keine nennt. Sonst
|
||||||
|
* ginge jede Fassung aus anderem Anlass (Text, Notiz, neue Datei) still ohne Marken hervor, weil die Aufrufer die
|
||||||
|
* Metadaten selbst zusammenstellen. Eine ausdrücklich genannte Liste, auch eine leere, gilt unverändert.
|
||||||
|
* Der Altwert `decision_seconds` wird dabei einmal zu einer Marke umgesetzt und nicht erneut geschrieben.
|
||||||
|
*
|
||||||
|
* @param array<string, mixed> $metadata
|
||||||
|
* @return array<string, mixed>
|
||||||
|
*/
|
||||||
|
private function withCarriedMarkers(ContentElement $element, array $metadata): array
|
||||||
|
{
|
||||||
|
$hasFile = (is_string($metadata['file'] ?? null) && $metadata['file'] !== '')
|
||||||
|
|| (is_string($metadata['incoming'] ?? null) && $metadata['incoming'] !== '');
|
||||||
|
|
||||||
|
if (! $hasFile || array_key_exists('markers', $metadata)) {
|
||||||
|
return $metadata;
|
||||||
|
}
|
||||||
|
|
||||||
|
$latest = $element->versions()->orderByDesc('number')->first();
|
||||||
|
$markers = FilmMarkers::ofVersion($latest);
|
||||||
|
|
||||||
|
if ($markers !== [] || FilmMarkers::hasMarkers($latest)) {
|
||||||
|
$metadata['markers'] = $markers;
|
||||||
|
unset($metadata['decision_seconds']);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $metadata;
|
||||||
|
}
|
||||||
|
|
||||||
public function draftElementVersion(
|
public function draftElementVersion(
|
||||||
ContentElement $element,
|
ContentElement $element,
|
||||||
?string $body = null,
|
?string $body = null,
|
||||||
|
|||||||
@@ -0,0 +1,243 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Domain\Media;
|
||||||
|
|
||||||
|
use App\Domain\Catalog\ContentElement;
|
||||||
|
use App\Domain\Catalog\ContentElementVersion;
|
||||||
|
use App\Domain\Catalog\DomainRuleException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Marken eines Films: Sprungmarken und Stopps an der Filmfassung (`metadata['markers']`).
|
||||||
|
*
|
||||||
|
* Eine Marke: t (Sekunden, auf 0,1 gerundet), label (Titel), stop (hält die Wiedergabe an), prompt (einfacher Text,
|
||||||
|
* optional). Kapitel sind Marken ohne stop. Eine Liste je Fassung, kein zweites Feld.
|
||||||
|
*
|
||||||
|
* Eine Stelle löst die Altlast auf: Der frühere Einzelwert `decision_seconds` gilt nur, solange die Fassung den
|
||||||
|
* Schlüssel `markers` nicht hat. Hat sie ihn (auch leer), zählt er allein, damit gelöschte Marken nicht zurückkehren.
|
||||||
|
*
|
||||||
|
* Prüfen und Reparieren sind getrennt: `normalize` lehnt Fehler ab (Speichern), `ofVersion` repariert gespeicherte
|
||||||
|
* Daten, damit eine beschädigte Liste nie eine Seite zerstört (Lesen).
|
||||||
|
*/
|
||||||
|
final class FilmMarkers
|
||||||
|
{
|
||||||
|
public const LEGACY_LABEL = 'Entscheidung';
|
||||||
|
|
||||||
|
public const MIN_GAP = 1.0;
|
||||||
|
|
||||||
|
public const MAX_MARKERS = 100;
|
||||||
|
|
||||||
|
public const MAX_LABEL = 120;
|
||||||
|
|
||||||
|
public const MAX_PROMPT = 1000;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Prüft und vereinheitlicht eine Liste zum Speichern.
|
||||||
|
*
|
||||||
|
* @return list<array{t: float, label: string, stop: bool, prompt: string}>
|
||||||
|
*
|
||||||
|
* @throws DomainRuleException
|
||||||
|
*/
|
||||||
|
public static function normalize(mixed $raw): array
|
||||||
|
{
|
||||||
|
if (! is_array($raw)) {
|
||||||
|
throw new DomainRuleException('Die Marken müssen als Liste vorliegen.');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (count($raw) > self::MAX_MARKERS) {
|
||||||
|
throw new DomainRuleException('Ein Film kann höchstens '.self::MAX_MARKERS.' Marken haben.');
|
||||||
|
}
|
||||||
|
|
||||||
|
$list = [];
|
||||||
|
|
||||||
|
foreach (array_values($raw) as $index => $entry) {
|
||||||
|
$list[] = self::one($entry, $index + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
usort($list, fn (array $a, array $b): int => $a['t'] <=> $b['t']);
|
||||||
|
|
||||||
|
for ($i = 1; $i < count($list); $i++) {
|
||||||
|
if ($list[$i]['t'] - $list[$i - 1]['t'] < self::MIN_GAP - 1e-9) {
|
||||||
|
throw new DomainRuleException(
|
||||||
|
'Zwei Marken brauchen mindestens '.self::format(self::MIN_GAP).' Sekunde Abstand ('
|
||||||
|
.self::format($list[$i - 1]['t']).' s und '.self::format($list[$i]['t']).' s).',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $list;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Marken, die zu einer Fassung gehören, so wie sie angezeigt und ausgeliefert werden.
|
||||||
|
*
|
||||||
|
* @return list<array{t: float, label: string, stop: bool, prompt: string}>
|
||||||
|
*/
|
||||||
|
public static function ofVersion(?ContentElementVersion $version): array
|
||||||
|
{
|
||||||
|
$metadata = is_array($version?->metadata) ? $version->metadata : [];
|
||||||
|
|
||||||
|
if (array_key_exists('markers', $metadata)) {
|
||||||
|
return is_array($metadata['markers']) ? self::repair($metadata['markers']) : [];
|
||||||
|
}
|
||||||
|
|
||||||
|
$legacy = $metadata['decision_seconds'] ?? null;
|
||||||
|
|
||||||
|
if (is_numeric($legacy) && (float) $legacy > 0) {
|
||||||
|
return [['t' => self::round((float) $legacy), 'label' => self::LEGACY_LABEL, 'stop' => true, 'prompt' => '']];
|
||||||
|
}
|
||||||
|
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Ob die Fassung die Marken ausdrücklich führt (auch als leere Liste). */
|
||||||
|
public static function hasMarkers(?ContentElementVersion $version): bool
|
||||||
|
{
|
||||||
|
return is_array($version?->metadata) && array_key_exists('markers', $version->metadata);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param list<array<string, mixed>> $a
|
||||||
|
* @param list<array<string, mixed>> $b
|
||||||
|
*/
|
||||||
|
public static function same(array $a, array $b): bool
|
||||||
|
{
|
||||||
|
return json_encode(self::repair($a)) === json_encode(self::repair($b));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Hinweis nach einer neuen Datei: Eine Fassung hat eine andere Datei als davor, und die Marken sind seither nicht
|
||||||
|
* mehr geändert worden (und nicht leer). Sie wurden nie gegen den neuen Film geprüft. Der Hinweis endet mit der
|
||||||
|
* nächsten Fassung, die die Marken ändert. Nichts davon wird gespeichert, es folgt aus den Fassungen.
|
||||||
|
*/
|
||||||
|
public static function fileChangedWithoutMarkers(ContentElement $element): bool
|
||||||
|
{
|
||||||
|
$versions = $element->versions()->orderByDesc('number')->get();
|
||||||
|
$latest = $versions->first();
|
||||||
|
|
||||||
|
if ($latest === null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$markers = self::ofVersion($latest);
|
||||||
|
|
||||||
|
if ($markers === []) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($versions->values() as $position => $version) {
|
||||||
|
// Spätere Fassungen haben die Marken schon einmal angefasst: dann ist der Hinweis erledigt.
|
||||||
|
if (! self::same(self::ofVersion($version), $markers)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$previous = $versions->get($position + 1);
|
||||||
|
|
||||||
|
if ($previous === null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Die Fassung mit anderer Datei: Ihre Marken gelten für den neuen Film, gleich ob sie vom alten stammen oder
|
||||||
|
// zusammen mit der Datei angepasst wurden. Es gibt keinen Zustand „geprüft“, nur die nächste Änderung.
|
||||||
|
if (self::fileOf($version) !== self::fileOf($previous)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Zeit wie angezeigt: ohne überflüssige Nachkommastelle, mit Komma.
|
||||||
|
*/
|
||||||
|
public static function format(float $seconds): string
|
||||||
|
{
|
||||||
|
$text = number_format(self::round($seconds), 1, ',', '');
|
||||||
|
|
||||||
|
return str_ends_with($text, ',0') ? substr($text, 0, -2) : $text;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function round(float $seconds): float
|
||||||
|
{
|
||||||
|
return round($seconds, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static function fileOf(ContentElementVersion $version): ?string
|
||||||
|
{
|
||||||
|
$file = is_array($version->metadata) ? ($version->metadata['file'] ?? null) : null;
|
||||||
|
|
||||||
|
return is_string($file) && $file !== '' ? $file : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array{t: float, label: string, stop: bool, prompt: string}
|
||||||
|
*/
|
||||||
|
private static function one(mixed $entry, int $number): array
|
||||||
|
{
|
||||||
|
if (! is_array($entry)) {
|
||||||
|
throw new DomainRuleException('Marke '.$number.' ist keine gültige Marke.');
|
||||||
|
}
|
||||||
|
|
||||||
|
$time = $entry['t'] ?? null;
|
||||||
|
|
||||||
|
if (! is_numeric($time) || ! is_finite((float) $time) || (float) $time < 0) {
|
||||||
|
throw new DomainRuleException('Marke '.$number.': Die Zeit muss eine Zahl ab 0 Sekunden sein.');
|
||||||
|
}
|
||||||
|
|
||||||
|
$label = trim((string) ($entry['label'] ?? ''));
|
||||||
|
|
||||||
|
if ($label === '' || mb_strlen($label) > self::MAX_LABEL) {
|
||||||
|
throw new DomainRuleException('Marke '.$number.': Der Titel braucht 1 bis '.self::MAX_LABEL.' Zeichen.');
|
||||||
|
}
|
||||||
|
|
||||||
|
$prompt = trim((string) ($entry['prompt'] ?? ''));
|
||||||
|
|
||||||
|
if (mb_strlen($prompt) > self::MAX_PROMPT) {
|
||||||
|
throw new DomainRuleException('Marke '.$number.': Der Text darf höchstens '.self::MAX_PROMPT.' Zeichen haben.');
|
||||||
|
}
|
||||||
|
|
||||||
|
return [
|
||||||
|
't' => self::round((float) $time),
|
||||||
|
'label' => $label,
|
||||||
|
'stop' => ($entry['stop'] ?? false) === true,
|
||||||
|
'prompt' => $prompt,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Lesen ohne Ausnahmen: Unbrauchbares entfällt, zu dichte Marken weichen der früheren.
|
||||||
|
*
|
||||||
|
* @param array<int|string, mixed> $raw
|
||||||
|
* @return list<array{t: float, label: string, stop: bool, prompt: string}>
|
||||||
|
*/
|
||||||
|
private static function repair(array $raw): array
|
||||||
|
{
|
||||||
|
$valid = [];
|
||||||
|
|
||||||
|
foreach ($raw as $entry) {
|
||||||
|
try {
|
||||||
|
$valid[] = self::one($entry, 0);
|
||||||
|
} catch (DomainRuleException) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
usort($valid, fn (array $a, array $b): int => $a['t'] <=> $b['t']);
|
||||||
|
$result = [];
|
||||||
|
|
||||||
|
foreach ($valid as $marker) {
|
||||||
|
$last = $result === [] ? null : $result[count($result) - 1];
|
||||||
|
|
||||||
|
if ($last !== null && self::MIN_GAP - 1e-9 > $marker['t'] - $last['t']) {
|
||||||
|
if ($marker['stop'] && ! $last['stop']) {
|
||||||
|
$result[count($result) - 1] = $marker;
|
||||||
|
}
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$result[] = $marker;
|
||||||
|
}
|
||||||
|
|
||||||
|
return array_slice($result, 0, self::MAX_MARKERS);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,127 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Domain\Media;
|
||||||
|
|
||||||
|
use App\Domain\Catalog\ContentElement;
|
||||||
|
use App\Domain\Catalog\DomainRuleException;
|
||||||
|
use Illuminate\Support\Carbon;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Arbeitsstand der Marken eines Films, bevor eine Fassung entsteht.
|
||||||
|
*
|
||||||
|
* Er liegt als Objekt in `content_elements.marker_draft`: { base_version, markers, saved_at }. `null` heißt: kein
|
||||||
|
* Arbeitsstand, es gelten die Marken der neuesten Fassung. Ein Arbeitsstand mit leerer Liste heißt ausdrücklich
|
||||||
|
* „alle Marken löschen“ und darf deshalb nie mit empty() oder filled() geprüft werden.
|
||||||
|
*
|
||||||
|
* Mitglieder sehen den Arbeitsstand nie. Er wird auch nicht gesondert protokolliert: Das Protokoll liefert die
|
||||||
|
* Fassung. `saved_at` dient als Marke gegen gleichzeitiges Speichern (nicht `updated_at` des Elements, das sich bei
|
||||||
|
* jedem Redaktionsspeichern ändert).
|
||||||
|
*/
|
||||||
|
class MarkerDraft
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @return array{base_version: int, markers: list<array<string, mixed>>, saved_at: string}|null
|
||||||
|
*/
|
||||||
|
public function current(ContentElement $element): ?array
|
||||||
|
{
|
||||||
|
$stored = ContentElement::query()->whereKey($element->getKey())->value('marker_draft');
|
||||||
|
|
||||||
|
return $this->read($stored);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Die Marken, mit denen die Redaktion gerade arbeitet: Arbeitsstand, sonst neueste Fassung.
|
||||||
|
*
|
||||||
|
* @return list<array<string, mixed>>
|
||||||
|
*/
|
||||||
|
public function effective(ContentElement $element): array
|
||||||
|
{
|
||||||
|
$draft = $this->current($element);
|
||||||
|
|
||||||
|
if ($draft !== null) {
|
||||||
|
return FilmMarkers::normalize($draft['markers']);
|
||||||
|
}
|
||||||
|
|
||||||
|
return FilmMarkers::ofVersion($element->versions()->orderByDesc('number')->first());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Speichert den Arbeitsstand. `$token` ist das `saved_at`, das der Aufrufer zuletzt gesehen hat (null: Er hat keinen
|
||||||
|
* Arbeitsstand gesehen). Hat inzwischen jemand anders gespeichert, wird abgelehnt.
|
||||||
|
*
|
||||||
|
* @return array{base_version: int, markers: list<array<string, mixed>>, saved_at: string}
|
||||||
|
*
|
||||||
|
* @throws DomainRuleException
|
||||||
|
*/
|
||||||
|
public function save(ContentElement $element, mixed $markers, ?string $token): array
|
||||||
|
{
|
||||||
|
if ($element->output_class !== 'film') {
|
||||||
|
throw new DomainRuleException('Nur Filme haben Marken.');
|
||||||
|
}
|
||||||
|
|
||||||
|
$normalized = FilmMarkers::normalize($markers);
|
||||||
|
|
||||||
|
return DB::transaction(function () use ($element, $normalized, $token): array {
|
||||||
|
$row = ContentElement::query()->whereKey($element->getKey())->lockForUpdate()->firstOrFail();
|
||||||
|
$existing = $this->read($row->getRawOriginal('marker_draft'));
|
||||||
|
|
||||||
|
if (($existing['saved_at'] ?? null) !== $token) {
|
||||||
|
throw new DomainRuleException('Die Marken wurden inzwischen von jemand anderem gespeichert. Lade die Seite neu und prüfe den aktuellen Stand.');
|
||||||
|
}
|
||||||
|
|
||||||
|
$draft = [
|
||||||
|
'base_version' => (int) $row->versions()->max('number'),
|
||||||
|
'markers' => $normalized,
|
||||||
|
'saved_at' => Carbon::now()->format('Y-m-d\TH:i:s.u'),
|
||||||
|
];
|
||||||
|
$row->forceFill(['marker_draft' => $draft])->save();
|
||||||
|
$element->setAttribute('marker_draft', $draft);
|
||||||
|
|
||||||
|
return $draft;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public function discard(ContentElement $element): void
|
||||||
|
{
|
||||||
|
ContentElement::query()->whereKey($element->getKey())->update(['marker_draft' => null]);
|
||||||
|
$element->setAttribute('marker_draft', null);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Räumt den Arbeitsstand ab, aber nur den, der gelesen wurde (`saved_at`). Hat inzwischen jemand neu gespeichert,
|
||||||
|
* bleibt dessen Stand erhalten.
|
||||||
|
*/
|
||||||
|
public function discardIf(ContentElement $element, string $savedAt): void
|
||||||
|
{
|
||||||
|
DB::transaction(function () use ($element, $savedAt): void {
|
||||||
|
$row = ContentElement::query()->whereKey($element->getKey())->lockForUpdate()->firstOrFail();
|
||||||
|
$existing = $this->read($row->getRawOriginal('marker_draft'));
|
||||||
|
|
||||||
|
if ($existing !== null && $existing['saved_at'] === $savedAt) {
|
||||||
|
$row->forceFill(['marker_draft' => null])->save();
|
||||||
|
$element->setAttribute('marker_draft', null);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array{base_version: int, markers: list<array<string, mixed>>, saved_at: string}|null
|
||||||
|
*/
|
||||||
|
private function read(mixed $stored): ?array
|
||||||
|
{
|
||||||
|
if (is_string($stored)) {
|
||||||
|
$stored = json_decode($stored, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! is_array($stored) || ! array_key_exists('markers', $stored) || ! is_array($stored['markers'])) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return [
|
||||||
|
'base_version' => (int) ($stored['base_version'] ?? 0),
|
||||||
|
'markers' => $stored['markers'],
|
||||||
|
'saved_at' => (string) ($stored['saved_at'] ?? ''),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -27,6 +27,7 @@
|
|||||||
use App\Filament\Support\EditorialCatalog;
|
use App\Filament\Support\EditorialCatalog;
|
||||||
use App\Filament\Support\ElementRevision;
|
use App\Filament\Support\ElementRevision;
|
||||||
use App\Filament\Support\ManagesEditorialSurface;
|
use App\Filament\Support\ManagesEditorialSurface;
|
||||||
|
use App\Filament\Support\ManagesFilmMarkers;
|
||||||
use App\Filament\Support\ManagesRichFields;
|
use App\Filament\Support\ManagesRichFields;
|
||||||
use App\Filament\Support\MediaLibrary;
|
use App\Filament\Support\MediaLibrary;
|
||||||
use App\Filament\Support\ReportsDomainRules;
|
use App\Filament\Support\ReportsDomainRules;
|
||||||
@@ -47,6 +48,7 @@
|
|||||||
class ViewContentElement extends ViewRecord
|
class ViewContentElement extends ViewRecord
|
||||||
{
|
{
|
||||||
use ManagesEditorialSurface;
|
use ManagesEditorialSurface;
|
||||||
|
use ManagesFilmMarkers;
|
||||||
use ManagesRichFields;
|
use ManagesRichFields;
|
||||||
use ReportsDomainRules;
|
use ReportsDomainRules;
|
||||||
use WithFileUploads;
|
use WithFileUploads;
|
||||||
@@ -132,6 +134,12 @@ public function mount(int|string $record): void
|
|||||||
|
|
||||||
$bereich = (string) request()->query('bereich', 'inhalt');
|
$bereich = (string) request()->query('bereich', 'inhalt');
|
||||||
$this->bereich = $this->normalBereich($bereich);
|
$this->bereich = $this->normalBereich($bereich);
|
||||||
|
|
||||||
|
// Die Markenbearbeitung braucht den Stand, den die Seite beim Öffnen sieht: Sie öffnet nur über den Reiter.
|
||||||
|
if ($this->bereich === 'marken') {
|
||||||
|
$this->bereich = 'inhalt';
|
||||||
|
}
|
||||||
|
|
||||||
$this->thumbnailAlt = (string) ($this->getRecord()->thumbnail_alt ?? '');
|
$this->thumbnailAlt = (string) ($this->getRecord()->thumbnail_alt ?? '');
|
||||||
$this->bildQuelle = $this->getRecord()->output_class === 'film' ? 'film' : 'upload';
|
$this->bildQuelle = $this->getRecord()->output_class === 'film' ? 'film' : 'upload';
|
||||||
$this->fillEditorial();
|
$this->fillEditorial();
|
||||||
@@ -149,6 +157,14 @@ public function mount(int|string $record): void
|
|||||||
public function updatedBereich(string $value): void
|
public function updatedBereich(string $value): void
|
||||||
{
|
{
|
||||||
$this->bereich = $this->normalBereich($value);
|
$this->bereich = $this->normalBereich($value);
|
||||||
|
|
||||||
|
if ($this->bereich === 'marken') {
|
||||||
|
if ($this->getRecord()->output_class === 'film') {
|
||||||
|
$this->openMarkers();
|
||||||
|
} else {
|
||||||
|
$this->bereich = 'inhalt';
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -159,7 +175,7 @@ public function updatedBereich(string $value): void
|
|||||||
public function normalBereich(string $value): string
|
public function normalBereich(string $value): string
|
||||||
{
|
{
|
||||||
return match ($value) {
|
return match ($value) {
|
||||||
'inhalt', 'vorschaubild', 'verwendung', 'vorschau', 'website' => $value,
|
'inhalt', 'vorschaubild', 'verwendung', 'vorschau', 'website', 'marken' => $value,
|
||||||
'fassungen' => 'inhalt',
|
'fassungen' => 'inhalt',
|
||||||
'beschreibung', 'praesentation', 'redaktion' => 'website',
|
'beschreibung', 'praesentation', 'redaktion' => 'website',
|
||||||
default => 'inhalt',
|
default => 'inhalt',
|
||||||
@@ -479,6 +495,8 @@ public function reviseAction(): Action
|
|||||||
// Vor dem Anlegen prüfen: danach gäbe es eine andere neueste Fassung.
|
// Vor dem Anlegen prüfen: danach gäbe es eine andere neueste Fassung.
|
||||||
$textOffen = $this->textUnsaved();
|
$textOffen = $this->textUnsaved();
|
||||||
$this->report(function () use ($data): string {
|
$this->report(function () use ($data): string {
|
||||||
|
// Ungespeicherte Markenzeilen gingen sonst still verloren.
|
||||||
|
$this->guardUnsavedMarkers();
|
||||||
/** @var ContentElement $element */
|
/** @var ContentElement $element */
|
||||||
$element = $this->getRecord();
|
$element = $this->getRecord();
|
||||||
|
|
||||||
|
|||||||
@@ -23,6 +23,7 @@
|
|||||||
use App\Domain\Catalog\RightsProfile;
|
use App\Domain\Catalog\RightsProfile;
|
||||||
use App\Domain\Catalog\RightsProfileVersion;
|
use App\Domain\Catalog\RightsProfileVersion;
|
||||||
use App\Domain\Catalog\StatusValue;
|
use App\Domain\Catalog\StatusValue;
|
||||||
|
use App\Domain\Media\FilmMarkers;
|
||||||
|
|
||||||
class CatalogReading
|
class CatalogReading
|
||||||
{
|
{
|
||||||
@@ -239,8 +240,13 @@ public function elementVersions(ContentElement $element): array
|
|||||||
$lines[] = 'Die Datei wird noch übernommen.';
|
$lines[] = 'Die Datei wird noch übernommen.';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_numeric($metadata['decision_seconds'] ?? null)) {
|
$markers = FilmMarkers::ofVersion($version);
|
||||||
$lines[] = 'Entscheidungsmarke bei '.(int) $metadata['decision_seconds'].' Sekunden';
|
|
||||||
|
if ($markers !== []) {
|
||||||
|
$stops = count(array_filter($markers, fn (array $marker): bool => $marker['stop']));
|
||||||
|
$lines[] = count($markers).(count($markers) === 1 ? ' Marke' : ' Marken')
|
||||||
|
.($stops > 0 ? ', davon '.$stops.' mit Stopp' : '').': '
|
||||||
|
.implode(', ', array_map(fn (array $marker): string => FilmMarkers::format($marker['t']).' s '.$marker['label'], $markers));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_string($metadata['error'] ?? null) && $metadata['error'] !== '') {
|
if (is_string($metadata['error'] ?? null) && $metadata['error'] !== '') {
|
||||||
|
|||||||
@@ -3,11 +3,12 @@
|
|||||||
namespace App\Filament\Support;
|
namespace App\Filament\Support;
|
||||||
|
|
||||||
use App\Domain\Catalog\ContentElement;
|
use App\Domain\Catalog\ContentElement;
|
||||||
use App\Domain\Catalog\ContentElementVersion;
|
|
||||||
use App\Domain\Catalog\ContentService;
|
use App\Domain\Catalog\ContentService;
|
||||||
use App\Domain\Catalog\DomainRuleException;
|
use App\Domain\Catalog\DomainRuleException;
|
||||||
use App\Domain\Catalog\EmbeddedImages;
|
use App\Domain\Catalog\EmbeddedImages;
|
||||||
use App\Domain\Catalog\FormattedText;
|
use App\Domain\Catalog\FormattedText;
|
||||||
|
use App\Domain\Media\FilmMarkers;
|
||||||
|
use App\Domain\Media\MarkerDraft;
|
||||||
use App\Filament\Resources\ContentElements\Pages\EditContentElement;
|
use App\Filament\Resources\ContentElements\Pages\EditContentElement;
|
||||||
use Filament\Forms\Components\Component;
|
use Filament\Forms\Components\Component;
|
||||||
use Filament\Forms\Components\TextInput;
|
use Filament\Forms\Components\TextInput;
|
||||||
@@ -32,24 +33,31 @@ public static function publish(ContentElement $record, array $data): string
|
|||||||
$metadata['file'] = $previousFile;
|
$metadata['file'] = $previousFile;
|
||||||
}
|
}
|
||||||
|
|
||||||
$decision = is_numeric($data['decision_seconds'] ?? null) ? (int) $data['decision_seconds'] : null;
|
// Marken: der Arbeitsstand, sonst die der neuesten Fassung. Der Arbeitsstand wird frisch gelesen, denn der
|
||||||
|
// Datensatz der Seite kann älter sein. Ohne Datei in der neuen Fassung gibt es keine Marken.
|
||||||
|
$drafts = app(MarkerDraft::class);
|
||||||
|
$draft = $drafts->current($record);
|
||||||
|
$hasFile = array_key_exists('incoming', $metadata) || array_key_exists('file', $metadata);
|
||||||
|
$latestMarkers = FilmMarkers::ofVersion($latest);
|
||||||
|
$markers = $draft !== null ? FilmMarkers::normalize($draft['markers']) : $latestMarkers;
|
||||||
|
$markersChanged = ! FilmMarkers::same($markers, $latestMarkers);
|
||||||
|
|
||||||
if ($decision !== null) {
|
if ($hasFile && ($draft !== null || $markers !== [] || FilmMarkers::hasMarkers($latest))) {
|
||||||
$metadata['decision_seconds'] = $decision;
|
$metadata['markers'] = $markers;
|
||||||
}
|
}
|
||||||
|
|
||||||
$body = is_string($data['body'] ?? null) ? (FormattedText::canonical($data['body']) ?: null) : null;
|
$body = is_string($data['body'] ?? null) ? (FormattedText::canonical($data['body']) ?: null) : null;
|
||||||
$note = is_string($data['change_note'] ?? null) ? $data['change_note'] : 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
|
$changed = $incoming !== null
|
||||||
|| $dropFile
|
|| $dropFile
|
||||||
|| ! FormattedText::same($body, $latest?->body)
|
|| ! FormattedText::same($body, $latest?->body)
|
||||||
|| $decision !== $previousDecision
|
|| $markersChanged
|
||||||
|| (is_string($note) && trim($note) !== '');
|
|| (is_string($note) && trim($note) !== '');
|
||||||
|
|
||||||
if (! $changed) {
|
if (! $changed) {
|
||||||
|
// Ein Arbeitsstand, der den Marken der Fassung gleicht, ist erledigt.
|
||||||
|
self::settle($drafts, $record, $draft, $hasFile);
|
||||||
|
|
||||||
return 'Text und Datei sind gleich geblieben, deshalb gibt es keine neue Fassung.';
|
return 'Text und Datei sind gleich geblieben, deshalb gibt es keine neue Fassung.';
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -58,6 +66,7 @@ public static function publish(ContentElement $record, array $data): string
|
|||||||
}
|
}
|
||||||
|
|
||||||
app(ContentService::class)->publishElementVersion($record, $body, $metadata, $note);
|
app(ContentService::class)->publishElementVersion($record, $body, $metadata, $note);
|
||||||
|
self::settle($drafts, $record, $draft, $hasFile || $dropFile);
|
||||||
|
|
||||||
return $incoming !== null
|
return $incoming !== null
|
||||||
? 'Die neue Fassung ist angelegt. Die Datei wird übernommen; die bisherige Fassung bleibt.'
|
? 'Die neue Fassung ist angelegt. Die Datei wird übernommen; die bisherige Fassung bleibt.'
|
||||||
@@ -77,11 +86,6 @@ public static function fields(ContentElement $element): array
|
|||||||
Toggle::make('drop_file')
|
Toggle::make('drop_file')
|
||||||
->label('Datei in der neuen Fassung nicht mehr verwenden')
|
->label('Datei in der neuen Fassung nicht mehr verwenden')
|
||||||
->visible(fn (): bool => is_string(self::fileOf($element))),
|
->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'),
|
TextInput::make('change_note')->label('Änderungsnotiz'),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
@@ -93,12 +97,16 @@ private static function fileOf(ContentElement $element): mixed
|
|||||||
return is_array($latest?->metadata) ? ($latest->metadata['file'] ?? null) : null;
|
return is_array($latest?->metadata) ? ($latest->metadata['file'] ?? null) : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static function decisionOf(?ContentElementVersion $version): ?int
|
/**
|
||||||
|
* Räumt den Arbeitsstand ab, der gerade übernommen oder als gleich erkannt wurde. Nur der Stand, der gelesen wurde:
|
||||||
|
* Hat inzwischen jemand neu gespeichert, bleibt dessen Stand erhalten.
|
||||||
|
*
|
||||||
|
* @param array{base_version: int, markers: list<array<string, mixed>>, saved_at: string}|null $draft
|
||||||
|
*/
|
||||||
|
private static function settle(MarkerDraft $drafts, ContentElement $record, ?array $draft, bool $applies): void
|
||||||
{
|
{
|
||||||
if (! is_array($version?->metadata) || ! is_numeric($version->metadata['decision_seconds'] ?? null)) {
|
if ($draft !== null && $applies) {
|
||||||
return null;
|
$drafts->discardIf($record, $draft['saved_at']);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (int) $version->metadata['decision_seconds'];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,160 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Filament\Support;
|
||||||
|
|
||||||
|
use App\Domain\Catalog\ContentElement;
|
||||||
|
use App\Domain\Catalog\ContentElementVersion;
|
||||||
|
use App\Domain\Catalog\DomainRuleException;
|
||||||
|
use App\Domain\Media\FilmMarkers;
|
||||||
|
use App\Domain\Media\MarkerDraft;
|
||||||
|
use App\Filament\Resources\ContentElements\ContentElementResource;
|
||||||
|
use App\Http\Controllers\ContentPreviewController;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reiter „Marken“ im Medienmanager: Sprungmarken und Stopps eines Films bearbeiten.
|
||||||
|
*
|
||||||
|
* Die Zeilen bleiben im Browser, bis „Marken speichern“ den Arbeitsstand am Element schreibt (MarkerDraft). Der
|
||||||
|
* Arbeitsstand ändert nichts, was Mitglieder sehen: Erst „Neue Fassung anlegen“ übernimmt ihn in eine Fassung.
|
||||||
|
* `markerToken` ist das `saved_at` des Arbeitsstands, den die Seite beim Öffnen gesehen hat, und schützt vor
|
||||||
|
* gleichzeitigem Speichern; `markerDirty` meldet der Seite ungespeicherte Zeilen, damit keine Fassung ohne sie entsteht.
|
||||||
|
*
|
||||||
|
* Die Seite arbeitet immer an der neuesten Fassung. Ältere Fassungen zeigen ihre Marken nur lesend.
|
||||||
|
*/
|
||||||
|
trait ManagesFilmMarkers
|
||||||
|
{
|
||||||
|
public ?string $markerToken = null;
|
||||||
|
|
||||||
|
public bool $markerDirty = false;
|
||||||
|
|
||||||
|
/** Beim Öffnen des Reiters: den Stand merken, den die Seite jetzt zeigt. */
|
||||||
|
protected function openMarkers(): void
|
||||||
|
{
|
||||||
|
$element = $this->getRecord();
|
||||||
|
$this->markerToken = $element->output_class === 'film'
|
||||||
|
? app(MarkerDraft::class)->current($element)['saved_at'] ?? null
|
||||||
|
: null;
|
||||||
|
$this->markerDirty = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param list<array<string, mixed>> $rows
|
||||||
|
* @return array{ok: bool, message: string, markers?: list<array<string, mixed>>, token?: ?string}
|
||||||
|
*/
|
||||||
|
public function saveMarkers(array $rows): array
|
||||||
|
{
|
||||||
|
abort_unless(ContentElementResource::editor(), 403);
|
||||||
|
$element = $this->getRecord();
|
||||||
|
|
||||||
|
try {
|
||||||
|
$draft = app(MarkerDraft::class)->save($element, $this->markerRows($rows), $this->markerToken);
|
||||||
|
} catch (DomainRuleException $exception) {
|
||||||
|
return ['ok' => false, 'message' => $exception->getMessage()];
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->markerToken = $draft['saved_at'];
|
||||||
|
$this->markerDirty = false;
|
||||||
|
|
||||||
|
return [
|
||||||
|
'ok' => true,
|
||||||
|
'message' => 'Der Arbeitsstand ist gespeichert. Mitglieder sehen ihn erst mit einer neuen Fassung und einem neuen Artikelstand.',
|
||||||
|
'markers' => $draft['markers'],
|
||||||
|
'token' => $draft['saved_at'],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array{ok: bool, message: string, markers?: list<array<string, mixed>>, token?: ?string}
|
||||||
|
*/
|
||||||
|
public function discardMarkers(): array
|
||||||
|
{
|
||||||
|
abort_unless(ContentElementResource::editor(), 403);
|
||||||
|
$element = $this->getRecord();
|
||||||
|
app(MarkerDraft::class)->discard($element);
|
||||||
|
$this->markerToken = null;
|
||||||
|
$this->markerDirty = false;
|
||||||
|
|
||||||
|
return [
|
||||||
|
'ok' => true,
|
||||||
|
'message' => 'Der Arbeitsstand ist verworfen. Es gelten wieder die Marken der neuesten Fassung.',
|
||||||
|
'markers' => app(MarkerDraft::class)->effective($element),
|
||||||
|
'token' => null,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Daten für den Reiter.
|
||||||
|
*
|
||||||
|
* @return array<string, mixed>
|
||||||
|
*/
|
||||||
|
public function markerData(): array
|
||||||
|
{
|
||||||
|
/** @var ContentElement $element */
|
||||||
|
$element = $this->getRecord();
|
||||||
|
$latest = $element->versions()->orderByDesc('number')->first();
|
||||||
|
$drafts = app(MarkerDraft::class);
|
||||||
|
$draft = $drafts->current($element);
|
||||||
|
$playback = $latest instanceof ContentElementVersion ? app(ContentPreviewController::class)->playback($latest) : null;
|
||||||
|
|
||||||
|
return [
|
||||||
|
'markerVersion' => $latest,
|
||||||
|
'markerPlayback' => $playback,
|
||||||
|
'markerRows' => $drafts->effective($element),
|
||||||
|
'markerHasDraft' => $draft !== null,
|
||||||
|
'markerDraftOlder' => $draft !== null && $latest instanceof ContentElementVersion && $draft['base_version'] !== $latest->number,
|
||||||
|
'markerDraftBase' => $draft['base_version'] ?? null,
|
||||||
|
'markerFileHint' => FilmMarkers::fileChangedWithoutMarkers($element),
|
||||||
|
// Bearbeiten geht, sobald die neueste Fassung eine Datei hat (auch noch nicht abspielbar: Zeiten lassen sich tippen).
|
||||||
|
'markerCanEdit' => ContentElementResource::editor()
|
||||||
|
&& $latest instanceof ContentElementVersion
|
||||||
|
&& is_array($latest->metadata)
|
||||||
|
&& (filled($latest->metadata['file'] ?? null) || filled($latest->metadata['incoming'] ?? null)),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Die Marken der gezeigten Fassung als Text für die Fassungsansicht (nur lesend). */
|
||||||
|
public function markerSummary(?ContentElementVersion $version): string
|
||||||
|
{
|
||||||
|
$markers = FilmMarkers::ofVersion($version);
|
||||||
|
|
||||||
|
if ($markers === []) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
return implode(', ', array_map(
|
||||||
|
fn (array $marker): string => FilmMarkers::format($marker['t']).' s '.$marker['label'].($marker['stop'] ? ' (Stopp)' : ''),
|
||||||
|
$markers,
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Verweigert das Anlegen einer Fassung, solange Zeilen ungespeichert sind: Sie gingen sonst still verloren. */
|
||||||
|
protected function guardUnsavedMarkers(): void
|
||||||
|
{
|
||||||
|
if ($this->markerDirty) {
|
||||||
|
throw new DomainRuleException('Die Marken haben ungespeicherte Änderungen. Speichere oder verwirf sie zuerst, sonst fehlen sie in der neuen Fassung.');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Zeilen aus dem Browser: Die Zeit darf mit Komma kommen, das Häkchen ist ein echter Wahrheitswert.
|
||||||
|
*
|
||||||
|
* @param list<array<string, mixed>> $rows
|
||||||
|
* @return list<array<string, mixed>>
|
||||||
|
*/
|
||||||
|
private function markerRows(array $rows): array
|
||||||
|
{
|
||||||
|
return array_map(function (mixed $row): mixed {
|
||||||
|
if (! is_array($row)) {
|
||||||
|
return $row;
|
||||||
|
}
|
||||||
|
|
||||||
|
$time = $row['t'] ?? null;
|
||||||
|
|
||||||
|
return [
|
||||||
|
't' => is_string($time) ? str_replace(',', '.', trim($time)) : $time,
|
||||||
|
'label' => $row['label'] ?? '',
|
||||||
|
'stop' => filter_var($row['stop'] ?? false, FILTER_VALIDATE_BOOLEAN),
|
||||||
|
'prompt' => $row['prompt'] ?? '',
|
||||||
|
];
|
||||||
|
}, array_values($rows));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
return new class extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Arbeitsstand der Marken eines Films, bevor eine Fassung entsteht. Nur ergänzend: Die freigegebenen Marken
|
||||||
|
* liegen unverändert in `content_element_versions.metadata`.
|
||||||
|
*/
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
Schema::table('content_elements', function (Blueprint $table) {
|
||||||
|
$table->json('marker_draft')->nullable()->after('thumbnail_error');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
Schema::table('content_elements', function (Blueprint $table) {
|
||||||
|
$table->dropColumn('marker_draft');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -11,7 +11,9 @@ # Umsetzungsplan: Zentraler Videoplayer (Website-Vollbild und Mitgliederbereich)
|
|||||||
| 0.1 Signaturerneuerung | **umgesetzt auf `feature/videoplayer-grundlagen` (01.12.2026), noch nicht auf `develop`.** Server: `config/media.php` (Reserve 60 min, Höchstdauer 720 min, Ersatzdauer 240 min; Env `MEDIA_STREAM_RESERVE_MINUTES`, `MEDIA_STREAM_MAX_MINUTES`, `MEDIA_STREAM_FALLBACK_MINUTES`), `StreamLifetime` (Filmlänge = Summe der `#EXTINF`-Werte der ersten Teilliste, keine Migration), Endpunkt `member.playback.renew` mit `DecideAccess` und Tupelprüfung, Nachweis nur wenn im Zeitfenster noch keiner steht (`DeliveryLog::writeUnlessRecent`). Client: `player/renewal.js`, `player/source.js`, `data-hls-renew`; Vitest (24 Tests) im Gate (`jstest`). **Nicht abgedeckt:** Dateimodus (Filme ohne HLS) und Download bleiben bei 10 Minuten (0.2/0.3); die Hauptliste auf der Seite gilt weiter 10 Minuten und wird bei 403 über den Endpunkt erneuert. Der iPhone-Weg (nativ, Wiederaufnahme bei Fehler) ist nur als Logik getestet. Tatsache zum Entzug: Jeder Abruf prüft `DecideAccess`, die längere Laufzeit verlängert die Nachlaufzeit nach Entzug nicht (Test `test_an_expired_segment_link_is_refused_and_a_revoked_grant_stops_a_valid_one_at_once`); damit entfällt die offene Frage der Nachlaufzeit in Nr. 10. |
|
| 0.1 Signaturerneuerung | **umgesetzt auf `feature/videoplayer-grundlagen` (01.12.2026), noch nicht auf `develop`.** Server: `config/media.php` (Reserve 60 min, Höchstdauer 720 min, Ersatzdauer 240 min; Env `MEDIA_STREAM_RESERVE_MINUTES`, `MEDIA_STREAM_MAX_MINUTES`, `MEDIA_STREAM_FALLBACK_MINUTES`), `StreamLifetime` (Filmlänge = Summe der `#EXTINF`-Werte der ersten Teilliste, keine Migration), Endpunkt `member.playback.renew` mit `DecideAccess` und Tupelprüfung, Nachweis nur wenn im Zeitfenster noch keiner steht (`DeliveryLog::writeUnlessRecent`). Client: `player/renewal.js`, `player/source.js`, `data-hls-renew`; Vitest (24 Tests) im Gate (`jstest`). **Nicht abgedeckt:** Dateimodus (Filme ohne HLS) und Download bleiben bei 10 Minuten (0.2/0.3); die Hauptliste auf der Seite gilt weiter 10 Minuten und wird bei 403 über den Endpunkt erneuert. Der iPhone-Weg (nativ, Wiederaufnahme bei Fehler) ist nur als Logik getestet. Tatsache zum Entzug: Jeder Abruf prüft `DecideAccess`, die längere Laufzeit verlängert die Nachlaufzeit nach Entzug nicht (Test `test_an_expired_segment_link_is_refused_and_a_revoked_grant_stops_a_valid_one_at_once`); damit entfällt die offene Frage der Nachlaufzeit in Nr. 10. |
|
||||||
| 0.2, 0.3 Dateimodus und Downloads | **umgesetzt (01.12.2026):** `fileResponse` nutzt `ServesByteRanges` (206/416, `Accept-Ranges`, Dateiname und `attachment` bleiben, Download lässt sich fortsetzen). Nachweis: ein vollständiger Abruf schreibt einen Eintrag, Teilabrufe innerhalb von 10 Minuten (Laufzeit der Adresse) nur, wenn noch keiner steht (`DeliveryLog::writeUnlessRecent`). Prüfsumme je Datei einmal (`FileChecksum`, gemerkt nach Pfad, Größe und Änderungszeit, beim Speichern vorgewärmt); ohne lesbare Datei `null`. **Abweichung vom Plan:** Der Wert liegt im Cache, nicht in `metadata['checksum']` (Fassungen sind unveränderlich, ein Nachtragen würde den Inhaltshash ändern); nach einem Cache-Verlust wird beim nächsten Abruf neu gerechnet. Sicht ungeprüft: Safari/iPhone im Dateimodus. |
|
| 0.2, 0.3 Dateimodus und Downloads | **umgesetzt (01.12.2026):** `fileResponse` nutzt `ServesByteRanges` (206/416, `Accept-Ranges`, Dateiname und `attachment` bleiben, Download lässt sich fortsetzen). Nachweis: ein vollständiger Abruf schreibt einen Eintrag, Teilabrufe innerhalb von 10 Minuten (Laufzeit der Adresse) nur, wenn noch keiner steht (`DeliveryLog::writeUnlessRecent`). Prüfsumme je Datei einmal (`FileChecksum`, gemerkt nach Pfad, Größe und Änderungszeit, beim Speichern vorgewärmt); ohne lesbare Datei `null`. **Abweichung vom Plan:** Der Wert liegt im Cache, nicht in `metadata['checksum']` (Fassungen sind unveränderlich, ein Nachtragen würde den Inhaltshash ändern); nach einem Cache-Verlust wird beim nächsten Abruf neu gerechnet. Sicht ungeprüft: Safari/iPhone im Dateimodus. |
|
||||||
| 0.8 Entscheidungsmarke | **teilweise:** toter Handler (`data-course-decision`, `data-course-restart`, `data-decision`) aus `app.js` und der ungenutzte Schlüssel `decision` in `LibraryController::show` entfernt. Das Feld `decision_seconds` im Verwaltungsformular (`ElementRevision`) und seine Anzeige (`CatalogReading`) bleiben bis zum Marker-Editor (Stufe 3) als Altwert; `CoursePlayerTest` bleibt bis dahin unverändert. Der Vollbild-Knopf im Mitgliederbereich nutzt jetzt `player/fullscreen.js` (vorher nur `requestFullscreen`, auf dem iPhone ohne Wirkung); auf dem Gerät nicht geprüft. |
|
| 0.8 Entscheidungsmarke | **teilweise:** toter Handler (`data-course-decision`, `data-course-restart`, `data-decision`) aus `app.js` und der ungenutzte Schlüssel `decision` in `LibraryController::show` entfernt. Das Feld `decision_seconds` im Verwaltungsformular (`ElementRevision`) und seine Anzeige (`CatalogReading`) bleiben bis zum Marker-Editor (Stufe 3) als Altwert; `CoursePlayerTest` bleibt bis dahin unverändert. Der Vollbild-Knopf im Mitgliederbereich nutzt jetzt `player/fullscreen.js` (vorher nur `requestFullscreen`, auf dem iPhone ohne Wirkung); auf dem Gerät nicht geprüft. |
|
||||||
| 0.4–0.6, 0.9, 1b, 3, 4 | nicht begonnen |
|
| 0.6 hls.js aufgeschoben laden | **umgesetzt (01.12.2026):** `player/lazy.js`. hls.js ist ein eigener Teil im Build (Hauptbündel 595 kB → 19,6 kB, gzip 186 → 6,5 kB; hls.js 579 kB nur bei Bedarf). Das Skript wird geladen, sobald ein Film sichtbar wird; die Quelle wird erst beim ersten Klick oder bei Leertaste/Eingabe gebunden und mit derselben Geste abgespielt (ein `<video controls>` ohne Quelle löst in Edge kein „play“ aus, deshalb wird die erste Bedienung im Capture-Schritt abgefangen). **Abweichung vom Plan:** nicht `autoStartLoad: false`, denn hls.js holt die Hauptliste bei `loadSource` trotzdem. **Verhaltensänderung:** Der Nachweis der Auslieferung entsteht beim ersten Abspielen, nicht beim Seitenaufruf (Zählweise, Nr. 10, mit dem Datenschutzbeauftragten abstimmen). Ohne Poster zeigt der Film vor dem Start eine leere Fläche. Ein spät gestarteter Film trifft eine abgelaufene Hauptliste; die Erneuerung deckt das ab (Test). In Vorschau und Auswahl (ohne Erneuerungsadresse) würde eine abgelaufene Hauptliste still scheitern. Geprüft: Vitest, Edge auf luf-test (13 Prüfungen). **Nicht geprüft:** iPhone/Safari (dort entscheidet `Hls.isSupported()`, der Start innerhalb der Geste ist nur im Edge-Fall belegt). |
|
||||||
|
| Markenlogik (`markers.js`, Teil von 1b) | **umgesetzt als reine Logik mit 33 Tests (01.12.2026), noch nicht an die Oberfläche angebunden.** Lesen und Prüfen, Altwert `decision_seconds`, Verfolger (Überquerung in kleinem Schritt, kein Auslösen beim Springen über oder auf eine Marke, kein erneuter Halt nach dem Fortsetzen, Betrachterschalter). Mutationsprobe: drei eingebaute Fehler werden erkannt. |
|
||||||
|
| 0.4, 0.5, 0.9, 1b (Rest), 3, 4 | nicht begonnen |
|
||||||
|
|
||||||
Ursprünglicher Stand: Vorschlag zur Freigabe; die Entscheidungen in Abschnitt 8 sind bis auf die genannten offen.
|
Ursprünglicher Stand: Vorschlag zur Freigabe; die Entscheidungen in Abschnitt 8 sind bis auf die genannten offen.
|
||||||
**Grundlage:** `docs/architektur/08_Medien_Streaming_Kennzeichnung.md` (§3, §5), `docs/architektur/medienzugriff-fuer-komponenten.md`, ADR-43, `docs/analysen/medienauslieferung-performance-2026-11-30.md` (im Folgenden „Performance-Analyse“, Befunde W1…, M1…, Maßnahmen A1…, B1…).
|
**Grundlage:** `docs/architektur/08_Medien_Streaming_Kennzeichnung.md` (§3, §5), `docs/architektur/medienzugriff-fuer-komponenten.md`, ADR-43, `docs/analysen/medienauslieferung-performance-2026-11-30.md` (im Folgenden „Performance-Analyse“, Befunde W1…, M1…, Maßnahmen A1…, B1…).
|
||||||
|
|||||||
+3
-1
@@ -8,6 +8,7 @@ import './inquiry-widget.js';
|
|||||||
import './member-nav.js';
|
import './member-nav.js';
|
||||||
import { canFullscreen, enterFullscreen } from './player/fullscreen.js';
|
import { canFullscreen, enterFullscreen } from './player/fullscreen.js';
|
||||||
import { bindLazySource, createHlsLoader } from './player/lazy.js';
|
import { bindLazySource, createHlsLoader } from './player/lazy.js';
|
||||||
|
import './player/marker-editor.js';
|
||||||
|
|
||||||
// hls.js wird erst bei Bedarf geladen (eigener Teil im Build) und der Film erst beim ersten Abspielen gebunden.
|
// hls.js wird erst bei Bedarf geladen (eigener Teil im Build) und der Film erst beim ersten Abspielen gebunden.
|
||||||
const hlsLoader = createHlsLoader();
|
const hlsLoader = createHlsLoader();
|
||||||
@@ -24,7 +25,8 @@ function attachPlayback(video) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
video.dataset.playbackReady = '1';
|
video.dataset.playbackReady = '1';
|
||||||
bindLazySource(video, { source, renewUrl: video.dataset.hlsRenew || null, loader: hlsLoader });
|
// Die Steuerung bleibt am Element, damit die Markenbearbeitung den Film ohne Klick binden und springen kann.
|
||||||
|
video.lufPlayer = bindLazySource(video, { source, renewUrl: video.dataset.hlsRenew || null, loader: hlsLoader });
|
||||||
}
|
}
|
||||||
|
|
||||||
function scanPlayback(root) {
|
function scanPlayback(root) {
|
||||||
|
|||||||
@@ -0,0 +1,86 @@
|
|||||||
|
/*
|
||||||
|
* Autostopp: verbindet ein <video> mit dem Markenverfolger (markers.js).
|
||||||
|
*
|
||||||
|
* Eine Umsetzung für alle Oberflächen: Die Vorschau der Redaktion nutzt sie jetzt, der Mitglieder-Player später. Die
|
||||||
|
* Oberfläche meldet sich über `onStop` (Karte mit Titel und Text zeigen) und `onResume` (Karte schließen) und ruft
|
||||||
|
* `resume()` für „Weiter“ auf.
|
||||||
|
*
|
||||||
|
* Beim Halt wird die Zeit auf die Marke gesetzt. timeupdate kommt etwa alle 250 ms, der Film läuft also bis zu einer
|
||||||
|
* Viertelsekunde über die Marke; das Zurücksetzen verhindert, dass der Halt hinter dem Bild liegt, das gemeint war.
|
||||||
|
* Das Zurücksetzen löst selbst ein „seeking“/„seeked“ aus; der Verfolger hält die Marke danach stumm (Landeschutz),
|
||||||
|
* damit „Weiter“ nicht sofort wieder anhält.
|
||||||
|
*/
|
||||||
|
import { createMarkerTracker } from './markers.js';
|
||||||
|
|
||||||
|
export function bindAutostop(video, markers, { autoStop = true, onStop = () => undefined, onResume = () => undefined } = {}) {
|
||||||
|
const tracker = createMarkerTracker(markers, { autoStop });
|
||||||
|
let stopped = null;
|
||||||
|
|
||||||
|
const handlers = {
|
||||||
|
timeupdate() {
|
||||||
|
const hit = tracker.update(video.currentTime);
|
||||||
|
|
||||||
|
if (!hit) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
stopped = hit;
|
||||||
|
video.pause();
|
||||||
|
video.currentTime = hit.t;
|
||||||
|
onStop(hit);
|
||||||
|
},
|
||||||
|
seeking() {
|
||||||
|
tracker.seeking();
|
||||||
|
},
|
||||||
|
seeked() {
|
||||||
|
tracker.seeked(video.currentTime);
|
||||||
|
},
|
||||||
|
play() {
|
||||||
|
if (stopped !== null) {
|
||||||
|
stopped = null;
|
||||||
|
onResume();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
Object.entries(handlers).forEach(([name, handler]) => video.addEventListener(name, handler));
|
||||||
|
|
||||||
|
return {
|
||||||
|
/** Die Marke, an der gerade angehalten wurde, sonst null. */
|
||||||
|
get stopped() {
|
||||||
|
return stopped;
|
||||||
|
},
|
||||||
|
/** „Weiter“: von der Marke aus weiterspielen. */
|
||||||
|
resume() {
|
||||||
|
if (stopped === null) {
|
||||||
|
return Promise.resolve();
|
||||||
|
}
|
||||||
|
|
||||||
|
const marker = stopped;
|
||||||
|
stopped = null;
|
||||||
|
onResume(marker);
|
||||||
|
|
||||||
|
return Promise.resolve(video.play?.()).catch(() => undefined);
|
||||||
|
},
|
||||||
|
/** Betrachterschalter „Automatische Stopps“. Ein ausgeschalteter Schalter gibt auch einen offenen Halt frei. */
|
||||||
|
setAutoStop(value) {
|
||||||
|
tracker.setAutoStop(value);
|
||||||
|
|
||||||
|
if (value !== true && stopped !== null) {
|
||||||
|
stopped = null;
|
||||||
|
onResume();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
get autoStop() {
|
||||||
|
return tracker.autoStop;
|
||||||
|
},
|
||||||
|
/** Neue Markenliste (zum Beispiel nach Bearbeitung in der Redaktion). */
|
||||||
|
setMarkers(next) {
|
||||||
|
tracker.setMarkers(next);
|
||||||
|
stopped = null;
|
||||||
|
},
|
||||||
|
destroy() {
|
||||||
|
Object.entries(handlers).forEach(([name, handler]) => video.removeEventListener(name, handler));
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -0,0 +1,158 @@
|
|||||||
|
import { describe, expect, it, vi } from 'vitest';
|
||||||
|
import { bindAutostop } from './autostop.js';
|
||||||
|
|
||||||
|
const stop = (t, label = 'Stopp') => ({ t, label, stop: true, prompt: '' });
|
||||||
|
|
||||||
|
/** Ein <video>, das Ereignisse so abgibt, wie der Browser es tut: Setzen der Zeit löst seeking und seeked aus. */
|
||||||
|
function fakeVideo() {
|
||||||
|
const listeners = {};
|
||||||
|
const video = {
|
||||||
|
_time: 0,
|
||||||
|
paused: false,
|
||||||
|
pauseCalls: 0,
|
||||||
|
play: vi.fn(() => { video.paused = false; fire('play'); return Promise.resolve(); }),
|
||||||
|
pause() { video.paused = true; video.pauseCalls += 1; },
|
||||||
|
get currentTime() { return video._time; },
|
||||||
|
set currentTime(value) { video._time = value; fire('seeking'); fire('seeked'); },
|
||||||
|
addEventListener(name, handler) { (listeners[name] ??= []).push(handler); },
|
||||||
|
removeEventListener(name, handler) { listeners[name] = (listeners[name] ?? []).filter((entry) => entry !== handler); },
|
||||||
|
listeners,
|
||||||
|
};
|
||||||
|
|
||||||
|
function fire(name) {
|
||||||
|
(listeners[name] ?? []).slice().forEach((handler) => handler({}));
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Läuft von `from` bis `to` in Schritten und meldet jedes Mal timeupdate (nur solange nicht pausiert). */
|
||||||
|
video.run = (from, to, step = 0.25) => {
|
||||||
|
video._time = from;
|
||||||
|
|
||||||
|
for (let time = from; time <= to + 1e-9 && !video.paused; time += step) {
|
||||||
|
video._time = Number(time.toFixed(3));
|
||||||
|
fire('timeupdate');
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
video.fire = fire;
|
||||||
|
|
||||||
|
return video;
|
||||||
|
}
|
||||||
|
|
||||||
|
describe('bindAutostop', () => {
|
||||||
|
it('hält an der Stoppmarke an, setzt die Zeit auf die Marke und meldet den Halt', () => {
|
||||||
|
const video = fakeVideo();
|
||||||
|
const onStop = vi.fn();
|
||||||
|
bindAutostop(video, [stop(10)], { onStop });
|
||||||
|
|
||||||
|
video.run(9, 12);
|
||||||
|
|
||||||
|
expect(video.paused).toBe(true);
|
||||||
|
expect(video.currentTime).toBe(10);
|
||||||
|
expect(onStop).toHaveBeenCalledTimes(1);
|
||||||
|
expect(onStop).toHaveBeenCalledWith(stop(10));
|
||||||
|
});
|
||||||
|
|
||||||
|
it('läuft bei „Weiter“ weiter und hält nicht erneut an derselben Marke', () => {
|
||||||
|
const video = fakeVideo();
|
||||||
|
const onResume = vi.fn();
|
||||||
|
const player = bindAutostop(video, [stop(10)], { onResume });
|
||||||
|
video.run(9, 12);
|
||||||
|
|
||||||
|
player.resume();
|
||||||
|
video.run(10.25, 14);
|
||||||
|
|
||||||
|
expect(video.play).toHaveBeenCalledTimes(1);
|
||||||
|
expect(onResume).toHaveBeenCalledTimes(1);
|
||||||
|
expect(video.paused).toBe(false);
|
||||||
|
expect(player.stopped).toBeNull();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('hält danach an der nächsten Marke an', () => {
|
||||||
|
const video = fakeVideo();
|
||||||
|
const onStop = vi.fn();
|
||||||
|
const player = bindAutostop(video, [stop(10, 'a'), stop(20, 'b')], { onStop });
|
||||||
|
video.run(9, 12);
|
||||||
|
|
||||||
|
player.resume();
|
||||||
|
video.run(10.25, 22);
|
||||||
|
|
||||||
|
expect(onStop.mock.calls.map(([marker]) => marker.label)).toEqual(['a', 'b']);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('schließt die Karte auch, wenn der Betrachter selbst auf Abspielen drückt', () => {
|
||||||
|
const video = fakeVideo();
|
||||||
|
const onResume = vi.fn();
|
||||||
|
const player = bindAutostop(video, [stop(10)], { onResume });
|
||||||
|
video.run(9, 12);
|
||||||
|
|
||||||
|
video.play();
|
||||||
|
|
||||||
|
expect(onResume).toHaveBeenCalledTimes(1);
|
||||||
|
expect(player.stopped).toBeNull();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('hält beim Springen über die Marke nicht an', () => {
|
||||||
|
const video = fakeVideo();
|
||||||
|
const onStop = vi.fn();
|
||||||
|
bindAutostop(video, [stop(10)], { onStop });
|
||||||
|
video.run(5, 6);
|
||||||
|
|
||||||
|
video.currentTime = 15;
|
||||||
|
video.run(15, 18);
|
||||||
|
|
||||||
|
expect(onStop).not.toHaveBeenCalled();
|
||||||
|
expect(video.paused).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('hält mit ausgeschaltetem Schalter nirgends an, und das Ausschalten gibt einen offenen Halt frei', () => {
|
||||||
|
const video = fakeVideo();
|
||||||
|
const onResume = vi.fn();
|
||||||
|
const player = bindAutostop(video, [stop(10, 'a'), stop(20, 'b')], { onResume });
|
||||||
|
video.run(9, 12);
|
||||||
|
expect(player.stopped?.label).toBe('a');
|
||||||
|
|
||||||
|
player.setAutoStop(false);
|
||||||
|
|
||||||
|
expect(player.stopped).toBeNull();
|
||||||
|
expect(onResume).toHaveBeenCalledTimes(1);
|
||||||
|
|
||||||
|
video.play();
|
||||||
|
video.run(10.25, 22);
|
||||||
|
expect(video.paused).toBe(false);
|
||||||
|
expect(player.autoStop).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('nimmt eine neue Markenliste an und vergisst den offenen Halt', () => {
|
||||||
|
const video = fakeVideo();
|
||||||
|
const player = bindAutostop(video, [stop(10)]);
|
||||||
|
video.run(9, 12);
|
||||||
|
|
||||||
|
player.setMarkers([stop(30)]);
|
||||||
|
|
||||||
|
expect(player.stopped).toBeNull();
|
||||||
|
video.play();
|
||||||
|
video.run(29.5, 31);
|
||||||
|
expect(video.paused).toBe(true);
|
||||||
|
expect(video.currentTime).toBe(30);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('wirkt nach destroy() nicht mehr', () => {
|
||||||
|
const video = fakeVideo();
|
||||||
|
const player = bindAutostop(video, [stop(10)]);
|
||||||
|
|
||||||
|
player.destroy();
|
||||||
|
video.run(9, 12);
|
||||||
|
|
||||||
|
expect(video.paused).toBe(false);
|
||||||
|
expect(Object.values(video.listeners).flat()).toHaveLength(0);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('lässt „Weiter“ ohne offenen Halt wirkungslos', async () => {
|
||||||
|
const video = fakeVideo();
|
||||||
|
const player = bindAutostop(video, [stop(10)]);
|
||||||
|
|
||||||
|
await player.resume();
|
||||||
|
|
||||||
|
expect(video.play).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -67,7 +67,7 @@ export function bindLazySource(video, {
|
|||||||
stopObserving();
|
stopObserving();
|
||||||
};
|
};
|
||||||
|
|
||||||
const finish = (Hls) => {
|
const finish = (Hls, play = true) => {
|
||||||
// Das Element kann während des Ladens entfernt worden sein (Seitenwechsel, Livewire): dann nichts binden.
|
// Das Element kann während des Ladens entfernt worden sein (Seitenwechsel, Livewire): dann nichts binden.
|
||||||
if (video.isConnected === false) {
|
if (video.isConnected === false) {
|
||||||
state = 'idle';
|
state = 'idle';
|
||||||
@@ -78,25 +78,38 @@ export function bindLazySource(video, {
|
|||||||
attach(video, { Hls, source, renewUrl });
|
attach(video, { Hls, source, renewUrl });
|
||||||
state = 'started';
|
state = 'started';
|
||||||
unbind();
|
unbind();
|
||||||
|
|
||||||
|
if (play) {
|
||||||
Promise.resolve(video.play?.()).catch(() => undefined);
|
Promise.resolve(video.play?.()).catch(() => undefined);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const start = () => {
|
/**
|
||||||
|
* Quelle binden und, mit `play`, abspielen. Ohne `play` nur binden: Die Redaktion springt im Film zu einer Marke,
|
||||||
|
* ohne dass er losläuft. Das Binden holt auch dann die Hauptliste (im Mitgliederbereich samt Nachweis).
|
||||||
|
*/
|
||||||
|
const start = ({ play = true } = {}) => {
|
||||||
if (state !== 'idle') {
|
if (state !== 'idle') {
|
||||||
return;
|
return Promise.resolve(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
state = 'starting';
|
state = 'starting';
|
||||||
|
|
||||||
if (loader.ready) {
|
if (loader.ready) {
|
||||||
finish(loader.ready);
|
finish(loader.ready, play);
|
||||||
|
|
||||||
return;
|
return Promise.resolve(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
loader.load().then(finish).catch(() => {
|
return loader.load().then((Hls) => {
|
||||||
|
finish(Hls, play);
|
||||||
|
|
||||||
|
return state;
|
||||||
|
}).catch(() => {
|
||||||
// Skript nicht ladbar (Netz): zurück in den Anfangszustand, der nächste Klick versucht es erneut.
|
// Skript nicht ladbar (Netz): zurück in den Anfangszustand, der nächste Klick versucht es erneut.
|
||||||
state = 'idle';
|
state = 'idle';
|
||||||
|
|
||||||
|
return state;
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -129,6 +129,28 @@ describe('bindLazySource', () => {
|
|||||||
expect(state.video.play).toHaveBeenCalledTimes(1);
|
expect(state.video.play).toHaveBeenCalledTimes(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('bindet auf Anforderung ohne abzuspielen und meldet danach den Zustand', async () => {
|
||||||
|
const state = setup();
|
||||||
|
|
||||||
|
const result = await state.controller.start({ play: false });
|
||||||
|
|
||||||
|
expect(result).toBe('started');
|
||||||
|
expect(state.attach).toHaveBeenCalledTimes(1);
|
||||||
|
expect(state.video.play).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('bindet ohne Abspielen auch dann, wenn das Skript schon geladen ist, und danach nie ein zweites Mal', async () => {
|
||||||
|
const state = setup();
|
||||||
|
state.observer.onVisible();
|
||||||
|
await flush();
|
||||||
|
|
||||||
|
expect(await state.controller.start({ play: false })).toBe('started');
|
||||||
|
expect(await state.controller.start()).toBe('started');
|
||||||
|
|
||||||
|
expect(state.attach).toHaveBeenCalledTimes(1);
|
||||||
|
expect(state.video.play).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
it('bindet bei mehreren Klicks nur einmal', async () => {
|
it('bindet bei mehreren Klicks nur einmal', async () => {
|
||||||
const state = setup();
|
const state = setup();
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,230 @@
|
|||||||
|
/*
|
||||||
|
* Markeneditor im Medienmanager (Reiter „Marken“): Alpine-Komponente `lufMarkerEditor`.
|
||||||
|
*
|
||||||
|
* Dünn gehalten: Zeilenlogik steht in marker-rows.js, Halten an Marken in autostop.js (dieselbe Umsetzung wie später im
|
||||||
|
* Mitglieder-Player), Binden der Quelle in lazy.js. Die Zeilen bleiben im Browser, bis „Marken speichern“ den
|
||||||
|
* Arbeitsstand über Livewire schreibt (ManagesFilmMarkers::saveMarkers).
|
||||||
|
*/
|
||||||
|
import { bindAutostop } from './autostop.js';
|
||||||
|
import { formatSeconds, fromMarkers, newRow, sortRows, toPayload, toPreviewMarkers, toSeconds, secondsField } from './marker-rows.js';
|
||||||
|
import { parseMarkers } from './markers.js';
|
||||||
|
|
||||||
|
const BIND_WAIT_MS = 4000;
|
||||||
|
|
||||||
|
export function markerEditor(config) {
|
||||||
|
return {
|
||||||
|
rows: fromMarkers(config.rows),
|
||||||
|
token: config.token ?? null,
|
||||||
|
canEdit: config.canEdit === true,
|
||||||
|
hasDraft: config.hasDraft === true,
|
||||||
|
dirty: false,
|
||||||
|
saving: false,
|
||||||
|
message: '',
|
||||||
|
failed: false,
|
||||||
|
confirmDiscard: false,
|
||||||
|
stopped: null,
|
||||||
|
position: 0,
|
||||||
|
duration: null,
|
||||||
|
autoStop: true,
|
||||||
|
video: null,
|
||||||
|
player: null,
|
||||||
|
|
||||||
|
init() {
|
||||||
|
this.video = this.$root.querySelector('video');
|
||||||
|
|
||||||
|
if (!this.video) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.player = bindAutostop(this.video, this.previewMarkers(), {
|
||||||
|
autoStop: this.autoStop,
|
||||||
|
onStop: (marker) => { this.stopped = marker; },
|
||||||
|
onResume: () => { this.stopped = null; },
|
||||||
|
});
|
||||||
|
this.video.addEventListener('timeupdate', () => { this.position = this.video.currentTime; });
|
||||||
|
this.video.addEventListener('loadedmetadata', () => { this.duration = this.video.duration; });
|
||||||
|
this.video.addEventListener('durationchange', () => { this.duration = this.video.duration; });
|
||||||
|
this.$watch('rows', () => this.player.setMarkers(this.previewMarkers()), { deep: true });
|
||||||
|
this.$watch('autoStop', (value) => this.player.setAutoStop(value));
|
||||||
|
},
|
||||||
|
|
||||||
|
previewMarkers() {
|
||||||
|
return parseMarkers(toPreviewMarkers(this.rows));
|
||||||
|
},
|
||||||
|
|
||||||
|
// ---- Anzeige ----
|
||||||
|
|
||||||
|
clock(seconds) {
|
||||||
|
return formatSeconds(seconds);
|
||||||
|
},
|
||||||
|
|
||||||
|
rowClock(row) {
|
||||||
|
const seconds = toSeconds(row.t);
|
||||||
|
|
||||||
|
return seconds === null ? 'Zeit unlesbar' : formatSeconds(seconds);
|
||||||
|
},
|
||||||
|
|
||||||
|
beyondEnd(row) {
|
||||||
|
const seconds = toSeconds(row.t);
|
||||||
|
|
||||||
|
return seconds !== null && this.duration !== null && Number.isFinite(this.duration) && seconds > this.duration;
|
||||||
|
},
|
||||||
|
|
||||||
|
get hasBeyondEnd() {
|
||||||
|
return this.rows.some((row) => this.beyondEnd(row));
|
||||||
|
},
|
||||||
|
|
||||||
|
get status() {
|
||||||
|
if (this.dirty) {
|
||||||
|
return 'Ungespeicherte Änderungen';
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.hasDraft ? 'Arbeitsstand, noch nicht veröffentlicht' : 'Entspricht der neuesten Fassung';
|
||||||
|
},
|
||||||
|
|
||||||
|
// ---- Bearbeiten ----
|
||||||
|
|
||||||
|
touch() {
|
||||||
|
if (!this.canEdit) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.dirty = true;
|
||||||
|
this.message = '';
|
||||||
|
this.failed = false;
|
||||||
|
// Dem Server melden, dass Zeilen offen sind: „Neue Fassung anlegen“ lehnt dann ab statt sie zu verlieren.
|
||||||
|
this.$wire.markerDirty = true;
|
||||||
|
},
|
||||||
|
|
||||||
|
add() {
|
||||||
|
this.rows = sortRows([...this.rows, newRow(this.video ? this.video.currentTime : 0)]);
|
||||||
|
this.touch();
|
||||||
|
},
|
||||||
|
|
||||||
|
remove(key) {
|
||||||
|
this.rows = this.rows.filter((row) => row.key !== key);
|
||||||
|
this.touch();
|
||||||
|
},
|
||||||
|
|
||||||
|
useCurrent(row) {
|
||||||
|
if (!this.video) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
row.t = secondsField(this.video.currentTime);
|
||||||
|
this.rows = sortRows(this.rows);
|
||||||
|
this.touch();
|
||||||
|
},
|
||||||
|
|
||||||
|
tidy() {
|
||||||
|
this.rows = sortRows(this.rows);
|
||||||
|
},
|
||||||
|
|
||||||
|
// ---- Film ----
|
||||||
|
|
||||||
|
/** Die Quelle ohne Abspielen binden (Springen soll den Film nicht starten). */
|
||||||
|
async ensureBound() {
|
||||||
|
const waited = Date.now();
|
||||||
|
|
||||||
|
while (!this.video.lufPlayer && Date.now() - waited < BIND_WAIT_MS) {
|
||||||
|
await new Promise((resolve) => setTimeout(resolve, 50));
|
||||||
|
}
|
||||||
|
|
||||||
|
await this.video.lufPlayer?.start({ play: false });
|
||||||
|
},
|
||||||
|
|
||||||
|
async jump(row) {
|
||||||
|
const seconds = toSeconds(row.t);
|
||||||
|
|
||||||
|
if (!this.video || seconds === null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
await this.ensureBound();
|
||||||
|
|
||||||
|
const go = () => { this.video.currentTime = seconds; };
|
||||||
|
|
||||||
|
if (this.video.readyState >= 1) {
|
||||||
|
go();
|
||||||
|
} else {
|
||||||
|
this.video.addEventListener('loadedmetadata', go, { once: true });
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
async resume() {
|
||||||
|
await this.player?.resume();
|
||||||
|
},
|
||||||
|
|
||||||
|
// ---- Speichern ----
|
||||||
|
|
||||||
|
async save() {
|
||||||
|
if (!this.canEdit || this.saving) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.saving = true;
|
||||||
|
this.message = '';
|
||||||
|
|
||||||
|
try {
|
||||||
|
const result = await this.$wire.saveMarkers(toPayload(this.rows));
|
||||||
|
|
||||||
|
this.failed = result?.ok !== true;
|
||||||
|
this.message = result?.message ?? 'Das Speichern hat nicht geantwortet.';
|
||||||
|
|
||||||
|
if (result?.ok === true) {
|
||||||
|
this.rows = fromMarkers(result.markers);
|
||||||
|
this.token = result.token ?? null;
|
||||||
|
this.hasDraft = true;
|
||||||
|
this.dirty = false;
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
this.failed = true;
|
||||||
|
this.message = 'Das Speichern ist fehlgeschlagen. Die Eingaben bleiben stehen; versuche es noch einmal.';
|
||||||
|
} finally {
|
||||||
|
this.saving = false;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
async discard() {
|
||||||
|
if (!this.canEdit || this.saving) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.saving = true;
|
||||||
|
this.confirmDiscard = false;
|
||||||
|
|
||||||
|
try {
|
||||||
|
const result = await this.$wire.discardMarkers();
|
||||||
|
|
||||||
|
this.failed = result?.ok !== true;
|
||||||
|
this.message = result?.message ?? '';
|
||||||
|
|
||||||
|
if (result?.ok === true) {
|
||||||
|
this.rows = fromMarkers(result.markers);
|
||||||
|
this.token = null;
|
||||||
|
this.hasDraft = false;
|
||||||
|
this.dirty = false;
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
this.failed = true;
|
||||||
|
this.message = 'Das Verwerfen ist fehlgeschlagen. Versuche es noch einmal.';
|
||||||
|
} finally {
|
||||||
|
this.saving = false;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
// Alpine kann vor oder nach diesem Skript starten: in beiden Fällen anmelden. Der Reiter rendert erst nach einem Klick,
|
||||||
|
// also nach dem Start; ein Aufruf über die Adresse öffnet den Reiter deshalb nicht (ViewContentElement::mount).
|
||||||
|
function register(Alpine) {
|
||||||
|
Alpine.data('lufMarkerEditor', markerEditor);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeof window !== 'undefined') {
|
||||||
|
if (window.Alpine) {
|
||||||
|
register(window.Alpine);
|
||||||
|
}
|
||||||
|
|
||||||
|
document.addEventListener('alpine:init', () => register(window.Alpine));
|
||||||
|
}
|
||||||
@@ -0,0 +1,121 @@
|
|||||||
|
/*
|
||||||
|
* Zeilen des Markeneditors: Eingabe von Zeiten, Anzeige, Sortierung, Umwandlung für den Server.
|
||||||
|
*
|
||||||
|
* Reine Logik ohne DOM (marker-rows.test.js). Der Server prüft endgültig (FilmMarkers::normalize); hier geht es um
|
||||||
|
* Eingabekomfort: Komma als Dezimalzeichen, Zeiten als „m:ss“ und eine stabile Reihenfolge.
|
||||||
|
*/
|
||||||
|
|
||||||
|
let counter = 0;
|
||||||
|
|
||||||
|
/** Zeit aus einer Eingabe: „12,5“, „12.5“, „1:05“, „1:05,5“. Gibt null zurück, wenn nichts Brauchbares dasteht. */
|
||||||
|
export function toSeconds(input) {
|
||||||
|
if (typeof input === 'number') {
|
||||||
|
return Number.isFinite(input) && input >= 0 ? input : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
const text = String(input ?? '').trim().replace(',', '.');
|
||||||
|
|
||||||
|
if (text === '') {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
const clock = text.match(/^(\d+):([0-5]?\d(?:\.\d+)?)$/);
|
||||||
|
|
||||||
|
if (clock) {
|
||||||
|
return Number(clock[1]) * 60 + Number(clock[2]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!/^\d+(\.\d+)?$/.test(text)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return Number(text);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** „1:05,5“ für 65,5 Sekunden; unter einer Minute „0:07“ mit Zehntel nur, wenn es eines gibt. */
|
||||||
|
export function formatSeconds(seconds) {
|
||||||
|
if (!Number.isFinite(seconds) || seconds < 0) {
|
||||||
|
return '–';
|
||||||
|
}
|
||||||
|
|
||||||
|
const rounded = Math.round(seconds * 10) / 10;
|
||||||
|
const minutes = Math.floor(rounded / 60);
|
||||||
|
const rest = rounded - minutes * 60;
|
||||||
|
const whole = Math.floor(rest);
|
||||||
|
const tenth = Math.round((rest - whole) * 10);
|
||||||
|
|
||||||
|
return `${minutes}:${String(whole).padStart(2, '0')}${tenth > 0 ? ',' + tenth : ''}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Zeit für das Eingabefeld: Sekunden mit einer Nachkommastelle, ohne überflüssige Null, mit Komma. */
|
||||||
|
export function secondsField(seconds) {
|
||||||
|
const rounded = Math.round(seconds * 10) / 10;
|
||||||
|
|
||||||
|
return String(rounded).replace('.', ',');
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Zeilen aus der Markenliste des Servers (jede Zeile bekommt einen Schlüssel für die Anzeige). */
|
||||||
|
export function fromMarkers(markers) {
|
||||||
|
return (markers ?? []).map((marker) => ({
|
||||||
|
key: `m${(counter += 1)}`,
|
||||||
|
t: secondsField(marker.t),
|
||||||
|
label: marker.label ?? '',
|
||||||
|
stop: marker.stop === true,
|
||||||
|
prompt: marker.prompt ?? '',
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Neue Zeile an der Stelle `seconds`. */
|
||||||
|
export function newRow(seconds) {
|
||||||
|
return {
|
||||||
|
key: `m${(counter += 1)}`,
|
||||||
|
t: secondsField(seconds),
|
||||||
|
label: '',
|
||||||
|
stop: false,
|
||||||
|
prompt: '',
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Nach Zeit ordnen; Zeilen mit unlesbarer Zeit bleiben unten in ihrer Reihenfolge, damit sie nicht wandern. */
|
||||||
|
export function sortRows(rows) {
|
||||||
|
const timed = rows.map((row, index) => ({ row, index, t: toSeconds(row.t) }));
|
||||||
|
|
||||||
|
return timed
|
||||||
|
.sort((a, b) => {
|
||||||
|
if (a.t === null && b.t === null) {
|
||||||
|
return a.index - b.index;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (a.t === null) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (b.t === null) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return a.t - b.t || a.index - b.index;
|
||||||
|
})
|
||||||
|
.map((entry) => entry.row);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Was an den Server geht: Zeit als Zahl (oder, wenn unlesbar, der Text, damit der Server den Fehler benennt). */
|
||||||
|
export function toPayload(rows) {
|
||||||
|
return rows.map((row) => {
|
||||||
|
const seconds = toSeconds(row.t);
|
||||||
|
|
||||||
|
return {
|
||||||
|
t: seconds === null ? String(row.t ?? '') : seconds,
|
||||||
|
label: String(row.label ?? ''),
|
||||||
|
stop: row.stop === true,
|
||||||
|
prompt: row.stop === true ? String(row.prompt ?? '') : '',
|
||||||
|
};
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Zeilen als Marken für die Vorschau: nur gültige Zeiten, noch ohne Prüfung der Abstände (das macht parseMarkers). */
|
||||||
|
export function toPreviewMarkers(rows) {
|
||||||
|
return rows
|
||||||
|
.map((row) => ({ t: toSeconds(row.t), label: row.label, stop: row.stop === true, prompt: row.prompt }))
|
||||||
|
.filter((marker) => marker.t !== null);
|
||||||
|
}
|
||||||
@@ -0,0 +1,110 @@
|
|||||||
|
import { describe, expect, it } from 'vitest';
|
||||||
|
import { formatSeconds, fromMarkers, newRow, secondsField, sortRows, toPayload, toPreviewMarkers, toSeconds } from './marker-rows.js';
|
||||||
|
|
||||||
|
describe('toSeconds', () => {
|
||||||
|
it('liest Zahlen mit Komma oder Punkt', () => {
|
||||||
|
expect(toSeconds('12,5')).toBe(12.5);
|
||||||
|
expect(toSeconds('12.5')).toBe(12.5);
|
||||||
|
expect(toSeconds(' 42 ')).toBe(42);
|
||||||
|
expect(toSeconds(7)).toBe(7);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('liest Minuten und Sekunden', () => {
|
||||||
|
expect(toSeconds('1:05')).toBe(65);
|
||||||
|
expect(toSeconds('1:05,5')).toBe(65.5);
|
||||||
|
expect(toSeconds('12:00')).toBe(720);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('gibt bei Unbrauchbarem null zurück', () => {
|
||||||
|
expect(toSeconds('')).toBeNull();
|
||||||
|
expect(toSeconds('bald')).toBeNull();
|
||||||
|
expect(toSeconds('-3')).toBeNull();
|
||||||
|
expect(toSeconds('1:75')).toBeNull();
|
||||||
|
expect(toSeconds('1,2,3')).toBeNull();
|
||||||
|
expect(toSeconds(-1)).toBeNull();
|
||||||
|
expect(toSeconds(Number.NaN)).toBeNull();
|
||||||
|
expect(toSeconds(null)).toBeNull();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('Anzeige', () => {
|
||||||
|
it('formatiert Zeiten als Minuten und Sekunden', () => {
|
||||||
|
expect(formatSeconds(0)).toBe('0:00');
|
||||||
|
expect(formatSeconds(7)).toBe('0:07');
|
||||||
|
expect(formatSeconds(65.5)).toBe('1:05,5');
|
||||||
|
expect(formatSeconds(3600)).toBe('60:00');
|
||||||
|
expect(formatSeconds(-1)).toBe('–');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('schreibt die Zeit für das Eingabefeld mit Komma und ohne überflüssige Null', () => {
|
||||||
|
expect(secondsField(12)).toBe('12');
|
||||||
|
expect(secondsField(12.5)).toBe('12,5');
|
||||||
|
expect(secondsField(12.04)).toBe('12');
|
||||||
|
expect(secondsField(0.25)).toBe('0,3');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('Zeilen', () => {
|
||||||
|
it('macht aus Marken Zeilen mit eindeutigen Schlüsseln', () => {
|
||||||
|
const rows = fromMarkers([
|
||||||
|
{ t: 10, label: 'A', stop: false, prompt: '' },
|
||||||
|
{ t: 42.5, label: 'B', stop: true, prompt: 'Frage' },
|
||||||
|
]);
|
||||||
|
|
||||||
|
expect(rows.map((row) => row.t)).toEqual(['10', '42,5']);
|
||||||
|
expect(rows[1]).toMatchObject({ label: 'B', stop: true, prompt: 'Frage' });
|
||||||
|
expect(new Set(rows.map((row) => row.key)).size).toBe(2);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('legt eine neue Zeile an der gegebenen Stelle an', () => {
|
||||||
|
expect(newRow(12.34)).toMatchObject({ t: '12,3', label: '', stop: false, prompt: '' });
|
||||||
|
});
|
||||||
|
|
||||||
|
it('ordnet nach Zeit und lässt unlesbare Zeiten unten stehen, ohne sie zu verschieben', () => {
|
||||||
|
const rows = [
|
||||||
|
{ key: 'a', t: '30' },
|
||||||
|
{ key: 'b', t: 'bald' },
|
||||||
|
{ key: 'c', t: '5' },
|
||||||
|
{ key: 'd', t: '' },
|
||||||
|
{ key: 'e', t: '1:00' },
|
||||||
|
];
|
||||||
|
|
||||||
|
expect(sortRows(rows).map((row) => row.key)).toEqual(['c', 'a', 'e', 'b', 'd']);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('behält bei gleicher Zeit die Reihenfolge', () => {
|
||||||
|
const rows = [{ key: 'a', t: '5' }, { key: 'b', t: '5' }];
|
||||||
|
|
||||||
|
expect(sortRows(rows).map((row) => row.key)).toEqual(['a', 'b']);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('toPayload', () => {
|
||||||
|
it('schickt Zahlen und echte Wahrheitswerte, den Text nur bei Stopps', () => {
|
||||||
|
const payload = toPayload([
|
||||||
|
{ key: 'a', t: '12,5', label: 'A', stop: false, prompt: 'bleibt weg' },
|
||||||
|
{ key: 'b', t: '1:05', label: 'B', stop: true, prompt: 'Frage' },
|
||||||
|
]);
|
||||||
|
|
||||||
|
expect(payload).toEqual([
|
||||||
|
{ t: 12.5, label: 'A', stop: false, prompt: '' },
|
||||||
|
{ t: 65, label: 'B', stop: true, prompt: 'Frage' },
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('reicht unlesbare Zeiten als Text durch, damit der Server den Fehler benennt', () => {
|
||||||
|
expect(toPayload([{ t: 'bald', label: 'A' }])[0].t).toBe('bald');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('toPreviewMarkers', () => {
|
||||||
|
it('nimmt nur Zeilen mit lesbarer Zeit', () => {
|
||||||
|
const markers = toPreviewMarkers([
|
||||||
|
{ t: '10', label: 'A', stop: true, prompt: '' },
|
||||||
|
{ t: 'bald', label: 'B', stop: true, prompt: '' },
|
||||||
|
]);
|
||||||
|
|
||||||
|
expect(markers).toHaveLength(1);
|
||||||
|
expect(markers[0]).toMatchObject({ t: 10, stop: true });
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -70,10 +70,10 @@ export function parseMarkers(raw, { duration = null } = {}) {
|
|||||||
* Liste für einen Film: die neue Markenliste, sonst der Altwert `decision_seconds` als einzelne Stoppmarke.
|
* Liste für einen Film: die neue Markenliste, sonst der Altwert `decision_seconds` als einzelne Stoppmarke.
|
||||||
*/
|
*/
|
||||||
export function markersFor({ markers = null, decisionSeconds = null } = {}, options = {}) {
|
export function markersFor({ markers = null, decisionSeconds = null } = {}, options = {}) {
|
||||||
const list = parseMarkers(markers, options);
|
// Der Altwert gilt nur, solange die Fassung gar keine Markenliste führt. Eine ausdrücklich leere Liste heißt
|
||||||
|
// „keine Marken“; sonst kehrte eine gelöschte Entscheidungsmarke zurück (wie FilmMarkers::ofVersion im Server).
|
||||||
if (list.length > 0) {
|
if (Array.isArray(markers)) {
|
||||||
return list;
|
return parseMarkers(markers, options);
|
||||||
}
|
}
|
||||||
|
|
||||||
const legacy = Number(decisionSeconds);
|
const legacy = Number(decisionSeconds);
|
||||||
|
|||||||
@@ -66,6 +66,10 @@ describe('markersFor', () => {
|
|||||||
expect(markersFor({ markers: [{ t: 5, label: 'a' }], decisionSeconds: 99 })[0].t).toBe(5);
|
expect(markersFor({ markers: [{ t: 5, label: 'a' }], decisionSeconds: 99 })[0].t).toBe(5);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('bringt den Altwert nicht zurück, wenn die Liste ausdrücklich leer ist', () => {
|
||||||
|
expect(markersFor({ markers: [], decisionSeconds: 42 })).toEqual([]);
|
||||||
|
});
|
||||||
|
|
||||||
it('macht den Altwert zur einzelnen Stoppmarke', () => {
|
it('macht den Altwert zur einzelnen Stoppmarke', () => {
|
||||||
expect(markersFor({ markers: null, decisionSeconds: 42 })).toEqual([{ t: 42, label: 'Entscheidung', stop: true, prompt: '' }]);
|
expect(markersFor({ markers: null, decisionSeconds: 42 })).toEqual([{ t: 42, label: 'Entscheidung', stop: true, prompt: '' }]);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -0,0 +1,128 @@
|
|||||||
|
{{--
|
||||||
|
Reiter „Marken“ im Medienmanager (nur Filme). Die Zeilen bleiben im Browser, bis „Marken speichern“ den Arbeitsstand
|
||||||
|
schreibt; Mitglieder sehen ihn erst mit einer neuen Fassung. Die Vorlage wird mit wire:ignore gerendert: Der Film
|
||||||
|
spielt weiter und offene Zeilen gehen bei einer Antwort des Servers nicht verloren. Beim Verlassen des Reiters
|
||||||
|
entsteht sie neu.
|
||||||
|
--}}
|
||||||
|
@php
|
||||||
|
$konfig = [
|
||||||
|
'rows' => $markerRows,
|
||||||
|
'token' => $this->markerToken,
|
||||||
|
'canEdit' => $markerCanEdit,
|
||||||
|
'hasDraft' => $markerHasDraft,
|
||||||
|
];
|
||||||
|
$poster = \App\Domain\Media\ThumbnailRef::url('editorial.card', 'element', $element->id, $element->thumbnail_path, 'mittel', $element->updated_at);
|
||||||
|
@endphp
|
||||||
|
|
||||||
|
<section class="vw vw-marken" aria-labelledby="marken-titel">
|
||||||
|
@if (! $markerVersion)
|
||||||
|
<div class="vw-leer vw-leer-breit"><strong>Noch keine Fassung</strong><p>Marken gehören zu einer Filmfassung. Lege zuerst eine Fassung mit der Filmdatei an.</p></div>
|
||||||
|
@else
|
||||||
|
<div class="vw-medien-raster" wire:ignore wire:key="marken-{{ $markerVersion->id }}"
|
||||||
|
x-data="lufMarkerEditor(@js($konfig))">
|
||||||
|
<div class="vw-medien-haupt">
|
||||||
|
<div>
|
||||||
|
<h2 id="marken-titel" class="vw-abschnitt-titel">Marken an Fassung {{ $markerVersion->number }}</h2>
|
||||||
|
<p class="vw-feld-hilfe">Sprungmarken gliedern den Film in Kapitel. Eine Marke mit Stopp hält die Wiedergabe an, bis das Mitglied „Weiter“ wählt. Alles hier ist ein Arbeitsstand: Mitglieder sehen die Marken erst, wenn du eine neue Fassung anlegst und diese in einen Artikelstand kommt.</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
@if ($markerFileHint)
|
||||||
|
<p class="vw-band is-achtung" role="status">@include('filament.verwaltung.icon', ['name' => 'achtung'])<span><strong>Neue Filmdatei.</strong> Die Marken wurden nicht gegen den neuen Film geprüft, besonders Stopps können an der falschen Stelle sitzen. Prüfe die Marken und speichere sie; der Hinweis endet mit der nächsten Fassung, die Marken ändert.</span></p>
|
||||||
|
@endif
|
||||||
|
@if ($markerDraftOlder)
|
||||||
|
<p class="vw-band is-achtung" role="status">@include('filament.verwaltung.icon', ['name' => 'achtung'])<span>Der Arbeitsstand stammt aus Fassung {{ $markerDraftBase }}; seither ist Fassung {{ $markerVersion->number }} entstanden. Prüfe ihn, bevor du eine Fassung anlegst.</span></p>
|
||||||
|
@endif
|
||||||
|
|
||||||
|
@if ($markerPlayback)
|
||||||
|
<div class="vw-abspieler">
|
||||||
|
@include('content.video', ['playback' => $markerPlayback, 'poster' => $poster, 'style' => 'width: 100%; max-height: 34rem; background: #111;'])
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<template x-if="stopped">
|
||||||
|
<p class="vw-band" role="status">
|
||||||
|
<span>
|
||||||
|
<strong x-text="'Halt bei ' + clock(stopped.t) + ': ' + stopped.label"></strong>
|
||||||
|
<span x-show="stopped.prompt" x-text="stopped.prompt" style="display: block;"></span>
|
||||||
|
</span>
|
||||||
|
<button type="button" class="vw-btn is-primary is-small" x-on:click="resume()" style="margin-left: auto;">Weiter</button>
|
||||||
|
</p>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<div class="vw-marken-werkzeug">
|
||||||
|
<span class="vw-feld-hilfe">Position: <strong x-text="clock(position)"></strong><template x-if="duration"><span> von <span x-text="clock(duration)"></span></span></template></span>
|
||||||
|
<label class="vw-marke-stopp"><input type="checkbox" x-model="autoStop"> Automatische Stopps in der Vorschau</label>
|
||||||
|
</div>
|
||||||
|
@else
|
||||||
|
<div class="vw-leer"><strong>Keine Filmdatei zum Abspielen</strong><p>Die Datei wird noch übernommen oder liegt nicht vor. Marken lassen sich setzen, sobald sie abspielbar ist.</p></div>
|
||||||
|
@endif
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<aside class="vw-medien-seite" aria-labelledby="marken-liste-titel">
|
||||||
|
<h2 id="marken-liste-titel" class="vw-abschnitt-titel">Marken <span class="vw-rolle-zahl" x-text="'· ' + rows.length"></span></h2>
|
||||||
|
<p class="vw-feld-hilfe" role="status"><span class="vw-punkt is-im-text" x-bind:class="dirty ? 'is-offen' : (hasDraft ? 'is-offen' : 'is-gut')"></span><span x-text="status"></span></p>
|
||||||
|
|
||||||
|
<p class="vw-band is-achtung" x-show="hasBeyondEnd" x-cloak>@include('filament.verwaltung.icon', ['name' => 'achtung'])<span>Mindestens eine Marke liegt hinter dem Ende des Films.</span></p>
|
||||||
|
|
||||||
|
<p class="vw-feld-hilfe" x-show="rows.length === 0">Dieser Film hat noch keine Marken.</p>
|
||||||
|
|
||||||
|
<ol class="vw-marken-liste" aria-label="Marken, nach Zeit geordnet" x-on:input="touch()" x-on:change="touch()">
|
||||||
|
<template x-for="(row, index) in rows" x-bind:key="row.key">
|
||||||
|
<li class="vw-marke" x-bind:class="{ 'is-stopp': row.stop, 'is-spaet': beyondEnd(row) }">
|
||||||
|
<div class="vw-marke-zeile">
|
||||||
|
<label class="vw-feldlabel vw-marke-zeit">
|
||||||
|
<span>Zeit in Sekunden</span>
|
||||||
|
<input class="vw-eingabe" type="text" inputmode="decimal" autocomplete="off" x-model="row.t" x-on:change="tidy()" x-bind:disabled="!canEdit" x-bind:aria-label="'Zeit in Sekunden, Marke ' + (index + 1)">
|
||||||
|
</label>
|
||||||
|
<span class="vw-marke-uhr" x-text="rowClock(row)"></span>
|
||||||
|
<span class="vw-kapsel is-geaendert" x-show="beyondEnd(row)">hinter dem Ende</span>
|
||||||
|
</div>
|
||||||
|
<label class="vw-feldlabel">
|
||||||
|
<span>Titel</span>
|
||||||
|
<input class="vw-eingabe" type="text" maxlength="120" x-model="row.label" x-bind:disabled="!canEdit" x-bind:aria-label="'Titel, Marke ' + (index + 1)">
|
||||||
|
</label>
|
||||||
|
<label class="vw-marke-stopp"><input type="checkbox" x-model="row.stop" x-bind:disabled="!canEdit"> Hält die Wiedergabe an</label>
|
||||||
|
<label class="vw-feldlabel" x-show="row.stop" x-cloak>
|
||||||
|
<span>Text beim Stopp (einfacher Text, optional)</span>
|
||||||
|
<textarea class="vw-eingabe" rows="3" maxlength="1000" x-model="row.prompt" x-bind:disabled="!canEdit" x-bind:aria-label="'Text beim Stopp, Marke ' + (index + 1)"></textarea>
|
||||||
|
</label>
|
||||||
|
<div class="vw-knoepfe">
|
||||||
|
<button type="button" class="vw-btn is-small" x-on:click="jump(row)" x-bind:disabled="!video">Zur Marke springen</button>
|
||||||
|
<template x-if="canEdit">
|
||||||
|
<button type="button" class="vw-btn is-small" x-on:click="useCurrent(row)">Aktuelle Position übernehmen</button>
|
||||||
|
</template>
|
||||||
|
<template x-if="canEdit">
|
||||||
|
<button type="button" class="vw-btn is-small" x-on:click="remove(row.key)" x-bind:aria-label="'Marke ' + (index + 1) + ' entfernen'">Entfernen</button>
|
||||||
|
</template>
|
||||||
|
</div>
|
||||||
|
</li>
|
||||||
|
</template>
|
||||||
|
</ol>
|
||||||
|
|
||||||
|
@if ($markerCanEdit)
|
||||||
|
<div class="vw-knoepfe vw-trennlinie">
|
||||||
|
<button type="button" class="vw-btn" x-on:click="add()">@include('filament.verwaltung.icon', ['name' => 'plus'])Marke an dieser Position</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<p x-show="message" x-cloak x-bind:class="failed ? 'vw-meldung is-fehler' : 'vw-meldung'" x-bind:role="failed ? 'alert' : 'status'"><span x-text="message"></span></p>
|
||||||
|
|
||||||
|
<div class="vw-knoepfe">
|
||||||
|
<button type="button" class="vw-btn is-primary" x-on:click="save()" x-bind:disabled="saving || !dirty">Marken speichern</button>
|
||||||
|
<template x-if="(hasDraft || dirty) && !confirmDiscard">
|
||||||
|
<button type="button" class="vw-link is-quiet" x-on:click="confirmDiscard = true">Arbeitsstand verwerfen</button>
|
||||||
|
</template>
|
||||||
|
<template x-if="confirmDiscard">
|
||||||
|
<span class="vw-knoepfe">
|
||||||
|
<span class="vw-feld-hilfe">Der Arbeitsstand geht verloren, die Marken der Fassung bleiben.</span>
|
||||||
|
<button type="button" class="vw-btn is-small" x-on:click="discard()">Ja, verwerfen</button>
|
||||||
|
<button type="button" class="vw-link is-quiet" x-on:click="confirmDiscard = false">Abbrechen</button>
|
||||||
|
</span>
|
||||||
|
</template>
|
||||||
|
</div>
|
||||||
|
<p class="vw-feld-hilfe">Zum Veröffentlichen: „Neue Fassung anlegen“. Ungespeicherte Zeilen blockieren das Anlegen, damit nichts verloren geht.</p>
|
||||||
|
@else
|
||||||
|
<p class="vw-feld-hilfe">Du kannst die Marken ansehen. Bearbeiten dürfen Redakteurinnen und Redakteure, sobald der Film abspielbar ist.</p>
|
||||||
|
@endif
|
||||||
|
</aside>
|
||||||
|
</div>
|
||||||
|
@endif
|
||||||
|
</section>
|
||||||
@@ -56,13 +56,14 @@
|
|||||||
@endforeach
|
@endforeach
|
||||||
|
|
||||||
<div class="vw-register" role="tablist" aria-label="Bereiche des Mediums">
|
<div class="vw-register" role="tablist" aria-label="Bereiche des Mediums">
|
||||||
@foreach ([
|
@foreach (array_filter([
|
||||||
'inhalt' => 'Inhalt und Fassungen',
|
'inhalt' => 'Inhalt und Fassungen',
|
||||||
|
'marken' => $element->output_class === 'film' && $versions->isNotEmpty() ? 'Marken' : null,
|
||||||
'vorschaubild' => 'Vorschaubild',
|
'vorschaubild' => 'Vorschaubild',
|
||||||
'verwendung' => 'Verwendung',
|
'verwendung' => 'Verwendung',
|
||||||
'vorschau' => 'Vorschau',
|
'vorschau' => 'Vorschau',
|
||||||
'website' => 'Website',
|
'website' => 'Website',
|
||||||
] as $value => $label)
|
]) as $value => $label)
|
||||||
<button type="button" role="tab" wire:click="$set('bereich', '{{ $value }}')" aria-selected="{{ $fokus === $value ? 'true' : 'false' }}" tabindex="{{ $fokus === $value ? '0' : '-1' }}"
|
<button type="button" role="tab" wire:click="$set('bereich', '{{ $value }}')" aria-selected="{{ $fokus === $value ? 'true' : 'false' }}" tabindex="{{ $fokus === $value ? '0' : '-1' }}"
|
||||||
x-data x-on:keydown.right.prevent="$el.nextElementSibling?.focus()" x-on:keydown.left.prevent="$el.previousElementSibling?.focus()">
|
x-data x-on:keydown.right.prevent="$el.nextElementSibling?.focus()" x-on:keydown.left.prevent="$el.previousElementSibling?.focus()">
|
||||||
{{ $label }}
|
{{ $label }}
|
||||||
@@ -202,6 +203,10 @@
|
|||||||
@endif
|
@endif
|
||||||
@endif
|
@endif
|
||||||
|
|
||||||
|
@if ($element->output_class === 'film' && ($fassungMarken = $this->markerSummary($shown)) !== '')
|
||||||
|
<p class="vw-feld-hilfe"><strong>Marken dieser Fassung:</strong> {{ $fassungMarken }}. Änderungen gehören in den Reiter „Marken“ und ergeben eine neue Fassung.</p>
|
||||||
|
@endif
|
||||||
|
|
||||||
<div class="vw-fassung-verwendung">
|
<div class="vw-fassung-verwendung">
|
||||||
<h3>Eingebunden in</h3>
|
<h3>Eingebunden in</h3>
|
||||||
@forelse ($verwendet as $usage)
|
@forelse ($verwendet as $usage)
|
||||||
@@ -289,6 +294,8 @@
|
|||||||
</aside>
|
</aside>
|
||||||
@endif
|
@endif
|
||||||
</div>
|
</div>
|
||||||
|
@elseif ($fokus === 'marken' && $element->output_class === 'film')
|
||||||
|
@include('filament.media.marken', $this->markerData())
|
||||||
@elseif ($fokus === 'verwendung')
|
@elseif ($fokus === 'verwendung')
|
||||||
@php
|
@php
|
||||||
$card = $this->usageCard();
|
$card = $this->usageCard();
|
||||||
|
|||||||
@@ -304,6 +304,18 @@
|
|||||||
.vw-abschnitt-titel { display: flex; flex-wrap: wrap; align-items: center; gap: 0.6rem; margin: 0; font-size: var(--vw-section); font-weight: 750; color: var(--vw-ink); }
|
.vw-abschnitt-titel { display: flex; flex-wrap: wrap; align-items: center; gap: 0.6rem; margin: 0; font-size: var(--vw-section); font-weight: 750; color: var(--vw-ink); }
|
||||||
.vw-abspieler { max-width: 60rem; border-radius: var(--vw-radius); overflow: hidden; }
|
.vw-abspieler { max-width: 60rem; border-radius: var(--vw-radius); overflow: hidden; }
|
||||||
.vw-abspieler :is(video, img, iframe) { width: 100%; max-height: 34rem; display: block; background: #111; }
|
.vw-abspieler :is(video, img, iframe) { width: 100%; max-height: 34rem; display: block; background: #111; }
|
||||||
|
/* Markeneditor (Reiter „Marken“ des Medienmanagers) */
|
||||||
|
.vw-marken-werkzeug { display: flex; flex-wrap: wrap; gap: 0.5rem 1.25rem; align-items: center; }
|
||||||
|
.vw-marken-liste { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.75rem; }
|
||||||
|
.vw-marke { display: grid; gap: 0.6rem; padding: 0.8rem 0.9rem; border: 1px solid var(--vw-line); border-left-width: 0.3rem; border-radius: var(--vw-radius); background: var(--vw-surface); }
|
||||||
|
.vw-marke.is-stopp { border-left-color: var(--vw-warn); }
|
||||||
|
.vw-marke.is-spaet { background: var(--vw-warn-soft); border-color: var(--vw-warn); }
|
||||||
|
.vw-marke-zeile { display: flex; flex-wrap: wrap; gap: 0.5rem 0.75rem; align-items: end; }
|
||||||
|
.vw-marke-zeit { width: 8rem; }
|
||||||
|
.vw-marke-uhr { color: var(--vw-quiet); font-size: var(--vw-small); min-height: var(--vw-target); display: inline-flex; align-items: center; }
|
||||||
|
.vw-marke-stopp { display: inline-flex; gap: 0.5rem; align-items: center; min-height: var(--vw-target); cursor: pointer; font-size: var(--vw-small); font-weight: 650; }
|
||||||
|
.vw-marke-stopp input { width: 1.25rem; height: 1.25rem; accent-color: var(--vw-pine); cursor: pointer; }
|
||||||
|
.vw-marke textarea.vw-eingabe { resize: vertical; }
|
||||||
.vw-vorschaubild { aspect-ratio: 16 / 9; border-radius: var(--vw-radius); overflow: hidden; background: #e4ebe5; display: grid; place-items: center; color: var(--vw-quiet); }
|
.vw-vorschaubild { aspect-ratio: 16 / 9; border-radius: var(--vw-radius); overflow: hidden; background: #e4ebe5; display: grid; place-items: center; color: var(--vw-quiet); }
|
||||||
.vw-vorschaubild img { width: 100%; height: 100%; object-fit: cover; display: block; }
|
.vw-vorschaubild img { width: 100%; height: 100%; object-fit: cover; display: block; }
|
||||||
.vw-ausklapp { border-top: 1px solid var(--vw-line); padding-top: 0.25rem; }
|
.vw-ausklapp { border-top: 1px solid var(--vw-line); padding-top: 0.25rem; }
|
||||||
|
|||||||
@@ -0,0 +1,288 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Tests\Feature;
|
||||||
|
|
||||||
|
use App\Domain\Catalog\ContentElement;
|
||||||
|
use App\Domain\Catalog\ContentService;
|
||||||
|
use App\Domain\Media\FilmMarkers;
|
||||||
|
use App\Domain\Media\MarkerDraft;
|
||||||
|
use App\Filament\Resources\ContentElements\Pages\ViewContentElement;
|
||||||
|
use App\Models\User;
|
||||||
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||||
|
use Livewire\Features\SupportTesting\Testable;
|
||||||
|
use Livewire\Livewire;
|
||||||
|
use Tests\TestCase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Markeneditor im Medienmanager: eigener Reiter „Marken“ für Filme, Arbeitsstand speichern und verwerfen, Schutz vor
|
||||||
|
* gleichzeitigem Speichern, Rechte und der Hinweis nach einer neuen Datei.
|
||||||
|
*/
|
||||||
|
class FilmMarkersEditorTest extends TestCase
|
||||||
|
{
|
||||||
|
use RefreshDatabase;
|
||||||
|
|
||||||
|
private const MARKERS = [
|
||||||
|
['t' => 10.0, 'label' => 'Einstieg', 'stop' => false, 'prompt' => ''],
|
||||||
|
['t' => 42.0, 'label' => 'Entscheidung', 'stop' => true, 'prompt' => 'Was würdest du tun?'],
|
||||||
|
];
|
||||||
|
|
||||||
|
private function signIn(string $role = 'redakteur'): User
|
||||||
|
{
|
||||||
|
$user = User::factory()->{$role}()->create();
|
||||||
|
$user->saveAppAuthenticationSecret('JBSWY3DPEHPK3PXP');
|
||||||
|
$this->actingAs($user, 'staff');
|
||||||
|
|
||||||
|
return $user;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function film(array $metadata = ['file' => 'inhalte/film.mp4', 'markers' => self::MARKERS]): ContentElement
|
||||||
|
{
|
||||||
|
$element = app(ContentService::class)->createElement('film', 'film', 'Übungsfilm');
|
||||||
|
app(ContentService::class)->publishElementVersion($element, null, $metadata);
|
||||||
|
|
||||||
|
return $element->fresh();
|
||||||
|
}
|
||||||
|
|
||||||
|
private function open(ContentElement $element): Testable
|
||||||
|
{
|
||||||
|
return Livewire::test(ViewContentElement::class, ['record' => $element->getKey()]);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function rows(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
['t' => '12,5', 'label' => 'Neuer Einstieg', 'stop' => false, 'prompt' => ''],
|
||||||
|
['t' => 40, 'label' => 'Entscheidung', 'stop' => true, 'prompt' => 'Und jetzt?'],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_the_marker_register_is_offered_for_films_only(): void
|
||||||
|
{
|
||||||
|
$this->signIn();
|
||||||
|
$text = app(ContentService::class)->createElement('text', 'text', 'Ein Text');
|
||||||
|
app(ContentService::class)->publishElementVersion($text, '<p>Hallo</p>');
|
||||||
|
|
||||||
|
$this->open($this->film())->assertSeeHtml("wire:click=\"\$set('bereich', 'marken')\"");
|
||||||
|
$this->open($text->fresh())->assertDontSeeHtml("wire:click=\"\$set('bereich', 'marken')\"");
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_a_marker_link_in_the_address_opens_the_normal_view(): void
|
||||||
|
{
|
||||||
|
$this->signIn();
|
||||||
|
$element = $this->film();
|
||||||
|
|
||||||
|
$component = $this->open($element);
|
||||||
|
$component->set('bereich', 'marken');
|
||||||
|
|
||||||
|
$this->assertSame('marken', $component->get('bereich'));
|
||||||
|
$this->assertSame('inhalte/film.mp4', $element->versions()->first()->metadata['file']);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_the_register_shows_the_markers_of_the_latest_version_and_who_may_edit(): void
|
||||||
|
{
|
||||||
|
$this->signIn();
|
||||||
|
|
||||||
|
$this->open($this->film())
|
||||||
|
->set('bereich', 'marken')
|
||||||
|
->assertSee('Einstieg')
|
||||||
|
->assertSee('Entscheidung')
|
||||||
|
->assertSee('Marken speichern');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_a_reader_without_the_editor_role_sees_the_markers_but_cannot_edit(): void
|
||||||
|
{
|
||||||
|
$this->signIn('katalogverwalter');
|
||||||
|
|
||||||
|
$this->open($this->film())
|
||||||
|
->set('bereich', 'marken')
|
||||||
|
->assertSee('Einstieg')
|
||||||
|
->assertDontSee('Marken speichern');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_saving_stores_the_draft_and_returns_the_normalized_rows_and_a_token(): void
|
||||||
|
{
|
||||||
|
$this->signIn();
|
||||||
|
$element = $this->film();
|
||||||
|
$component = $this->open($element)->set('bereich', 'marken')->set('markerDirty', true);
|
||||||
|
|
||||||
|
$component->call('saveMarkers', $this->rows());
|
||||||
|
|
||||||
|
$draft = app(MarkerDraft::class)->current($element);
|
||||||
|
$this->assertNotNull($draft);
|
||||||
|
$this->assertSame(['Neuer Einstieg', 'Entscheidung'], array_column($draft['markers'], 'label'));
|
||||||
|
$this->assertEquals(12.5, $draft['markers'][0]['t']);
|
||||||
|
$this->assertSame($draft['saved_at'], $component->get('markerToken'));
|
||||||
|
$this->assertFalse($component->get('markerDirty'));
|
||||||
|
$this->assertSame(1, $element->versions()->count());
|
||||||
|
$this->assertEquals(self::MARKERS, FilmMarkers::ofVersion($element->versions()->first()));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_the_save_result_names_the_outcome_for_the_page(): void
|
||||||
|
{
|
||||||
|
$this->signIn();
|
||||||
|
$element = $this->film();
|
||||||
|
|
||||||
|
$result = $this->open($element)->set('bereich', 'marken')->call('saveMarkers', $this->rows())->effects['returns'][0] ?? null;
|
||||||
|
|
||||||
|
$this->assertTrue($result['ok']);
|
||||||
|
$this->assertCount(2, $result['markers']);
|
||||||
|
$this->assertNotSame('', (string) $result['token']);
|
||||||
|
$this->assertStringContainsString('neuen Fassung', $result['message']);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_invalid_rows_are_refused_with_the_reason_and_leave_the_draft_alone(): void
|
||||||
|
{
|
||||||
|
$this->signIn();
|
||||||
|
$element = $this->film();
|
||||||
|
$component = $this->open($element)->set('bereich', 'marken');
|
||||||
|
$component->call('saveMarkers', $this->rows());
|
||||||
|
$kept = app(MarkerDraft::class)->current($element);
|
||||||
|
|
||||||
|
$result = $component->call('saveMarkers', [
|
||||||
|
['t' => 5, 'label' => 'A'],
|
||||||
|
['t' => 5.5, 'label' => 'B'],
|
||||||
|
])->effects['returns'][0] ?? null;
|
||||||
|
|
||||||
|
$this->assertFalse($result['ok']);
|
||||||
|
$this->assertStringContainsString('Abstand', $result['message']);
|
||||||
|
$this->assertEquals($kept, app(MarkerDraft::class)->current($element));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_a_save_after_someone_else_saved_is_refused(): void
|
||||||
|
{
|
||||||
|
$this->signIn();
|
||||||
|
$element = $this->film();
|
||||||
|
$component = $this->open($element)->set('bereich', 'marken');
|
||||||
|
$component->call('saveMarkers', $this->rows());
|
||||||
|
$draft = app(MarkerDraft::class)->current($element);
|
||||||
|
app(MarkerDraft::class)->save($element, [['t' => 99, 'label' => 'Von anderer Hand']], $draft['saved_at']);
|
||||||
|
|
||||||
|
$result = $component->call('saveMarkers', $this->rows())->effects['returns'][0] ?? null;
|
||||||
|
|
||||||
|
$this->assertFalse($result['ok']);
|
||||||
|
$this->assertStringContainsString('inzwischen', $result['message']);
|
||||||
|
$this->assertSame('Von anderer Hand', app(MarkerDraft::class)->current($element)['markers'][0]['label']);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_the_register_starts_from_the_draft_that_exists_when_it_opens(): void
|
||||||
|
{
|
||||||
|
$this->signIn();
|
||||||
|
$element = $this->film();
|
||||||
|
$draft = app(MarkerDraft::class)->save($element, [['t' => 30, 'label' => 'Aus dem Arbeitsstand']], null);
|
||||||
|
|
||||||
|
$component = $this->open($element)->set('bereich', 'marken');
|
||||||
|
|
||||||
|
$component->assertSee('Aus dem Arbeitsstand')->assertDontSee('Einstieg');
|
||||||
|
$this->assertSame($draft['saved_at'], $component->get('markerToken'));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_only_editors_can_save_or_discard(): void
|
||||||
|
{
|
||||||
|
$this->signIn('katalogverwalter');
|
||||||
|
$element = $this->film();
|
||||||
|
|
||||||
|
$this->open($element)->call('saveMarkers', $this->rows())->assertForbidden();
|
||||||
|
$this->open($element)->call('discardMarkers')->assertForbidden();
|
||||||
|
$this->assertNull(app(MarkerDraft::class)->current($element));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_a_text_element_refuses_markers_on_the_server(): void
|
||||||
|
{
|
||||||
|
$this->signIn();
|
||||||
|
$text = app(ContentService::class)->createElement('text', 'text', 'Ein Text');
|
||||||
|
app(ContentService::class)->publishElementVersion($text, '<p>Hallo</p>');
|
||||||
|
|
||||||
|
$result = $this->open($text->fresh())->call('saveMarkers', $this->rows())->effects['returns'][0] ?? null;
|
||||||
|
|
||||||
|
$this->assertFalse($result['ok']);
|
||||||
|
$this->assertNull(app(MarkerDraft::class)->current($text));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_discarding_returns_to_the_markers_of_the_version(): void
|
||||||
|
{
|
||||||
|
$this->signIn();
|
||||||
|
$element = $this->film();
|
||||||
|
$component = $this->open($element)->set('bereich', 'marken');
|
||||||
|
$component->call('saveMarkers', $this->rows());
|
||||||
|
|
||||||
|
$result = $component->call('discardMarkers')->effects['returns'][0] ?? null;
|
||||||
|
|
||||||
|
$this->assertTrue($result['ok']);
|
||||||
|
$this->assertEquals(self::MARKERS, $result['markers']);
|
||||||
|
$this->assertNull(app(MarkerDraft::class)->current($element));
|
||||||
|
$this->assertNull($component->get('markerToken'));
|
||||||
|
$this->assertFalse($component->get('markerDirty'));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_a_new_version_is_refused_while_marker_rows_are_unsaved(): void
|
||||||
|
{
|
||||||
|
$this->signIn();
|
||||||
|
$element = $this->film();
|
||||||
|
|
||||||
|
$this->open($element)
|
||||||
|
->set('markerDirty', true)
|
||||||
|
->callAction('revise', ['body' => 'Neuer Text', 'change_note' => 'Text'])
|
||||||
|
->assertNotified('Die Marken haben ungespeicherte Änderungen. Speichere oder verwirf sie zuerst, sonst fehlen sie in der neuen Fassung.');
|
||||||
|
|
||||||
|
$this->assertSame(1, $element->versions()->count());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_a_new_version_applies_the_saved_draft_from_the_page(): void
|
||||||
|
{
|
||||||
|
$this->signIn();
|
||||||
|
$element = $this->film();
|
||||||
|
$component = $this->open($element)->set('bereich', 'marken');
|
||||||
|
$component->call('saveMarkers', $this->rows());
|
||||||
|
|
||||||
|
$component->callAction('revise', ['change_note' => 'Marken angepasst']);
|
||||||
|
|
||||||
|
$latest = $element->versions()->orderByDesc('number')->first();
|
||||||
|
$this->assertSame(2, $latest->number);
|
||||||
|
$this->assertSame(['Neuer Einstieg', 'Entscheidung'], array_column(FilmMarkers::ofVersion($latest), 'label'));
|
||||||
|
$this->assertNull(app(MarkerDraft::class)->current($element));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_the_register_tells_when_the_markers_have_not_been_checked_against_a_new_file(): void
|
||||||
|
{
|
||||||
|
$this->signIn();
|
||||||
|
$element = $this->film();
|
||||||
|
app(ContentService::class)->publishElementVersion($element, null, ['file' => 'inhalte/zweit.mp4']);
|
||||||
|
|
||||||
|
$this->open($element->fresh())
|
||||||
|
->set('bereich', 'marken')
|
||||||
|
->assertSee('Neue Filmdatei')
|
||||||
|
->assertSee('Prüfe die Marken');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_the_register_says_when_the_draft_differs_from_the_published_markers(): void
|
||||||
|
{
|
||||||
|
$this->signIn();
|
||||||
|
$element = $this->film();
|
||||||
|
app(MarkerDraft::class)->save($element, [['t' => 30, 'label' => 'Entwurf']], null);
|
||||||
|
|
||||||
|
$this->open($element->fresh())
|
||||||
|
->set('bereich', 'marken')
|
||||||
|
->assertSee('Arbeitsstand')
|
||||||
|
->assertSee('hasDraft\u0022:true', false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_the_register_warns_when_the_draft_is_older_than_the_latest_version(): void
|
||||||
|
{
|
||||||
|
$this->signIn();
|
||||||
|
$element = $this->film();
|
||||||
|
app(MarkerDraft::class)->save($element, [['t' => 30, 'label' => 'Entwurf']], null);
|
||||||
|
// Eine Fassung entsteht auf einem Weg, der den Arbeitsstand nicht berührt.
|
||||||
|
app(ContentService::class)->publishElementVersion($element, null, ['file' => 'inhalte/zweit.mp4', 'markers' => self::MARKERS]);
|
||||||
|
|
||||||
|
$this->open($element->fresh())
|
||||||
|
->set('bereich', 'marken')
|
||||||
|
->assertSee('stammt aus Fassung 1');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_the_version_view_names_the_markers_of_the_shown_version(): void
|
||||||
|
{
|
||||||
|
$this->signIn();
|
||||||
|
|
||||||
|
$this->open($this->film())->assertSee('Marken dieser Fassung')->assertSee('Einstieg');
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,404 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Tests\Feature;
|
||||||
|
|
||||||
|
use App\Domain\Catalog\ContentElement;
|
||||||
|
use App\Domain\Catalog\ContentElementVersion;
|
||||||
|
use App\Domain\Catalog\ContentService;
|
||||||
|
use App\Domain\Catalog\DomainRuleException;
|
||||||
|
use App\Domain\Media\FilmMarkers;
|
||||||
|
use App\Domain\Media\MarkerDraft;
|
||||||
|
use App\Filament\Support\CatalogReading;
|
||||||
|
use App\Filament\Support\ElementRevision;
|
||||||
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||||
|
use Illuminate\Support\Facades\Storage;
|
||||||
|
use Tests\TestCase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Marken eines Films: Arbeitsstand am Element, Übernahme in die Fassung und vor allem: Keine Marke geht verloren,
|
||||||
|
* wenn eine Fassung aus anderem Anlass entsteht (Text, neue Datei, Notiz).
|
||||||
|
*/
|
||||||
|
class FilmMarkersWorkflowTest extends TestCase
|
||||||
|
{
|
||||||
|
use RefreshDatabase;
|
||||||
|
|
||||||
|
// Hinweis: Gespeichertes JSON verliert die Nachkommastelle (10.0 wird 10). Verglichen wird deshalb der Wert
|
||||||
|
// (assertEquals), und FilmMarkers::same/ofVersion normalisieren beim Lesen, damit daraus keine Scheinänderung wird.
|
||||||
|
|
||||||
|
private const MARKERS = [
|
||||||
|
['t' => 10.0, 'label' => 'Einstieg', 'stop' => false, 'prompt' => ''],
|
||||||
|
['t' => 42.0, 'label' => 'Entscheidung', 'stop' => true, 'prompt' => 'Was würdest du tun?'],
|
||||||
|
];
|
||||||
|
|
||||||
|
private function film(array $metadata = ['file' => 'inhalte/film.mp4'], ?string $body = null): ContentElement
|
||||||
|
{
|
||||||
|
$element = app(ContentService::class)->createElement('film', 'film', 'Übungsfilm');
|
||||||
|
app(ContentService::class)->publishElementVersion($element, $body, $metadata);
|
||||||
|
|
||||||
|
return $element->fresh();
|
||||||
|
}
|
||||||
|
|
||||||
|
private function latest(ContentElement $element): ContentElementVersion
|
||||||
|
{
|
||||||
|
return $element->versions()->orderByDesc('number')->firstOrFail();
|
||||||
|
}
|
||||||
|
|
||||||
|
private function filmWithMarkers(): ContentElement
|
||||||
|
{
|
||||||
|
return $this->film(['file' => 'inhalte/film.mp4', 'markers' => self::MARKERS]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---- Keine Marke geht verloren -------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
public function test_a_text_only_revision_keeps_file_and_markers(): void
|
||||||
|
{
|
||||||
|
$element = $this->filmWithMarkers();
|
||||||
|
|
||||||
|
ElementRevision::publish($element, ['body' => 'Neuer Begleittext', 'change_note' => 'Text']);
|
||||||
|
|
||||||
|
$latest = $this->latest($element);
|
||||||
|
$this->assertSame(2, $latest->number);
|
||||||
|
$this->assertSame('inhalte/film.mp4', $latest->metadata['file']);
|
||||||
|
$this->assertEquals(self::MARKERS, $latest->metadata['markers']);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_the_service_carries_markers_when_a_caller_passes_the_same_file_without_them(): void
|
||||||
|
{
|
||||||
|
$element = $this->filmWithMarkers();
|
||||||
|
|
||||||
|
app(ContentService::class)->publishElementVersion($element, 'Notiz', ['file' => 'inhalte/film.mp4']);
|
||||||
|
|
||||||
|
$this->assertEquals(self::MARKERS, $this->latest($element)->metadata['markers']);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_the_service_respects_an_explicit_empty_list(): void
|
||||||
|
{
|
||||||
|
$element = $this->filmWithMarkers();
|
||||||
|
|
||||||
|
app(ContentService::class)->publishElementVersion($element, 'Notiz', ['file' => 'inhalte/film.mp4', 'markers' => []]);
|
||||||
|
|
||||||
|
$this->assertSame([], $this->latest($element)->metadata['markers']);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_a_new_file_keeps_the_markers_through_the_file_job(): void
|
||||||
|
{
|
||||||
|
Storage::fake('cms_incoming');
|
||||||
|
Storage::fake('media_derived');
|
||||||
|
Storage::disk('cms_incoming')->put('inhalte/neu.mp4', 'filmbytes');
|
||||||
|
$element = $this->filmWithMarkers();
|
||||||
|
|
||||||
|
ElementRevision::publish($element, ['incoming' => ['inhalte/neu.mp4']]);
|
||||||
|
|
||||||
|
$latest = $this->latest($element);
|
||||||
|
$this->assertSame(2, $latest->number);
|
||||||
|
$this->assertNotSame('inhalte/film.mp4', $latest->metadata['file']);
|
||||||
|
$this->assertEquals(self::MARKERS, $latest->metadata['markers']);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_dropping_the_file_drops_the_markers_and_the_draft(): void
|
||||||
|
{
|
||||||
|
$element = $this->filmWithMarkers();
|
||||||
|
app(MarkerDraft::class)->save($element, [['t' => 5, 'label' => 'Neu']], null);
|
||||||
|
|
||||||
|
ElementRevision::publish($element->fresh(), ['body' => 'Nur Text', 'drop_file' => true]);
|
||||||
|
|
||||||
|
$latest = $this->latest($element);
|
||||||
|
$this->assertArrayNotHasKey('file', $latest->metadata ?? []);
|
||||||
|
$this->assertArrayNotHasKey('markers', $latest->metadata ?? []);
|
||||||
|
$this->assertNull(app(MarkerDraft::class)->current($element));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_old_decision_value_becomes_a_marker_once_and_is_not_written_again(): void
|
||||||
|
{
|
||||||
|
$element = $this->film(['file' => 'inhalte/film.mp4', 'decision_seconds' => 12]);
|
||||||
|
|
||||||
|
ElementRevision::publish($element, ['body' => 'Text', 'change_note' => 'Text']);
|
||||||
|
|
||||||
|
$latest = $this->latest($element);
|
||||||
|
$this->assertEquals([['t' => 12.0, 'label' => 'Entscheidung', 'stop' => true, 'prompt' => '']], $latest->metadata['markers']);
|
||||||
|
$this->assertArrayNotHasKey('decision_seconds', $latest->metadata);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_a_deleted_marker_list_does_not_bring_the_old_decision_value_back(): void
|
||||||
|
{
|
||||||
|
$element = $this->film(['file' => 'inhalte/film.mp4', 'decision_seconds' => 12]);
|
||||||
|
app(MarkerDraft::class)->save($element, [], null);
|
||||||
|
|
||||||
|
ElementRevision::publish($element->fresh(), []);
|
||||||
|
ElementRevision::publish($element->fresh(), ['body' => 'Text', 'change_note' => 'x']);
|
||||||
|
|
||||||
|
$this->assertSame([], $this->latest($element)->metadata['markers']);
|
||||||
|
$this->assertSame([], FilmMarkers::ofVersion($this->latest($element)));
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---- Arbeitsstand ---------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
public function test_without_a_draft_the_effective_markers_are_those_of_the_latest_version(): void
|
||||||
|
{
|
||||||
|
$element = $this->filmWithMarkers();
|
||||||
|
|
||||||
|
$this->assertNull(app(MarkerDraft::class)->current($element));
|
||||||
|
$this->assertSame(self::MARKERS, app(MarkerDraft::class)->effective($element));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_saving_a_draft_stores_the_normalized_list_with_its_base_and_a_token(): void
|
||||||
|
{
|
||||||
|
$element = $this->filmWithMarkers();
|
||||||
|
|
||||||
|
$draft = app(MarkerDraft::class)->save($element, [
|
||||||
|
['t' => '50', 'label' => ' Neu ', 'stop' => true],
|
||||||
|
['t' => 5, 'label' => 'Anfang'],
|
||||||
|
], null);
|
||||||
|
|
||||||
|
$this->assertSame(1, $draft['base_version']);
|
||||||
|
$this->assertSame(['Anfang', 'Neu'], array_column($draft['markers'], 'label'));
|
||||||
|
$this->assertNotSame('', $draft['saved_at']);
|
||||||
|
$this->assertEquals($draft, app(MarkerDraft::class)->current($element));
|
||||||
|
$this->assertEquals($draft['markers'], app(MarkerDraft::class)->effective($element));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_the_draft_never_changes_what_members_see(): void
|
||||||
|
{
|
||||||
|
$element = $this->filmWithMarkers();
|
||||||
|
|
||||||
|
app(MarkerDraft::class)->save($element, [['t' => 99, 'label' => 'Nur Arbeitsstand']], null);
|
||||||
|
|
||||||
|
$this->assertSame(self::MARKERS, FilmMarkers::ofVersion($this->latest($element)));
|
||||||
|
$this->assertSame(1, $element->versions()->count());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_an_invalid_draft_is_refused_and_leaves_the_stored_one_untouched(): void
|
||||||
|
{
|
||||||
|
$element = $this->filmWithMarkers();
|
||||||
|
$kept = app(MarkerDraft::class)->save($element, [['t' => 5, 'label' => 'Gut']], null);
|
||||||
|
|
||||||
|
try {
|
||||||
|
app(MarkerDraft::class)->save($element, [['t' => 5, 'label' => 'A'], ['t' => 5.5, 'label' => 'B']], $kept['saved_at']);
|
||||||
|
$this->fail('Zu dichte Marken hätten abgelehnt werden müssen.');
|
||||||
|
} catch (DomainRuleException) {
|
||||||
|
$this->assertEquals($kept, app(MarkerDraft::class)->current($element));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_saving_with_a_stale_token_is_refused(): void
|
||||||
|
{
|
||||||
|
$element = $this->filmWithMarkers();
|
||||||
|
$first = app(MarkerDraft::class)->save($element, [['t' => 5, 'label' => 'A']], null);
|
||||||
|
app(MarkerDraft::class)->save($element, [['t' => 6, 'label' => 'B']], $first['saved_at']);
|
||||||
|
|
||||||
|
$this->expectException(DomainRuleException::class);
|
||||||
|
$this->expectExceptionMessage('inzwischen');
|
||||||
|
app(MarkerDraft::class)->save($element, [['t' => 7, 'label' => 'C']], $first['saved_at']);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_creating_a_first_draft_while_another_exists_is_refused(): void
|
||||||
|
{
|
||||||
|
$element = $this->filmWithMarkers();
|
||||||
|
app(MarkerDraft::class)->save($element, [['t' => 5, 'label' => 'A']], null);
|
||||||
|
|
||||||
|
$this->expectException(DomainRuleException::class);
|
||||||
|
app(MarkerDraft::class)->save($element, [['t' => 6, 'label' => 'B']], null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_an_empty_draft_is_a_draft_that_deletes_all_markers(): void
|
||||||
|
{
|
||||||
|
$element = $this->filmWithMarkers();
|
||||||
|
|
||||||
|
app(MarkerDraft::class)->save($element, [], null);
|
||||||
|
|
||||||
|
$this->assertNotNull(app(MarkerDraft::class)->current($element));
|
||||||
|
$this->assertSame([], app(MarkerDraft::class)->effective($element));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_discarding_returns_to_the_markers_of_the_version(): void
|
||||||
|
{
|
||||||
|
$element = $this->filmWithMarkers();
|
||||||
|
app(MarkerDraft::class)->save($element, [], null);
|
||||||
|
|
||||||
|
app(MarkerDraft::class)->discard($element);
|
||||||
|
|
||||||
|
$this->assertNull(app(MarkerDraft::class)->current($element));
|
||||||
|
$this->assertSame(self::MARKERS, app(MarkerDraft::class)->effective($element));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_the_draft_belongs_to_the_element_only(): void
|
||||||
|
{
|
||||||
|
$one = $this->filmWithMarkers();
|
||||||
|
$other = $this->filmWithMarkers();
|
||||||
|
|
||||||
|
app(MarkerDraft::class)->save($one, [], null);
|
||||||
|
|
||||||
|
$this->assertNull(app(MarkerDraft::class)->current($other));
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---- Übernahme in die Fassung ---------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
public function test_creating_a_version_applies_the_draft_and_clears_it(): void
|
||||||
|
{
|
||||||
|
$element = $this->filmWithMarkers();
|
||||||
|
$draft = app(MarkerDraft::class)->save($element, [['t' => 20, 'label' => 'Verschoben', 'stop' => true]], null);
|
||||||
|
|
||||||
|
$message = ElementRevision::publish($element->fresh(), []);
|
||||||
|
|
||||||
|
$latest = $this->latest($element);
|
||||||
|
$this->assertSame(2, $latest->number);
|
||||||
|
$this->assertEquals($draft['markers'], $latest->metadata['markers']);
|
||||||
|
$this->assertSame('inhalte/film.mp4', $latest->metadata['file']);
|
||||||
|
$this->assertNull(app(MarkerDraft::class)->current($element));
|
||||||
|
$this->assertEquals(self::MARKERS, $element->versions()->where('number', 1)->firstOrFail()->metadata['markers']);
|
||||||
|
$this->assertStringContainsString('neue Fassung', $message);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_a_change_to_the_markers_alone_counts_as_a_change(): void
|
||||||
|
{
|
||||||
|
$element = $this->filmWithMarkers();
|
||||||
|
app(MarkerDraft::class)->save($element, [['t' => 11, 'label' => 'Einstieg']], null);
|
||||||
|
|
||||||
|
ElementRevision::publish($element->fresh(), []);
|
||||||
|
|
||||||
|
$this->assertSame(2, $element->versions()->count());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_a_draft_equal_to_the_version_creates_no_version_but_is_cleared(): void
|
||||||
|
{
|
||||||
|
$element = $this->filmWithMarkers();
|
||||||
|
app(MarkerDraft::class)->save($element, self::MARKERS, null);
|
||||||
|
|
||||||
|
$message = ElementRevision::publish($element->fresh(), []);
|
||||||
|
|
||||||
|
$this->assertSame(1, $element->versions()->count());
|
||||||
|
$this->assertStringContainsString('keine neue Fassung', $message);
|
||||||
|
$this->assertNull(app(MarkerDraft::class)->current($element));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_the_same_markers_written_with_other_numbers_create_no_phantom_version(): void
|
||||||
|
{
|
||||||
|
$element = $this->film(['file' => 'inhalte/film.mp4', 'markers' => [['t' => 42, 'label' => 'A', 'stop' => true, 'prompt' => '']]]);
|
||||||
|
app(MarkerDraft::class)->save($element, [['t' => '42.0', 'label' => 'A', 'stop' => true]], null);
|
||||||
|
|
||||||
|
ElementRevision::publish($element->fresh(), []);
|
||||||
|
|
||||||
|
$this->assertSame(1, $element->versions()->count());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_without_any_change_there_is_no_new_version(): void
|
||||||
|
{
|
||||||
|
$element = $this->filmWithMarkers();
|
||||||
|
|
||||||
|
$message = ElementRevision::publish($element->fresh(), []);
|
||||||
|
|
||||||
|
$this->assertSame(1, $element->versions()->count());
|
||||||
|
$this->assertStringContainsString('keine neue Fassung', $message);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_markers_alone_never_make_a_version_without_text_or_file(): void
|
||||||
|
{
|
||||||
|
$element = app(ContentService::class)->createElement('film', 'film', 'Leer');
|
||||||
|
app(MarkerDraft::class)->save($element, [['t' => 5, 'label' => 'A']], null);
|
||||||
|
|
||||||
|
try {
|
||||||
|
ElementRevision::publish($element->fresh(), []);
|
||||||
|
$this->fail('Ohne Text und Datei darf keine Fassung entstehen.');
|
||||||
|
} catch (DomainRuleException $e) {
|
||||||
|
$this->assertStringContainsString('Text oder eine Datei', $e->getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->assertSame(0, $element->versions()->count());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_the_draft_is_read_fresh_when_a_version_is_created(): void
|
||||||
|
{
|
||||||
|
$element = $this->filmWithMarkers();
|
||||||
|
$stale = $element->fresh();
|
||||||
|
app(MarkerDraft::class)->save($element, [['t' => 30, 'label' => 'Später gespeichert']], null);
|
||||||
|
|
||||||
|
ElementRevision::publish($stale, []);
|
||||||
|
|
||||||
|
$this->assertSame('Später gespeichert', $this->latest($element)->metadata['markers'][0]['label']);
|
||||||
|
$this->assertNull(app(MarkerDraft::class)->current($element));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_a_failed_version_keeps_the_draft(): void
|
||||||
|
{
|
||||||
|
$element = app(ContentService::class)->createElement('film', 'film', 'Leer');
|
||||||
|
app(MarkerDraft::class)->save($element, [['t' => 5, 'label' => 'A']], null);
|
||||||
|
|
||||||
|
try {
|
||||||
|
ElementRevision::publish($element->fresh(), []);
|
||||||
|
} catch (DomainRuleException) {
|
||||||
|
// erwartet
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->assertNotNull(app(MarkerDraft::class)->current($element));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_the_version_list_names_the_markers_instead_of_the_old_decision_value(): void
|
||||||
|
{
|
||||||
|
$element = $this->filmWithMarkers();
|
||||||
|
$legacy = $this->film(['file' => 'inhalte/alt.mp4', 'decision_seconds' => 12]);
|
||||||
|
|
||||||
|
$lines = implode("\n", app(CatalogReading::class)->elementVersions($element));
|
||||||
|
$legacyLines = implode("\n", app(CatalogReading::class)->elementVersions($legacy));
|
||||||
|
|
||||||
|
$this->assertStringContainsString('2 Marken, davon 1 mit Stopp: 10 s Einstieg, 42 s Entscheidung', $lines);
|
||||||
|
$this->assertStringContainsString('1 Marke, davon 1 mit Stopp: 12 s Entscheidung', $legacyLines);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---- Hinweis nach einer neuen Datei ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
public function test_a_new_file_with_unchanged_markers_is_reported_for_a_check(): void
|
||||||
|
{
|
||||||
|
$element = $this->filmWithMarkers();
|
||||||
|
app(ContentService::class)->publishElementVersion($element, null, ['file' => 'inhalte/zweit.mp4']);
|
||||||
|
|
||||||
|
$this->assertTrue(FilmMarkers::fileChangedWithoutMarkers($element->fresh()));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_a_new_file_published_together_with_a_draft_is_reported_too(): void
|
||||||
|
{
|
||||||
|
Storage::fake('cms_incoming');
|
||||||
|
Storage::fake('media_derived');
|
||||||
|
Storage::disk('cms_incoming')->put('inhalte/neu.mp4', 'filmbytes');
|
||||||
|
$element = $this->filmWithMarkers();
|
||||||
|
app(MarkerDraft::class)->save($element, [['t' => 12, 'label' => 'Angepasst']], null);
|
||||||
|
|
||||||
|
ElementRevision::publish($element->fresh(), ['incoming' => ['inhalte/neu.mp4']]);
|
||||||
|
|
||||||
|
// Die Marken wurden zwar angepasst, aber nicht gegen den neuen Film geprüft: Es gibt keinen Zustand „geprüft“.
|
||||||
|
$this->assertTrue(FilmMarkers::fileChangedWithoutMarkers($element->fresh()));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_the_hint_stays_through_later_versions_that_leave_the_markers_alone(): void
|
||||||
|
{
|
||||||
|
$element = $this->filmWithMarkers();
|
||||||
|
app(ContentService::class)->publishElementVersion($element, null, ['file' => 'inhalte/zweit.mp4']);
|
||||||
|
ElementRevision::publish($element->fresh(), ['body' => 'Neuer Text', 'change_note' => 'Text']);
|
||||||
|
|
||||||
|
$this->assertTrue(FilmMarkers::fileChangedWithoutMarkers($element->fresh()));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_only_films_can_have_a_marker_draft(): void
|
||||||
|
{
|
||||||
|
$text = app(ContentService::class)->createElement('text', 'text', 'Kein Film');
|
||||||
|
|
||||||
|
$this->expectException(DomainRuleException::class);
|
||||||
|
$this->expectExceptionMessage('Filme');
|
||||||
|
app(MarkerDraft::class)->save($text, [['t' => 5, 'label' => 'A']], null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_the_hint_is_gone_once_the_markers_were_touched(): void
|
||||||
|
{
|
||||||
|
$element = $this->filmWithMarkers();
|
||||||
|
app(ContentService::class)->publishElementVersion($element, null, ['file' => 'inhalte/zweit.mp4']);
|
||||||
|
app(MarkerDraft::class)->save($element, [['t' => 12, 'label' => 'Angepasst']], null);
|
||||||
|
ElementRevision::publish($element->fresh(), []);
|
||||||
|
|
||||||
|
$this->assertFalse(FilmMarkers::fileChangedWithoutMarkers($element->fresh()));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_there_is_no_hint_for_a_film_without_markers_or_a_single_version(): void
|
||||||
|
{
|
||||||
|
$this->assertFalse(FilmMarkers::fileChangedWithoutMarkers($this->film()));
|
||||||
|
$this->assertFalse(FilmMarkers::fileChangedWithoutMarkers($this->filmWithMarkers()));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6,6 +6,7 @@
|
|||||||
use App\Domain\Catalog\ContentElementVersion;
|
use App\Domain\Catalog\ContentElementVersion;
|
||||||
use App\Domain\Catalog\ContentService;
|
use App\Domain\Catalog\ContentService;
|
||||||
use App\Domain\Catalog\ContentVersionStatus;
|
use App\Domain\Catalog\ContentVersionStatus;
|
||||||
|
use App\Domain\Media\MarkerDraft;
|
||||||
use App\Domain\Media\MediaRendition;
|
use App\Domain\Media\MediaRendition;
|
||||||
use App\Domain\Media\ThumbnailDeriver;
|
use App\Domain\Media\ThumbnailDeriver;
|
||||||
use App\Filament\Resources\Combinations\CombinationResource;
|
use App\Filament\Resources\Combinations\CombinationResource;
|
||||||
@@ -75,13 +76,14 @@ public function test_an_uploaded_file_becomes_a_ready_version(): void
|
|||||||
$editor = User::factory()->redakteur()->create();
|
$editor = User::factory()->redakteur()->create();
|
||||||
$editor->saveAppAuthenticationSecret('JBSWY3DPEHPK3PXP');
|
$editor->saveAppAuthenticationSecret('JBSWY3DPEHPK3PXP');
|
||||||
$this->actingAs($editor, 'staff');
|
$this->actingAs($editor, 'staff');
|
||||||
|
// Die Entscheidungsmarke ist keine Eingabe der Fassung mehr, sondern eine Marke aus dem Arbeitsstand.
|
||||||
|
app(MarkerDraft::class)->save($element, [['t' => 12, 'label' => 'Entscheidung', 'stop' => true]], null);
|
||||||
|
|
||||||
Livewire::test(ViewContentElement::class, ['record' => $element->getKey()])
|
Livewire::test(ViewContentElement::class, ['record' => $element->getKey()])
|
||||||
->callAction('revise', [
|
->callAction('revise', [
|
||||||
'working_title' => 'Übungsfilm',
|
'working_title' => 'Übungsfilm',
|
||||||
'body' => 'Anleitung zum Film',
|
'body' => 'Anleitung zum Film',
|
||||||
'incoming' => ['inhalte/film.mp4'],
|
'incoming' => ['inhalte/film.mp4'],
|
||||||
'decision_seconds' => 12,
|
|
||||||
])
|
])
|
||||||
->assertHasNoFormErrors();
|
->assertHasNoFormErrors();
|
||||||
|
|
||||||
@@ -90,7 +92,10 @@ public function test_an_uploaded_file_becomes_a_ready_version(): void
|
|||||||
$this->assertNotNull($version);
|
$this->assertNotNull($version);
|
||||||
$this->assertSame(ContentVersionStatus::Bereit, $version->status);
|
$this->assertSame(ContentVersionStatus::Bereit, $version->status);
|
||||||
$this->assertSame('inhalte/'.$version->id.'/film.mp4', $version->metadata['file']);
|
$this->assertSame('inhalte/'.$version->id.'/film.mp4', $version->metadata['file']);
|
||||||
$this->assertSame(12, $version->metadata['decision_seconds']);
|
$this->assertEquals(12, $version->metadata['markers'][0]['t']);
|
||||||
|
$this->assertTrue($version->metadata['markers'][0]['stop']);
|
||||||
|
$this->assertArrayNotHasKey('decision_seconds', $version->metadata);
|
||||||
|
$this->assertNull(app(MarkerDraft::class)->current($element));
|
||||||
$this->assertSame(MediaUploadLimit::KILOBYTES, EditContentElement::uploadField()->getMaxSize());
|
$this->assertSame(MediaUploadLimit::KILOBYTES, EditContentElement::uploadField()->getMaxSize());
|
||||||
$this->assertSame(MediaUploadLimit::rules(), FileUploadConfiguration::rules());
|
$this->assertSame(MediaUploadLimit::rules(), FileUploadConfiguration::rules());
|
||||||
Storage::disk('media_derived')->assertExists($version->metadata['file']);
|
Storage::disk('media_derived')->assertExists($version->metadata['file']);
|
||||||
|
|||||||
@@ -0,0 +1,137 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Tests\Unit;
|
||||||
|
|
||||||
|
use App\Domain\Catalog\ContentElementVersion;
|
||||||
|
use App\Domain\Catalog\DomainRuleException;
|
||||||
|
use App\Domain\Media\FilmMarkers;
|
||||||
|
use PHPUnit\Framework\Attributes\DataProvider;
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
|
class FilmMarkersTest extends TestCase
|
||||||
|
{
|
||||||
|
private function version(?array $metadata): ContentElementVersion
|
||||||
|
{
|
||||||
|
return new ContentElementVersion(['metadata' => $metadata]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_a_list_is_normalized_to_one_canonical_form(): void
|
||||||
|
{
|
||||||
|
$list = FilmMarkers::normalize([
|
||||||
|
['t' => '30', 'label' => ' Kapitel zwei ', 'stop' => false],
|
||||||
|
['t' => 10.04, 'label' => 'Entscheidung', 'stop' => true, 'prompt' => ' Was fällt auf? '],
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->assertSame([
|
||||||
|
['t' => 10.0, 'label' => 'Entscheidung', 'stop' => true, 'prompt' => 'Was fällt auf?'],
|
||||||
|
['t' => 30.0, 'label' => 'Kapitel zwei', 'stop' => false, 'prompt' => ''],
|
||||||
|
], $list);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_the_same_time_written_differently_is_the_same_list(): void
|
||||||
|
{
|
||||||
|
$a = FilmMarkers::normalize([['t' => 42, 'label' => 'A']]);
|
||||||
|
$b = FilmMarkers::normalize([['t' => 42.0, 'label' => 'A']]);
|
||||||
|
$c = FilmMarkers::normalize([['t' => '42.04', 'label' => 'A']]);
|
||||||
|
|
||||||
|
$this->assertTrue(FilmMarkers::same($a, $b));
|
||||||
|
$this->assertTrue(FilmMarkers::same($a, $c));
|
||||||
|
$this->assertSame(json_encode($a), json_encode($b));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_an_empty_list_is_valid_and_means_no_markers(): void
|
||||||
|
{
|
||||||
|
$this->assertSame([], FilmMarkers::normalize([]));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array<string, array{0: mixed, 1: string}>
|
||||||
|
*/
|
||||||
|
public static function invalidLists(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'keine Liste' => ['abc', 'Liste'],
|
||||||
|
'negative Zeit' => [[['t' => -1, 'label' => 'A']], 'Zeit'],
|
||||||
|
'Zeit ist Text' => [[['t' => 'bald', 'label' => 'A']], 'Zeit'],
|
||||||
|
'Zeit fehlt' => [[['label' => 'A']], 'Zeit'],
|
||||||
|
'Titel fehlt' => [[['t' => 5, 'label' => ' ']], 'Titel'],
|
||||||
|
'Titel zu lang' => [[['t' => 5, 'label' => str_repeat('x', 121)]], 'Titel'],
|
||||||
|
'Text zu lang' => [[['t' => 5, 'label' => 'A', 'prompt' => str_repeat('x', 1001)]], 'Text'],
|
||||||
|
'zu dicht' => [[['t' => 10, 'label' => 'A'], ['t' => 10.5, 'label' => 'B']], 'Abstand'],
|
||||||
|
'zwei gleiche Zeiten' => [[['t' => 10, 'label' => 'A'], ['t' => 10.04, 'label' => 'B']], 'Abstand'],
|
||||||
|
'Eintrag ist keine Marke' => [['x'], 'Marke'],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
#[DataProvider('invalidLists')]
|
||||||
|
public function test_invalid_lists_are_refused_with_a_reason(mixed $raw, string $word): void
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
FilmMarkers::normalize($raw);
|
||||||
|
$this->fail('Die Liste hätte abgelehnt werden müssen.');
|
||||||
|
} catch (DomainRuleException $e) {
|
||||||
|
$this->assertStringContainsString($word, $e->getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_more_than_a_hundred_markers_are_refused(): void
|
||||||
|
{
|
||||||
|
$list = [];
|
||||||
|
|
||||||
|
for ($i = 0; $i < 101; $i++) {
|
||||||
|
$list[] = ['t' => $i * 2, 'label' => 'M'.$i];
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->expectException(DomainRuleException::class);
|
||||||
|
FilmMarkers::normalize($list);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_a_version_without_any_marker_data_has_none(): void
|
||||||
|
{
|
||||||
|
$this->assertSame([], FilmMarkers::ofVersion(null));
|
||||||
|
$this->assertSame([], FilmMarkers::ofVersion($this->version(null)));
|
||||||
|
$this->assertSame([], FilmMarkers::ofVersion($this->version(['file' => 'x.mp4'])));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_the_old_decision_value_reads_as_one_stop_marker(): void
|
||||||
|
{
|
||||||
|
$this->assertSame(
|
||||||
|
[['t' => 12.0, 'label' => 'Entscheidung', 'stop' => true, 'prompt' => '']],
|
||||||
|
FilmMarkers::ofVersion($this->version(['decision_seconds' => 12])),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_an_old_decision_value_of_zero_is_no_marker(): void
|
||||||
|
{
|
||||||
|
$this->assertSame([], FilmMarkers::ofVersion($this->version(['decision_seconds' => 0])));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_the_markers_key_wins_even_when_it_is_empty(): void
|
||||||
|
{
|
||||||
|
$this->assertSame([], FilmMarkers::ofVersion($this->version(['markers' => [], 'decision_seconds' => 12])));
|
||||||
|
$this->assertCount(1, FilmMarkers::ofVersion($this->version([
|
||||||
|
'markers' => [['t' => 5, 'label' => 'A', 'stop' => false, 'prompt' => '']],
|
||||||
|
'decision_seconds' => 12,
|
||||||
|
])));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_stored_data_that_became_unreadable_is_repaired_instead_of_breaking_the_page(): void
|
||||||
|
{
|
||||||
|
$list = FilmMarkers::ofVersion($this->version(['markers' => [
|
||||||
|
['t' => 20, 'label' => 'B', 'stop' => false],
|
||||||
|
['t' => -3, 'label' => 'kaputt'],
|
||||||
|
'müll',
|
||||||
|
['t' => 20.2, 'label' => 'zu dicht'],
|
||||||
|
['t' => 5, 'label' => 'A', 'stop' => true],
|
||||||
|
]]));
|
||||||
|
|
||||||
|
$this->assertSame(['A', 'B'], array_column($list, 'label'));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_the_presence_of_the_markers_key_is_detectable(): void
|
||||||
|
{
|
||||||
|
$this->assertTrue(FilmMarkers::hasMarkers($this->version(['markers' => []])));
|
||||||
|
$this->assertFalse(FilmMarkers::hasMarkers($this->version(['decision_seconds' => 3])));
|
||||||
|
$this->assertFalse(FilmMarkers::hasMarkers(null));
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in new issue
Block a user