Complete 0.7.1 fixes
This commit is contained in:
1 parent
a08b02c34b
commit
64f55a8b1f
26 files changed
+610
-168
No files matched your search
@@ -15,6 +15,13 @@
|
||||
)
|
||||
);
|
||||
let visible = $derived(filtered.slice(0, 120));
|
||||
|
||||
function openAndFocus(event: MouseEvent) {
|
||||
if (menu.open) return;
|
||||
event.preventDefault();
|
||||
menu.open = true;
|
||||
searchInput.focus({ preventScroll: true });
|
||||
}
|
||||
</script>
|
||||
|
||||
<div class="icon-picker">
|
||||
@@ -25,7 +32,7 @@
|
||||
if (menu.open) queueMicrotask(() => searchInput.focus());
|
||||
}}
|
||||
>
|
||||
<summary><AppIcon name={name || 'circle'} /> Icon auswählen</summary>
|
||||
<summary onclick={openAndFocus}><AppIcon name={name || 'circle'} /> Icon auswählen</summary>
|
||||
<div class="icon-picker-popover">
|
||||
<label
|
||||
><span class="sr-only">Icons durchsuchen</span><input
|
||||
|
||||
@@ -62,7 +62,6 @@
|
||||
</article>
|
||||
{:else if content.mode === 'image'}
|
||||
<article class="output-content output-image-only">
|
||||
{#if content.topics.length}<p class="output-topics">{content.topics.join(' · ')}</p>{/if}
|
||||
{#if imageSrc}<img src={imageSrc} alt={content.images?.[0]?.altText ?? content.title} />{/if}
|
||||
</article>
|
||||
{:else if content.mode === 'link'}
|
||||
|
||||
@@ -27,11 +27,13 @@
|
||||
shows,
|
||||
shares,
|
||||
fixedShowId = '',
|
||||
catalogPanel = false,
|
||||
form = null
|
||||
}: {
|
||||
shows: ShareShow[];
|
||||
shares: ShareItem[];
|
||||
fixedShowId?: string;
|
||||
catalogPanel?: boolean;
|
||||
form?: {
|
||||
intent?: string;
|
||||
error?: string;
|
||||
@@ -104,18 +106,37 @@
|
||||
}
|
||||
</script>
|
||||
|
||||
<button
|
||||
class="secondary-button share-dialog-trigger"
|
||||
type="button"
|
||||
onclick={() => dialog.showModal()}
|
||||
>
|
||||
<AppIcon name="link" /> Lesefreigaben
|
||||
</button>
|
||||
<dialog bind:this={dialog} class="share-management-dialog">
|
||||
<section
|
||||
class="quiet-panel share-management"
|
||||
aria-labelledby={`share-title-${fixedShowId || 'all'}`}
|
||||
{#if catalogPanel}
|
||||
<section class="quiet-panel share-catalog-panel">
|
||||
<div class="panel-heading">
|
||||
<div>
|
||||
<p class="eyebrow">Gastzugänge</p>
|
||||
<h2>Lesefreigaben</h2>
|
||||
</div>
|
||||
<button
|
||||
class="compact-add-button share-dialog-trigger"
|
||||
type="button"
|
||||
aria-label="Lesefreigaben"
|
||||
onclick={() => dialog.showModal()}
|
||||
>
|
||||
<AppIcon name="link" /> Freigaben verwalten
|
||||
</button>
|
||||
</div>
|
||||
<p class="catalog-note">
|
||||
Sendungen gezielt als widerrufbaren Leselink mit wählbarem Informationsumfang teilen.
|
||||
</p>
|
||||
</section>
|
||||
{:else}
|
||||
<button
|
||||
class="secondary-button share-dialog-trigger"
|
||||
type="button"
|
||||
onclick={() => dialog.showModal()}
|
||||
>
|
||||
<AppIcon name="link" /> Lesefreigaben
|
||||
</button>
|
||||
{/if}
|
||||
<dialog bind:this={dialog} class="share-management-dialog">
|
||||
<section class="share-management" aria-labelledby={`share-title-${fixedShowId || 'all'}`}>
|
||||
<div class="panel-heading">
|
||||
<div>
|
||||
<p class="eyebrow">Gastzugänge</p>
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
import InlineTitleEditor from './InlineTitleEditor.svelte';
|
||||
import NavIcon from './NavIcon.svelte';
|
||||
import PieceEditorDialog from './PieceEditorDialog.svelte';
|
||||
import PresentationDisplay from './PresentationDisplay.svelte';
|
||||
import type { PieceUsage } from '#lib/server/shows.js';
|
||||
|
||||
let {
|
||||
@@ -32,6 +33,11 @@
|
||||
untrack(() => ({ ...usage, tools: usage.tools.map((tool) => ({ ...tool })) }))
|
||||
);
|
||||
let dirty = $state(false);
|
||||
let selectedSourceId = $state(
|
||||
untrack(
|
||||
() => usage.sources.find((source) => source.url === usage.presentationSourceUrl)?.id ?? ''
|
||||
)
|
||||
);
|
||||
onMount(() => {
|
||||
if (open) editor.showModal();
|
||||
});
|
||||
@@ -43,6 +49,16 @@
|
||||
return Number((seconds / 60).toFixed(2));
|
||||
}
|
||||
|
||||
function previewHtml(value: string) {
|
||||
return value
|
||||
.replaceAll('&', '&')
|
||||
.replaceAll('<', '<')
|
||||
.replaceAll('>', '>')
|
||||
.replaceAll('"', '"')
|
||||
.replaceAll("'", ''')
|
||||
.replaceAll('\n', '<br>');
|
||||
}
|
||||
|
||||
function requestClose() {
|
||||
if (dirty && !confirm('Ungespeicherte Änderungen verwerfen und Editor schließen?')) return;
|
||||
dirty = false;
|
||||
@@ -50,14 +66,46 @@
|
||||
}
|
||||
|
||||
function presentationSourceChanged(event: Event) {
|
||||
const index = Number((event.currentTarget as HTMLSelectElement).value);
|
||||
const source = draft.sources[index];
|
||||
selectedSourceId = (event.currentTarget as HTMLSelectElement).value;
|
||||
const source = draft.sources.find((item) => item.id === selectedSourceId);
|
||||
if (!source) return;
|
||||
draft.presentationSourceLabel = source.label;
|
||||
draft.presentationSourceUrl = source.url;
|
||||
draft.presentationSourceTimecodeSeconds = source.timecodeSeconds;
|
||||
}
|
||||
|
||||
let previewContent = $derived({
|
||||
mode: draft.presentationMode,
|
||||
topics: draft.topics.map((topic) => topic.name),
|
||||
title: draft.outputTitle || draft.title,
|
||||
html: previewHtml(draft.presentation),
|
||||
source: draft.presentationSourceUrl
|
||||
? {
|
||||
label: draft.presentationSourceLabel,
|
||||
url: draft.presentationSourceUrl,
|
||||
timecodeSeconds: draft.presentationSourceTimecodeSeconds
|
||||
}
|
||||
: null,
|
||||
previewTitle: draft.presentationTitle,
|
||||
description: draft.presentationDescription,
|
||||
imageUrl: draft.presentationMode === 'link' ? draft.presentationImageUrl : '',
|
||||
siteName: draft.presentationSiteName,
|
||||
provider: draft.presentationProvider,
|
||||
providerId: draft.presentationProviderId,
|
||||
embedUrl: '',
|
||||
sources: [],
|
||||
images: selectedMedia
|
||||
? [{ id: selectedMedia.originalMediaId, altText: selectedMedia.altText }]
|
||||
: []
|
||||
});
|
||||
let previewImageSrc = $derived(
|
||||
selectedMedia && draft.presentationMode === 'text'
|
||||
? '/media'
|
||||
: selectedMedia && draft.presentationMode === 'image'
|
||||
? `/media/${selectedMedia.originalMediaId}`
|
||||
: ''
|
||||
);
|
||||
|
||||
const enhanceEditor: SubmitFunction = async (input) => {
|
||||
const finish = await enhanceCommand(input);
|
||||
return async (result) => {
|
||||
@@ -139,6 +187,26 @@
|
||||
<details class="piece-meta-details">
|
||||
<summary>Dauer und Einplanung</summary>
|
||||
<div class="piece-meta-grid">
|
||||
<label
|
||||
>Vorbereitungsstatus<select
|
||||
name="preparationStatus"
|
||||
bind:value={draft.preparationStatus}
|
||||
>
|
||||
<option value="preparing">In Vorbereitung</option>
|
||||
<option value="ready">Sendefertig</option>
|
||||
</select></label
|
||||
>
|
||||
<label
|
||||
>Vorbereitungsaufwand<select
|
||||
name="preparationEffort"
|
||||
bind:value={draft.preparationEffort}
|
||||
>
|
||||
<option value={null}>Nicht angegeben</option>
|
||||
<option value="low">Gering</option>
|
||||
<option value="medium">Mittel</option>
|
||||
<option value="high">Hoch</option>
|
||||
</select></label
|
||||
>
|
||||
<label
|
||||
>Dauer in Minuten<input
|
||||
name="durationMinutes"
|
||||
@@ -275,12 +343,12 @@
|
||||
<div class="presentation-settings">
|
||||
<label class="wide-field"
|
||||
>{draft.presentationMode === 'video' ? 'Video-URL' : 'Quelle/URL'}<select
|
||||
bind:value={selectedSourceId}
|
||||
onchange={presentationSourceChanged}
|
||||
>
|
||||
{#each draft.sources as source, index (source.id)}
|
||||
<option value={index} selected={source.url === draft.presentationSourceUrl}
|
||||
>{source.label || source.url}</option
|
||||
>
|
||||
<option value="">Quelle auswählen</option>
|
||||
{#each draft.sources as source (source.id)}
|
||||
<option value={source.id}>{source.label || source.url}</option>
|
||||
{/each}
|
||||
</select></label
|
||||
>
|
||||
@@ -332,16 +400,16 @@
|
||||
class="usage-media-picker"
|
||||
>
|
||||
<legend>Hochgeladenes Präsentationsbild</legend>
|
||||
<label
|
||||
><input
|
||||
type="radio"
|
||||
checked={!draft.presentationMediaId}
|
||||
onchange={() => {
|
||||
draft.presentationMediaId = null;
|
||||
dirty = true;
|
||||
}}
|
||||
/> Kein Bild</label
|
||||
>
|
||||
{#if draft.presentationMode === 'text'}<label
|
||||
><input
|
||||
type="radio"
|
||||
checked={!draft.presentationMediaId}
|
||||
onchange={() => {
|
||||
draft.presentationMediaId = null;
|
||||
dirty = true;
|
||||
}}
|
||||
/> Kein Bild</label
|
||||
>{/if}
|
||||
<div class="media-grid">
|
||||
{#each draft.media as media (media.id)}<label class="media-presentation-choice"
|
||||
><input
|
||||
@@ -358,31 +426,7 @@
|
||||
</div>
|
||||
</fieldset>{/if}
|
||||
<aside class="piece-presentation-preview" aria-label="Präsentationsvorschau">
|
||||
<p class="output-kicker">Vorschau · {draft.presentationMode}</p>
|
||||
<h4>{draft.outputTitle || draft.title}</h4>
|
||||
{#if draft.presentationMode === 'text'}
|
||||
<p class="preview-markdown-source">
|
||||
{draft.presentation || 'Noch kein öffentlicher Text.'}
|
||||
</p>
|
||||
{#if selectedMedia}<img
|
||||
src={`/media/${selectedMedia.originalMediaId}`}
|
||||
alt={selectedMedia.altText}
|
||||
/>{/if}
|
||||
{:else if draft.presentationMode === 'image'}
|
||||
{#if selectedMedia}<img
|
||||
src={`/media/${selectedMedia.originalMediaId}`}
|
||||
alt={selectedMedia.altText}
|
||||
/>{/if}
|
||||
{:else if draft.presentationMode === 'link'}
|
||||
{#if draft.presentationImageUrl}<img src={draft.presentationImageUrl} alt="" />{/if}
|
||||
<p>
|
||||
{draft.presentationDescription ||
|
||||
draft.presentationSourceUrl ||
|
||||
'Noch keine Vorschauangaben.'}
|
||||
</p>
|
||||
{:else}
|
||||
<p>{draft.presentationSourceUrl || 'Noch keine Video-URL ausgewählt.'}</p>
|
||||
{/if}
|
||||
<PresentationDisplay content={previewContent} imageSrc={previewImageSrc} />
|
||||
</aside>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
@@ -62,7 +62,7 @@ describe('database setup', () => {
|
||||
database.close();
|
||||
|
||||
expect(counts).toEqual({
|
||||
migrations: 18,
|
||||
migrations: 19,
|
||||
pieces: 6,
|
||||
shows: 2,
|
||||
usages: 5,
|
||||
|
||||
@@ -286,6 +286,40 @@ describe('live mode', () => {
|
||||
expect(media).toBeNull();
|
||||
expect(await getPresentationMedia(token, 'unknown-image')).toBeNull();
|
||||
|
||||
getDatabase()
|
||||
.prepare(
|
||||
`INSERT INTO usage_media_snapshots
|
||||
(id, usage_id, original_media_id, alt_text, position, is_presentation)
|
||||
VALUES ('presentation-snapshot', 'usage-console', 'presentation-image',
|
||||
'Konsole auf dem Tisch', 0, 1)`
|
||||
)
|
||||
.run();
|
||||
getDatabase()
|
||||
.prepare(
|
||||
`UPDATE piece_usages SET presentation_mode_snapshot = 'text',
|
||||
presentation_image_only_snapshot = 1,
|
||||
presentation_image_url_snapshot = 'https://private.example.test/not-for-image-mode'
|
||||
WHERE id = 'usage-console'`
|
||||
)
|
||||
.run();
|
||||
presentUsage(
|
||||
'show-october',
|
||||
'usage-console',
|
||||
'present-image-only',
|
||||
getLiveView('show-october').liveRevision
|
||||
);
|
||||
expect(getPresentationView(token)?.content).toMatchObject({
|
||||
mode: 'image',
|
||||
imageUrl: '',
|
||||
images: [{ id: 'presentation-snapshot', altText: 'Konsole auf dem Tisch' }],
|
||||
sources: []
|
||||
});
|
||||
expect(await getPresentationMedia(token, 'presentation-snapshot')).toMatchObject({
|
||||
mimeType: 'image/png',
|
||||
byteSize: 10,
|
||||
altText: 'Konsole auf dem Tisch'
|
||||
});
|
||||
|
||||
const replacementToken = issuePresentationAccess('show-october');
|
||||
expect(replacementToken).toBe(token);
|
||||
expect(getPresentationView(token)?.content?.title).toBe(
|
||||
|
||||
+16
-12
@@ -1224,10 +1224,11 @@ function getPresentationViewForShow(showId: string): PresentationView {
|
||||
}
|
||||
| undefined;
|
||||
if (!usage) return { revision: state.presentation_revision, content: null };
|
||||
const mode = usage.presentation_mode_snapshot;
|
||||
return {
|
||||
revision: state.presentation_revision,
|
||||
content: {
|
||||
mode: usage.presentation_mode_snapshot,
|
||||
mode,
|
||||
topics: (
|
||||
database
|
||||
.prepare('SELECT name FROM usage_topic_snapshots WHERE usage_id = ? ORDER BY position')
|
||||
@@ -1244,7 +1245,7 @@ function getPresentationViewForShow(showId: string): PresentationView {
|
||||
: null,
|
||||
previewTitle: usage.presentation_title_meta_snapshot,
|
||||
description: usage.presentation_description_snapshot,
|
||||
imageUrl: usage.presentation_image_url_snapshot,
|
||||
imageUrl: mode === 'link' ? usage.presentation_image_url_snapshot : '',
|
||||
siteName: usage.presentation_site_name_snapshot,
|
||||
provider: usage.presentation_provider_snapshot,
|
||||
providerId: usage.presentation_provider_id_snapshot,
|
||||
@@ -1254,21 +1255,23 @@ function getPresentationViewForShow(showId: string): PresentationView {
|
||||
usage.presentation_source_timecode_snapshot
|
||||
),
|
||||
sources: [],
|
||||
images: (
|
||||
database
|
||||
.prepare(
|
||||
`SELECT id, alt_text FROM usage_media_snapshots
|
||||
WHERE usage_id = ? AND is_presentation = 1`
|
||||
)
|
||||
.all(state.presentation_usage_id) as { id: string; alt_text: string }[]
|
||||
).map((media) => ({ id: media.id, altText: media.alt_text }))
|
||||
images: ['text', 'image'].includes(mode)
|
||||
? (
|
||||
database
|
||||
.prepare(
|
||||
`SELECT id, alt_text FROM usage_media_snapshots
|
||||
WHERE usage_id = ? AND is_presentation = 1`
|
||||
)
|
||||
.all(state.presentation_usage_id) as { id: string; alt_text: string }[]
|
||||
).map((media) => ({ id: media.id, altText: media.alt_text }))
|
||||
: []
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export async function getPresentationPreviewImage(token: string) {
|
||||
const view = getPresentationView(token);
|
||||
if (!view?.content?.imageUrl || view.content.mode === 'text') return null;
|
||||
if (!view?.content?.imageUrl || view.content.mode !== 'link') return null;
|
||||
try {
|
||||
return await fetchPresentationImage(view.content.imageUrl);
|
||||
} catch {
|
||||
@@ -1292,7 +1295,8 @@ export async function getPresentationMedia(
|
||||
JOIN show_sections s ON s.id = u.show_section_id
|
||||
JOIN piece_media pm ON pm.id = ums.original_media_id
|
||||
WHERE state.show_id = ? AND s.show_id = state.show_id
|
||||
AND s.is_reserve_bank = 0 AND ums.id = ? AND ums.is_presentation = 1`
|
||||
AND s.is_reserve_bank = 0 AND ums.id = ? AND ums.is_presentation = 1
|
||||
AND (u.presentation_image_only_snapshot = 1 OR u.presentation_mode_snapshot = 'text')`
|
||||
)
|
||||
.get(showId, snapshotId) as
|
||||
{ storage_name: string; mime_type: string; byte_size: number; alt_text: string } | undefined;
|
||||
|
||||
@@ -61,31 +61,55 @@ function editedUsage(usage: PieceUsage, overrides: Partial<PieceUsage> = {}) {
|
||||
presentationImageUrl: edited.presentationImageUrl,
|
||||
presentationSiteName: edited.presentationSiteName,
|
||||
presentationMediaId: edited.presentationMediaId,
|
||||
preparationStatus: edited.preparationStatus,
|
||||
preparationEffort: edited.preparationEffort,
|
||||
ownNotes: edited.ownNotes,
|
||||
durationSeconds: edited.durationSeconds
|
||||
};
|
||||
}
|
||||
|
||||
describe('show builder data layer', () => {
|
||||
it('lists only scheduled preparing originals as concrete usage snapshots', () => {
|
||||
it('tracks preparation on the concrete usage independently from its original', () => {
|
||||
const database = getDatabase();
|
||||
database
|
||||
.prepare(
|
||||
"UPDATE pieces SET status = 'preparing', preparation_effort = 'high' WHERE id = 'piece-console'"
|
||||
)
|
||||
.run();
|
||||
const usages = listPreparationUsages();
|
||||
database.prepare("UPDATE pieces SET status = 'preparing' WHERE id = 'piece-sounds'").run();
|
||||
const show = getShow('show-october')!;
|
||||
const planned = addPieceUsage(show.id, show.revision, {
|
||||
pieceId: 'piece-console',
|
||||
sectionId: show.sections[0].id
|
||||
});
|
||||
|
||||
expect(usages.map((usage) => usage.usageId)).toEqual(['usage-games-console', 'usage-console']);
|
||||
expect(usages[1]).toMatchObject({
|
||||
database
|
||||
.prepare(
|
||||
"UPDATE pieces SET status = 'ready', preparation_effort = 'low' WHERE id = 'piece-console'"
|
||||
)
|
||||
.run();
|
||||
const usages = listPreparationUsages();
|
||||
expect(usages.map((usage) => usage.usageId)).toEqual([planned.id]);
|
||||
expect(usages[0]).toMatchObject({
|
||||
showId: 'show-october',
|
||||
showTitle: 'Herbstsendung: Kleine Welten',
|
||||
sectionName: 'Kleine Welten',
|
||||
sectionName: show.sections[0].name,
|
||||
title: 'Die kleine Konsole mit dem großen Dreh',
|
||||
preparationEffort: 'high',
|
||||
topics: [{ name: 'Gaming' }]
|
||||
});
|
||||
expect(usages.some((usage) => usage.title === 'Drei Sounds, ein Spiel')).toBe(false);
|
||||
|
||||
const plannedUsage = getShow(show.id)!.sections[0].usages.find(
|
||||
(usage) => usage.id === planned.id
|
||||
)!;
|
||||
updatePieceUsage(
|
||||
show.id,
|
||||
planned.id,
|
||||
planned.revision,
|
||||
editedUsage(plannedUsage, { preparationStatus: 'ready' })
|
||||
);
|
||||
expect(listPreparationUsages()).toEqual([]);
|
||||
});
|
||||
|
||||
it('creates a fundus original and usage atomically and idempotently', () => {
|
||||
|
||||
+123
-33
@@ -2,7 +2,7 @@ import { randomUUID } from 'node:crypto';
|
||||
import type Database from 'better-sqlite3';
|
||||
import { createPiece } from './content.js';
|
||||
import { getDatabase } from './database.js';
|
||||
import { detectVideoProvider, type PresentationMode } from './presentation.js';
|
||||
import { detectVideoProvider, type PresentationMode, type VideoProvider } from './presentation.js';
|
||||
|
||||
export const SHOW_STATUSES = ['draft', 'ready', 'live', 'completed'] as const;
|
||||
export const USAGE_STATUSES = ['open', 'current', 'done', 'skipped'] as const;
|
||||
@@ -10,6 +10,8 @@ export const USAGE_STATUSES = ['open', 'current', 'done', 'skipped'] as const;
|
||||
export type ShowStatus = (typeof SHOW_STATUSES)[number];
|
||||
export type EditableShowStatus = Exclude<ShowStatus, 'completed'>;
|
||||
export type UsageStatus = (typeof USAGE_STATUSES)[number];
|
||||
export type UsagePreparationStatus = 'preparing' | 'ready';
|
||||
export type PreparationEffort = 'low' | 'medium' | 'high' | null;
|
||||
|
||||
export type ShowListItem = {
|
||||
id: string;
|
||||
@@ -28,7 +30,7 @@ export type PreparationUsage = {
|
||||
showStartsAtUtc: string | null;
|
||||
sectionName: string;
|
||||
title: string;
|
||||
preparationEffort: 'low' | 'medium' | 'high' | null;
|
||||
preparationEffort: PreparationEffort;
|
||||
topics: UsageTopic[];
|
||||
};
|
||||
|
||||
@@ -53,6 +55,8 @@ export type PieceUsage = {
|
||||
originalPieceId: string | null;
|
||||
position: number;
|
||||
status: UsageStatus;
|
||||
preparationStatus: UsagePreparationStatus;
|
||||
preparationEffort: PreparationEffort;
|
||||
durationSeconds: number;
|
||||
title: string;
|
||||
outputTitle: string;
|
||||
@@ -70,7 +74,7 @@ export type PieceUsage = {
|
||||
presentationDescription: string;
|
||||
presentationImageUrl: string;
|
||||
presentationSiteName: string;
|
||||
presentationProvider: string;
|
||||
presentationProvider: VideoProvider | '';
|
||||
presentationProviderId: string;
|
||||
ownNotes: string;
|
||||
sources: { id: string; label: string; url: string; timecodeSeconds: number | null }[];
|
||||
@@ -186,6 +190,8 @@ export type PieceUsageUpdate = {
|
||||
presentationSiteName: string;
|
||||
ownNotes: string;
|
||||
durationSeconds: number;
|
||||
preparationStatus?: UsagePreparationStatus;
|
||||
preparationEffort?: PreparationEffort;
|
||||
tools?: { id: string; workUrl: string; note: string }[];
|
||||
presentationMediaId?: string | null;
|
||||
};
|
||||
@@ -231,6 +237,8 @@ type UsageRow = {
|
||||
original_piece_id: string | null;
|
||||
position: number;
|
||||
status: UsageStatus;
|
||||
preparation_status_snapshot: UsagePreparationStatus;
|
||||
preparation_effort_snapshot: PreparationEffort;
|
||||
duration_seconds: number;
|
||||
title_snapshot: string;
|
||||
output_title_snapshot: string;
|
||||
@@ -249,7 +257,7 @@ type UsageRow = {
|
||||
presentation_description_snapshot: string;
|
||||
presentation_image_url_snapshot: string;
|
||||
presentation_site_name_snapshot: string;
|
||||
presentation_provider_snapshot: string;
|
||||
presentation_provider_snapshot: VideoProvider | '';
|
||||
presentation_provider_id_snapshot: string;
|
||||
own_notes: string;
|
||||
};
|
||||
@@ -470,6 +478,8 @@ function usageFromRow(database: Database.Database, row: UsageRow): PieceUsage {
|
||||
originalPieceId: row.original_piece_id,
|
||||
position: row.position,
|
||||
status: row.status,
|
||||
preparationStatus: row.preparation_status_snapshot,
|
||||
preparationEffort: row.preparation_effort_snapshot,
|
||||
durationSeconds: row.duration_seconds,
|
||||
title: row.title_snapshot,
|
||||
outputTitle: row.output_title_snapshot,
|
||||
@@ -786,16 +796,16 @@ export function listPreparationUsages(): PreparationUsage[] {
|
||||
.prepare(
|
||||
`SELECT u.id AS usage_id, sh.id AS show_id, sh.title AS show_title,
|
||||
sh.starts_at_utc AS show_starts_at_utc, s.name AS section_name,
|
||||
u.title_snapshot, p.preparation_effort
|
||||
u.title_snapshot, u.preparation_effort_snapshot
|
||||
FROM piece_usages u
|
||||
JOIN show_sections s ON s.id = u.show_section_id
|
||||
JOIN shows sh ON sh.id = s.show_id
|
||||
JOIN pieces p ON p.id = u.original_piece_id
|
||||
WHERE sh.status IN ('draft', 'ready', 'live')
|
||||
AND s.is_reserve_bank = 0 AND p.deleted_at_utc IS NULL AND p.status = 'preparing'
|
||||
ORDER BY CASE p.preparation_effort
|
||||
AND s.is_reserve_bank = 0 AND u.preparation_status_snapshot = 'preparing'
|
||||
ORDER BY sh.starts_at_utc IS NULL, sh.starts_at_utc,
|
||||
CASE u.preparation_effort_snapshot
|
||||
WHEN 'high' THEN 0 WHEN 'medium' THEN 1 WHEN 'low' THEN 2 ELSE 3 END,
|
||||
sh.starts_at_utc IS NULL, sh.starts_at_utc, s.position, u.position`
|
||||
s.position, u.position`
|
||||
)
|
||||
.all() as {
|
||||
usage_id: string;
|
||||
@@ -804,7 +814,7 @@ export function listPreparationUsages(): PreparationUsage[] {
|
||||
show_starts_at_utc: string | null;
|
||||
section_name: string;
|
||||
title_snapshot: string;
|
||||
preparation_effort: PreparationUsage['preparationEffort'];
|
||||
preparation_effort_snapshot: PreparationUsage['preparationEffort'];
|
||||
}[];
|
||||
const topics = database.prepare(
|
||||
'SELECT name, icon_name FROM usage_topic_snapshots WHERE usage_id = ? ORDER BY position'
|
||||
@@ -816,7 +826,7 @@ export function listPreparationUsages(): PreparationUsage[] {
|
||||
showStartsAtUtc: row.show_starts_at_utc,
|
||||
sectionName: row.section_name,
|
||||
title: row.title_snapshot,
|
||||
preparationEffort: row.preparation_effort,
|
||||
preparationEffort: row.preparation_effort_snapshot,
|
||||
topics: (topics.all(row.usage_id) as { name: string; icon_name: string }[]).map((topic) => ({
|
||||
name: topic.name,
|
||||
iconName: topic.icon_name
|
||||
@@ -876,6 +886,7 @@ export function getShow(id: string): Show | null {
|
||||
const usageRows = database
|
||||
.prepare(
|
||||
`SELECT u.id, u.show_section_id, u.original_piece_id, u.position, u.status,
|
||||
u.preparation_status_snapshot, u.preparation_effort_snapshot,
|
||||
u.duration_seconds, u.title_snapshot, u.output_title_snapshot, u.intro_snapshot, u.research_snapshot,
|
||||
u.moderation_snapshot, u.interaction_snapshot, u.transition_snapshot, u.presentation_snapshot,
|
||||
CASE WHEN u.presentation_image_only_snapshot = 1 THEN 'image' ELSE u.presentation_mode_snapshot END AS presentation_mode_snapshot,
|
||||
@@ -1138,8 +1149,9 @@ export function duplicateCompletedShow(
|
||||
presentation_source_url_snapshot, presentation_source_timecode_snapshot,
|
||||
presentation_title_meta_snapshot, presentation_description_snapshot,
|
||||
presentation_image_url_snapshot, presentation_site_name_snapshot,
|
||||
presentation_provider_snapshot, presentation_provider_id_snapshot, presentation_image_only_snapshot, own_notes, is_reserve)
|
||||
VALUES (?, ?, ?, ?, 'open', ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`
|
||||
presentation_provider_snapshot, presentation_provider_id_snapshot, presentation_image_only_snapshot,
|
||||
preparation_status_snapshot, preparation_effort_snapshot, own_notes, is_reserve)
|
||||
VALUES (?, ?, ?, ?, 'open', ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`
|
||||
);
|
||||
for (const section of sections) {
|
||||
const sectionId = randomUUID();
|
||||
@@ -1182,6 +1194,8 @@ export function duplicateCompletedShow(
|
||||
usage.presentation_provider_snapshot,
|
||||
usage.presentation_provider_id_snapshot,
|
||||
usage.presentation_image_only_snapshot,
|
||||
usage.preparation_status_snapshot,
|
||||
usage.preparation_effort_snapshot,
|
||||
usage.own_notes,
|
||||
usage.is_reserve
|
||||
);
|
||||
@@ -1361,7 +1375,8 @@ export function addPieceUsage(
|
||||
COALESCE(ps.url, '') AS presentation_source_url,
|
||||
ps.timecode_seconds AS presentation_source_timecode,
|
||||
p.presentation_title, p.presentation_description, p.presentation_image_url,
|
||||
p.presentation_site_name, p.presentation_provider, p.presentation_provider_id
|
||||
p.presentation_site_name, p.presentation_provider, p.presentation_provider_id,
|
||||
p.preparation_effort
|
||||
FROM pieces p LEFT JOIN piece_sources ps ON ps.piece_id = p.id
|
||||
AND ps.position = p.presentation_source_position WHERE p.id = ?`
|
||||
)
|
||||
@@ -1387,6 +1402,7 @@ export function addPieceUsage(
|
||||
presentation_provider: string;
|
||||
presentation_provider_id: string;
|
||||
status: string;
|
||||
preparation_effort: PreparationEffort;
|
||||
}
|
||||
| undefined;
|
||||
if (!piece) throw new Error('NOT_FOUND');
|
||||
@@ -1397,7 +1413,7 @@ export function addPieceUsage(
|
||||
) {
|
||||
throw new Error('NOT_FOUND');
|
||||
}
|
||||
if (piece.status !== 'ready') throw new Error('PIECE_NOT_READY');
|
||||
if (!['preparing', 'ready'].includes(piece.status)) throw new Error('PIECE_NOT_READY');
|
||||
const ids = (
|
||||
database
|
||||
.prepare('SELECT id FROM piece_usages WHERE show_section_id = ? ORDER BY position')
|
||||
@@ -1414,8 +1430,9 @@ export function addPieceUsage(
|
||||
presentation_source_url_snapshot, presentation_source_timecode_snapshot,
|
||||
presentation_title_meta_snapshot, presentation_description_snapshot,
|
||||
presentation_image_url_snapshot, presentation_site_name_snapshot,
|
||||
presentation_provider_snapshot, presentation_provider_id_snapshot, own_notes, is_reserve)
|
||||
VALUES (?, ?, ?, ?, 'open', ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, '', ?)`
|
||||
presentation_provider_snapshot, presentation_provider_id_snapshot,
|
||||
preparation_status_snapshot, preparation_effort_snapshot, own_notes, is_reserve)
|
||||
VALUES (?, ?, ?, ?, 'open', ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, '', ?)`
|
||||
)
|
||||
.run(
|
||||
id,
|
||||
@@ -1442,6 +1459,8 @@ export function addPieceUsage(
|
||||
piece.presentation_site_name,
|
||||
piece.presentation_provider,
|
||||
piece.presentation_provider_id,
|
||||
piece.status,
|
||||
piece.preparation_effort,
|
||||
input.sectionId === null ? 1 : 0
|
||||
);
|
||||
snapshotPieceRelations(database, id, input.pieceId);
|
||||
@@ -1523,6 +1542,7 @@ export function duplicatePieceUsage(
|
||||
presentation_title_meta_snapshot, presentation_description_snapshot,
|
||||
presentation_image_url_snapshot, presentation_site_name_snapshot,
|
||||
presentation_provider_snapshot, presentation_provider_id_snapshot,
|
||||
preparation_status_snapshot, preparation_effort_snapshot,
|
||||
own_notes, is_reserve FROM piece_usages WHERE id = ?`
|
||||
)
|
||||
.get(usageId) as Omit<UsageRow, 'id' | 'show_section_id' | 'position'> & {
|
||||
@@ -1545,8 +1565,9 @@ export function duplicatePieceUsage(
|
||||
presentation_source_url_snapshot, presentation_source_timecode_snapshot,
|
||||
presentation_title_meta_snapshot, presentation_description_snapshot,
|
||||
presentation_image_url_snapshot, presentation_site_name_snapshot,
|
||||
presentation_provider_snapshot, presentation_provider_id_snapshot, own_notes, is_reserve)
|
||||
VALUES (?, ?, ?, ?, 'open', ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`
|
||||
presentation_provider_snapshot, presentation_provider_id_snapshot,
|
||||
preparation_status_snapshot, preparation_effort_snapshot, own_notes, is_reserve)
|
||||
VALUES (?, ?, ?, ?, 'open', ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`
|
||||
)
|
||||
.run(
|
||||
id,
|
||||
@@ -1573,6 +1594,8 @@ export function duplicatePieceUsage(
|
||||
source.presentation_site_name_snapshot,
|
||||
source.presentation_provider_snapshot,
|
||||
source.presentation_provider_id_snapshot,
|
||||
source.preparation_status_snapshot,
|
||||
source.preparation_effort_snapshot,
|
||||
source.own_notes,
|
||||
source.is_reserve
|
||||
);
|
||||
@@ -1601,7 +1624,8 @@ export function refreshPieceUsageFromOriginal(
|
||||
COALESCE(ps.url, '') AS presentation_source_url,
|
||||
ps.timecode_seconds AS presentation_source_timecode,
|
||||
p.presentation_title, p.presentation_description, p.presentation_image_url,
|
||||
p.presentation_site_name, p.presentation_provider, p.presentation_provider_id
|
||||
p.presentation_site_name, p.presentation_provider, p.presentation_provider_id,
|
||||
p.status, p.preparation_effort
|
||||
FROM piece_usages u JOIN pieces p ON p.id = u.original_piece_id
|
||||
LEFT JOIN piece_sources ps ON ps.piece_id = p.id
|
||||
AND ps.position = p.presentation_source_position
|
||||
@@ -1628,9 +1652,12 @@ export function refreshPieceUsageFromOriginal(
|
||||
presentation_site_name: string;
|
||||
presentation_provider: string;
|
||||
presentation_provider_id: string;
|
||||
status: string;
|
||||
preparation_effort: PreparationEffort;
|
||||
}
|
||||
| undefined;
|
||||
if (!source) throw new Error('ORIGINAL_NOT_FOUND');
|
||||
if (!['preparing', 'ready'].includes(source.status)) throw new Error('PIECE_NOT_READY');
|
||||
database
|
||||
.prepare(
|
||||
`UPDATE piece_usages SET title_snapshot = ?, output_title_snapshot = ?, duration_seconds = ?, intro_snapshot = ?,
|
||||
@@ -1640,7 +1667,8 @@ export function refreshPieceUsageFromOriginal(
|
||||
presentation_source_timecode_snapshot = ?, presentation_title_meta_snapshot = ?,
|
||||
presentation_description_snapshot = ?, presentation_image_url_snapshot = ?,
|
||||
presentation_site_name_snapshot = ?, presentation_provider_snapshot = ?,
|
||||
presentation_provider_id_snapshot = ? WHERE id = ?`
|
||||
presentation_provider_id_snapshot = ?, preparation_status_snapshot = ?,
|
||||
preparation_effort_snapshot = ? WHERE id = ?`
|
||||
)
|
||||
.run(
|
||||
source.title,
|
||||
@@ -1663,6 +1691,8 @@ export function refreshPieceUsageFromOriginal(
|
||||
source.presentation_site_name,
|
||||
source.presentation_provider,
|
||||
source.presentation_provider_id,
|
||||
source.status,
|
||||
source.preparation_effort,
|
||||
usageId
|
||||
);
|
||||
snapshotPieceRelations(
|
||||
@@ -1687,6 +1717,18 @@ export function updatePieceUsage(
|
||||
const title = cleanText(input.title, 200, 'title', true);
|
||||
const outputTitle = cleanText(input.outputTitle, 300, 'output_title');
|
||||
const duration = validDuration(input.durationSeconds)!;
|
||||
if (
|
||||
input.preparationStatus !== undefined &&
|
||||
!['preparing', 'ready'].includes(input.preparationStatus)
|
||||
) {
|
||||
throw new Error('INVALID_PREPARATION_STATUS');
|
||||
}
|
||||
if (
|
||||
input.preparationEffort !== undefined &&
|
||||
![null, 'low', 'medium', 'high'].includes(input.preparationEffort)
|
||||
) {
|
||||
throw new Error('INVALID_PREPARATION_EFFORT');
|
||||
}
|
||||
const values = {
|
||||
intro: cleanText(input.intro, 50_000, 'intro'),
|
||||
research: cleanText(input.research, 50_000, 'research'),
|
||||
@@ -1697,7 +1739,7 @@ export function updatePieceUsage(
|
||||
presentation: cleanText(input.presentation, 50_000, 'presentation'),
|
||||
ownNotes: cleanText(input.ownNotes, 50_000, 'notes')
|
||||
};
|
||||
const presentation = validPresentation(
|
||||
const submittedPresentation = validPresentation(
|
||||
input.presentationMode,
|
||||
input.presentationSourceLabel,
|
||||
input.presentationSourceUrl,
|
||||
@@ -1711,6 +1753,57 @@ export function updatePieceUsage(
|
||||
return database.transaction(() => {
|
||||
const result = bumpShow(database, showId, expectedRevision);
|
||||
usageSection(database, showId, usageId);
|
||||
const currentPreparation = database
|
||||
.prepare(
|
||||
`SELECT preparation_status_snapshot, preparation_effort_snapshot
|
||||
FROM piece_usages WHERE id = ?`
|
||||
)
|
||||
.get(usageId) as {
|
||||
preparation_status_snapshot: UsagePreparationStatus;
|
||||
preparation_effort_snapshot: PreparationEffort;
|
||||
};
|
||||
let presentation = submittedPresentation;
|
||||
if (presentation.mode === 'link' || presentation.mode === 'video') {
|
||||
const source = database
|
||||
.prepare(
|
||||
`SELECT label, url, timecode_seconds FROM usage_source_snapshots
|
||||
WHERE usage_id = ? AND url = ?`
|
||||
)
|
||||
.get(usageId, presentation.sourceUrl) as
|
||||
{ label: string; url: string; timecode_seconds: number | null } | undefined;
|
||||
if (!source) throw new Error('INVALID_PRESENTATION');
|
||||
presentation = validPresentation(
|
||||
presentation.mode,
|
||||
source.label,
|
||||
source.url,
|
||||
source.timecode_seconds,
|
||||
presentation.title,
|
||||
presentation.description,
|
||||
presentation.imageUrl,
|
||||
presentation.siteName
|
||||
);
|
||||
}
|
||||
const selectedMediaId =
|
||||
input.presentationMediaId === undefined
|
||||
? ((
|
||||
database
|
||||
.prepare(
|
||||
'SELECT id FROM usage_media_snapshots WHERE usage_id = ? AND is_presentation = 1'
|
||||
)
|
||||
.get(usageId) as { id: string } | undefined
|
||||
)?.id ?? null)
|
||||
: input.presentationMediaId;
|
||||
if (
|
||||
selectedMediaId !== null &&
|
||||
!database
|
||||
.prepare('SELECT 1 FROM usage_media_snapshots WHERE id = ? AND usage_id = ?')
|
||||
.get(selectedMediaId, usageId)
|
||||
) {
|
||||
throw new Error('INVALID_PRESENTATION_MEDIA');
|
||||
}
|
||||
if (presentation.mode === 'image' && !selectedMediaId) {
|
||||
throw new Error('INVALID_PRESENTATION_MEDIA');
|
||||
}
|
||||
database
|
||||
.prepare(
|
||||
`UPDATE piece_usages SET title_snapshot = ?, output_title_snapshot = ?, intro_snapshot = ?, research_snapshot = ?,
|
||||
@@ -1720,7 +1813,8 @@ export function updatePieceUsage(
|
||||
presentation_title_meta_snapshot = ?, presentation_description_snapshot = ?,
|
||||
presentation_image_url_snapshot = ?, presentation_site_name_snapshot = ?,
|
||||
presentation_provider_snapshot = ?, presentation_provider_id_snapshot = ?,
|
||||
own_notes = ?, duration_seconds = ? WHERE id = ?`
|
||||
own_notes = ?, duration_seconds = ?, preparation_status_snapshot = ?,
|
||||
preparation_effort_snapshot = ? WHERE id = ?`
|
||||
)
|
||||
.run(
|
||||
title,
|
||||
@@ -1744,6 +1838,10 @@ export function updatePieceUsage(
|
||||
presentation.providerId,
|
||||
values.ownNotes,
|
||||
duration,
|
||||
input.preparationStatus ?? currentPreparation.preparation_status_snapshot,
|
||||
input.preparationEffort === undefined
|
||||
? currentPreparation.preparation_effort_snapshot
|
||||
: input.preparationEffort,
|
||||
usageId
|
||||
);
|
||||
if (input.tools) {
|
||||
@@ -1776,23 +1874,15 @@ export function updatePieceUsage(
|
||||
}
|
||||
}
|
||||
if (input.presentationMediaId !== undefined) {
|
||||
if (
|
||||
input.presentationMediaId !== null &&
|
||||
!database
|
||||
.prepare('SELECT 1 FROM usage_media_snapshots WHERE id = ? AND usage_id = ?')
|
||||
.get(input.presentationMediaId, usageId)
|
||||
) {
|
||||
throw new Error('INVALID_PRESENTATION_MEDIA');
|
||||
}
|
||||
database
|
||||
.prepare('UPDATE usage_media_snapshots SET is_presentation = 0 WHERE usage_id = ?')
|
||||
.run(usageId);
|
||||
if (input.presentationMediaId !== null) {
|
||||
if (selectedMediaId !== null) {
|
||||
database
|
||||
.prepare(
|
||||
'UPDATE usage_media_snapshots SET is_presentation = 1 WHERE id = ? AND usage_id = ?'
|
||||
)
|
||||
.run(input.presentationMediaId, usageId);
|
||||
.run(selectedMediaId, usageId);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
|
||||
Reference in new issue
Block a user