mirror of
https://github.com/cpvalente/ontime.git
synced 2026-09-05 22:39:11 +00:00
Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 9d2c86d6be |
@@ -7,15 +7,13 @@
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover" />
|
||||
<meta name="theme-color" content="#101010" />
|
||||
<meta name="ontime" content="ontime - time keeping for live events" />
|
||||
<meta name="apple-mobile-web-app-capable" content="yes" />
|
||||
<meta name="mobile-web-app-capable" content="yes" />
|
||||
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />
|
||||
<meta name="apple-mobile-web-app-title" content="Ontime" />
|
||||
<link rel="apple-touch-icon" href="ontime-logo.png" />
|
||||
<link rel="icon" type="image/png" href="ontime-logo.png" />
|
||||
<link rel="manifest" href="site.webmanifest" />
|
||||
<link rel="manifest" href="manifest.json" />
|
||||
<meta name="robots" content="noindex" />
|
||||
<title>Ontime</title>
|
||||
<title>ontime</title>
|
||||
</head>
|
||||
<body>
|
||||
<noscript>You need to enable JavaScript to run this app.</noscript>
|
||||
|
||||
@@ -1,21 +1,19 @@
|
||||
{
|
||||
"name": "Ontime",
|
||||
"short_name": "Ontime",
|
||||
"name": "ontime",
|
||||
"short_name": "ontime",
|
||||
"icons": [
|
||||
{
|
||||
"src": "ontime-logo-192.png",
|
||||
"sizes": "192x192",
|
||||
"type": "image/png"
|
||||
"src": "favicon.ico",
|
||||
"type": "image/x-icon"
|
||||
},
|
||||
{
|
||||
"src": "ontime-logo-512.png",
|
||||
"sizes": "512x512",
|
||||
"src": "ontime-logo.png",
|
||||
"type": "image/png"
|
||||
}
|
||||
],
|
||||
"scope": "./",
|
||||
"start_url": "./",
|
||||
"display": "standalone",
|
||||
"theme_color": "#101010",
|
||||
"display": "",
|
||||
"theme_color": "#121212",
|
||||
"background_color": "#101010"
|
||||
}
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 21 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 84 KiB |
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"name": "",
|
||||
"short_name": "",
|
||||
"icons": [{ "src": "ontime-logo.png", "sizes": "295x295", "type": "image/png" }],
|
||||
"theme_color": "#121212",
|
||||
"background_color": "#101010",
|
||||
"display": "standalone"
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
import axios from 'axios';
|
||||
import type { ReportData } from 'ontime-types';
|
||||
import { OntimeReport } from 'ontime-types';
|
||||
|
||||
import { ontimeQueryClient } from '../../common/queryClient';
|
||||
import { REPORT, apiEntryUrl } from './constants';
|
||||
@@ -8,13 +8,18 @@ import type { RequestOptions } from './requestOptions';
|
||||
export const reportUrl = `${apiEntryUrl}/report`;
|
||||
|
||||
/**
|
||||
* HTTP request to fetch the report
|
||||
* HTTP request to fetch all reports
|
||||
*/
|
||||
export async function fetchReport(options?: RequestOptions): Promise<ReportData> {
|
||||
export async function fetchReport(options?: RequestOptions): Promise<OntimeReport> {
|
||||
const res = await axios.get(reportUrl, { signal: options?.signal });
|
||||
return res.data;
|
||||
}
|
||||
|
||||
export async function deleteReport(id: string) {
|
||||
await axios.delete(`${reportUrl}/${id}`);
|
||||
await ontimeQueryClient.invalidateQueries({ queryKey: REPORT });
|
||||
}
|
||||
|
||||
export async function deleteAllReport() {
|
||||
await axios.delete(`${reportUrl}/all`);
|
||||
await ontimeQueryClient.invalidateQueries({ queryKey: REPORT });
|
||||
|
||||
@@ -1,34 +1,17 @@
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
import type { ReportData } from 'ontime-types';
|
||||
import { OntimeReport } from 'ontime-types';
|
||||
import { MILLIS_PER_HOUR } from 'ontime-utils';
|
||||
|
||||
import { REPORT } from '../api/constants';
|
||||
import { fetchReport } from '../api/report';
|
||||
|
||||
const emptyReport: ReportData = {
|
||||
eventReports: {},
|
||||
rundown: null,
|
||||
show: {
|
||||
plannedStart: null,
|
||||
plannedEnd: null,
|
||||
plannedDuration: null,
|
||||
actualStart: null,
|
||||
actualEnd: null,
|
||||
actualDuration: null,
|
||||
},
|
||||
};
|
||||
|
||||
export default function useReport() {
|
||||
const { data: report, refetch } = useQuery<ReportData>({
|
||||
const { data, refetch } = useQuery<OntimeReport>({
|
||||
queryKey: REPORT,
|
||||
queryFn: ({ signal }) => fetchReport({ signal }),
|
||||
placeholderData: (previousData) => previousData,
|
||||
placeholderData: (previousData, _previousQuery) => previousData,
|
||||
staleTime: MILLIS_PER_HOUR,
|
||||
});
|
||||
|
||||
return {
|
||||
data: report?.eventReports ?? emptyReport.eventReports,
|
||||
report: report ?? emptyReport,
|
||||
refetch,
|
||||
};
|
||||
return { data: data ?? {}, refetch };
|
||||
}
|
||||
|
||||
@@ -0,0 +1,81 @@
|
||||
import { Playback, RuntimeStore, TimerPhase, TimerType, runtimeStorePlaceholder } from 'ontime-types';
|
||||
|
||||
import { resolveTimerDisplay } from '../useSocket.utils';
|
||||
|
||||
const eventTimer = { ...runtimeStorePlaceholder.timer, current: 5_000 };
|
||||
const groupTimer = {
|
||||
...runtimeStorePlaceholder.timer,
|
||||
current: 25_000,
|
||||
phase: TimerPhase.Default,
|
||||
playback: Playback.Play,
|
||||
};
|
||||
|
||||
function makeState(patch: Partial<RuntimeStore> = {}): RuntimeStore {
|
||||
return {
|
||||
...runtimeStorePlaceholder,
|
||||
timer: eventTimer,
|
||||
eventNow: {
|
||||
id: 'event-1',
|
||||
timerType: TimerType.CountUp,
|
||||
countToEnd: true,
|
||||
} as RuntimeStore['eventNow'],
|
||||
...patch,
|
||||
};
|
||||
}
|
||||
|
||||
describe('resolveTimerDisplay()', () => {
|
||||
it('uses the event timer by default', () => {
|
||||
expect(resolveTimerDisplay(makeState())).toMatchObject({
|
||||
time: eventTimer,
|
||||
timerType: TimerType.CountUp,
|
||||
countToEnd: true,
|
||||
usesGroupTimer: false,
|
||||
});
|
||||
});
|
||||
|
||||
it('uses the group timer and display type when enabled', () => {
|
||||
const display = resolveTimerDisplay(
|
||||
makeState({
|
||||
groupNow: { useGroupTimer: true, timerType: TimerType.CountDown } as RuntimeStore['groupNow'],
|
||||
groupTimer,
|
||||
}),
|
||||
);
|
||||
|
||||
expect(display).toMatchObject({
|
||||
time: groupTimer,
|
||||
timerType: TimerType.CountDown,
|
||||
countToEnd: false,
|
||||
usesGroupTimer: true,
|
||||
eventTimer,
|
||||
eventTimerType: TimerType.CountUp,
|
||||
});
|
||||
});
|
||||
|
||||
it('ignores a group timer when the group setting is disabled', () => {
|
||||
const display = resolveTimerDisplay(
|
||||
makeState({
|
||||
groupNow: { useGroupTimer: false, timerType: TimerType.CountDown } as RuntimeStore['groupNow'],
|
||||
groupTimer,
|
||||
}),
|
||||
);
|
||||
|
||||
expect(display.time).toBe(eventTimer);
|
||||
expect(display.usesGroupTimer).toBe(false);
|
||||
});
|
||||
|
||||
it('falls back entirely to the event display while group timer data is unavailable', () => {
|
||||
const display = resolveTimerDisplay(
|
||||
makeState({
|
||||
groupNow: { useGroupTimer: true, timerType: TimerType.CountDown } as RuntimeStore['groupNow'],
|
||||
groupTimer: null,
|
||||
}),
|
||||
);
|
||||
|
||||
expect(display).toMatchObject({
|
||||
time: eventTimer,
|
||||
timerType: TimerType.CountUp,
|
||||
countToEnd: true,
|
||||
usesGroupTimer: false,
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -2,8 +2,8 @@ import { MaybeString } from 'ontime-types';
|
||||
import { RefObject, useCallback, useEffect } from 'react';
|
||||
|
||||
function scrollToComponent<ComponentRef extends HTMLElement, ScrollRef extends HTMLElement>(
|
||||
componentRef: RefObject<ComponentRef | null>,
|
||||
scrollRef: RefObject<ScrollRef | null>,
|
||||
componentRef: RefObject<ComponentRef>,
|
||||
scrollRef: RefObject<ScrollRef>,
|
||||
topOffset: number,
|
||||
) {
|
||||
if (!componentRef.current || !scrollRef.current) {
|
||||
@@ -21,16 +21,18 @@ interface UseFollowComponentProps {
|
||||
followRef: RefObject<HTMLElement | null>;
|
||||
scrollRef: RefObject<HTMLElement | null>;
|
||||
doFollow: boolean;
|
||||
followTrigger: MaybeString; // this would be an entry id or null
|
||||
getTopOffset: () => number;
|
||||
topOffset?: number;
|
||||
setScrollFlag?: (newValue: boolean) => void;
|
||||
followTrigger?: MaybeString; // this would be an entry id or null
|
||||
}
|
||||
|
||||
export default function useFollowComponent({
|
||||
followRef,
|
||||
scrollRef,
|
||||
doFollow,
|
||||
topOffset = 100,
|
||||
setScrollFlag,
|
||||
followTrigger,
|
||||
getTopOffset,
|
||||
}: UseFollowComponentProps) {
|
||||
// when trigger moves, view should follow
|
||||
useEffect(() => {
|
||||
@@ -39,17 +41,25 @@ export default function useFollowComponent({
|
||||
}
|
||||
|
||||
if (followRef.current && scrollRef.current) {
|
||||
setScrollFlag?.(true);
|
||||
// Use requestAnimationFrame to ensure the component is fully loaded
|
||||
window.requestAnimationFrame(() => {
|
||||
// resolve the offset after layout, so that measured values are up to date
|
||||
scrollToComponent(followRef, scrollRef, getTopOffset());
|
||||
scrollToComponent(followRef as RefObject<HTMLElement>, scrollRef as RefObject<HTMLElement>, topOffset);
|
||||
setScrollFlag?.(false);
|
||||
});
|
||||
}
|
||||
}, [followTrigger, doFollow, followRef, scrollRef, getTopOffset]);
|
||||
}, [followTrigger, doFollow, followRef, scrollRef, setScrollFlag, topOffset]);
|
||||
|
||||
const scrollToRefComponent = useCallback(() => {
|
||||
scrollToComponent(followRef, scrollRef, getTopOffset());
|
||||
}, [followRef, scrollRef, getTopOffset]);
|
||||
const scrollToRefComponent = useCallback(
|
||||
(componentRef = followRef, containerRef = scrollRef, offset = topOffset) => {
|
||||
if (componentRef && containerRef) {
|
||||
// @ts-expect-error -- we know this are not null
|
||||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
||||
scrollToComponent(componentRef!, containerRef!, offset);
|
||||
}
|
||||
},
|
||||
[followRef, scrollRef, topOffset],
|
||||
);
|
||||
|
||||
return scrollToRefComponent;
|
||||
}
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import { OffsetMode, RuntimeStore, SimpleDirection, SimplePlayback, TimerMessage, TimerType } from 'ontime-types';
|
||||
import { OffsetMode, RuntimeStore, SimpleDirection, SimplePlayback, TimerMessage } from 'ontime-types';
|
||||
|
||||
import { useRuntimeStore } from '../stores/runtime';
|
||||
import { sendSocket } from '../utils/socket';
|
||||
import { resolveTimerDisplay } from './useSocket.utils';
|
||||
|
||||
const createSelector =
|
||||
<T>(selector: (state: RuntimeStore) => T) =>
|
||||
@@ -38,15 +39,19 @@ export const useExternalMessageInput = createSelector((state: RuntimeStore) => (
|
||||
visible: state.message.timer.secondarySource === 'secondary',
|
||||
}));
|
||||
|
||||
export const useMessagePreview = createSelector((state: RuntimeStore) => ({
|
||||
export const useMessagePreview = createSelector((state: RuntimeStore) => {
|
||||
const timerDisplay = resolveTimerDisplay(state);
|
||||
return {
|
||||
blink: state.message.timer.blink,
|
||||
blackout: state.message.timer.blackout,
|
||||
phase: state.timer.phase,
|
||||
phase: timerDisplay.time.phase,
|
||||
secondarySource: state.message.timer.secondarySource,
|
||||
showTimerMessage: state.message.timer.visible && Boolean(state.message.timer.text),
|
||||
timerType: state.eventNow?.timerType ?? null,
|
||||
countToEnd: state.eventNow?.countToEnd ?? false,
|
||||
}));
|
||||
timerType: timerDisplay.timerType,
|
||||
countToEnd: timerDisplay.countToEnd,
|
||||
usesGroupTimer: timerDisplay.usesGroupTimer,
|
||||
};
|
||||
});
|
||||
|
||||
export const setMessage = {
|
||||
timerText: (payload: string) => sendSocket('message', { timer: { text: payload } }),
|
||||
@@ -230,20 +235,26 @@ export const useFlagTimerOverView = createSelector((state: RuntimeStore) => ({
|
||||
|
||||
/* ======================= View specific subscriptions ======================= */
|
||||
|
||||
export const useTimerSocket = createSelector((state: RuntimeStore) => ({
|
||||
export const useTimerSocket = createSelector((state: RuntimeStore) => {
|
||||
const timerDisplay = resolveTimerDisplay(state);
|
||||
return {
|
||||
eventNext: state.eventNext,
|
||||
eventNow: state.eventNow,
|
||||
message: state.message,
|
||||
time: state.timer,
|
||||
time: timerDisplay.time,
|
||||
eventTimer: timerDisplay.eventTimer,
|
||||
clock: state.clock,
|
||||
timerTypeNow: state.eventNow?.timerType ?? TimerType.CountDown,
|
||||
countToEndNow: state.eventNow?.countToEnd ?? false,
|
||||
timerTypeNow: timerDisplay.timerType,
|
||||
eventTimerType: timerDisplay.eventTimerType,
|
||||
countToEndNow: timerDisplay.countToEnd,
|
||||
usesGroupTimer: timerDisplay.usesGroupTimer,
|
||||
auxTimer: {
|
||||
aux1: state.auxtimer1.current,
|
||||
aux2: state.auxtimer2.current,
|
||||
aux3: state.auxtimer3.current,
|
||||
},
|
||||
}));
|
||||
};
|
||||
});
|
||||
|
||||
export const useCountdownSocket = createSelector((state: RuntimeStore) => ({
|
||||
playback: state.timer.playback,
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
import { RuntimeStore, TimerType } from 'ontime-types';
|
||||
|
||||
type TimerDisplaySource = Pick<RuntimeStore, 'eventNow' | 'groupNow' | 'groupTimer' | 'timer'>;
|
||||
|
||||
export function resolveTimerDisplay(state: TimerDisplaySource) {
|
||||
const eventTimerType = state.eventNow?.timerType ?? TimerType.CountDown;
|
||||
|
||||
if (state.groupNow?.useGroupTimer === true && state.groupTimer !== null) {
|
||||
return {
|
||||
time: state.groupTimer,
|
||||
timerType: state.groupNow.timerType,
|
||||
countToEnd: false,
|
||||
usesGroupTimer: true,
|
||||
eventTimer: state.timer,
|
||||
eventTimerType,
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
time: state.timer,
|
||||
timerType: eventTimerType,
|
||||
countToEnd: state.eventNow?.countToEnd ?? false,
|
||||
usesGroupTimer: false,
|
||||
eventTimer: state.timer,
|
||||
eventTimerType,
|
||||
};
|
||||
}
|
||||
@@ -6,6 +6,6 @@ import { useEffect } from 'react';
|
||||
*/
|
||||
export function useWindowTitle(title: string) {
|
||||
useEffect(() => {
|
||||
document.title = `Ontime - ${title}`;
|
||||
document.title = `ontime - ${title}`;
|
||||
}, []);
|
||||
}
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
import type { OntimeEventReport } from 'ontime-types';
|
||||
import { dayInMs, MILLIS_PER_MINUTE } from 'ontime-utils';
|
||||
|
||||
import { getEventVariance } from '../report';
|
||||
|
||||
it('uses captured days when measuring an event across midnight', () => {
|
||||
const report: OntimeEventReport = {
|
||||
startedAt: dayInMs - 5 * MILLIS_PER_MINUTE,
|
||||
startedAtDay: 0,
|
||||
endedAt: 5 * MILLIS_PER_MINUTE,
|
||||
endedAtDay: 1,
|
||||
scheduledStart: dayInMs - 5 * MILLIS_PER_MINUTE,
|
||||
scheduledDay: 0,
|
||||
scheduledDuration: 10 * MILLIS_PER_MINUTE,
|
||||
};
|
||||
|
||||
expect(getEventVariance(report)).toMatchObject({
|
||||
actualDuration: 10 * MILLIS_PER_MINUTE,
|
||||
delta: 0,
|
||||
status: 'ontime',
|
||||
});
|
||||
expect(getEventVariance({ ...report, endedAt: null })).toMatchObject({ status: 'not-run' });
|
||||
});
|
||||
@@ -1,6 +1,6 @@
|
||||
import { OntimeDelay, OntimeEvent, OntimeGroup, SupportedEntry } from 'ontime-types';
|
||||
import { OntimeDelay, OntimeEvent, OntimeGroup, SupportedEntry, TimerType } from 'ontime-types';
|
||||
|
||||
import { initRundownMetadata } from '../rundownMetadata';
|
||||
import { getFlatRundownMetadata, initRundownMetadata } from '../rundownMetadata';
|
||||
|
||||
describe('initRundownMetadata()', () => {
|
||||
it('processes nested rundown data', () => {
|
||||
@@ -300,3 +300,36 @@ describe('initRundownMetadata()', () => {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('getFlatRundownMetadata()', () => {
|
||||
it('exposes group timer settings on a group and its events', () => {
|
||||
const group = {
|
||||
id: 'group',
|
||||
type: SupportedEntry.Group,
|
||||
entries: ['event'],
|
||||
colour: 'red',
|
||||
useGroupTimer: true,
|
||||
timerType: TimerType.CountUp,
|
||||
} as OntimeGroup;
|
||||
const event = {
|
||||
id: 'event',
|
||||
type: SupportedEntry.Event,
|
||||
parent: group.id,
|
||||
timeStart: 0,
|
||||
timeEnd: 1,
|
||||
duration: 1,
|
||||
dayOffset: 0,
|
||||
gap: 0,
|
||||
skip: false,
|
||||
linkStart: false,
|
||||
} as OntimeEvent;
|
||||
|
||||
const flat = getFlatRundownMetadata(
|
||||
{ entries: { [group.id]: group, [event.id]: event }, flatOrder: [group.id, event.id] },
|
||||
null,
|
||||
);
|
||||
|
||||
expect(flat[0]).toMatchObject({ groupUsesTimer: true, groupTimerType: TimerType.CountUp });
|
||||
expect(flat[1]).toMatchObject({ groupUsesTimer: true, groupTimerType: TimerType.CountUp });
|
||||
});
|
||||
});
|
||||
|
||||
@@ -58,16 +58,4 @@ describe('formatDuration()', () => {
|
||||
expect(formatDuration(2 * MILLIS_PER_HOUR + 6 * MILLIS_PER_MINUTE + 45 * MILLIS_PER_SECOND, false)).toBe('2h6m45s');
|
||||
expect(formatDuration(599702, false)).toBe('9m59s');
|
||||
});
|
||||
it('formats durations differently with and without seconds', () => {
|
||||
expect(formatDuration(0, false)).toBe('0m');
|
||||
expect(formatDuration(0, true)).toBe('0m');
|
||||
expect(formatDuration(30 * MILLIS_PER_SECOND, false)).toBe('30s');
|
||||
expect(formatDuration(30 * MILLIS_PER_SECOND, true)).toBe('');
|
||||
expect(formatDuration(2 * MILLIS_PER_HOUR + 30 * MILLIS_PER_SECOND, false)).toBe('2h30s');
|
||||
expect(formatDuration(2 * MILLIS_PER_HOUR + 30 * MILLIS_PER_SECOND, true)).toBe('2h');
|
||||
expect(formatDuration(2 * MILLIS_PER_HOUR + 10 * MILLIS_PER_MINUTE + 30 * MILLIS_PER_SECOND, false)).toBe(
|
||||
'2h10m30s',
|
||||
);
|
||||
expect(formatDuration(2 * MILLIS_PER_HOUR + 10 * MILLIS_PER_MINUTE + 30 * MILLIS_PER_SECOND, true)).toBe('2h10m');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,29 +0,0 @@
|
||||
import type { MaybeNumber, OntimeEventReport } from 'ontime-types';
|
||||
import { dayInMs, MILLIS_PER_SECOND } from 'ontime-utils';
|
||||
|
||||
type EventVariance = {
|
||||
actualDuration: MaybeNumber;
|
||||
delta: number;
|
||||
status: 'ontime' | 'over' | 'under' | 'not-run';
|
||||
};
|
||||
|
||||
const notRun: EventVariance = { actualDuration: null, delta: 0, status: 'not-run' };
|
||||
|
||||
export function getReportTimePosition(time: number, day: number): number;
|
||||
export function getReportTimePosition(time: MaybeNumber, day: number | null): MaybeNumber;
|
||||
export function getReportTimePosition(time: MaybeNumber, day: number | null): MaybeNumber {
|
||||
return time === null || day === null ? null : day * dayInMs + time;
|
||||
}
|
||||
|
||||
export function getEventVariance(entry: OntimeEventReport | undefined): EventVariance {
|
||||
if (!entry) return notRun;
|
||||
|
||||
const start = getReportTimePosition(entry.startedAt, entry.startedAtDay);
|
||||
const end = getReportTimePosition(entry.endedAt, entry.endedAtDay);
|
||||
if (start === null || end === null) return notRun;
|
||||
|
||||
const actualDuration = end - start;
|
||||
const delta = actualDuration - entry.scheduledDuration;
|
||||
if (Math.abs(delta) < MILLIS_PER_SECOND) return { actualDuration, delta, status: 'ontime' };
|
||||
return { actualDuration, delta, status: delta > 0 ? 'over' : 'under' };
|
||||
}
|
||||
@@ -3,9 +3,11 @@ import {
|
||||
OntimeDelay,
|
||||
OntimeEntry,
|
||||
OntimeEvent,
|
||||
OntimeGroup,
|
||||
OntimeMilestone,
|
||||
PlayableEvent,
|
||||
Rundown,
|
||||
TimerType,
|
||||
isOntimeEvent,
|
||||
isOntimeGroup,
|
||||
isPlayableEvent,
|
||||
@@ -29,7 +31,11 @@ export type RundownMetadata = {
|
||||
isFirstAfterGroup: boolean;
|
||||
};
|
||||
|
||||
export type ExtendedEntry<T extends OntimeEntry = OntimeEntry> = T & RundownMetadata;
|
||||
export type ExtendedEntry<T extends OntimeEntry = OntimeEntry> = T &
|
||||
RundownMetadata & {
|
||||
groupUsesTimer?: boolean;
|
||||
groupTimerType?: TimerType;
|
||||
};
|
||||
|
||||
export const lastMetadataKey = 'LAST';
|
||||
|
||||
@@ -65,10 +71,23 @@ export function getFlatRundownMetadata(
|
||||
): ExtendedEntry[] {
|
||||
const { process } = initRundownMetadata(selectedEventId);
|
||||
const flatRundown: ExtendedEntry[] = [];
|
||||
let activeGroup: OntimeGroup | null = null;
|
||||
|
||||
for (const id of data.flatOrder) {
|
||||
const entry = data.entries[id];
|
||||
const extendedEntry = { ...entry, ...process(entry) };
|
||||
if (isOntimeGroup(entry)) {
|
||||
activeGroup = entry;
|
||||
} else if (entry.parent !== activeGroup?.id) {
|
||||
activeGroup = null;
|
||||
}
|
||||
|
||||
const timerGroup = isOntimeGroup(entry) ? entry : activeGroup;
|
||||
const extendedEntry = {
|
||||
...entry,
|
||||
...process(entry),
|
||||
groupUsesTimer: timerGroup?.useGroupTimer ?? false,
|
||||
groupTimerType: timerGroup?.timerType,
|
||||
};
|
||||
flatRundown.push(extendedEntry);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
th.over {
|
||||
color: $playback-over;
|
||||
}
|
||||
|
||||
th.under {
|
||||
color: $playback-under;
|
||||
}
|
||||
@@ -1,72 +1,103 @@
|
||||
import { useMemo } from 'react';
|
||||
import { IoDownloadOutline, IoTrashBin } from 'react-icons/io5';
|
||||
import { IoTrashBin } from 'react-icons/io5';
|
||||
|
||||
import { deleteAllReport } from '../../../../common/api/report';
|
||||
import { createBlob, downloadBlob } from '../../../../common/api/utils';
|
||||
import Button from '../../../../common/components/buttons/Button';
|
||||
import useReport from '../../../../common/hooks-query/useReport';
|
||||
import useRundown from '../../../../common/hooks-query/useRundown';
|
||||
import { cx } from '../../../../common/utils/styleUtils';
|
||||
import { formatTime } from '../../../../common/utils/time';
|
||||
import * as Panel from '../../panel-utils/PanelUtils';
|
||||
import ReportShowSummary from './composite/ReportShowSummary';
|
||||
import ReportTable from './composite/ReportTable';
|
||||
import { getCombinedReport, getGroupReports, getRunSummary, makeReportCSV } from './reportSettings.utils';
|
||||
import { CombinedReport, getCombinedReport, makeReportCSV } from './reportSettings.utils';
|
||||
|
||||
import style from './ReportSettings.module.scss';
|
||||
|
||||
export default function ReportSettings() {
|
||||
const { report } = useReport();
|
||||
const { eventReports, rundown, show } = report;
|
||||
|
||||
const { combinedReport, groups, summary } = useMemo(() => {
|
||||
const entries = rundown?.entries ?? {};
|
||||
return {
|
||||
combinedReport: rundown ? getCombinedReport(eventReports, entries, rundown.flatOrder) : [],
|
||||
groups: rundown ? getGroupReports(eventReports, entries, rundown.order) : [],
|
||||
summary: getRunSummary(eventReports, entries, rundown?.flatOrder ?? []),
|
||||
};
|
||||
}, [eventReports, rundown]);
|
||||
|
||||
const hasReport = rundown !== null && Object.keys(eventReports).length > 0;
|
||||
const downloadCSV = () => {
|
||||
if (!hasReport) return;
|
||||
const { data: reportData } = useReport();
|
||||
const { data } = useRundown();
|
||||
|
||||
const clearReport = async () => await deleteAllReport();
|
||||
const downloadCSV = (combinedReport: CombinedReport[]) => {
|
||||
if (!combinedReport) {
|
||||
return;
|
||||
}
|
||||
const csv = makeReportCSV(combinedReport);
|
||||
const blob = createBlob(csv, 'text/csv;charset=utf-8;');
|
||||
downloadBlob(blob, 'ontime-report.csv');
|
||||
};
|
||||
|
||||
const combinedReport = useMemo(() => {
|
||||
return getCombinedReport(reportData, data.entries, data.flatOrder);
|
||||
}, [reportData, data.entries, data.flatOrder]);
|
||||
|
||||
return (
|
||||
<Panel.Section>
|
||||
<Panel.Card>
|
||||
<Panel.SubHeader>
|
||||
Report
|
||||
<Panel.SubHeader>Report</Panel.SubHeader>
|
||||
<Panel.Divider />
|
||||
<Panel.Section>
|
||||
<Panel.Title>
|
||||
Manage report
|
||||
<Panel.InlineElements>
|
||||
<Button onClick={downloadCSV} disabled={!hasReport}>
|
||||
<IoDownloadOutline />
|
||||
<Button onClick={() => downloadCSV(combinedReport)} disabled={combinedReport.length === 0}>
|
||||
<IoTrashBin />
|
||||
Export CSV
|
||||
</Button>
|
||||
<Button variant='subtle-destructive' onClick={deleteAllReport} disabled={!hasReport}>
|
||||
<Button variant='subtle-destructive' onClick={clearReport} disabled={combinedReport.length === 0}>
|
||||
<IoTrashBin />
|
||||
Clear Report
|
||||
Clear All
|
||||
</Button>
|
||||
</Panel.InlineElements>
|
||||
</Panel.SubHeader>
|
||||
<Panel.Divider />
|
||||
|
||||
{!hasReport ? (
|
||||
</Panel.Title>
|
||||
</Panel.Section>
|
||||
<Panel.Section>
|
||||
<Panel.EmptyState
|
||||
title='No report yet'
|
||||
description='Start an event to record actual timings against the schedule.'
|
||||
<Panel.Table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>#</th>
|
||||
<th>Cue</th>
|
||||
<th>Title</th>
|
||||
<th>Scheduled Start</th>
|
||||
<th>Actual Start</th>
|
||||
<th>Scheduled End</th>
|
||||
<th>Actual End</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{combinedReport.length === 0 && (
|
||||
<Panel.TableEmpty
|
||||
title='No report data yet'
|
||||
description='Reports are generated as you run through the show, comparing scheduled times against what actually happened.'
|
||||
/>
|
||||
</Panel.Section>
|
||||
) : (
|
||||
<>
|
||||
<Panel.Section>
|
||||
<ReportShowSummary rundownTitle={rundown.title} show={show} summary={summary} />
|
||||
</Panel.Section>
|
||||
<Panel.Section>
|
||||
<ReportTable rows={combinedReport} groups={groups} />
|
||||
</Panel.Section>
|
||||
</>
|
||||
)}
|
||||
|
||||
{combinedReport.map((entry) => {
|
||||
const start = (() => {
|
||||
if (entry.actualStart === null) return null;
|
||||
if (entry.actualStart <= entry.scheduledStart) return 'under';
|
||||
return 'over';
|
||||
})();
|
||||
const end = (() => {
|
||||
if (entry.actualEnd === null) return null;
|
||||
if (entry.actualEnd <= entry.scheduledEnd) return 'under';
|
||||
return 'over';
|
||||
})();
|
||||
return (
|
||||
<tr key={entry.id}>
|
||||
<th>{entry.index}</th>
|
||||
<th>{entry.cue}</th>
|
||||
<th>{entry.title}</th>
|
||||
<th className={cx([start && style[start]])}>{formatTime(entry.scheduledStart)}</th>
|
||||
<th className={cx([start && style[start]])}>{formatTime(entry.actualStart)}</th>
|
||||
<th className={cx([end && style[end]])}>{formatTime(entry.scheduledEnd)}</th>
|
||||
<th className={cx([end && style[end]])}>{formatTime(entry.actualEnd)}</th>
|
||||
</tr>
|
||||
);
|
||||
})}
|
||||
</tbody>
|
||||
</Panel.Table>
|
||||
</Panel.Section>
|
||||
</Panel.Card>
|
||||
</Panel.Section>
|
||||
);
|
||||
|
||||
-156
@@ -1,156 +0,0 @@
|
||||
import type { OntimeEventReport, OntimeReport } from 'ontime-types';
|
||||
import {
|
||||
createDelay,
|
||||
createEvent,
|
||||
createGroup,
|
||||
dayInMs,
|
||||
MILLIS_PER_HOUR,
|
||||
MILLIS_PER_MINUTE,
|
||||
MILLIS_PER_SECOND,
|
||||
} from 'ontime-utils';
|
||||
|
||||
import {
|
||||
formatOffset,
|
||||
getCombinedReport,
|
||||
getGroupReports,
|
||||
getRunSummary,
|
||||
getShowOffsets,
|
||||
makeReportCSV,
|
||||
} from '../reportSettings.utils';
|
||||
|
||||
function makeEvent(id: string, patch = {}) {
|
||||
const event = createEvent({ id, title: id, ...patch });
|
||||
if (!event) throw new Error('Failed to create test event');
|
||||
return event;
|
||||
}
|
||||
|
||||
function makeReport(patch: Partial<OntimeEventReport> = {}): OntimeEventReport {
|
||||
return {
|
||||
startedAt: 5 * MILLIS_PER_MINUTE,
|
||||
startedAtDay: 1,
|
||||
endedAt: 15 * MILLIS_PER_MINUTE,
|
||||
endedAtDay: 1,
|
||||
scheduledStart: dayInMs - 5 * MILLIS_PER_MINUTE,
|
||||
scheduledDay: 0,
|
||||
scheduledDuration: 10 * MILLIS_PER_MINUTE,
|
||||
...patch,
|
||||
};
|
||||
}
|
||||
|
||||
describe('getCombinedReport()', () => {
|
||||
it('uses the captured schedule and absolute day when calculating offsets', () => {
|
||||
const entry = makeEvent('a', { timeStart: 0, duration: 99 * MILLIS_PER_MINUTE });
|
||||
const rows = getCombinedReport({ a: makeReport() }, { a: entry }, ['a']);
|
||||
|
||||
expect(rows[0]).toMatchObject({
|
||||
scheduledStart: dayInMs - 5 * MILLIS_PER_MINUTE,
|
||||
scheduledEnd: dayInMs + 5 * MILLIS_PER_MINUTE,
|
||||
startOffset: 10 * MILLIS_PER_MINUTE,
|
||||
endOffset: 10 * MILLIS_PER_MINUTE,
|
||||
});
|
||||
});
|
||||
|
||||
it('includes unplayed events but excludes skipped and non-event entries', () => {
|
||||
const ran = makeEvent('ran');
|
||||
const unplayed = makeEvent('unplayed', { timeStart: 20 * MILLIS_PER_MINUTE });
|
||||
const skipped = makeEvent('skipped', { skip: true });
|
||||
const delay = createDelay({ id: 'delay' });
|
||||
const report: OntimeReport = { ran: makeReport({ scheduledStart: 0, scheduledDay: 0 }) };
|
||||
|
||||
const rows = getCombinedReport(report, { ran, unplayed, skipped, delay }, ['ran', 'unplayed', 'skipped', 'delay']);
|
||||
|
||||
expect(rows.map(({ id }) => id)).toEqual(['ran', 'unplayed']);
|
||||
expect(rows[1]).toMatchObject({ scheduledStart: unplayed.timeStart, actualStart: null, actualEnd: null });
|
||||
});
|
||||
});
|
||||
|
||||
describe('report calculations', () => {
|
||||
it('keeps finishing time separate from running time', () => {
|
||||
const offsets = getShowOffsets({
|
||||
plannedStart: 19 * MILLIS_PER_HOUR,
|
||||
plannedEnd: 21 * MILLIS_PER_HOUR,
|
||||
plannedDuration: 2 * MILLIS_PER_HOUR,
|
||||
actualStart: 19 * MILLIS_PER_HOUR - 10 * MILLIS_PER_MINUTE,
|
||||
actualEnd: 21 * MILLIS_PER_HOUR - 6 * MILLIS_PER_MINUTE,
|
||||
actualDuration: 2 * MILLIS_PER_HOUR + 4 * MILLIS_PER_MINUTE,
|
||||
});
|
||||
|
||||
expect(offsets).toMatchObject({
|
||||
startOffset: -10 * MILLIS_PER_MINUTE,
|
||||
endOffset: -6 * MILLIS_PER_MINUTE,
|
||||
durationOffset: 4 * MILLIS_PER_MINUTE,
|
||||
});
|
||||
});
|
||||
|
||||
it('measures completed groups against their target', () => {
|
||||
const group = createGroup({ id: 'group', entries: ['a', 'b'], targetDuration: 30 * MILLIS_PER_MINUTE });
|
||||
const entries = {
|
||||
group,
|
||||
a: makeEvent('a', { parent: group.id, duration: 10 * MILLIS_PER_MINUTE }),
|
||||
b: makeEvent('b', { parent: group.id, duration: 10 * MILLIS_PER_MINUTE }),
|
||||
};
|
||||
const report: OntimeReport = {
|
||||
a: makeReport({ startedAt: 0, startedAtDay: 0, endedAt: 10 * MILLIS_PER_MINUTE, endedAtDay: 0 }),
|
||||
b: makeReport({
|
||||
startedAt: 15 * MILLIS_PER_MINUTE,
|
||||
startedAtDay: 0,
|
||||
endedAt: 25 * MILLIS_PER_MINUTE,
|
||||
endedAtDay: 0,
|
||||
}),
|
||||
};
|
||||
|
||||
expect(getGroupReports(report, entries, [group.id])[0]).toMatchObject({
|
||||
elapsed: 25 * MILLIS_PER_MINUTE,
|
||||
variance: -5 * MILLIS_PER_MINUTE,
|
||||
eventsRun: 2,
|
||||
eventsPlanned: 2,
|
||||
});
|
||||
expect(getGroupReports({ a: report.a }, entries, [group.id])[0].variance).toBeNull();
|
||||
});
|
||||
|
||||
it('summarises completed events and excludes skipped events from the plan', () => {
|
||||
const entries = { a: makeEvent('a'), b: makeEvent('b', { skip: true }) };
|
||||
const report = {
|
||||
a: makeReport({ startedAt: 0, startedAtDay: 0, endedAt: 15 * MILLIS_PER_MINUTE, endedAtDay: 0 }),
|
||||
b: makeReport({ startedAt: 0, startedAtDay: 0, endedAt: 30 * MILLIS_PER_MINUTE, endedAtDay: 0 }),
|
||||
};
|
||||
|
||||
expect(getRunSummary(report, entries, ['a', 'b'])).toEqual({ eventsRun: 2, eventsPlanned: 1 });
|
||||
});
|
||||
});
|
||||
|
||||
describe('report formatting', () => {
|
||||
it.each([
|
||||
[null, '–'],
|
||||
[MILLIS_PER_SECOND / 2, 'On time'],
|
||||
[4 * MILLIS_PER_MINUTE + 12 * MILLIS_PER_SECOND, '+4m12s'],
|
||||
[-MILLIS_PER_MINUTE, '-1m'],
|
||||
])('formats offset %s', (value, expected) => {
|
||||
expect(formatOffset(value)).toBe(expected);
|
||||
});
|
||||
|
||||
it('exports group context and leaves missing actual times empty', () => {
|
||||
const csv = makeReportCSV([
|
||||
{
|
||||
id: 'a',
|
||||
index: 1,
|
||||
title: 'Welcome',
|
||||
cue: '1',
|
||||
parent: 'act1',
|
||||
groupTitle: 'Act 1',
|
||||
scheduledStart: 0,
|
||||
scheduledEnd: 10 * MILLIS_PER_MINUTE,
|
||||
actualStart: null,
|
||||
startOffset: null,
|
||||
actualEnd: null,
|
||||
endOffset: null,
|
||||
},
|
||||
]);
|
||||
|
||||
const fields = csv.trim().split('\n')[1].split(',');
|
||||
expect(csv).toContain('Group');
|
||||
expect(fields[1]).toBe('Act 1');
|
||||
expect(fields[5]).toBe('');
|
||||
expect(fields[7]).toBe('');
|
||||
});
|
||||
});
|
||||
-104
@@ -1,104 +0,0 @@
|
||||
// Panel.Table nests its own padding inside the section it sits in, so the
|
||||
// summary takes the same inset to keep one left edge down the whole panel
|
||||
.inset {
|
||||
padding: 0 var(--panel-card-padding, 2rem);
|
||||
}
|
||||
|
||||
.summary {
|
||||
padding: 1.25rem;
|
||||
background-color: $gray-1200;
|
||||
border-radius: 3px;
|
||||
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 1rem;
|
||||
}
|
||||
|
||||
.title {
|
||||
margin: 0;
|
||||
color: $ui-white;
|
||||
font-size: 1rem;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.body {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
justify-content: space-between;
|
||||
flex-wrap: wrap;
|
||||
gap: 1rem 2.5rem;
|
||||
}
|
||||
|
||||
.headline {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.25rem;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.headlineLabel,
|
||||
.metricLabel {
|
||||
color: $gray-300;
|
||||
font-size: calc(1rem - 2px);
|
||||
}
|
||||
|
||||
.headlineValue {
|
||||
font-size: 1.75rem;
|
||||
font-weight: 600;
|
||||
line-height: 1.1;
|
||||
font-variant-numeric: tabular-nums;
|
||||
}
|
||||
|
||||
.unavailable {
|
||||
max-width: 32rem;
|
||||
color: $warning-orange;
|
||||
font-size: calc(1rem - 2px);
|
||||
line-height: 1.4;
|
||||
}
|
||||
|
||||
.metrics {
|
||||
display: grid;
|
||||
grid-template-columns: auto auto auto;
|
||||
align-items: baseline;
|
||||
gap: 0.375rem 1.5rem;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.metricValue,
|
||||
.metricOffset {
|
||||
margin: 0;
|
||||
font-variant-numeric: tabular-nums;
|
||||
}
|
||||
|
||||
.metricValue {
|
||||
display: flex;
|
||||
align-items: baseline;
|
||||
gap: 0.5rem;
|
||||
}
|
||||
|
||||
.planned,
|
||||
.arrow {
|
||||
color: $gray-300;
|
||||
}
|
||||
|
||||
.actual {
|
||||
color: $ui-white;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.metricOffset {
|
||||
justify-self: end;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.over {
|
||||
color: $playback-over;
|
||||
}
|
||||
|
||||
.under {
|
||||
color: $playback-under;
|
||||
}
|
||||
|
||||
.none {
|
||||
color: $gray-300;
|
||||
}
|
||||
-118
@@ -1,118 +0,0 @@
|
||||
import type { MaybeNumber, ShowReport } from 'ontime-types';
|
||||
|
||||
import { cx, enDash } from '../../../../../common/utils/styleUtils';
|
||||
import { formatDuration, formatTime } from '../../../../../common/utils/time';
|
||||
import { formatOffset, getShowOffsets, offsetTone } from '../reportSettings.utils';
|
||||
import type { RunSummary } from '../reportSettings.utils';
|
||||
|
||||
import style from './ReportShowSummary.module.scss';
|
||||
|
||||
interface ReportShowSummaryProps {
|
||||
rundownTitle: string;
|
||||
show: ShowReport;
|
||||
summary: RunSummary;
|
||||
}
|
||||
|
||||
/**
|
||||
* Leads the report with whether the show ran to the length it was planned for.
|
||||
*
|
||||
* Running time is the headline rather than finishing time because it is the
|
||||
* part the team controls and the part that carries into the next run of the
|
||||
* same rundown. Finishing time is the other question a report is asked, and
|
||||
* the two can point opposite ways, so it stays beside it as its own row
|
||||
* rather than being folded into a single figure.
|
||||
*/
|
||||
export default function ReportShowSummary({ rundownTitle, show, summary }: ReportShowSummaryProps) {
|
||||
const offsets = getShowOffsets(show);
|
||||
|
||||
/**
|
||||
* A show that stopped early has no meaningful end: its last event is simply
|
||||
* where it got to. Measuring that against the plan would report a show which
|
||||
* never finished as having come in comfortably short.
|
||||
*/
|
||||
const didReachEnd = summary.eventsRun > 0 && summary.eventsRun === summary.eventsPlanned;
|
||||
const hasPlan = offsets.startOffset !== null;
|
||||
|
||||
return (
|
||||
<div className={style.inset}>
|
||||
<section className={style.summary} aria-labelledby='report-summary-title'>
|
||||
<h4 id='report-summary-title' className={style.title}>
|
||||
{rundownTitle || 'Untitled rundown'}
|
||||
</h4>
|
||||
|
||||
<div className={style.body}>
|
||||
<div className={style.headline}>
|
||||
<span className={style.headlineLabel}>{didReachEnd ? 'Show duration' : 'Show incomplete'}</span>
|
||||
{didReachEnd && offsets.durationOffset !== null ? (
|
||||
<span className={cx([style.headlineValue, style[offsetTone(offsets.durationOffset)]])}>
|
||||
{formatOffset(offsets.durationOffset)}
|
||||
</span>
|
||||
) : (
|
||||
<span className={style.unavailable}>The show did not reach the end of the rundown.</span>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<dl className={style.metrics}>
|
||||
{hasPlan && (
|
||||
<Metric
|
||||
label='Started'
|
||||
planned={formatMaybeTime(show.plannedStart)}
|
||||
actual={formatMaybeTime(show.actualStart)}
|
||||
offset={offsets.startOffset}
|
||||
/>
|
||||
)}
|
||||
{hasPlan && didReachEnd && (
|
||||
<Metric
|
||||
label='Ended'
|
||||
planned={formatMaybeTime(show.plannedEnd)}
|
||||
actual={formatMaybeTime(show.actualEnd)}
|
||||
offset={offsets.endOffset}
|
||||
/>
|
||||
)}
|
||||
{didReachEnd && (
|
||||
<Metric
|
||||
label='Duration'
|
||||
planned={formatMaybeDuration(show.plannedDuration)}
|
||||
actual={formatMaybeDuration(show.actualDuration)}
|
||||
/>
|
||||
)}
|
||||
</dl>
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function Metric({
|
||||
label,
|
||||
planned,
|
||||
actual,
|
||||
offset,
|
||||
}: {
|
||||
label: string;
|
||||
planned: string;
|
||||
actual: string;
|
||||
offset?: MaybeNumber;
|
||||
}) {
|
||||
return (
|
||||
<>
|
||||
<dt className={style.metricLabel}>{label}</dt>
|
||||
<dd className={style.metricValue}>
|
||||
<span className={style.planned}>{planned}</span>
|
||||
<span className={style.arrow}>→</span>
|
||||
<span className={style.actual}>{actual}</span>
|
||||
</dd>
|
||||
<dd className={cx([style.metricOffset, offset !== undefined && style[offsetTone(offset)]])}>
|
||||
{offset === undefined ? '' : formatOffset(offset)}
|
||||
</dd>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
function formatMaybeTime(value: MaybeNumber): string {
|
||||
return value === null ? enDash : formatTime(value);
|
||||
}
|
||||
|
||||
function formatMaybeDuration(value: MaybeNumber): string {
|
||||
return value === null ? enDash : formatDuration(value, false);
|
||||
}
|
||||
-144
@@ -1,144 +0,0 @@
|
||||
$rail: var(--user-bg, #{$gray-500});
|
||||
$event-wash: var(--event-bg, transparent);
|
||||
|
||||
// event rows carry their values in td, not th: the panel's th styling is meant
|
||||
// for column headings and renders whatever it holds small, bold and upper case
|
||||
td.over {
|
||||
color: $playback-over;
|
||||
}
|
||||
|
||||
td.under {
|
||||
color: $playback-under;
|
||||
}
|
||||
|
||||
.eventRow td {
|
||||
background-color: color-mix(in srgb, #{$gray-1300} 96%, #{$event-wash} 4%);
|
||||
}
|
||||
|
||||
.groupedRow td:first-child {
|
||||
box-shadow: inset 2px 0 $rail;
|
||||
// clear the rail rather than sitting against it
|
||||
padding-left: 0.75rem;
|
||||
}
|
||||
|
||||
.groupRow > * {
|
||||
background-color: color-mix(in srgb, #{$gray-1300} 88%, #{$rail} 12%);
|
||||
vertical-align: top;
|
||||
}
|
||||
|
||||
.groupSpacer {
|
||||
height: 0.75rem;
|
||||
background: transparent !important;
|
||||
|
||||
td {
|
||||
height: 0.75rem;
|
||||
padding: 0;
|
||||
background: transparent !important;
|
||||
}
|
||||
}
|
||||
|
||||
th.groupSummary {
|
||||
padding: 0.5rem 1rem;
|
||||
box-shadow: inset 4px 0 $rail;
|
||||
|
||||
text-align: left;
|
||||
text-transform: none;
|
||||
letter-spacing: normal;
|
||||
|
||||
> * {
|
||||
text-transform: none;
|
||||
}
|
||||
}
|
||||
|
||||
.groupTitle,
|
||||
.groupLabel,
|
||||
.groupValues {
|
||||
display: block;
|
||||
}
|
||||
|
||||
.groupTitle {
|
||||
color: $ui-white;
|
||||
font-size: 1rem;
|
||||
font-weight: 600;
|
||||
text-transform: none;
|
||||
}
|
||||
|
||||
.groupBody {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
flex-wrap: wrap;
|
||||
justify-content: space-between;
|
||||
gap: 0.75rem 2.5rem;
|
||||
margin-top: 0.75rem;
|
||||
}
|
||||
|
||||
.groupHeadline {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.25rem;
|
||||
}
|
||||
|
||||
.groupLabel,
|
||||
.groupMetrics dt {
|
||||
color: $gray-400;
|
||||
font-size: calc(1rem - 3px);
|
||||
font-weight: 400;
|
||||
}
|
||||
|
||||
.groupHeadlineValue {
|
||||
font-size: 1.25rem;
|
||||
font-weight: 600;
|
||||
line-height: 1.1;
|
||||
font-variant-numeric: tabular-nums;
|
||||
}
|
||||
|
||||
.groupMetrics {
|
||||
display: grid;
|
||||
grid-template-columns: auto auto;
|
||||
align-items: baseline;
|
||||
gap: 0.375rem 1.5rem;
|
||||
margin: 0;
|
||||
font-variant-numeric: tabular-nums;
|
||||
}
|
||||
|
||||
.groupMetrics dd {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.groupValues {
|
||||
display: flex;
|
||||
gap: 0.5rem;
|
||||
color: $gray-300;
|
||||
|
||||
b {
|
||||
color: $ui-white;
|
||||
font-weight: 600;
|
||||
}
|
||||
}
|
||||
|
||||
.unavailable {
|
||||
color: $gray-400;
|
||||
font-size: calc(1rem - 3px);
|
||||
font-weight: 400;
|
||||
}
|
||||
|
||||
.arrow {
|
||||
color: $gray-500;
|
||||
}
|
||||
|
||||
.over {
|
||||
color: $playback-over;
|
||||
}
|
||||
|
||||
.under {
|
||||
color: $playback-under;
|
||||
}
|
||||
|
||||
.none {
|
||||
color: $ui-white;
|
||||
}
|
||||
|
||||
.eventCue,
|
||||
.eventIndex {
|
||||
color: $gray-300;
|
||||
}
|
||||
@@ -1,182 +0,0 @@
|
||||
import type { EntryId } from 'ontime-types';
|
||||
import { useMemo } from 'react';
|
||||
|
||||
import { cx, enDash } from '../../../../../common/utils/styleUtils';
|
||||
import { formatDuration, formatTime } from '../../../../../common/utils/time';
|
||||
import * as Panel from '../../../panel-utils/PanelUtils';
|
||||
import { formatOffset, offsetTone } from '../reportSettings.utils';
|
||||
import type { CombinedReport, GroupReport } from '../reportSettings.utils';
|
||||
|
||||
import style from './ReportTable.module.scss';
|
||||
|
||||
interface ReportTableProps {
|
||||
rows: CombinedReport[];
|
||||
groups: GroupReport[];
|
||||
}
|
||||
|
||||
type ReportColourStyle = React.CSSProperties & Partial<Record<'--event-bg' | '--user-bg', string | undefined>>;
|
||||
|
||||
/**
|
||||
* The report laid out the way the show was planned: blocks, then the events
|
||||
* inside them. Each block carries how it ran against the budget set for it.
|
||||
*/
|
||||
export default function ReportTable({ rows, groups }: ReportTableProps) {
|
||||
// groups are rendered where their first event appears, so the table follows
|
||||
// the rundown rather than a separate ordering
|
||||
const sections = useMemo(() => makeSections(rows, groups), [rows, groups]);
|
||||
|
||||
return (
|
||||
<Panel.Table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>#</th>
|
||||
<th>Cue</th>
|
||||
<th>Title</th>
|
||||
<th>Scheduled Start</th>
|
||||
<th>Actual Start</th>
|
||||
<th>Scheduled End</th>
|
||||
<th>Actual End</th>
|
||||
</tr>
|
||||
</thead>
|
||||
{sections.map((section, index) => (
|
||||
<tbody key={section.key}>
|
||||
{section.group && index > 0 && <GroupSpacer />}
|
||||
{section.group && <GroupRow group={section.group} />}
|
||||
{section.rows.map((entry) => (
|
||||
<EventRow
|
||||
key={entry.id}
|
||||
entry={entry}
|
||||
groupColour={section.group?.colour}
|
||||
grouped={section.group !== null}
|
||||
/>
|
||||
))}
|
||||
</tbody>
|
||||
))}
|
||||
</Panel.Table>
|
||||
);
|
||||
}
|
||||
|
||||
function GroupSpacer() {
|
||||
return (
|
||||
<tr aria-hidden='true' className={style.groupSpacer}>
|
||||
<td colSpan={7} />
|
||||
</tr>
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* A group read the same way as the show above it: what it was measured
|
||||
* against, what it actually did, and how much of it ran.
|
||||
*/
|
||||
function GroupRow({ group }: { group: GroupReport }) {
|
||||
const hasTarget = group.targetDuration !== null;
|
||||
const measuredAgainst = group.targetDuration ?? group.scheduledDuration;
|
||||
const unavailableReason = group.eventsRun === 0 ? 'Did not run' : 'Still running';
|
||||
|
||||
return (
|
||||
<tr className={style.groupRow} style={groupColourStyle(group.colour)}>
|
||||
<th scope='rowgroup' colSpan={7} className={style.groupSummary}>
|
||||
<span className={style.groupTitle}>{group.title || 'Untitled group'}</span>
|
||||
<div className={style.groupBody}>
|
||||
<div className={style.groupHeadline}>
|
||||
<span className={style.groupLabel}>{hasTarget ? 'Against target' : 'Against schedule'}</span>
|
||||
{group.variance === null ? (
|
||||
<span className={style.unavailable}>{unavailableReason}</span>
|
||||
) : (
|
||||
<span className={cx([style.groupHeadlineValue, style[offsetTone(group.variance)]])}>
|
||||
{formatOffset(group.variance)}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
<dl className={style.groupMetrics}>
|
||||
<dt>{hasTarget ? 'Target' : 'Scheduled'}</dt>
|
||||
<dd className={style.groupValues}>
|
||||
<span>{formatDuration(measuredAgainst, false)}</span>
|
||||
<span className={style.arrow}>→</span>
|
||||
<b>{group.elapsed === null ? enDash : formatDuration(group.elapsed, false)}</b>
|
||||
</dd>
|
||||
{group.actualStart !== null && group.actualEnd !== null && (
|
||||
<>
|
||||
<dt>Ran</dt>
|
||||
<dd className={style.groupValues}>
|
||||
<span>{formatTime(group.actualStart)}</span>
|
||||
<span className={style.arrow}>→</span>
|
||||
<b>{formatTime(group.actualEnd)}</b>
|
||||
</dd>
|
||||
</>
|
||||
)}
|
||||
</dl>
|
||||
</div>
|
||||
</th>
|
||||
</tr>
|
||||
);
|
||||
}
|
||||
|
||||
function EventRow({ entry, groupColour, grouped }: { entry: CombinedReport; groupColour?: string; grouped: boolean }) {
|
||||
const start = offsetTone(entry.startOffset);
|
||||
const end = offsetTone(entry.endOffset);
|
||||
|
||||
return (
|
||||
<tr className={cx([style.eventRow, grouped && style.groupedRow])} style={eventColours(entry.colour, groupColour)}>
|
||||
<td className={style.eventIndex}>{entry.index}</td>
|
||||
<td className={style.eventCue}>{entry.cue}</td>
|
||||
<td>{entry.title}</td>
|
||||
<td>{formatTime(entry.scheduledStart)}</td>
|
||||
<td className={cx([style[start]])}>{formatTime(entry.actualStart)}</td>
|
||||
<td>{formatTime(entry.scheduledEnd)}</td>
|
||||
<td className={cx([style[end]])}>{formatTime(entry.actualEnd)}</td>
|
||||
</tr>
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Uses the cuesheet's custom property for group colour. Left unset when the
|
||||
* group has none so the stylesheet can provide a neutral edge.
|
||||
*/
|
||||
function groupColourStyle(colour?: string): ReportColourStyle {
|
||||
const style: ReportColourStyle = {};
|
||||
if (colour) style['--user-bg'] = colour;
|
||||
return style;
|
||||
}
|
||||
|
||||
/** Keeps the event wash distinct from its parent group's identifying rail. */
|
||||
function eventColours(eventColour: string, groupColour?: string): ReportColourStyle {
|
||||
const style: ReportColourStyle = {};
|
||||
if (eventColour) style['--event-bg'] = eventColour;
|
||||
if (groupColour) style['--user-bg'] = groupColour;
|
||||
return style;
|
||||
}
|
||||
|
||||
type Section = {
|
||||
key: string;
|
||||
group: GroupReport | null;
|
||||
rows: CombinedReport[];
|
||||
};
|
||||
|
||||
/**
|
||||
* Splits the rows into the blocks they belong to, keeping rundown order and
|
||||
* leaving ungrouped events in their own run of rows.
|
||||
*/
|
||||
function makeSections(rows: CombinedReport[], groups: GroupReport[]): Section[] {
|
||||
const byId = new Map<EntryId, GroupReport>(groups.map((group) => [group.id, group]));
|
||||
const sections: Section[] = [];
|
||||
let current: Section | null = null;
|
||||
|
||||
let currentParent: EntryId | null | undefined;
|
||||
|
||||
for (const row of rows) {
|
||||
if (current === null || row.parent !== currentParent) {
|
||||
currentParent = row.parent;
|
||||
// index keeps the key unique even if a group were to appear twice
|
||||
current = {
|
||||
key: `${row.parent ?? 'ungrouped'}-${sections.length}`,
|
||||
group: row.parent ? (byId.get(row.parent) ?? null) : null,
|
||||
rows: [],
|
||||
};
|
||||
sections.push(current);
|
||||
}
|
||||
current.rows.push(row);
|
||||
}
|
||||
|
||||
return sections;
|
||||
}
|
||||
+46
-198
@@ -1,241 +1,89 @@
|
||||
import type { EntryId, MaybeNumber, OntimeGroup, OntimeReport, RundownEntries, ShowReport } from 'ontime-types';
|
||||
import { isOntimeEvent, isOntimeGroup } from 'ontime-types';
|
||||
import { dayInMs, MILLIS_PER_SECOND } from 'ontime-utils';
|
||||
import { EntryId, MaybeNumber, OntimeReport, RundownEntries, isOntimeEvent } from 'ontime-types';
|
||||
|
||||
import { makeCSVFromArrayOfArrays } from '../../../../common/utils/csv';
|
||||
import { getEventVariance, getReportTimePosition } from '../../../../common/utils/report';
|
||||
import { enDash } from '../../../../common/utils/styleUtils';
|
||||
import { formatDuration, formatTime } from '../../../../common/utils/time';
|
||||
import { formatTime } from '../../../../common/utils/time';
|
||||
|
||||
export type CombinedReport = {
|
||||
id: EntryId;
|
||||
index: number;
|
||||
title: string;
|
||||
cue: string;
|
||||
colour: string;
|
||||
/** the group this event belongs to, so the report can mirror the rundown */
|
||||
parent: EntryId | null;
|
||||
groupTitle: string;
|
||||
scheduledStart: number;
|
||||
actualStart: MaybeNumber;
|
||||
startOffset: MaybeNumber;
|
||||
scheduledEnd: number;
|
||||
actualEnd: MaybeNumber;
|
||||
endOffset: MaybeNumber;
|
||||
};
|
||||
|
||||
type ShowOffsets = {
|
||||
startOffset: MaybeNumber;
|
||||
endOffset: MaybeNumber;
|
||||
durationOffset: MaybeNumber;
|
||||
};
|
||||
|
||||
export type GroupReport = {
|
||||
id: EntryId;
|
||||
title: string;
|
||||
colour: string;
|
||||
targetDuration: MaybeNumber;
|
||||
scheduledDuration: number;
|
||||
actualStart: MaybeNumber;
|
||||
actualEnd: MaybeNumber;
|
||||
elapsed: MaybeNumber;
|
||||
variance: MaybeNumber;
|
||||
eventsRun: number;
|
||||
eventsPlanned: number;
|
||||
};
|
||||
|
||||
export type RunSummary = {
|
||||
eventsRun: number;
|
||||
eventsPlanned: number;
|
||||
};
|
||||
|
||||
/**
|
||||
* Creates a combined report with the rundown data.
|
||||
*
|
||||
* Events that ran are measured against the schedule recorded at the time,
|
||||
* not the rundown's current values, so editing the rundown afterwards does
|
||||
* not change how a show that already happened is reported. Events that never
|
||||
* ran have no snapshot and fall back to the rundown.
|
||||
* Creates a combined report with the rundown data
|
||||
*/
|
||||
export function getCombinedReport(
|
||||
report: OntimeReport,
|
||||
rundown: RundownEntries,
|
||||
flatOrder: EntryId[],
|
||||
): CombinedReport[] {
|
||||
if (Object.keys(report).length === 0 || flatOrder.length === 0) return [];
|
||||
if (Object.keys(report).length === 0) return [];
|
||||
if (flatOrder.length === 0) return [];
|
||||
|
||||
const combinedReport: CombinedReport[] = [];
|
||||
|
||||
let index = 1;
|
||||
for (const id of flatOrder) {
|
||||
for (let i = 0; i < flatOrder.length; i++) {
|
||||
const id = flatOrder[i];
|
||||
const entry = rundown[id];
|
||||
// skipped events were never meant to run, listing them alongside events
|
||||
// that did would also disagree with the summary, which excludes them
|
||||
if (!entry || !isOntimeEvent(entry) || entry.skip) continue;
|
||||
|
||||
const parent = entry.parent;
|
||||
const group = parent ? rundown[parent] : undefined;
|
||||
const reported = report[id];
|
||||
const scheduledStart = reported?.scheduledStart ?? entry.timeStart;
|
||||
const scheduledDay = reported?.scheduledDay ?? entry.dayOffset;
|
||||
const scheduledStartPosition = getReportTimePosition(scheduledStart, scheduledDay);
|
||||
const actualStartPosition = reported ? getReportTimePosition(reported.startedAt, reported.startedAtDay) : null;
|
||||
const actualEndPosition = reported ? getReportTimePosition(reported.endedAt, reported.endedAtDay) : null;
|
||||
const scheduledDuration = reported?.scheduledDuration ?? entry.duration;
|
||||
if (!entry || !isOntimeEvent(entry)) continue;
|
||||
|
||||
if (!(id in report)) {
|
||||
combinedReport.push({
|
||||
id,
|
||||
index,
|
||||
id: id,
|
||||
index: index,
|
||||
title: entry.title,
|
||||
cue: entry.cue,
|
||||
colour: entry.colour,
|
||||
parent,
|
||||
groupTitle: group && isOntimeGroup(group) ? group.title : '',
|
||||
// an event that ran is measured against the plan it ran on, one that
|
||||
// did not has no snapshot and falls back to the rundown
|
||||
scheduledStart,
|
||||
scheduledEnd: scheduledStart + scheduledDuration,
|
||||
actualStart: reported?.startedAt ?? null,
|
||||
startOffset: getOffset(actualStartPosition, scheduledStartPosition),
|
||||
actualEnd: reported?.endedAt ?? null,
|
||||
endOffset: getOffset(actualEndPosition, scheduledStartPosition + scheduledDuration),
|
||||
scheduledStart: entry.timeStart,
|
||||
actualEnd: null,
|
||||
scheduledEnd: entry.timeEnd,
|
||||
actualStart: null,
|
||||
});
|
||||
}
|
||||
|
||||
if (id in report) {
|
||||
combinedReport.push({
|
||||
id: id,
|
||||
index: index,
|
||||
title: entry.title,
|
||||
cue: entry.cue,
|
||||
scheduledStart: entry.timeStart,
|
||||
actualEnd: report[id].endedAt,
|
||||
scheduledEnd: entry.timeEnd,
|
||||
actualStart: report[id].startedAt,
|
||||
});
|
||||
}
|
||||
index++;
|
||||
}
|
||||
|
||||
return combinedReport;
|
||||
}
|
||||
|
||||
function getOffset(actual: MaybeNumber, scheduled: number): MaybeNumber {
|
||||
return actual === null ? null : actual - scheduled;
|
||||
}
|
||||
|
||||
export function getShowOffsets(show: ShowReport): ShowOffsets {
|
||||
const { plannedDuration, actualDuration } = show;
|
||||
return {
|
||||
startOffset: getWallClockOffset(show.plannedStart, show.actualStart),
|
||||
endOffset: getWallClockOffset(show.plannedEnd, show.actualEnd),
|
||||
durationOffset: plannedDuration === null || actualDuration === null ? null : actualDuration - plannedDuration,
|
||||
};
|
||||
}
|
||||
|
||||
function getWallClockOffset(planned: MaybeNumber, actual: MaybeNumber): MaybeNumber {
|
||||
if (planned === null || actual === null) return null;
|
||||
|
||||
const offset = actual - planned;
|
||||
if (offset < -dayInMs / 2) return offset + dayInMs;
|
||||
if (offset > dayInMs / 2) return offset - dayInMs;
|
||||
return offset;
|
||||
}
|
||||
|
||||
export function getGroupReports(report: OntimeReport, entries: RundownEntries, order: EntryId[]): GroupReport[] {
|
||||
const groups: GroupReport[] = [];
|
||||
for (const id of order) {
|
||||
const group = entries[id];
|
||||
if (group && isOntimeGroup(group)) groups.push(getGroupReport(group, report, entries));
|
||||
}
|
||||
return groups;
|
||||
}
|
||||
|
||||
function getGroupReport(group: OntimeGroup, report: OntimeReport, entries: RundownEntries): GroupReport {
|
||||
let scheduledDuration = 0;
|
||||
let eventsPlanned = 0;
|
||||
let eventsRun = 0;
|
||||
let firstStart = Number.POSITIVE_INFINITY;
|
||||
let lastEnd = Number.NEGATIVE_INFINITY;
|
||||
let actualStart: MaybeNumber = null;
|
||||
let actualEnd: MaybeNumber = null;
|
||||
|
||||
for (const childId of group.entries) {
|
||||
const child = entries[childId];
|
||||
if (!child || !isOntimeEvent(child) || child.skip) continue;
|
||||
|
||||
eventsPlanned += 1;
|
||||
const reported = report[childId];
|
||||
scheduledDuration += reported?.scheduledDuration ?? child.duration;
|
||||
|
||||
const variance = getEventVariance(reported);
|
||||
if (variance.actualDuration === null || !reported) continue;
|
||||
|
||||
eventsRun += 1;
|
||||
const start = getReportTimePosition(reported.startedAt, reported.startedAtDay);
|
||||
const end = getReportTimePosition(reported.endedAt, reported.endedAtDay);
|
||||
if (start !== null && start < firstStart) {
|
||||
firstStart = start;
|
||||
actualStart = reported.startedAt;
|
||||
}
|
||||
if (end !== null && end > lastEnd) {
|
||||
lastEnd = end;
|
||||
actualEnd = reported.endedAt;
|
||||
}
|
||||
}
|
||||
|
||||
const elapsed = actualStart === null || actualEnd === null ? null : lastEnd - firstStart;
|
||||
const measuredAgainst = group.targetDuration ?? scheduledDuration;
|
||||
const isComplete = eventsRun > 0 && eventsRun === eventsPlanned;
|
||||
|
||||
return {
|
||||
id: group.id,
|
||||
title: group.title,
|
||||
colour: group.colour,
|
||||
targetDuration: group.targetDuration,
|
||||
scheduledDuration,
|
||||
actualStart,
|
||||
actualEnd,
|
||||
elapsed,
|
||||
variance: elapsed === null || !isComplete ? null : elapsed - measuredAgainst,
|
||||
eventsRun,
|
||||
eventsPlanned,
|
||||
};
|
||||
}
|
||||
|
||||
export function getRunSummary(report: OntimeReport, entries: RundownEntries, order: EntryId[]): RunSummary {
|
||||
const eventsPlanned = order.filter((id) => {
|
||||
const entry = entries[id];
|
||||
return entry && isOntimeEvent(entry) && !entry.skip;
|
||||
}).length;
|
||||
const eventsRun = Object.values(report).filter((entry) => getEventVariance(entry).status !== 'not-run').length;
|
||||
return { eventsRun, eventsPlanned };
|
||||
}
|
||||
const csvHeader = ['Index', 'Title', 'Cue', 'Scheduled Start', 'Actual Start', 'Scheduled End', 'Actual End'];
|
||||
|
||||
/**
|
||||
* Signed offset, eg "+4m12s" / "-1m", following Ontime's convention that
|
||||
* positive means behind schedule.
|
||||
*/
|
||||
export function formatOffset(value: MaybeNumber): string {
|
||||
if (value === null) return enDash;
|
||||
if (Math.abs(value) < MILLIS_PER_SECOND) return 'On time';
|
||||
return `${value > 0 ? '+' : '-'}${formatDuration(Math.abs(value), false)}`;
|
||||
}
|
||||
|
||||
export function offsetTone(value: MaybeNumber): 'over' | 'under' | 'none' {
|
||||
if (value === null || Math.abs(value) < MILLIS_PER_SECOND) return 'none';
|
||||
return value > 0 ? 'over' : 'under';
|
||||
}
|
||||
|
||||
function formatCsvTime(value: MaybeNumber): string {
|
||||
return value === null ? '' : formatTime(value);
|
||||
}
|
||||
|
||||
const csvHeader = ['Index', 'Group', 'Cue', 'Title', 'Scheduled Start', 'Actual Start', 'Scheduled End', 'Actual End'];
|
||||
|
||||
/**
|
||||
* Transforms a CombinedReport into a CSV string.
|
||||
*
|
||||
* Exported as one row per event with its group named, rather than with
|
||||
* rollups baked in, so it stays the dataset a report is built from.
|
||||
* Transforms a CombinedReport into a CSV string
|
||||
*/
|
||||
export function makeReportCSV(combinedReport: CombinedReport[]) {
|
||||
const csv = combinedReport.map((entry) => [
|
||||
String(entry.index),
|
||||
entry.groupTitle,
|
||||
entry.cue,
|
||||
entry.title,
|
||||
formatTime(entry.scheduledStart),
|
||||
formatCsvTime(entry.actualStart),
|
||||
formatTime(entry.scheduledEnd),
|
||||
formatCsvTime(entry.actualEnd),
|
||||
]);
|
||||
const csv: string[][] = [];
|
||||
csv.push(csvHeader);
|
||||
|
||||
return makeCSVFromArrayOfArrays([csvHeader, ...csv]);
|
||||
for (const entry of combinedReport) {
|
||||
csv.push([
|
||||
String(entry.index),
|
||||
entry.title,
|
||||
entry.cue,
|
||||
formatTime(entry.scheduledStart),
|
||||
formatTime(entry.actualStart),
|
||||
formatTime(entry.scheduledEnd),
|
||||
formatTime(entry.actualEnd),
|
||||
]);
|
||||
}
|
||||
|
||||
return makeCSVFromArrayOfArrays(csv);
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ export default function ShutdownPanel() {
|
||||
{!isOntimeCloud && (
|
||||
<Panel.Section>
|
||||
<Button variant='destructive' onClick={handler.open} disabled={!canShutdown}>
|
||||
Shutdown Ontime
|
||||
Shutdown ontime
|
||||
</Button>
|
||||
{!canShutdown && <Panel.Description>Only available from the machine running Ontime.</Panel.Description>}
|
||||
</Panel.Section>
|
||||
|
||||
@@ -27,6 +27,13 @@
|
||||
border-top: 1px solid $white-7;
|
||||
}
|
||||
|
||||
.timerSource {
|
||||
color: $active-indicator;
|
||||
font-size: 0.75rem;
|
||||
font-weight: 600;
|
||||
text-transform: uppercase;
|
||||
}
|
||||
|
||||
.blackout {
|
||||
display: none;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { TimerPhase, TimerType } from 'ontime-types';
|
||||
import { IoArrowDown, IoArrowUp, IoBan, IoTime } from 'react-icons/io5';
|
||||
import { IoArrowDown, IoArrowUp, IoBan, IoTime, IoTimerOutline } from 'react-icons/io5';
|
||||
import { LuArrowDownToLine } from 'react-icons/lu';
|
||||
|
||||
import { CornerWithPip } from '../../../common/components/editor-utils/EditorUtils';
|
||||
@@ -20,7 +20,8 @@ const secondarySourceLabels: Record<string, string> = {
|
||||
};
|
||||
|
||||
export default function TimerPreview() {
|
||||
const { blink, blackout, countToEnd, phase, secondarySource, showTimerMessage, timerType } = useMessagePreview();
|
||||
const { blink, blackout, countToEnd, phase, secondarySource, showTimerMessage, timerType, usesGroupTimer } =
|
||||
useMessagePreview();
|
||||
const { data } = useViewSettings();
|
||||
|
||||
const main = (() => {
|
||||
@@ -35,7 +36,9 @@ export default function TimerPreview() {
|
||||
|
||||
const secondary = (() => {
|
||||
// message is a fullscreen overlay or secondary is not active
|
||||
if (showTimerMessage || !secondarySource) return null;
|
||||
if (showTimerMessage) return null;
|
||||
if (usesGroupTimer) return 'Event timer';
|
||||
if (!secondarySource) return null;
|
||||
|
||||
// we need to check aux first since it takes priority
|
||||
return secondarySourceLabels[secondarySource];
|
||||
@@ -55,6 +58,7 @@ export default function TimerPreview() {
|
||||
<div className={style.preview}>
|
||||
<CornerWithPip onExtractClick={(event) => handleLinks('timer', event)} pipElement={<PipRoot />} />
|
||||
<div className={contentClasses}>
|
||||
{usesGroupTimer && <div className={style.timerSource}>Group timer</div>}
|
||||
<div
|
||||
className={style.mainContent}
|
||||
data-phase={showColourOverride && phase}
|
||||
@@ -65,6 +69,14 @@ export default function TimerPreview() {
|
||||
{secondary !== null && <div className={style.secondaryContent}>{secondary}</div>}
|
||||
</div>
|
||||
<div className={style.eventStatus}>
|
||||
<Tooltip
|
||||
text='Timer display controlled by group'
|
||||
render={<span />}
|
||||
className={style.statusIcon}
|
||||
data-active={usesGroupTimer}
|
||||
>
|
||||
<IoTimerOutline />
|
||||
</Tooltip>
|
||||
<Tooltip
|
||||
text='Time type: Count down'
|
||||
render={<span />}
|
||||
|
||||
@@ -18,12 +18,6 @@
|
||||
padding-bottom: 95vh;
|
||||
}
|
||||
|
||||
.groupSection {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 2px;
|
||||
}
|
||||
|
||||
.editPrompt {
|
||||
position: fixed;
|
||||
z-index: $zindex-dialog;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { OntimeView, isOntimeEvent, isOntimeGroup } from 'ontime-types';
|
||||
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
||||
import { Fragment, useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
||||
|
||||
import EmptyFill from '../../common/components/state/EmptyFill';
|
||||
import EmptyPage from '../../common/components/state/EmptyPage';
|
||||
@@ -25,10 +25,7 @@ import { OperatorData, useOperatorData } from './useOperatorData';
|
||||
|
||||
import style from './Operator.module.scss';
|
||||
|
||||
/** Keeps the running event clear of the list edge when no group header is pinned above it */
|
||||
const edgeOffset = 50;
|
||||
/** How far the running event may drift from where we placed it before we stop following */
|
||||
const followTolerance = 50;
|
||||
const selectedOffset = 50;
|
||||
|
||||
export default function OperatorLoader() {
|
||||
const { data, status } = useOperatorData();
|
||||
@@ -57,20 +54,11 @@ function Operator({ rundown, rundownMetadata, customFields, settings }: Operator
|
||||
const [lockAutoScroll, setLockAutoScroll] = useState(false);
|
||||
const selectedRef = useRef<HTMLDivElement | null>(null);
|
||||
const scrollRef = useRef<HTMLDivElement | null>(null);
|
||||
const stickyHeaderRef = useRef<HTMLDivElement | null>(null);
|
||||
|
||||
// The header height varies with the viewport, so measure it at scroll time.
|
||||
const getTopOffset = useCallback(() => {
|
||||
const header = stickyHeaderRef.current;
|
||||
// Sit right under the pinned header, so it covers the previous event instead of half of it.
|
||||
return header ? header.offsetHeight + 2 : edgeOffset;
|
||||
}, []);
|
||||
|
||||
const scrollToComponent = useFollowComponent({
|
||||
followRef: selectedRef,
|
||||
scrollRef,
|
||||
doFollow: !lockAutoScroll,
|
||||
getTopOffset,
|
||||
topOffset: selectedOffset,
|
||||
followTrigger: selectedEventId,
|
||||
});
|
||||
|
||||
@@ -94,16 +82,15 @@ function Operator({ rundown, rundownMetadata, customFields, settings }: Operator
|
||||
|
||||
// prevent considering automated scrolls as user scrolls
|
||||
const handleUserScroll = () => {
|
||||
if (!selectedRef.current || !scrollRef.current) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (selectedRef?.current && scrollRef?.current) {
|
||||
const selectedRect = selectedRef.current.getBoundingClientRect();
|
||||
const scrollerRect = scrollRef.current.getBoundingClientRect();
|
||||
// Measure the drift from where an automated scroll would place the event.
|
||||
const distanceFromTop = selectedRect.top - scrollerRect.top - getTopOffset();
|
||||
const hasScrolledOutOfThreshold = distanceFromTop < -8 || distanceFromTop > followTolerance;
|
||||
if (selectedRect && scrollerRect) {
|
||||
const distanceFromTop = selectedRect.top - scrollerRect.top;
|
||||
const hasScrolledOutOfThreshold = distanceFromTop < -8 || distanceFromTop > selectedOffset;
|
||||
setLockAutoScroll(hasScrolledOutOfThreshold);
|
||||
}
|
||||
}
|
||||
};
|
||||
const throttledHandleScroll = throttle(handleUserScroll, 1000);
|
||||
|
||||
@@ -199,9 +186,9 @@ function Operator({ rundown, rundownMetadata, customFields, settings }: Operator
|
||||
}
|
||||
|
||||
return (
|
||||
<div className={style.groupSection} key={entry.id}>
|
||||
<Fragment key={entry.id}>
|
||||
<OperatorGroup
|
||||
ref={isCurrentParent ? stickyHeaderRef : undefined}
|
||||
key={entry.id}
|
||||
title={entry.title}
|
||||
colour={entry.colour}
|
||||
count={entry.entries.length}
|
||||
@@ -252,7 +239,7 @@ function Operator({ rundown, rundownMetadata, customFields, settings }: Operator
|
||||
/>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</Fragment>
|
||||
);
|
||||
}
|
||||
return null;
|
||||
|
||||
@@ -1,20 +1,13 @@
|
||||
.group {
|
||||
width: 100%;
|
||||
/* Padding is kept under the min-height so a single line fits without the list having to shrink the header,
|
||||
while a taller title still grows the row. */
|
||||
min-height: 2.5rem;
|
||||
padding: 0.25rem 0.75rem;
|
||||
padding: 0.4rem 0.75rem;
|
||||
border-left: 0.35rem solid var(--group-colour, $gray-500);
|
||||
background-color: $gray-1350;
|
||||
background: color-mix(in srgb, transparent 88%, var(--group-colour, $gray-500) 12%);
|
||||
font-size: 1.25rem;
|
||||
font-weight: 600;
|
||||
|
||||
position: sticky;
|
||||
/* Cover the list padding so rows cannot scroll above the header. */
|
||||
top: -0.25rem;
|
||||
z-index: 1;
|
||||
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 1rem;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { type CSSProperties, type Ref, memo } from 'react';
|
||||
import { CSSProperties, memo } from 'react';
|
||||
|
||||
import { getAccessibleColour } from '../../../common/utils/styleUtils';
|
||||
import { formatDuration } from '../../../common/utils/time';
|
||||
@@ -10,16 +10,15 @@ interface OperatorGroup {
|
||||
colour: string;
|
||||
count: number;
|
||||
duration: number;
|
||||
ref?: Ref<HTMLDivElement>;
|
||||
}
|
||||
|
||||
export default memo(OperatorGroup);
|
||||
function OperatorGroup({ title, colour, count, duration, ref }: OperatorGroup) {
|
||||
function OperatorGroup({ title, colour, count, duration }: OperatorGroup) {
|
||||
const groupColour = colour || '#929292';
|
||||
const groupColours = getAccessibleColour(groupColour);
|
||||
|
||||
return (
|
||||
<div className={style.group} style={{ ...groupColours, '--group-colour': groupColour } as CSSProperties} ref={ref}>
|
||||
<div className={style.group} style={{ ...groupColours, '--group-colour': groupColour } as CSSProperties}>
|
||||
<span className={style.title}>{title}</span>
|
||||
<span className={style.meta}>
|
||||
<span>{`${count} ${count === 1 ? 'event' : 'events'}`}</span>
|
||||
|
||||
@@ -32,6 +32,12 @@
|
||||
gap: 1rem;
|
||||
}
|
||||
|
||||
.timerDisplaySettings {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 1rem;
|
||||
}
|
||||
|
||||
.column {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
import { MaybeNumber, OntimeGroup } from 'ontime-types';
|
||||
import { MaybeNumber, OntimeGroup, TimerType } from 'ontime-types';
|
||||
import { millisToString } from 'ontime-utils';
|
||||
import { useCallback } from 'react';
|
||||
|
||||
import * as Editor from '../../../common/components/editor-utils/EditorUtils';
|
||||
import SwatchSelect from '../../../common/components/input/colour-input/SwatchSelect';
|
||||
import AppLink from '../../../common/components/link/app-link/AppLink';
|
||||
import Select from '../../../common/components/select/Select';
|
||||
import Switch from '../../../common/components/switch/Switch';
|
||||
import { useEntryActionsContext } from '../../../common/context/EntryActionsContext';
|
||||
import useCustomFields from '../../../common/hooks-query/useCustomFields';
|
||||
import { getOffsetState } from '../../../common/utils/offset';
|
||||
@@ -107,6 +109,38 @@ export default function GroupEditor({ group }: GroupEditorProps) {
|
||||
<EventTextArea field='note' label='Note' initialValue={group.note} submitHandler={handleSubmit} />
|
||||
</div>
|
||||
|
||||
<div className={style.column}>
|
||||
<Editor.Title>Timer display</Editor.Title>
|
||||
<div className={style.timerDisplaySettings}>
|
||||
<div>
|
||||
<Editor.Label htmlFor='useGroupTimer'>Use group timer</Editor.Label>
|
||||
<Editor.Label className={style.switchLabel}>
|
||||
<Switch
|
||||
id='useGroupTimer'
|
||||
checked={group.useGroupTimer}
|
||||
onCheckedChange={(useGroupTimer) => updateEntry({ id: group.id, useGroupTimer })}
|
||||
/>
|
||||
{group.useGroupTimer ? 'On' : 'Off'}
|
||||
</Editor.Label>
|
||||
</div>
|
||||
<div>
|
||||
<Editor.Label htmlFor='groupTimerType'>Timer type</Editor.Label>
|
||||
<Select
|
||||
id='groupTimerType'
|
||||
disabled={!group.useGroupTimer}
|
||||
value={group.timerType}
|
||||
onValueChange={(timerType: TimerType | null) => {
|
||||
if (timerType !== null) updateEntry({ id: group.id, timerType });
|
||||
}}
|
||||
options={[
|
||||
{ value: TimerType.CountDown, label: 'Count down' },
|
||||
{ value: TimerType.CountUp, label: 'Count up' },
|
||||
]}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className={style.column}>
|
||||
<Editor.Title>
|
||||
Custom Fields
|
||||
|
||||
@@ -335,6 +335,7 @@ export default function RundownEvent({
|
||||
eventIndex={eventIndex}
|
||||
endAction={endAction}
|
||||
timerType={timerType}
|
||||
groupTimerType={parentGroup?.useGroupTimer ? parentGroup.timerType : undefined}
|
||||
title={title}
|
||||
note={note}
|
||||
delay={delay}
|
||||
|
||||
@@ -9,6 +9,7 @@ import {
|
||||
IoPlayForward,
|
||||
IoPlaySkipForward,
|
||||
IoTime,
|
||||
IoTimerOutline,
|
||||
} from 'react-icons/io5';
|
||||
import { LuArrowDownToLine } from 'react-icons/lu';
|
||||
|
||||
@@ -35,6 +36,7 @@ interface RundownEventInnerProps {
|
||||
eventIndex: number;
|
||||
endAction: EndAction;
|
||||
timerType: TimerType;
|
||||
groupTimerType?: TimerType;
|
||||
title: string;
|
||||
note: string;
|
||||
delay: number;
|
||||
@@ -62,6 +64,7 @@ function RundownEventInner({
|
||||
countToEnd,
|
||||
endAction,
|
||||
timerType,
|
||||
groupTimerType,
|
||||
title,
|
||||
note,
|
||||
delay,
|
||||
@@ -141,6 +144,7 @@ function RundownEventInner({
|
||||
isPast={isPast}
|
||||
isLoaded={loaded}
|
||||
totalGap={totalGap}
|
||||
duration={duration}
|
||||
/>
|
||||
)}
|
||||
<div className={style.statusElements} id='entry-status' data-timertype={timerType}>
|
||||
@@ -149,6 +153,14 @@ function RundownEventInner({
|
||||
{loaded && <EventBlockProgressBar />}
|
||||
</div>
|
||||
<div className={style.eventStatus} tabIndex={-1}>
|
||||
{groupTimerType && (
|
||||
<Tooltip
|
||||
text={`Timer display controlled by group (${groupTimerType === TimerType.CountUp ? 'count up' : 'count down'})`}
|
||||
render={<span />}
|
||||
>
|
||||
<IoTimerOutline className={cx([style.statusIcon, style.active])} />
|
||||
</Tooltip>
|
||||
)}
|
||||
<Tooltip text={`Time type: ${timerType}`} render={<span />}>
|
||||
<TimerIcon type={timerType} className={style.statusIcon} />
|
||||
</Tooltip>
|
||||
|
||||
@@ -6,7 +6,6 @@ import { IoCheckmarkCircle } from 'react-icons/io5';
|
||||
import Tooltip from '../../../../common/components/tooltip/Tooltip';
|
||||
import useReport from '../../../../common/hooks-query/useReport';
|
||||
import { usePlayback } from '../../../../common/hooks/useSocket';
|
||||
import { getEventVariance } from '../../../../common/utils/report';
|
||||
import { cx } from '../../../../common/utils/styleUtils';
|
||||
import { formatDuration, useTimeUntilExpectedStart } from '../../../../common/utils/time';
|
||||
|
||||
@@ -21,6 +20,7 @@ interface RundownEventChipProps {
|
||||
isLoaded: boolean;
|
||||
className: string;
|
||||
totalGap: number;
|
||||
duration: number;
|
||||
isLinkedToLoaded: boolean;
|
||||
}
|
||||
|
||||
@@ -33,6 +33,7 @@ export default function RundownEventChip({
|
||||
className,
|
||||
totalGap,
|
||||
id,
|
||||
duration,
|
||||
isLinkedToLoaded,
|
||||
}: RundownEventChipProps) {
|
||||
const playback = usePlayback();
|
||||
@@ -44,9 +45,11 @@ export default function RundownEventChip({
|
||||
const playbackActive = isPlaybackActive(playback);
|
||||
|
||||
if (!playbackActive || isPast) {
|
||||
return <EventReport className={className} id={id} />;
|
||||
return <EventReport className={className} id={id} duration={duration} />;
|
||||
}
|
||||
|
||||
if (playbackActive) {
|
||||
// we extracted the component to avoid unnecessary calculations and re-renders
|
||||
return (
|
||||
<Tooltip text='Expected time until start' render={<span />} className={className}>
|
||||
<EventUntil
|
||||
@@ -60,6 +63,9 @@ export default function RundownEventChip({
|
||||
);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
interface EventUntilProps {
|
||||
timeStart: number;
|
||||
delay: number;
|
||||
@@ -80,30 +86,41 @@ function EventUntil({ timeStart, delay, dayOffset, totalGap, isLinkedToLoaded }:
|
||||
interface EventReportProps {
|
||||
className: string;
|
||||
id: string;
|
||||
duration: number;
|
||||
}
|
||||
|
||||
function EventReport({ className, id }: EventReportProps) {
|
||||
function EventReport(props: EventReportProps) {
|
||||
const { className, id, duration } = props;
|
||||
const { data } = useReport();
|
||||
const currentReport = data[id];
|
||||
|
||||
const [value, overUnderStyle, tooltip] = useMemo(() => {
|
||||
// Use the schedule recorded when the event ran so later rundown edits do
|
||||
// not change its report.
|
||||
const variance = getEventVariance(currentReport);
|
||||
if (variance.status === 'not-run') {
|
||||
if (!currentReport) {
|
||||
return [null, 'none', ''];
|
||||
}
|
||||
|
||||
if (variance.status === 'ontime') {
|
||||
const { startedAt, endedAt } = currentReport;
|
||||
if (!startedAt || !endedAt) {
|
||||
return [null, 'none', ''];
|
||||
}
|
||||
|
||||
const actualDuration = endedAt - startedAt;
|
||||
const difference = actualDuration - duration;
|
||||
const absDifference = Math.abs(difference);
|
||||
|
||||
if (absDifference < MILLIS_PER_SECOND) {
|
||||
return ['ontime', 'under', 'Event finished on time'];
|
||||
}
|
||||
|
||||
const absDifference = Math.abs(variance.delta);
|
||||
const isOver = variance.status === 'over';
|
||||
const tooltip = `Event ran ${isOver ? 'over' : 'under'} time by ${millisToString(absDifference)}`;
|
||||
const isOver = difference > 0;
|
||||
|
||||
const fullTimeValue = millisToString(absDifference);
|
||||
|
||||
const tooltip = `Event ran ${isOver ? 'over' : 'under'} time by ${fullTimeValue}`;
|
||||
|
||||
const value = `${isOver ? '+' : '-'}${formatDuration(absDifference, absDifference > 2 * MILLIS_PER_MINUTE)}`;
|
||||
return [value, variance.status, tooltip];
|
||||
}, [currentReport]);
|
||||
return [value, isOver ? 'over' : 'under', tooltip];
|
||||
}, [currentReport, duration]);
|
||||
|
||||
if (!value) {
|
||||
return null;
|
||||
|
||||
@@ -55,6 +55,14 @@
|
||||
gap: 0.5rem;
|
||||
}
|
||||
|
||||
.timerIndicator {
|
||||
display: grid;
|
||||
flex: 0 0 1.5rem;
|
||||
place-items: center;
|
||||
color: $active-indicator;
|
||||
font-size: 1rem;
|
||||
}
|
||||
|
||||
.metaRow {
|
||||
display: flex;
|
||||
gap: $block-clearance; // same as RundownEvent.eventTimers
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { useSortable } from '@dnd-kit/sortable';
|
||||
import { CSS } from '@dnd-kit/utilities';
|
||||
import { EntryId, OntimeGroup } from 'ontime-types';
|
||||
import { EntryId, OntimeGroup, TimerType } from 'ontime-types';
|
||||
import { MILLIS_PER_MINUTE } from 'ontime-utils';
|
||||
import { MouseEvent, useCallback, useRef } from 'react';
|
||||
import {
|
||||
@@ -9,6 +9,7 @@ import {
|
||||
IoDuplicateOutline,
|
||||
IoFolderOpenOutline,
|
||||
IoReorderTwo,
|
||||
IoTimerOutline,
|
||||
IoTrash,
|
||||
IoLockClosed,
|
||||
} from 'react-icons/io5';
|
||||
@@ -174,6 +175,14 @@ export default function RundownGroup({ data, hasCursor, collapsed, onCollapse }:
|
||||
<div className={style.header}>
|
||||
<div className={style.titleRow}>
|
||||
<TitleEditor title={data.title} entryId={data.id} placeholder='Group title' />
|
||||
{data.useGroupTimer && (
|
||||
<Tooltip
|
||||
text={`Group timer (${data.timerType === TimerType.CountUp ? 'count up' : 'count down'})`}
|
||||
render={<span className={style.timerIndicator} />}
|
||||
>
|
||||
<IoTimerOutline />
|
||||
</Tooltip>
|
||||
)}
|
||||
<IconButton aria-label='Collapse' variant='subtle-white' onClick={() => onCollapse(!collapsed, data.id)}>
|
||||
{collapsed ? <IoChevronUp /> : <IoChevronDown />}
|
||||
</IconButton>
|
||||
|
||||
@@ -100,20 +100,7 @@ $item-height: 3.5rem;
|
||||
flex-direction: column;
|
||||
overflow-y: auto;
|
||||
|
||||
padding-bottom: 95vh;
|
||||
}
|
||||
|
||||
/* Flex prevents row margins collapsing and bounds the sticky header to its group. */
|
||||
.sub-section {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
|
||||
/* The select view renders the same cards in a flat list. */
|
||||
.sub--group {
|
||||
position: sticky;
|
||||
top: 0;
|
||||
z-index: 1;
|
||||
}
|
||||
padding-bottom: max(8rem, calc(5rem + env(safe-area-inset-bottom)));
|
||||
}
|
||||
|
||||
/* ====================== LIST-ITEM ======================*/
|
||||
@@ -209,14 +196,9 @@ $item-height: 3.5rem;
|
||||
|
||||
.sub--group {
|
||||
box-shadow: inset 0 0 0 1px var(--user-color, $gray-1325);
|
||||
/* The opaque base prevents rows showing through; background shorthand cannot layer this colour. */
|
||||
background-color: var(--background-color-override, $viewer-background-color);
|
||||
background-image:
|
||||
background:
|
||||
linear-gradient(90deg, color-mix(in srgb, var(--user-color, transparent) 18%, transparent), transparent 42%),
|
||||
linear-gradient(
|
||||
var(--card-background-color-override, $viewer-card-bg-color),
|
||||
var(--card-background-color-override, $viewer-card-bg-color)
|
||||
);
|
||||
var(--card-background-color-override, $viewer-card-bg-color);
|
||||
|
||||
.sub__binder {
|
||||
background: var(--user-color, var(--card-background-color-override, $viewer-card-bg-color));
|
||||
@@ -248,16 +230,6 @@ $item-height: 3.5rem;
|
||||
}
|
||||
}
|
||||
|
||||
/* Reserve the green fill for the running event. */
|
||||
.sub--group.sub--live {
|
||||
box-shadow: inset 0 0 0 2px $active-green;
|
||||
}
|
||||
|
||||
/* Keep the armed state quieter than the live ring. */
|
||||
.sub--group.sub--armed {
|
||||
box-shadow: inset 0 0 0 2px $gray-1000;
|
||||
}
|
||||
|
||||
.sub__title {
|
||||
grid-area: title;
|
||||
padding-bottom: 0.5rem;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { MaybeNumber, OntimeEvent } from 'ontime-types';
|
||||
import { dayInMs } from 'ontime-utils';
|
||||
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
||||
import { useEffect, useRef, useState } from 'react';
|
||||
import { IoPencil } from 'react-icons/io5';
|
||||
|
||||
import Button from '../../common/components/buttons/Button';
|
||||
@@ -22,7 +22,6 @@ import {
|
||||
CountdownTarget,
|
||||
extendEventData,
|
||||
getIsLive,
|
||||
groupSubscriptionTargets,
|
||||
isOutsideRange,
|
||||
preferredFormat12,
|
||||
preferredFormat24,
|
||||
@@ -49,22 +48,11 @@ export default function CountdownSubscriptions({ subscribedEvents, goToEditMode
|
||||
const [lockAutoScroll, setLockAutoScroll] = useState(false);
|
||||
const selectedRef = useRef<HTMLDivElement | null>(null);
|
||||
const scrollRef = useRef<HTMLDivElement | null>(null);
|
||||
const stickyHeaderRef = useRef<HTMLDivElement | null>(null);
|
||||
|
||||
const sections = useMemo(() => groupSubscriptionTargets(subscribedEvents), [subscribedEvents]);
|
||||
|
||||
// Responsive sizing and wrapped titles make the sticky header height variable, so measure it at scroll time.
|
||||
const getStickyOffset = useCallback(() => {
|
||||
const header = stickyHeaderRef.current;
|
||||
// Preserve the combined margins between the header and running event.
|
||||
return header ? header.offsetHeight + 4 : 0;
|
||||
}, []);
|
||||
|
||||
const scrollToComponent = useFollowComponent({
|
||||
followRef: selectedRef,
|
||||
scrollRef,
|
||||
doFollow: !lockAutoScroll,
|
||||
getTopOffset: getStickyOffset,
|
||||
topOffset: 0,
|
||||
followTrigger: selectedEventId,
|
||||
});
|
||||
|
||||
@@ -87,16 +75,15 @@ export default function CountdownSubscriptions({ subscribedEvents, goToEditMode
|
||||
|
||||
// prevent considering automated scrolls as user scrolls
|
||||
const handleUserScroll = () => {
|
||||
if (!selectedRef.current || !scrollRef.current) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (selectedRef?.current && scrollRef?.current) {
|
||||
const selectedRect = selectedRef.current.getBoundingClientRect();
|
||||
const scrollerRect = scrollRef.current.getBoundingClientRect();
|
||||
// Keep the threshold relative to the visible rows below the sticky header.
|
||||
const distanceFromTop = selectedRect.top - scrollerRect.top - getStickyOffset();
|
||||
if (selectedRect && scrollerRect) {
|
||||
const distanceFromTop = selectedRect.top - scrollerRect.top;
|
||||
const hasScrolledOutOfThreshold = distanceFromTop < -8 || distanceFromTop > 50;
|
||||
setLockAutoScroll(hasScrolledOutOfThreshold);
|
||||
}
|
||||
}
|
||||
};
|
||||
const throttledHandleScroll = throttle(handleUserScroll, 1000);
|
||||
|
||||
@@ -111,14 +98,7 @@ export default function CountdownSubscriptions({ subscribedEvents, goToEditMode
|
||||
|
||||
return (
|
||||
<div className='list-container' onWheel={handleScroll} onTouchMove={handleScroll} ref={scrollRef}>
|
||||
{sections.map((section) => {
|
||||
const rows = section.group ? [section.group, ...section.events] : section.events;
|
||||
// the running event anchors the scroll, the group header stays pinned above it
|
||||
const anchorId = section.events.find((event) => getIsLive(event.id, selectedEventId, playback))?.id ?? null;
|
||||
|
||||
return (
|
||||
<div key={section.group?.id ?? rows[0].id} className='sub-section'>
|
||||
{rows.map((event) => {
|
||||
{subscribedEvents.map((event) => {
|
||||
// while a group is live, surface the running event's title as the secondary line
|
||||
const liveTitle = event.isGroup && event.liveEntry ? event.liveEntry.title : undefined;
|
||||
const secondaryData = liveTitle ?? getPropertyValue(event, secondarySource);
|
||||
@@ -127,24 +107,12 @@ export default function CountdownSubscriptions({ subscribedEvents, goToEditMode
|
||||
// a subscribed group is live when any of its children is the selected/running event
|
||||
const isLive = activeEntryId ? getIsLive(activeEntryId, selectedEventId, playback) : false;
|
||||
const isArmed = !isLive && activeEntryId === selectedEventId;
|
||||
// only ever hand the ref to a single row, sharing it would null it out on the next commit
|
||||
const isAnchor = isLive && (anchorId === null || event.id === anchorId);
|
||||
const rowRef = isAnchor ? selectedRef : event.isGroup && anchorId ? stickyHeaderRef : undefined;
|
||||
const countdownEvent = extendEventData(
|
||||
event,
|
||||
currentDay,
|
||||
actualStart,
|
||||
plannedStart,
|
||||
offset,
|
||||
mode,
|
||||
reportData,
|
||||
);
|
||||
const countdownEvent = extendEventData(event, currentDay, actualStart, plannedStart, offset, mode, reportData);
|
||||
const displayTitle = getPropertyValue(event, mainSource ?? 'title');
|
||||
|
||||
return (
|
||||
<div
|
||||
key={event.id}
|
||||
ref={rowRef}
|
||||
ref={isLive ? selectedRef : undefined}
|
||||
className={cx([
|
||||
'sub',
|
||||
isLive && 'sub--live',
|
||||
@@ -168,9 +136,6 @@ export default function CountdownSubscriptions({ subscribedEvents, goToEditMode
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
<div className={cx(['fab-container', !showFab && 'fab-container--hidden'])}>
|
||||
<Button variant='primary' size='xlarge' onClick={goToEditMode}>
|
||||
<IoPencil /> Edit
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { OntimeEntry, OntimeEvent, OntimeGroup, SupportedEntry } from 'ontime-types';
|
||||
|
||||
import { ExtendedEntry } from '../../common/utils/rundownMetadata';
|
||||
import { CountdownTarget, groupSubscriptionTargets, resolveSubscriptionTarget } from './countdown.utils';
|
||||
import { resolveSubscriptionTarget } from './countdown.utils';
|
||||
|
||||
/**
|
||||
* Minimal builders for the extended (metadata enriched) entries the countdown view consumes.
|
||||
@@ -126,89 +126,3 @@ describe('resolveSubscriptionTarget()', () => {
|
||||
expect(result?.liveEntry).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
describe('groupSubscriptionTargets()', () => {
|
||||
/**
|
||||
* Resolves a group the same way the view does, so that the tests exercise the real target shape
|
||||
* (a resolved group carries type Event, so the helper cannot rely on the entry type)
|
||||
*/
|
||||
function resolveGroup(group: ExtendedEntry<OntimeGroup>, flat: ExtendedEntry<OntimeEntry>[]): CountdownTarget {
|
||||
const resolved = resolveSubscriptionTarget(group, flat);
|
||||
if (resolved === null) {
|
||||
throw new Error('test setup: group has no playable children');
|
||||
}
|
||||
return resolved;
|
||||
}
|
||||
|
||||
it('returns no sections for an empty subscription list', () => {
|
||||
expect(groupSubscriptionTargets([])).toEqual([]);
|
||||
});
|
||||
|
||||
it('gives each ungrouped event its own section', () => {
|
||||
const e1 = makeEvent({ id: 'e1' });
|
||||
const e2 = makeEvent({ id: 'e2' });
|
||||
|
||||
expect(groupSubscriptionTargets([e1, e2])).toEqual([
|
||||
{ group: null, events: [e1] },
|
||||
{ group: null, events: [e2] },
|
||||
]);
|
||||
});
|
||||
|
||||
it('absorbs the children of a subscribed group into its section', () => {
|
||||
const group = makeGroup({ id: 'g1' });
|
||||
const c1 = makeEvent({ id: 'c1', parent: 'g1' });
|
||||
const c2 = makeEvent({ id: 'c2', parent: 'g1' });
|
||||
const resolved = resolveGroup(group, [group, c1, c2]);
|
||||
|
||||
expect(groupSubscriptionTargets([resolved, c1, c2])).toEqual([{ group: resolved, events: [c1, c2] }]);
|
||||
});
|
||||
|
||||
it('keeps a subscribed group with no subscribed children as an empty section', () => {
|
||||
const group = makeGroup({ id: 'g1' });
|
||||
const c1 = makeEvent({ id: 'c1', parent: 'g1' });
|
||||
const resolved = resolveGroup(group, [group, c1]);
|
||||
|
||||
expect(groupSubscriptionTargets([resolved])).toEqual([{ group: resolved, events: [] }]);
|
||||
});
|
||||
|
||||
it('does not absorb an event which belongs to a different group', () => {
|
||||
const group1 = makeGroup({ id: 'g1' });
|
||||
const c1 = makeEvent({ id: 'c1', parent: 'g1' });
|
||||
const group2 = makeGroup({ id: 'g2' });
|
||||
const c2 = makeEvent({ id: 'c2', parent: 'g2' });
|
||||
const flat = [group1, c1, group2, c2];
|
||||
const resolved1 = resolveGroup(group1, flat);
|
||||
const resolved2 = resolveGroup(group2, flat);
|
||||
|
||||
expect(groupSubscriptionTargets([resolved1, c1, resolved2, c2])).toEqual([
|
||||
{ group: resolved1, events: [c1] },
|
||||
{ group: resolved2, events: [c2] },
|
||||
]);
|
||||
});
|
||||
|
||||
it('does not absorb an event whose parent group is not subscribed', () => {
|
||||
const group1 = makeGroup({ id: 'g1' });
|
||||
const c1 = makeEvent({ id: 'c1', parent: 'g1' });
|
||||
const group2 = makeGroup({ id: 'g2' });
|
||||
const c2 = makeEvent({ id: 'c2', parent: 'g2' });
|
||||
const resolved1 = resolveGroup(group1, [group1, c1, group2, c2]);
|
||||
|
||||
// only the first group is subscribed, so the second group's child stands alone
|
||||
expect(groupSubscriptionTargets([resolved1, c1, c2])).toEqual([
|
||||
{ group: resolved1, events: [c1] },
|
||||
{ group: null, events: [c2] },
|
||||
]);
|
||||
});
|
||||
|
||||
it('closes a section when an ungrouped event follows a group', () => {
|
||||
const group = makeGroup({ id: 'g1' });
|
||||
const c1 = makeEvent({ id: 'c1', parent: 'g1' });
|
||||
const e1 = makeEvent({ id: 'e1' });
|
||||
const resolved = resolveGroup(group, [group, c1]);
|
||||
|
||||
expect(groupSubscriptionTargets([resolved, c1, e1])).toEqual([
|
||||
{ group: resolved, events: [c1] },
|
||||
{ group: null, events: [e1] },
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -252,42 +252,6 @@ export function resolveSubscriptionTarget(
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* A subscribed group along with the subscribed events which belong to it.
|
||||
* Events without a subscribed parent group form their own section with no group.
|
||||
*/
|
||||
export type CountdownSection = {
|
||||
group: CountdownTarget | null;
|
||||
events: CountdownTarget[];
|
||||
};
|
||||
|
||||
/**
|
||||
* Folds the flat, rundown ordered subscription targets into sections.
|
||||
* A group opens a section which absorbs the following targets that declare it as parent,
|
||||
* which allows the group to be rendered as a sticky header for its own events.
|
||||
*/
|
||||
export function groupSubscriptionTargets(targets: CountdownTarget[]): CountdownSection[] {
|
||||
const sections: CountdownSection[] = [];
|
||||
|
||||
for (const target of targets) {
|
||||
// resolveSubscriptionTarget spreads the first child, so we cannot rely on the entry type here
|
||||
if (target.isGroup) {
|
||||
sections.push({ group: target, events: [] });
|
||||
continue;
|
||||
}
|
||||
|
||||
const previousSection = sections.at(-1);
|
||||
if (previousSection?.group?.id === target.parent) {
|
||||
previousSection.events.push(target);
|
||||
continue;
|
||||
}
|
||||
|
||||
sections.push({ group: null, events: [target] });
|
||||
}
|
||||
|
||||
return sections;
|
||||
}
|
||||
|
||||
export function extendEventData(
|
||||
event: CountdownTarget,
|
||||
currentDay: number,
|
||||
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
.timerOverrideCell {
|
||||
display: grid;
|
||||
grid-template-columns: minmax(0, 1fr) 1.5rem;
|
||||
align-items: center;
|
||||
gap: 0.25rem;
|
||||
}
|
||||
|
||||
.timerOverrideIndicator {
|
||||
display: grid;
|
||||
place-items: center;
|
||||
color: $active-indicator;
|
||||
font-size: 1rem;
|
||||
}
|
||||
+42
-9
@@ -1,8 +1,18 @@
|
||||
import { CustomFields, TimeStrategy, URLPreset, isOntimeDelay, isOntimeEvent } from 'ontime-types';
|
||||
import {
|
||||
CustomFields,
|
||||
TimeStrategy,
|
||||
TimerType,
|
||||
URLPreset,
|
||||
isOntimeDelay,
|
||||
isOntimeEvent,
|
||||
isOntimeGroup,
|
||||
} from 'ontime-types';
|
||||
import { millisToString } from 'ontime-utils';
|
||||
import { useCallback } from 'react';
|
||||
import { IoTimerOutline } from 'react-icons/io5';
|
||||
|
||||
import DelayIndicator from '../../../../common/components/delay-indicator/DelayIndicator';
|
||||
import Tooltip from '../../../../common/components/tooltip/Tooltip';
|
||||
import type { ExtendedEntry } from '../../../../common/utils/rundownMetadata';
|
||||
import { formatDuration, formatTime } from '../../../../common/utils/time';
|
||||
import { AppMode } from '../../../../ontimeConfig';
|
||||
@@ -17,6 +27,8 @@ import MutedText from './MutedText';
|
||||
import SingleLineCell from './SingleLineCell';
|
||||
import TimeInput from './TimeInput';
|
||||
|
||||
import style from './cuesheetColsFactory.module.scss';
|
||||
|
||||
function getColumnLabel(column: CuesheetCellContext['column']): string {
|
||||
return typeof column.columnDef.header === 'string' ? column.columnDef.header : column.id;
|
||||
}
|
||||
@@ -105,10 +117,10 @@ function MakeDuration({ getValue, row, table, column }: CuesheetCellContext) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const { hideTableSeconds } = table.options.meta.options;
|
||||
const event = row.original;
|
||||
if (!isOntimeEvent(event)) {
|
||||
const duration = getValue() as number;
|
||||
return <MutedText numeric>{formatDuration(duration, false)}</MutedText>;
|
||||
return <MutedText numeric>{formatDuration(getValue() as number, hideTableSeconds)}</MutedText>;
|
||||
}
|
||||
|
||||
const { handleUpdateTimer } = table.options.meta;
|
||||
@@ -117,7 +129,7 @@ function MakeDuration({ getValue, row, table, column }: CuesheetCellContext) {
|
||||
|
||||
const duration = getValue() as number;
|
||||
const isDurationLocked = event.timeStrategy === TimeStrategy.LockDuration;
|
||||
const formattedDuration = formatDuration(duration, false);
|
||||
const formattedDuration = formatDuration(duration, hideTableSeconds);
|
||||
|
||||
const canWrite = column.columnDef.meta?.canWrite;
|
||||
if (!canWrite) {
|
||||
@@ -193,17 +205,38 @@ function MakeSingleLineField({ row, column, table }: CuesheetCellContext) {
|
||||
}
|
||||
|
||||
const canWrite = column.columnDef.meta?.canWrite;
|
||||
if (!canWrite) {
|
||||
return <GhostedText>{initialValue}</GhostedText>;
|
||||
}
|
||||
|
||||
return (
|
||||
const content = canWrite ? (
|
||||
<SingleLineCell
|
||||
initialValue={initialValue as string}
|
||||
fieldId={column.id}
|
||||
fieldLabel={getColumnLabel(column)}
|
||||
handleUpdate={update}
|
||||
/>
|
||||
) : (
|
||||
<GhostedText>{initialValue}</GhostedText>
|
||||
);
|
||||
|
||||
if (column.id !== 'title') {
|
||||
return content;
|
||||
}
|
||||
|
||||
const isGroupOverride = isOntimeGroup(row.original) && row.original.useGroupTimer;
|
||||
const isEventOverride = isOntimeEvent(row.original) && row.original.groupUsesTimer;
|
||||
if (!isGroupOverride && !isEventOverride) {
|
||||
return content;
|
||||
}
|
||||
|
||||
const timerType = isOntimeGroup(row.original) ? row.original.timerType : row.original.groupTimerType;
|
||||
const direction = timerType === TimerType.CountUp ? 'count up' : 'count down';
|
||||
const tooltip = isGroupOverride ? `Group timer (${direction})` : `Timer display controlled by group (${direction})`;
|
||||
|
||||
return (
|
||||
<div className={style.timerOverrideCell}>
|
||||
{content}
|
||||
<Tooltip text={tooltip} render={<span className={style.timerOverrideIndicator} />}>
|
||||
<IoTimerOutline />
|
||||
</Tooltip>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -35,6 +35,14 @@
|
||||
width: 100%;
|
||||
overflow: hidden;
|
||||
|
||||
.timer-source {
|
||||
color: $viewer-label-color;
|
||||
font-size: 0.75rem;
|
||||
font-weight: 600;
|
||||
text-align: center;
|
||||
text-transform: uppercase;
|
||||
}
|
||||
|
||||
.timer {
|
||||
opacity: 1;
|
||||
font-family: $viewer-font-family;
|
||||
|
||||
@@ -7,6 +7,7 @@ import { cx } from '../../../common/utils/styleUtils';
|
||||
import { getFormattedTimer, getTimerByType } from '../../common/viewUtils';
|
||||
import {
|
||||
getEstimatedFontSize,
|
||||
getEventTimerSecondary,
|
||||
getIsPlaying,
|
||||
getSecondaryDisplay,
|
||||
getShowMessage,
|
||||
@@ -23,7 +24,18 @@ interface PipTimerProps {
|
||||
}
|
||||
|
||||
export function PipTimer({ viewSettings }: PipTimerProps) {
|
||||
const { eventNow, message, time, clock, timerTypeNow, countToEndNow, auxTimer } = useTimerSocket();
|
||||
const {
|
||||
eventNow,
|
||||
message,
|
||||
time,
|
||||
eventTimer,
|
||||
clock,
|
||||
timerTypeNow,
|
||||
eventTimerType,
|
||||
countToEndNow,
|
||||
usesGroupTimer,
|
||||
auxTimer,
|
||||
} = useTimerSocket();
|
||||
|
||||
// gather modifiers
|
||||
const showOverlay = getShowMessage(message.timer);
|
||||
@@ -59,7 +71,9 @@ export function PipTimer({ viewSettings }: PipTimerProps) {
|
||||
return null;
|
||||
})();
|
||||
|
||||
const secondaryContent = getSecondaryDisplay(message, currentAux, 'min', false, true, false);
|
||||
const secondaryContent = usesGroupTimer
|
||||
? getEventTimerSecondary(eventTimer, eventTimerType, clock, 'min', false, true)
|
||||
: getSecondaryDisplay(message, currentAux, 'min', false, true, false);
|
||||
|
||||
// gather presentation styles
|
||||
const resolvedTimerColour = getTimerColour(viewSettings, undefined, showWarning, showDanger);
|
||||
@@ -77,6 +91,7 @@ export function PipTimer({ viewSettings }: PipTimerProps) {
|
||||
</div>
|
||||
|
||||
<div className='timer-container'>
|
||||
{usesGroupTimer && <div className='timer-source'>Group timer</div>}
|
||||
<div
|
||||
className={cx(['timer', !isPlaying && 'timer--paused', showFinished && 'timer--finished'])}
|
||||
style={{ fontSize: `${timerFontSize}vw` }}
|
||||
@@ -96,11 +111,11 @@ export function PipTimer({ viewSettings }: PipTimerProps) {
|
||||
className={cx(['progress-container', !isPlaying && 'progress-container--paused'])}
|
||||
now={time.current}
|
||||
complete={totalTime}
|
||||
eventId={eventNow?.id}
|
||||
eventId={usesGroupTimer ? undefined : eventNow?.id}
|
||||
normalColor={viewSettings.normalColor}
|
||||
warning={eventNow?.timeWarning}
|
||||
warning={usesGroupTimer ? undefined : eventNow?.timeWarning}
|
||||
warningColor={viewSettings.warningColor}
|
||||
danger={eventNow?.timeDanger}
|
||||
danger={usesGroupTimer ? undefined : eventNow?.timeDanger}
|
||||
dangerColor={viewSettings.dangerColor}
|
||||
hideOvertime={!showFinished}
|
||||
/>
|
||||
|
||||
@@ -89,6 +89,14 @@
|
||||
width: 100%;
|
||||
overflow: hidden;
|
||||
|
||||
.timer-source {
|
||||
color: var(--label-color-override, $viewer-label-color);
|
||||
font-size: $timer-label-size;
|
||||
font-weight: 600;
|
||||
text-align: center;
|
||||
text-transform: uppercase;
|
||||
}
|
||||
|
||||
.end-message {
|
||||
text-align: center;
|
||||
font-size: 11.5vw;
|
||||
|
||||
@@ -22,6 +22,7 @@ import { getTimerOptions, useTimerOptions } from './timer.options';
|
||||
import {
|
||||
getCardData,
|
||||
getEstimatedFontSize,
|
||||
getEventTimerSecondary,
|
||||
getIsPlaying,
|
||||
getSecondaryDisplay,
|
||||
getShowClock,
|
||||
@@ -52,7 +53,19 @@ export default function TimerLoader() {
|
||||
}
|
||||
|
||||
function Timer({ customFields, projectData, isMirrored, settings, viewSettings, entries }: TimerData) {
|
||||
const { eventNext, eventNow, message, time, clock, timerTypeNow, countToEndNow, auxTimer } = useTimerSocket();
|
||||
const {
|
||||
eventNext,
|
||||
eventNow,
|
||||
message,
|
||||
time,
|
||||
eventTimer,
|
||||
clock,
|
||||
timerTypeNow,
|
||||
eventTimerType,
|
||||
countToEndNow,
|
||||
usesGroupTimer,
|
||||
auxTimer,
|
||||
} = useTimerSocket();
|
||||
const {
|
||||
hideClock,
|
||||
hideCards,
|
||||
@@ -78,7 +91,7 @@ function Timer({ customFields, projectData, isMirrored, settings, viewSettings,
|
||||
const { getLocalizedString } = useTranslation();
|
||||
const localisedMinutes = getLocalizedString('common.minutes');
|
||||
|
||||
const showSoundPrompt = useTimerSound(time.phase, endSound);
|
||||
const showSoundPrompt = useTimerSound(eventTimer.phase, endSound);
|
||||
|
||||
// gather modifiers
|
||||
const viewTimerType = timerType ?? timerTypeNow;
|
||||
@@ -128,14 +141,18 @@ function Timer({ customFields, projectData, isMirrored, settings, viewSettings,
|
||||
return null;
|
||||
})();
|
||||
|
||||
const secondaryContent = getSecondaryDisplay(
|
||||
message,
|
||||
currentAux,
|
||||
const secondaryContent =
|
||||
usesGroupTimer && !hideSecondary
|
||||
? getEventTimerSecondary(
|
||||
eventTimer,
|
||||
eventTimerType,
|
||||
clock,
|
||||
localisedMinutes,
|
||||
hideTimerSeconds,
|
||||
removeLeadingZeros,
|
||||
hideSecondary,
|
||||
);
|
||||
timeformat,
|
||||
)
|
||||
: getSecondaryDisplay(message, currentAux, localisedMinutes, hideTimerSeconds, removeLeadingZeros, hideSecondary);
|
||||
|
||||
// gather presentation styles
|
||||
const resolvedTimerColour = getTimerColour(viewSettings, timerColour, showWarning, showDanger);
|
||||
@@ -176,6 +193,7 @@ function Timer({ customFields, projectData, isMirrored, settings, viewSettings,
|
||||
{showClock && <TimerAutoTickingClock clockFormat={timeformat} />}
|
||||
|
||||
<div className={cx(['timer-container', message.timer.blink && !showOverlay && 'blink'])}>
|
||||
{usesGroupTimer && <div className='timer-source'>Group timer</div>}
|
||||
{showEndMessage ? (
|
||||
<FitText mode='multi' min={64} max={256} className='end-message'>
|
||||
{freezeMessage}
|
||||
@@ -202,11 +220,11 @@ function Timer({ customFields, projectData, isMirrored, settings, viewSettings,
|
||||
className={cx(['progress-container', !isPlaying && 'progress-container--paused'])}
|
||||
now={time.current}
|
||||
complete={totalTime}
|
||||
eventId={eventNow?.id}
|
||||
eventId={usesGroupTimer ? undefined : eventNow?.id}
|
||||
normalColor={viewSettings.normalColor}
|
||||
warning={eventNow?.timeWarning}
|
||||
warning={usesGroupTimer ? undefined : eventNow?.timeWarning}
|
||||
warningColor={viewSettings.warningColor}
|
||||
danger={eventNow?.timeDanger}
|
||||
danger={usesGroupTimer ? undefined : eventNow?.timeDanger}
|
||||
dangerColor={viewSettings.dangerColor}
|
||||
hideOvertime={!showFinished}
|
||||
/>
|
||||
|
||||
@@ -1,6 +1,32 @@
|
||||
import { TimerPhase } from 'ontime-types';
|
||||
import { TimerPhase, TimerType } from 'ontime-types';
|
||||
|
||||
import { shouldPlayEndSound } from '../timer.utils';
|
||||
import { getEventTimerSecondary, shouldPlayEndSound } from '../timer.utils';
|
||||
|
||||
describe('getEventTimerSecondary()', () => {
|
||||
it('formats the event countdown as a labelled secondary value', () => {
|
||||
expect(
|
||||
getEventTimerSecondary({ current: 65_000, elapsed: 5_000 }, TimerType.CountDown, 0, 'min', false, false),
|
||||
).toBe('Event timer 00:01:05');
|
||||
});
|
||||
|
||||
it('preserves the event count-up display', () => {
|
||||
expect(getEventTimerSecondary({ current: 55_000, elapsed: 5_000 }, TimerType.CountUp, 0, 'min', false, false)).toBe(
|
||||
'Event timer 00:00:05',
|
||||
);
|
||||
});
|
||||
|
||||
it('falls back to remaining time when the event timer is hidden', () => {
|
||||
expect(getEventTimerSecondary({ current: 5_000, elapsed: 55_000 }, TimerType.None, 0, 'min', false, false)).toBe(
|
||||
'Event timer 00:00:05',
|
||||
);
|
||||
});
|
||||
|
||||
it('shows event progress instead of wall-clock time for clock events', () => {
|
||||
expect(
|
||||
getEventTimerSecondary({ current: 5_000, elapsed: 55_000 }, TimerType.Clock, 12_000, 'min', false, false),
|
||||
).toBe('Event timer 00:00:05');
|
||||
});
|
||||
});
|
||||
|
||||
describe('shouldPlayEndSound()', () => {
|
||||
test.each([TimerPhase.Default, TimerPhase.Warning, TimerPhase.Danger])(
|
||||
|
||||
@@ -6,11 +6,12 @@ import {
|
||||
RundownEntries,
|
||||
TimerMessage,
|
||||
TimerPhase,
|
||||
TimerState,
|
||||
TimerType,
|
||||
} from 'ontime-types';
|
||||
import { isPlaybackActive } from 'ontime-utils';
|
||||
|
||||
import { getFormattedTimer, getPropertyValue } from '../common/viewUtils';
|
||||
import { getFormattedTimer, getPropertyValue, getTimerByType } from '../common/viewUtils';
|
||||
|
||||
/**
|
||||
* Whether a message should be shown
|
||||
@@ -144,6 +145,25 @@ export function getSecondaryDisplay(
|
||||
return;
|
||||
}
|
||||
|
||||
export function getEventTimerSecondary(
|
||||
timer: Pick<TimerState, 'current' | 'elapsed'>,
|
||||
timerType: TimerType,
|
||||
clock: number,
|
||||
localisedMinutes: string,
|
||||
removeSeconds: boolean,
|
||||
removeLeadingZero: boolean,
|
||||
clockFormat?: string | null,
|
||||
): string {
|
||||
const effectiveType = timerType === TimerType.CountUp ? TimerType.CountUp : TimerType.CountDown;
|
||||
const value = getTimerByType(false, effectiveType, clock, timer);
|
||||
const display = getFormattedTimer(value, effectiveType, localisedMinutes, {
|
||||
removeSeconds,
|
||||
removeLeadingZero,
|
||||
clockFormat,
|
||||
});
|
||||
return `Event timer ${display}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* What should we be showing in the cards?
|
||||
*/
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
http-equiv="Content-Security-Policy"
|
||||
content="default-src 'self'; style-src 'unsafe-inline'; script-src 'self'"
|
||||
/>
|
||||
<title>Ontime</title>
|
||||
<title>ontime</title>
|
||||
<style>
|
||||
body {
|
||||
-webkit-user-select: none;
|
||||
@@ -92,7 +92,7 @@
|
||||
<body>
|
||||
<div class="container">
|
||||
<img src="../assets/logo.png" />
|
||||
<h1>Ontime · event timers</h1>
|
||||
<h1>ontime · event timers</h1>
|
||||
<div class="lds-ellipsis">
|
||||
<div></div>
|
||||
<div></div>
|
||||
|
||||
@@ -417,7 +417,7 @@ export function migrateRundown(
|
||||
timeEnd: null,
|
||||
duration: 0,
|
||||
isFirstLinked: false,
|
||||
});
|
||||
} as unknown as OntimeEntry);
|
||||
} else if (entry.type === 'delay') {
|
||||
append({ id: entry.id, type: SupportedEntry.Delay, duration: entry.duration, parent });
|
||||
}
|
||||
|
||||
@@ -1,164 +0,0 @@
|
||||
import type { PlayableEvent } from 'ontime-types';
|
||||
import { RefetchKey, TimerLifeCycle } from 'ontime-types';
|
||||
import { MILLIS_PER_MINUTE } from 'ontime-utils';
|
||||
import { vi } from 'vitest';
|
||||
|
||||
import { sendRefetch } from '../../../adapters/WebsocketAdapter.js';
|
||||
import { makeRuntimeStateData } from '../../../stores/__mocks__/runtimeState.mocks.js';
|
||||
import { makeOntimeEvent, makeRundown } from '../../rundown/__mocks__/rundown.mocks.js';
|
||||
import { clear, generate, generateReport, triggerReportEntry } from '../report.service.js';
|
||||
|
||||
vi.mock('../../../adapters/WebsocketAdapter.js', () => ({ sendRefetch: vi.fn() }));
|
||||
|
||||
const eventA = makeOntimeEvent({
|
||||
id: 'event-a',
|
||||
dayOffset: 0,
|
||||
timeStart: 0,
|
||||
timeEnd: MILLIS_PER_MINUTE,
|
||||
duration: MILLIS_PER_MINUTE,
|
||||
}) as PlayableEvent;
|
||||
const eventB = makeOntimeEvent({
|
||||
id: 'event-b',
|
||||
dayOffset: 0,
|
||||
timeStart: MILLIS_PER_MINUTE,
|
||||
timeEnd: 2 * MILLIS_PER_MINUTE,
|
||||
duration: MILLIS_PER_MINUTE,
|
||||
}) as PlayableEvent;
|
||||
|
||||
beforeEach(() => {
|
||||
clear();
|
||||
vi.clearAllMocks();
|
||||
});
|
||||
|
||||
it('records lifecycle times while keeping the schedule captured at start', () => {
|
||||
const start = makeRuntimeStateData({ eventNow: eventA, timer: { startedAt: 500 }, _startEpoch: 1 });
|
||||
triggerReportEntry(TimerLifeCycle.onStart, start);
|
||||
|
||||
const edited = { ...eventA, timeStart: 999, duration: 999 } as PlayableEvent;
|
||||
const stop = makeRuntimeStateData({ eventNow: edited, clock: 2 * MILLIS_PER_MINUTE, rundown: { currentDay: 1 } });
|
||||
triggerReportEntry(TimerLifeCycle.onStop, stop);
|
||||
|
||||
expect(generate()[eventA.id]).toEqual({
|
||||
startedAt: 500,
|
||||
startedAtDay: 0,
|
||||
endedAt: 2 * MILLIS_PER_MINUTE,
|
||||
endedAtDay: 1,
|
||||
scheduledStart: eventA.timeStart,
|
||||
scheduledDay: eventA.dayOffset,
|
||||
scheduledDuration: eventA.duration,
|
||||
});
|
||||
expect(sendRefetch).toHaveBeenCalledTimes(2);
|
||||
expect(sendRefetch).toHaveBeenLastCalledWith(RefetchKey.Report);
|
||||
});
|
||||
|
||||
it('falls back to the current event when a stop arrives without a start', () => {
|
||||
const stop = makeRuntimeStateData({ eventNow: eventA, clock: MILLIS_PER_MINUTE });
|
||||
triggerReportEntry(TimerLifeCycle.onStop, stop);
|
||||
|
||||
expect(generate()[eventA.id]).toMatchObject({
|
||||
startedAt: null,
|
||||
endedAt: MILLIS_PER_MINUTE,
|
||||
scheduledDuration: eventA.duration,
|
||||
});
|
||||
});
|
||||
|
||||
it('captures the rundown plan when a stop is the first report entry', () => {
|
||||
const rundown = makeRundown({
|
||||
id: 'run-1',
|
||||
title: 'Stopped without start',
|
||||
order: [eventA.id],
|
||||
entries: { [eventA.id]: eventA },
|
||||
});
|
||||
const stop = makeRuntimeStateData({
|
||||
eventNow: eventA,
|
||||
clock: MILLIS_PER_MINUTE,
|
||||
rundown: { plannedStart: 0, plannedEnd: MILLIS_PER_MINUTE },
|
||||
});
|
||||
|
||||
triggerReportEntry(TimerLifeCycle.onStop, stop, rundown);
|
||||
|
||||
expect(generateReport()).toMatchObject({
|
||||
eventReports: { [eventA.id]: { endedAt: MILLIS_PER_MINUTE } },
|
||||
rundown: { id: rundown.id, title: rundown.title },
|
||||
});
|
||||
});
|
||||
|
||||
it('accumulates entries until the report is explicitly cleared', () => {
|
||||
const firstRun = makeRuntimeStateData({ eventNow: eventA, timer: { startedAt: 0 }, _startEpoch: 1 });
|
||||
triggerReportEntry(TimerLifeCycle.onStart, firstRun);
|
||||
triggerReportEntry(TimerLifeCycle.onStart, { ...firstRun, eventNow: eventB, _startEpoch: 2 });
|
||||
|
||||
expect(Object.keys(generate())).toEqual([eventA.id, eventB.id]);
|
||||
});
|
||||
|
||||
it('returns the report with the rundown plan captured at its first event', () => {
|
||||
const rundown = makeRundown({
|
||||
id: 'run-1',
|
||||
title: 'Original title',
|
||||
order: [eventA.id, eventB.id],
|
||||
entries: { [eventA.id]: eventA, [eventB.id]: eventB },
|
||||
});
|
||||
const start = makeRuntimeStateData({
|
||||
eventNow: eventA,
|
||||
timer: { startedAt: 500 },
|
||||
_startEpoch: 1,
|
||||
rundown: { plannedStart: 0, plannedEnd: 2 * MILLIS_PER_MINUTE },
|
||||
});
|
||||
triggerReportEntry(TimerLifeCycle.onStart, start, rundown);
|
||||
triggerReportEntry(TimerLifeCycle.onStop, { ...start, clock: MILLIS_PER_MINUTE });
|
||||
rundown.title = 'Edited later';
|
||||
|
||||
expect(generateReport()).toMatchObject({
|
||||
rundown: { id: 'run-1', title: 'Original title' },
|
||||
eventReports: { [eventA.id]: { scheduledDuration: MILLIS_PER_MINUTE } },
|
||||
show: {
|
||||
plannedStart: 0,
|
||||
plannedEnd: 2 * MILLIS_PER_MINUTE,
|
||||
plannedDuration: 2 * MILLIS_PER_MINUTE,
|
||||
actualStart: 500,
|
||||
actualEnd: MILLIS_PER_MINUTE,
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it('clears the retained report and rundown snapshot together', () => {
|
||||
const rundown = makeRundown({ order: [eventA.id], entries: { [eventA.id]: eventA } });
|
||||
const state = makeRuntimeStateData({ eventNow: eventA, timer: { startedAt: 0 }, _startEpoch: 1 });
|
||||
triggerReportEntry(TimerLifeCycle.onStart, state, rundown);
|
||||
vi.clearAllMocks();
|
||||
clear();
|
||||
|
||||
expect(generateReport()).toMatchObject({ eventReports: {}, rundown: null });
|
||||
expect(sendRefetch).toHaveBeenCalledOnce();
|
||||
expect(sendRefetch).toHaveBeenCalledWith(RefetchKey.Report);
|
||||
});
|
||||
|
||||
it('captures a new plan after removing the final event by id', () => {
|
||||
const firstRundown = makeRundown({
|
||||
id: 'run-1',
|
||||
title: 'First run',
|
||||
order: [eventA.id],
|
||||
entries: { [eventA.id]: eventA },
|
||||
});
|
||||
const secondRundown = makeRundown({
|
||||
id: 'run-2',
|
||||
title: 'Second run',
|
||||
order: [eventB.id],
|
||||
entries: { [eventB.id]: eventB },
|
||||
});
|
||||
const firstStart = makeRuntimeStateData({ eventNow: eventA, timer: { startedAt: 0 }, _startEpoch: 1 });
|
||||
const secondStart = makeRuntimeStateData({
|
||||
eventNow: eventB,
|
||||
timer: { startedAt: MILLIS_PER_MINUTE },
|
||||
_startEpoch: 2,
|
||||
});
|
||||
|
||||
triggerReportEntry(TimerLifeCycle.onStart, firstStart, firstRundown);
|
||||
clear(eventA.id);
|
||||
triggerReportEntry(TimerLifeCycle.onStart, secondStart, secondRundown);
|
||||
|
||||
expect(generateReport()).toMatchObject({
|
||||
eventReports: { [eventB.id]: { startedAt: MILLIS_PER_MINUTE } },
|
||||
rundown: { id: secondRundown.id, title: secondRundown.title },
|
||||
});
|
||||
});
|
||||
@@ -1,72 +0,0 @@
|
||||
import type { OntimeEventReport, OntimeReport, PlayableEvent } from 'ontime-types';
|
||||
import { dayInMs, MILLIS_PER_HOUR, MILLIS_PER_MINUTE } from 'ontime-utils';
|
||||
|
||||
import { makeOntimeEvent, makeRundown } from '../../rundown/__mocks__/rundown.mocks.js';
|
||||
import { getActualShowTimes, getPlannedShowDuration } from '../report.utils.js';
|
||||
|
||||
function makeReport(patch: Partial<OntimeEventReport>): OntimeEventReport {
|
||||
return {
|
||||
startedAt: 0,
|
||||
startedAtDay: 0,
|
||||
endedAt: 0,
|
||||
endedAtDay: 0,
|
||||
scheduledStart: 0,
|
||||
scheduledDay: 0,
|
||||
scheduledDuration: 0,
|
||||
...patch,
|
||||
};
|
||||
}
|
||||
|
||||
describe('getActualShowTimes()', () => {
|
||||
it('preserves long gaps within the same day', () => {
|
||||
const report: OntimeReport = {
|
||||
morning: makeReport({ startedAt: 6 * MILLIS_PER_HOUR, endedAt: 7 * MILLIS_PER_HOUR }),
|
||||
evening: makeReport({ startedAt: 20 * MILLIS_PER_HOUR, endedAt: 21 * MILLIS_PER_HOUR }),
|
||||
};
|
||||
|
||||
expect(getActualShowTimes(report)).toEqual({
|
||||
actualStart: 6 * MILLIS_PER_HOUR,
|
||||
actualEnd: 21 * MILLIS_PER_HOUR,
|
||||
actualDuration: 15 * MILLIS_PER_HOUR,
|
||||
});
|
||||
});
|
||||
|
||||
it('orders events by their captured day across midnight', () => {
|
||||
const report: OntimeReport = {
|
||||
beforeMidnight: makeReport({
|
||||
startedAt: dayInMs - 10 * MILLIS_PER_MINUTE,
|
||||
endedAt: dayInMs - 5 * MILLIS_PER_MINUTE,
|
||||
}),
|
||||
afterMidnight: makeReport({
|
||||
startedAt: 0,
|
||||
startedAtDay: 1,
|
||||
endedAt: 10 * MILLIS_PER_MINUTE,
|
||||
endedAtDay: 1,
|
||||
}),
|
||||
};
|
||||
|
||||
expect(getActualShowTimes(report).actualDuration).toBe(20 * MILLIS_PER_MINUTE);
|
||||
});
|
||||
});
|
||||
|
||||
it('derives planned duration from playable, non-skipped events', () => {
|
||||
const first = makeOntimeEvent({
|
||||
id: 'first',
|
||||
dayOffset: 0,
|
||||
timeStart: 23 * MILLIS_PER_HOUR,
|
||||
duration: MILLIS_PER_HOUR,
|
||||
}) as PlayableEvent;
|
||||
const last = makeOntimeEvent({
|
||||
id: 'last',
|
||||
dayOffset: 1,
|
||||
timeStart: MILLIS_PER_HOUR,
|
||||
duration: MILLIS_PER_HOUR,
|
||||
}) as PlayableEvent;
|
||||
const skipped = makeOntimeEvent({ id: 'skipped', dayOffset: 2, timeStart: 0, duration: MILLIS_PER_HOUR, skip: true });
|
||||
const rundown = makeRundown({
|
||||
order: [first.id, last.id, skipped.id],
|
||||
entries: { [first.id]: first, [last.id]: last, [skipped.id]: skipped },
|
||||
});
|
||||
|
||||
expect(getPlannedShowDuration(rundown)).toBe(3 * MILLIS_PER_HOUR);
|
||||
});
|
||||
@@ -7,7 +7,7 @@ import * as report from './report.service.js';
|
||||
export const router: Router = express.Router();
|
||||
|
||||
router.get('/', (_req: Request, res: Response) => {
|
||||
res.status(200).json(report.generateReport());
|
||||
res.status(200).json(report.generate());
|
||||
});
|
||||
|
||||
router.delete('/all', (_req: Request, res: Response) => {
|
||||
|
||||
@@ -1,28 +1,12 @@
|
||||
import type { OntimeEventReport, OntimeReport, PlayableEvent, ReportData, Rundown, ShowReport } from 'ontime-types';
|
||||
import { RefetchKey, TimerLifeCycle } from 'ontime-types';
|
||||
import type { DeepReadonly } from 'ts-essentials';
|
||||
import { OntimeEventReport, OntimeReport, RefetchKey, TimerLifeCycle } from 'ontime-types';
|
||||
import { DeepReadonly } from 'ts-essentials';
|
||||
|
||||
import { sendRefetch } from '../../adapters/WebsocketAdapter.js';
|
||||
import type { RuntimeState } from '../../stores/runtimeState.js';
|
||||
import { getCurrentRundown } from '../rundown/rundown.dao.js';
|
||||
import { getActualShowTimes, getPlannedShowDuration } from './report.utils.js';
|
||||
import { RuntimeState } from '../../stores/runtimeState.js';
|
||||
|
||||
const report = new Map<string, OntimeEventReport>();
|
||||
|
||||
let formattedReport: OntimeReport | null = null;
|
||||
const emptyPlannedTimes: Pick<ShowReport, 'plannedStart' | 'plannedEnd' | 'plannedDuration'> = {
|
||||
plannedStart: null,
|
||||
plannedEnd: null,
|
||||
plannedDuration: null,
|
||||
};
|
||||
|
||||
/**
|
||||
* The plan the show was measured against, taken when it starts.
|
||||
* Snapshotted for the same reason the per event schedule is: editing the
|
||||
* rundown afterwards must not move the target a past show was judged by.
|
||||
*/
|
||||
let plannedTimes = emptyPlannedTimes;
|
||||
let rundownSnapshot: Rundown | null = null;
|
||||
|
||||
/**
|
||||
* generates a full report
|
||||
@@ -43,14 +27,9 @@ export function clear(id?: string) {
|
||||
formattedReport = null;
|
||||
if (id) {
|
||||
report.delete(id);
|
||||
if (report.size === 0) resetReportPlan();
|
||||
} else {
|
||||
// A full clear makes the next event start a new report instead of resuming this run.
|
||||
report.clear();
|
||||
resetReportPlan();
|
||||
}
|
||||
|
||||
sendRefetch(RefetchKey.Report);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -62,7 +41,6 @@ export function clear(id?: string) {
|
||||
export function triggerReportEntry(
|
||||
cycle: TimerLifeCycle.onStart | TimerLifeCycle.onStop,
|
||||
state: DeepReadonly<RuntimeState>,
|
||||
rundown: Readonly<Rundown> = getCurrentRundown(),
|
||||
) {
|
||||
if (!state.eventNow?.id) {
|
||||
return;
|
||||
@@ -71,80 +49,15 @@ export function triggerReportEntry(
|
||||
const eventId = state.eventNow.id;
|
||||
|
||||
if (cycle === TimerLifeCycle.onStart) {
|
||||
captureReportPlan(state, rundown);
|
||||
|
||||
report.set(eventId, {
|
||||
...getScheduleSnapshot(state.eventNow),
|
||||
startedAt: state.timer.startedAt,
|
||||
startedAtDay: state.rundown.currentDay ?? state.eventNow.dayOffset,
|
||||
endedAt: null,
|
||||
endedAtDay: null,
|
||||
});
|
||||
report.set(eventId, { startedAt: state.timer.startedAt, endedAt: null });
|
||||
formattedReport = null;
|
||||
sendRefetch(RefetchKey.Report);
|
||||
return;
|
||||
}
|
||||
|
||||
if (cycle === TimerLifeCycle.onStop) {
|
||||
captureReportPlan(state, rundown);
|
||||
const previous = report.get(eventId);
|
||||
const schedule = previous ?? getScheduleSnapshot(state.eventNow);
|
||||
report.set(eventId, {
|
||||
startedAt: previous?.startedAt ?? null,
|
||||
startedAtDay: previous?.startedAtDay ?? null,
|
||||
endedAt: state.clock,
|
||||
endedAtDay: state.rundown.currentDay ?? state.eventNow.dayOffset,
|
||||
scheduledStart: schedule.scheduledStart,
|
||||
scheduledDay: schedule.scheduledDay,
|
||||
scheduledDuration: schedule.scheduledDuration,
|
||||
});
|
||||
const startedAt = report.get(eventId)?.startedAt ?? null;
|
||||
report.set(eventId, { startedAt, endedAt: state.clock });
|
||||
formattedReport = null;
|
||||
sendRefetch(RefetchKey.Report);
|
||||
}
|
||||
}
|
||||
|
||||
function getScheduleSnapshot(
|
||||
event: Pick<PlayableEvent, 'timeStart' | 'dayOffset' | 'duration'>,
|
||||
): Pick<OntimeEventReport, 'scheduledStart' | 'scheduledDay' | 'scheduledDuration'> {
|
||||
return {
|
||||
scheduledStart: event.timeStart,
|
||||
scheduledDay: event.dayOffset,
|
||||
scheduledDuration: event.duration,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Captures the plan once, when the first event in the report is recorded.
|
||||
*/
|
||||
function captureReportPlan(state: DeepReadonly<RuntimeState>, rundown: Readonly<Rundown>) {
|
||||
if (rundownSnapshot !== null) return;
|
||||
|
||||
rundownSnapshot = structuredClone(rundown);
|
||||
plannedTimes = {
|
||||
plannedStart: state.rundown.plannedStart,
|
||||
plannedEnd: state.rundown.plannedEnd,
|
||||
plannedDuration: getPlannedShowDuration(rundownSnapshot),
|
||||
};
|
||||
}
|
||||
|
||||
function resetReportPlan() {
|
||||
plannedTimes = emptyPlannedTimes;
|
||||
rundownSnapshot = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Show level times for the report.
|
||||
* Planned times are the ones captured when the show started, actual times are
|
||||
* derived from the events that ran.
|
||||
*/
|
||||
function generateShowReport(): ShowReport {
|
||||
return { ...plannedTimes, ...getActualShowTimes(generate()) };
|
||||
}
|
||||
|
||||
export function generateReport(): ReportData {
|
||||
return {
|
||||
eventReports: generate(),
|
||||
rundown: rundownSnapshot,
|
||||
show: generateShowReport(),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,52 +0,0 @@
|
||||
import type { OntimeReport, Rundown, ShowReport } from 'ontime-types';
|
||||
import { isOntimeEvent } from 'ontime-types';
|
||||
import { dayInMs } from 'ontime-utils';
|
||||
|
||||
export function getActualShowTimes(
|
||||
report: OntimeReport,
|
||||
): Pick<ShowReport, 'actualStart' | 'actualEnd' | 'actualDuration'> {
|
||||
let firstStart = Number.POSITIVE_INFINITY;
|
||||
let lastEnd = Number.NEGATIVE_INFINITY;
|
||||
let actualStart: number | null = null;
|
||||
let actualEnd: number | null = null;
|
||||
|
||||
for (const entry of Object.values(report)) {
|
||||
if (entry.startedAt !== null && entry.startedAtDay !== null) {
|
||||
const start = entry.startedAtDay * dayInMs + entry.startedAt;
|
||||
if (start < firstStart) {
|
||||
firstStart = start;
|
||||
actualStart = entry.startedAt;
|
||||
}
|
||||
}
|
||||
|
||||
if (entry.endedAt !== null && entry.endedAtDay !== null) {
|
||||
const end = entry.endedAtDay * dayInMs + entry.endedAt;
|
||||
if (end > lastEnd) {
|
||||
lastEnd = end;
|
||||
actualEnd = entry.endedAt;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
actualStart,
|
||||
actualEnd,
|
||||
actualDuration: actualStart === null || actualEnd === null ? null : lastEnd - firstStart,
|
||||
};
|
||||
}
|
||||
|
||||
export function getPlannedShowDuration(rundown: Rundown): number | null {
|
||||
let firstStart = Number.POSITIVE_INFINITY;
|
||||
let lastEnd = Number.NEGATIVE_INFINITY;
|
||||
|
||||
for (const id of rundown.flatOrder) {
|
||||
const entry = rundown.entries[id];
|
||||
if (!entry || !isOntimeEvent(entry) || entry.skip) continue;
|
||||
|
||||
const start = entry.dayOffset * dayInMs + entry.timeStart;
|
||||
firstStart = Math.min(firstStart, start);
|
||||
lastEnd = Math.max(lastEnd, start + entry.duration);
|
||||
}
|
||||
|
||||
return Number.isFinite(firstStart) ? lastEnd - firstStart : null;
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
import { CustomFields, OntimeEvent, OntimeGroup, Rundown, SupportedEntry } from 'ontime-types';
|
||||
import { CustomFields, OntimeEvent, OntimeGroup, Rundown, SupportedEntry, TimerType } from 'ontime-types';
|
||||
|
||||
import { makeNewRundown } from '../../../models/dataModel.js';
|
||||
import { makeOntimeEvent, makeOntimeGroup, makeOntimeMilestone } from '../__mocks__/rundown.mocks.js';
|
||||
@@ -276,7 +276,13 @@ describe('parseRundown()', () => {
|
||||
expect(parsedRundown.order).toStrictEqual(['group']);
|
||||
expect(parsedRundown.flatOrder).toStrictEqual(['group', '1', '2']);
|
||||
expect(parsedRundown.entries).toMatchObject({
|
||||
group: { id: 'group', type: SupportedEntry.Group, entries: ['1', '2'] },
|
||||
group: {
|
||||
id: 'group',
|
||||
type: SupportedEntry.Group,
|
||||
entries: ['1', '2'],
|
||||
useGroupTimer: false,
|
||||
timerType: TimerType.CountDown,
|
||||
},
|
||||
'1': { id: '1', type: SupportedEntry.Event },
|
||||
'2': { id: '2', type: SupportedEntry.Milestone },
|
||||
});
|
||||
|
||||
@@ -25,6 +25,7 @@ import { parseRundown } from '../rundown.parser.js';
|
||||
import {
|
||||
calculateDayOffset,
|
||||
cloneEntryData,
|
||||
createGroupPatch,
|
||||
deleteById,
|
||||
doesInvalidateMetadata,
|
||||
getIntegerAndFraction,
|
||||
@@ -36,6 +37,25 @@ import {
|
||||
} from '../rundown.utils.js';
|
||||
|
||||
describe('test event validator', () => {
|
||||
it('creates groups with the shared timer disabled by default', () => {
|
||||
expect(createGroup({ id: 'group' })).toMatchObject({
|
||||
useGroupTimer: false,
|
||||
timerType: TimerType.CountDown,
|
||||
});
|
||||
});
|
||||
|
||||
it('limits group timers to count down and count up', () => {
|
||||
expect(createGroup({ timerType: TimerType.CountUp }).timerType).toBe(TimerType.CountUp);
|
||||
expect(createGroup({ timerType: TimerType.Clock }).timerType).toBe(TimerType.CountDown);
|
||||
});
|
||||
|
||||
it('rejects non-boolean group timer updates', () => {
|
||||
const group = createGroup({ useGroupTimer: false });
|
||||
const updated = createGroupPatch(group, { useGroupTimer: 'true' as never });
|
||||
|
||||
expect(updated.useGroupTimer).toBe(false);
|
||||
});
|
||||
|
||||
it('validates a good object', () => {
|
||||
const event = {
|
||||
title: 'test',
|
||||
|
||||
@@ -33,6 +33,7 @@ import {
|
||||
makeString,
|
||||
maxDuration,
|
||||
validateEndAction,
|
||||
validateGroupTimerType,
|
||||
validateTimerType,
|
||||
validateTimes,
|
||||
} from 'ontime-utils';
|
||||
@@ -180,6 +181,9 @@ export function createGroupPatch(originalGroup: OntimeGroup, patchGroup: Partial
|
||||
note: makeString(patchGroup.note, originalGroup.note),
|
||||
entries: patchGroup.entries ?? originalGroup.entries,
|
||||
targetDuration: maybeTargetDuration(),
|
||||
useGroupTimer:
|
||||
typeof patchGroup.useGroupTimer === 'boolean' ? patchGroup.useGroupTimer : originalGroup.useGroupTimer,
|
||||
timerType: validateGroupTimerType(patchGroup.timerType, originalGroup.timerType),
|
||||
colour: makeString(patchGroup.colour, originalGroup.colour),
|
||||
revision: originalGroup.revision,
|
||||
timeStart: originalGroup.timeStart,
|
||||
|
||||
@@ -206,6 +206,7 @@ export const startServer = async (): Promise<{ message: string; serverPort: numb
|
||||
eventStore.init({
|
||||
clock: state.clock,
|
||||
timer: state.timer,
|
||||
groupTimer: state.groupTimer,
|
||||
message: { ...runtimeStorePlaceholder.message },
|
||||
offset: state.offset,
|
||||
rundown: state.rundown,
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
body {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
background: #101010;
|
||||
background: #121212;
|
||||
color: #ffffff;
|
||||
font-family: sans-serif;
|
||||
overflow: hidden;
|
||||
|
||||
@@ -29,19 +29,15 @@ function makeHeadersWithFailingAuthorization(cookie?: string) {
|
||||
|
||||
describe('isPublicAssetRequest()', () => {
|
||||
it('allows root public assets without a prefix', () => {
|
||||
expect(isPublicAssetRequest('/site.webmanifest', '')).toBe(true);
|
||||
expect(isPublicAssetRequest('/manifest.json', '')).toBe(true);
|
||||
});
|
||||
|
||||
it('allows prefixed public assets in cloud deployments', () => {
|
||||
expect(isPublicAssetRequest('/stage-hash/manifest.json', '/stage-hash')).toBe(true);
|
||||
expect(isPublicAssetRequest('/stage-hash/site.webmanifest', '/stage-hash')).toBe(true);
|
||||
expect(isPublicAssetRequest('/stage-hash/ontime-logo.png?cache=1', '/stage-hash')).toBe(true);
|
||||
});
|
||||
|
||||
it('allows the PWA install icons', () => {
|
||||
expect(isPublicAssetRequest('/ontime-logo-192.png', '')).toBe(true);
|
||||
expect(isPublicAssetRequest('/ontime-logo-512.png', '')).toBe(true);
|
||||
});
|
||||
|
||||
it('keeps non-public paths protected', () => {
|
||||
expect(isPublicAssetRequest('/stage-hash/data', '/stage-hash')).toBe(false);
|
||||
expect(isPublicAssetRequest('/backstage', '')).toBe(false);
|
||||
|
||||
@@ -17,9 +17,8 @@ const publicAssets = new Set([
|
||||
'/favicon.ico',
|
||||
'/manifest.json',
|
||||
'/ontime-logo.png',
|
||||
'/ontime-logo-192.png',
|
||||
'/ontime-logo-512.png',
|
||||
'/robots.txt',
|
||||
'/site.webmanifest',
|
||||
]);
|
||||
|
||||
export function isPublicAssetRequest(originalUrl: string, prefix: string): boolean {
|
||||
|
||||
@@ -39,6 +39,8 @@ export const stageRundown: Rundown = {
|
||||
note: '',
|
||||
entries: ['9bf60f', 'bf71a2', 'c2697f', 'fa593e', 'a8b0b3'],
|
||||
targetDuration: null,
|
||||
useGroupTimer: false,
|
||||
timerType: TimerType.CountDown,
|
||||
colour: '#339E4E',
|
||||
custom: {},
|
||||
revision: 0,
|
||||
@@ -172,6 +174,8 @@ export const stageRundown: Rundown = {
|
||||
note: '',
|
||||
entries: ['0aaa7d'],
|
||||
targetDuration: null,
|
||||
useGroupTimer: false,
|
||||
timerType: TimerType.CountDown,
|
||||
colour: '#3E75E8',
|
||||
custom: {},
|
||||
revision: 0,
|
||||
@@ -219,6 +223,8 @@ export const stageRundown: Rundown = {
|
||||
note: '',
|
||||
entries: ['02afca', '75ce86', 'e10ed9', '07df89'],
|
||||
targetDuration: null,
|
||||
useGroupTimer: false,
|
||||
timerType: TimerType.CountDown,
|
||||
colour: '#339E4E',
|
||||
custom: {},
|
||||
revision: 0,
|
||||
@@ -360,6 +366,8 @@ export const backstageRundown: Rundown = {
|
||||
note: '',
|
||||
entries: ['bs0101', 'bs0102', 'bs0103', 'bs0104'],
|
||||
targetDuration: null,
|
||||
useGroupTimer: false,
|
||||
timerType: TimerType.CountDown,
|
||||
colour: '#A790F5',
|
||||
custom: {},
|
||||
revision: 0,
|
||||
@@ -476,6 +484,8 @@ export const backstageRundown: Rundown = {
|
||||
note: '',
|
||||
entries: ['bs0201', 'bs0202', 'bs0203', 'bs0204'],
|
||||
targetDuration: null,
|
||||
useGroupTimer: false,
|
||||
timerType: TimerType.CountDown,
|
||||
colour: '#339E4E',
|
||||
custom: {},
|
||||
revision: 0,
|
||||
@@ -588,6 +598,8 @@ export const backstageRundown: Rundown = {
|
||||
note: '',
|
||||
entries: ['bs0301'],
|
||||
targetDuration: null,
|
||||
useGroupTimer: false,
|
||||
timerType: TimerType.CountDown,
|
||||
colour: '#3E75E8',
|
||||
custom: {},
|
||||
revision: 0,
|
||||
@@ -634,6 +646,8 @@ export const backstageRundown: Rundown = {
|
||||
note: '',
|
||||
entries: ['bs0401', 'bs0402', 'bs0403', 'bs0404'],
|
||||
targetDuration: null,
|
||||
useGroupTimer: false,
|
||||
timerType: TimerType.CountDown,
|
||||
colour: '#339E4E',
|
||||
custom: {},
|
||||
revision: 0,
|
||||
@@ -768,6 +782,8 @@ export const broadcastRundown: Rundown = {
|
||||
note: '',
|
||||
entries: ['br0101', 'br0102', 'br0103'],
|
||||
targetDuration: null,
|
||||
useGroupTimer: false,
|
||||
timerType: TimerType.CountDown,
|
||||
colour: '#ED3333',
|
||||
custom: {},
|
||||
revision: 0,
|
||||
@@ -851,6 +867,8 @@ export const broadcastRundown: Rundown = {
|
||||
note: '',
|
||||
entries: ['br0201', 'br0202', 'br0203', 'br0204'],
|
||||
targetDuration: null,
|
||||
useGroupTimer: false,
|
||||
timerType: TimerType.CountDown,
|
||||
colour: '#339E4E',
|
||||
custom: {},
|
||||
revision: 0,
|
||||
@@ -959,6 +977,8 @@ export const broadcastRundown: Rundown = {
|
||||
note: '',
|
||||
entries: ['br0301', 'br0302'],
|
||||
targetDuration: null,
|
||||
useGroupTimer: false,
|
||||
timerType: TimerType.CountDown,
|
||||
colour: '#3E75E8',
|
||||
custom: {},
|
||||
revision: 0,
|
||||
@@ -1029,6 +1049,8 @@ export const broadcastRundown: Rundown = {
|
||||
note: '',
|
||||
entries: ['br0401', 'br0402', 'br0403'],
|
||||
targetDuration: null,
|
||||
useGroupTimer: false,
|
||||
timerType: TimerType.CountDown,
|
||||
colour: '#339E4E',
|
||||
custom: {},
|
||||
revision: 0,
|
||||
|
||||
@@ -4,6 +4,7 @@ import { MILLIS_PER_HOUR, MILLIS_PER_MINUTE, MILLIS_PER_SECOND, dayInMs, millisT
|
||||
import type { RuntimeState } from '../../stores/runtimeState.js';
|
||||
import {
|
||||
findDayOffset,
|
||||
getGroupTimer,
|
||||
getCurrent,
|
||||
getElapsed,
|
||||
getExpectedFinish,
|
||||
@@ -16,6 +17,91 @@ import {
|
||||
|
||||
const asTimeOfDay = (value: number): RuntimeState['clock'] => value as RuntimeState['clock'];
|
||||
|
||||
describe('getGroupTimer()', () => {
|
||||
const makeState = (patch: Partial<RuntimeState> = {}) =>
|
||||
({
|
||||
clock: asTimeOfDay(10_000),
|
||||
groupNow: {
|
||||
duration: 20_000,
|
||||
},
|
||||
rundown: {
|
||||
actualGroupStart: 5_000,
|
||||
},
|
||||
timer: {
|
||||
addedTime: 4_000,
|
||||
current: 1_000,
|
||||
elapsed: 99_000,
|
||||
phase: TimerPhase.Danger,
|
||||
playback: Playback.Play,
|
||||
},
|
||||
...patch,
|
||||
}) as RuntimeState;
|
||||
|
||||
it('returns null outside a group', () => {
|
||||
expect(getGroupTimer(makeState({ groupNow: null }))).toBeNull();
|
||||
});
|
||||
|
||||
it('derives elapsed and remaining time from the group start and duration', () => {
|
||||
expect(getGroupTimer(makeState())).toMatchObject({
|
||||
addedTime: 0,
|
||||
current: 15_000,
|
||||
duration: 20_000,
|
||||
elapsed: 5_000,
|
||||
expectedFinish: null,
|
||||
phase: TimerPhase.Default,
|
||||
playback: Playback.Play,
|
||||
secondaryTimer: null,
|
||||
startedAt: 5_000,
|
||||
});
|
||||
});
|
||||
|
||||
it('does not inherit event timer progress or added time', () => {
|
||||
const first = getGroupTimer(makeState());
|
||||
const second = getGroupTimer(
|
||||
makeState({
|
||||
timer: {
|
||||
...makeState().timer,
|
||||
addedTime: -8_000,
|
||||
current: -50_000,
|
||||
elapsed: 500_000,
|
||||
},
|
||||
}),
|
||||
);
|
||||
|
||||
expect(second).toEqual(first);
|
||||
});
|
||||
|
||||
it('keeps running while the loaded event is paused', () => {
|
||||
const timer = getGroupTimer(makeState({ timer: { ...makeState().timer, playback: Playback.Pause } }));
|
||||
|
||||
expect(timer?.playback).toBe(Playback.Play);
|
||||
});
|
||||
|
||||
it('handles a group running across midnight', () => {
|
||||
const timer = getGroupTimer(
|
||||
makeState({
|
||||
clock: asTimeOfDay(1_000),
|
||||
rundown: { ...makeState().rundown, actualGroupStart: 86_399_000 },
|
||||
}),
|
||||
);
|
||||
|
||||
expect(timer).toMatchObject({ current: 18_000, elapsed: 2_000 });
|
||||
});
|
||||
|
||||
it('uses the event phase before the group starts and overtime afterwards', () => {
|
||||
const pending = getGroupTimer(
|
||||
makeState({
|
||||
rundown: { ...makeState().rundown, actualGroupStart: null },
|
||||
timer: { ...makeState().timer, phase: TimerPhase.Pending },
|
||||
}),
|
||||
);
|
||||
const overtime = getGroupTimer(makeState({ clock: asTimeOfDay(30_001) }));
|
||||
|
||||
expect(pending).toMatchObject({ current: 20_000, elapsed: null, phase: TimerPhase.Pending });
|
||||
expect(overtime).toMatchObject({ current: -5_001, elapsed: 25_001, phase: TimerPhase.Overtime });
|
||||
});
|
||||
});
|
||||
|
||||
describe('getElapsed()', () => {
|
||||
it('returns active elapsed time from startedAt without add-time adjustments', () => {
|
||||
const state = {
|
||||
|
||||
@@ -7,6 +7,7 @@ import {
|
||||
findPreviousPlayableId,
|
||||
getEventAtIndex,
|
||||
getShouldClockUpdate,
|
||||
getShouldGroupTimerUpdate,
|
||||
getShouldOffsetUpdate,
|
||||
getShouldTimerUpdate,
|
||||
isNewSecond,
|
||||
@@ -95,6 +96,34 @@ describe('getShouldTimerUpdate()', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('getShouldGroupTimerUpdate()', () => {
|
||||
const timer: TimerState = {
|
||||
addedTime: 0,
|
||||
current: 10_000,
|
||||
duration: 10_000,
|
||||
elapsed: 0,
|
||||
expectedFinish: null,
|
||||
phase: TimerPhase.Default,
|
||||
playback: Playback.Play,
|
||||
secondaryTimer: null,
|
||||
startedAt: 0,
|
||||
};
|
||||
|
||||
it('updates when a group timer appears or disappears', () => {
|
||||
expect(getShouldGroupTimerUpdate(null, timer)).toBe(true);
|
||||
expect(getShouldGroupTimerUpdate(timer, null)).toBe(true);
|
||||
});
|
||||
|
||||
it('does not repeatedly publish an absent group timer', () => {
|
||||
expect(getShouldGroupTimerUpdate(null, null)).toBe(false);
|
||||
});
|
||||
|
||||
it('uses normal timer tick semantics while a group timer exists', () => {
|
||||
expect(getShouldGroupTimerUpdate(timer, { ...timer, current: 9_500 })).toBe(false);
|
||||
expect(getShouldGroupTimerUpdate(timer, { ...timer, current: 8_999 })).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe('getShouldOffsetUpdate()', () => {
|
||||
const baseOffset: Offset = {
|
||||
absolute: 0,
|
||||
|
||||
@@ -25,7 +25,7 @@ import { logger } from '../../classes/Logger.js';
|
||||
import { timerConfig } from '../../setup/config.js';
|
||||
import { eventStore } from '../../stores/EventStore.js';
|
||||
import * as runtimeState from '../../stores/runtimeState.js';
|
||||
import type { RuntimeState } from '../../stores/runtimeState.js';
|
||||
import type { RuntimeState, RuntimeStateSnapshot } from '../../stores/runtimeState.js';
|
||||
import { EventTimer } from '../EventTimer.js';
|
||||
import { restoreService } from '../restore-service/restore.service.js';
|
||||
import type { RestorePoint } from '../restore-service/restore.type.js';
|
||||
@@ -36,6 +36,7 @@ import {
|
||||
findPreviousPlayableId,
|
||||
getEventAtIndex,
|
||||
getShouldClockUpdate,
|
||||
getShouldGroupTimerUpdate,
|
||||
getShouldOffsetUpdate,
|
||||
getShouldTimerUpdate,
|
||||
isNewSecond,
|
||||
@@ -51,11 +52,11 @@ class RuntimeService {
|
||||
private lastIntegrationTimerValue = -1;
|
||||
|
||||
/** last known state */
|
||||
static previousState: RuntimeState;
|
||||
static previousState: RuntimeStateSnapshot;
|
||||
|
||||
constructor(eventTimer: EventTimer) {
|
||||
this.eventTimer = eventTimer;
|
||||
RuntimeService.previousState = {} as RuntimeState;
|
||||
RuntimeService.previousState = {} as RuntimeStateSnapshot;
|
||||
}
|
||||
|
||||
@broadcastResult
|
||||
@@ -710,6 +711,12 @@ function broadcastResult(_target: any, _propertyKey: string, descriptor: Propert
|
||||
RuntimeService.previousState.timer = { ...state.timer };
|
||||
}
|
||||
|
||||
const updateGroupTimer = getShouldGroupTimerUpdate(RuntimeService.previousState.groupTimer, state.groupTimer);
|
||||
if (updateGroupTimer) {
|
||||
batch.add('groupTimer', state.groupTimer);
|
||||
RuntimeService.previousState.groupTimer = state.groupTimer ? { ...state.groupTimer } : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* clock has changed by a second or more.
|
||||
* or the timer updated so we ensure that the timer and clock ticks are in sync
|
||||
|
||||
@@ -54,6 +54,15 @@ export function getShouldTimerUpdate(previousValue: TimerState | undefined, curr
|
||||
);
|
||||
}
|
||||
|
||||
export function getShouldGroupTimerUpdate(
|
||||
previousValue: TimerState | null | undefined,
|
||||
currentValue: TimerState | null,
|
||||
): boolean {
|
||||
if (previousValue === undefined) return true;
|
||||
if (previousValue === null || currentValue === null) return previousValue !== currentValue;
|
||||
return getShouldTimerUpdate(previousValue, currentValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether we should update the offset values
|
||||
* - `mode` triggers update
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Day, MaybeNumber, TimeOfDay, TimerPhase } from 'ontime-types';
|
||||
import { Day, MaybeNumber, Playback, TimeOfDay, TimerPhase, TimerState } from 'ontime-types';
|
||||
import { MILLIS_PER_HOUR, checkIsNow, dayInMs, isPlaybackActive } from 'ontime-utils';
|
||||
|
||||
import type { RuntimeState } from '../stores/runtimeState.js';
|
||||
@@ -111,6 +111,37 @@ export function getElapsed(state: RuntimeState): MaybeNumber {
|
||||
return Math.max(0, activeElapsed);
|
||||
}
|
||||
|
||||
/**
|
||||
* Derives a timer for the active group from wall-clock time.
|
||||
* Event timer controls such as pause and add time intentionally do not affect it.
|
||||
*/
|
||||
export function getGroupTimer(state: RuntimeState): TimerState | null {
|
||||
if (state.groupNow === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const { actualGroupStart } = state.rundown;
|
||||
const elapsed = actualGroupStart === null ? null : getTimeSinceStart(state.clock, actualGroupStart);
|
||||
const current = elapsed === null ? state.groupNow.duration : state.groupNow.duration - elapsed;
|
||||
|
||||
let phase = state.timer.phase;
|
||||
if (actualGroupStart !== null) {
|
||||
phase = current < 0 ? TimerPhase.Overtime : TimerPhase.Default;
|
||||
}
|
||||
|
||||
return {
|
||||
addedTime: 0,
|
||||
current,
|
||||
duration: state.groupNow.duration,
|
||||
elapsed,
|
||||
expectedFinish: null,
|
||||
phase,
|
||||
playback: actualGroupStart === null ? state.timer.playback : Playback.Play,
|
||||
secondaryTimer: null,
|
||||
startedAt: actualGroupStart,
|
||||
};
|
||||
}
|
||||
|
||||
function getTimeSinceStart(clock: TimeOfDay, startedAt: number): number {
|
||||
if (clock < startedAt) {
|
||||
return clock + dayInMs - startedAt;
|
||||
|
||||
@@ -13,6 +13,7 @@ import {
|
||||
Playback,
|
||||
Rundown,
|
||||
RundownState,
|
||||
RuntimeStore,
|
||||
TimeOfDay,
|
||||
TimerPhase,
|
||||
TimerState,
|
||||
@@ -39,6 +40,7 @@ import {
|
||||
getCurrent,
|
||||
getElapsed,
|
||||
getExpectedFinish,
|
||||
getGroupTimer,
|
||||
getRuntimeOffset,
|
||||
getTimerPhase,
|
||||
hasCrossedMidnight,
|
||||
@@ -104,7 +106,9 @@ const runtimeState: RuntimeState = {
|
||||
_startDayOffset: null,
|
||||
};
|
||||
|
||||
export function getState(): Readonly<RuntimeState> {
|
||||
export type RuntimeStateSnapshot = RuntimeState & Pick<RuntimeStore, 'groupTimer'>;
|
||||
|
||||
export function getState(): Readonly<RuntimeStateSnapshot> {
|
||||
// create a shallow copy of the state
|
||||
return {
|
||||
...runtimeState,
|
||||
@@ -115,6 +119,7 @@ export function getState(): Readonly<RuntimeState> {
|
||||
offset: { ...runtimeState.offset },
|
||||
rundown: { ...runtimeState.rundown },
|
||||
timer: { ...runtimeState.timer },
|
||||
groupTimer: getGroupTimer(runtimeState),
|
||||
_timer: { ...runtimeState._timer },
|
||||
_rundown: { ...runtimeState._rundown },
|
||||
};
|
||||
|
||||
@@ -38,12 +38,6 @@ When relevant, cover interactions among:
|
||||
|
||||
Pass time/state explicitly to keep rules deterministic and unit-testable.
|
||||
|
||||
## Reports
|
||||
|
||||
- A report is one aggregate containing its event records, show timing, and rundown snapshot.
|
||||
- Capture the rundown plan when the report starts; later rundown edits must not change it.
|
||||
- Store day offsets with report timestamps. Use absolute timeline positions for ordering and duration, and wall-clock values only for display.
|
||||
|
||||
## Imports and migrations
|
||||
|
||||
- Treat project files, spreadsheets, custom fields, migrated data as untrusted.
|
||||
|
||||
@@ -6,7 +6,7 @@ test.describe('pages routes are available', () => {
|
||||
test('editor', async ({ page }) => {
|
||||
await page.goto('/editor');
|
||||
|
||||
await expect(page).toHaveTitle(/ontime/i);
|
||||
await expect(page).toHaveTitle(/ontime/);
|
||||
await expect(page.getByTestId('editor-container')).toBeVisible();
|
||||
await expect(page.getByTestId('panel-rundown')).toBeVisible();
|
||||
await expect(page.getByTestId('panel-timer-control')).toBeVisible();
|
||||
@@ -16,38 +16,38 @@ test.describe('pages routes are available', () => {
|
||||
test('cuesheet', async ({ page }) => {
|
||||
await page.goto('/cuesheet');
|
||||
|
||||
await expect(page).toHaveTitle(/ontime/i);
|
||||
await expect(page).toHaveTitle(/ontime/);
|
||||
await expect(page.getByTestId('cuesheet')).toBeVisible();
|
||||
});
|
||||
|
||||
test('operator', async ({ page }) => {
|
||||
await page.goto('/op');
|
||||
|
||||
await expect(page).toHaveTitle(/ontime/i);
|
||||
await expect(page).toHaveTitle(/ontime/);
|
||||
});
|
||||
|
||||
test('timer', async ({ page }) => {
|
||||
await page.goto('/timer');
|
||||
|
||||
await expect(page).toHaveTitle(/ontime/i);
|
||||
await expect(page).toHaveTitle(/ontime/);
|
||||
});
|
||||
|
||||
test('backstage', async ({ page }) => {
|
||||
await page.goto('/backstage');
|
||||
|
||||
await expect(page).toHaveTitle(/ontime/i);
|
||||
await expect(page).toHaveTitle(/ontime/);
|
||||
});
|
||||
|
||||
test('studio', async ({ page }) => {
|
||||
await page.goto('/studio');
|
||||
|
||||
await expect(page).toHaveTitle(/ontime/i);
|
||||
await expect(page).toHaveTitle(/ontime/);
|
||||
});
|
||||
|
||||
test('countdown', async ({ page }) => {
|
||||
await page.goto('/countdown?sub=32d31');
|
||||
|
||||
await expect(page).toHaveTitle(/ontime/i);
|
||||
await expect(page).toHaveTitle(/ontime/);
|
||||
|
||||
await expect(page.getByText('Albania')).toBeVisible();
|
||||
await expect(page.getByText('Latvia')).toBeHidden();
|
||||
|
||||
@@ -92,12 +92,12 @@ test.describe('test view navigation feature', () => {
|
||||
test('not-found', async ({ page }) => {
|
||||
await page.goto('/not-found');
|
||||
|
||||
await expect(page).toHaveTitle(/ontime/i);
|
||||
await expect(page).toHaveTitle(/ontime/);
|
||||
await expect(page.getByRole('heading', { name: 'Not found' })).toBeVisible();
|
||||
|
||||
await page.goto('/preset/not-found');
|
||||
|
||||
await expect(page).toHaveTitle(/ontime/i);
|
||||
await expect(page).toHaveTitle(/ontime/);
|
||||
await expect(page.getByRole('heading', { name: 'Not found' })).toBeVisible();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -44,6 +44,8 @@ export type OntimeGroup = OntimeBaseEvent & {
|
||||
note: string;
|
||||
entries: EntryId[];
|
||||
targetDuration: MaybeNumber;
|
||||
useGroupTimer: boolean;
|
||||
timerType: TimerType;
|
||||
colour: string;
|
||||
custom: EntryCustomFields;
|
||||
// !==== RUNTIME METADATA ====! //
|
||||
|
||||
@@ -1,42 +1,8 @@
|
||||
import type { MaybeNumber } from '../../utils/utils.type.js';
|
||||
import type { EntryId } from './OntimeEntry.js';
|
||||
import type { Rundown } from './Rundown.type.js';
|
||||
|
||||
export type OntimeEventReport = {
|
||||
startedAt: MaybeNumber;
|
||||
startedAtDay: number | null;
|
||||
endedAt: MaybeNumber;
|
||||
endedAtDay: number | null;
|
||||
/**
|
||||
* Snapshot of the schedule taken when the event ran.
|
||||
* Keeping a copy is what makes a report a record: editing the rundown
|
||||
* afterwards no longer changes how a show that already happened is reported.
|
||||
*/
|
||||
scheduledStart: number;
|
||||
scheduledDay: number;
|
||||
scheduledDuration: number;
|
||||
};
|
||||
|
||||
export type OntimeReport = Record<EntryId, OntimeEventReport>;
|
||||
|
||||
/**
|
||||
* Show level times for the report.
|
||||
*
|
||||
* Planned times are snapshotted when the show starts, for the same reason the
|
||||
* per event schedule is. Actual times are derived from the events that ran.
|
||||
*/
|
||||
export type ShowReport = {
|
||||
plannedStart: MaybeNumber;
|
||||
plannedEnd: MaybeNumber;
|
||||
plannedDuration: MaybeNumber;
|
||||
actualStart: MaybeNumber;
|
||||
actualEnd: MaybeNumber;
|
||||
actualDuration: MaybeNumber;
|
||||
};
|
||||
|
||||
/** Recorded event timings together with the rundown plan they are measured against. */
|
||||
export type ReportData = {
|
||||
eventReports: OntimeReport;
|
||||
rundown: Rundown | null;
|
||||
show: ShowReport;
|
||||
};
|
||||
export type OntimeReport = Record<string, OntimeEventReport>;
|
||||
|
||||
@@ -17,6 +17,7 @@ export const runtimeStorePlaceholder: Readonly<RuntimeStore> = {
|
||||
secondaryTimer: null, // change on every update
|
||||
startedAt: null, // change can only be initiated by user
|
||||
},
|
||||
groupTimer: null,
|
||||
message: {
|
||||
timer: {
|
||||
text: '',
|
||||
|
||||
@@ -9,6 +9,7 @@ export type RuntimeStore = {
|
||||
// timer data
|
||||
clock: number;
|
||||
timer: TimerState;
|
||||
groupTimer: TimerState | null;
|
||||
|
||||
// messages service
|
||||
message: MessageState;
|
||||
|
||||
@@ -24,7 +24,7 @@ export { TimerType } from './definitions/TimerType.type.js';
|
||||
export type { Day, Duration, Instant, TimeOfDay } from './definitions/core/Temporal.js';
|
||||
|
||||
// ---> Report
|
||||
export type { OntimeReport, OntimeEventReport, ReportData, ShowReport } from './definitions/core/Report.type.js';
|
||||
export type { OntimeReport, OntimeEventReport } from './definitions/core/Report.type.js';
|
||||
|
||||
// ---> Automations
|
||||
export { ontimeActionKeyValues } from './definitions/core/Automation.type.js';
|
||||
|
||||
@@ -34,7 +34,14 @@ export {
|
||||
group as groupDef,
|
||||
milestone as milestoneDef,
|
||||
} from './src/rundown-utils/entryDefinitions.js';
|
||||
export { createDelay, createEvent, createGroup, createMilestone, makeString } from './src/rundown-utils/entryUtils.js';
|
||||
export {
|
||||
createDelay,
|
||||
createEvent,
|
||||
createGroup,
|
||||
createMilestone,
|
||||
makeString,
|
||||
validateGroupTimerType,
|
||||
} from './src/rundown-utils/entryUtils.js';
|
||||
|
||||
// time format utils
|
||||
export {
|
||||
|
||||
@@ -52,6 +52,8 @@ export const group: Omit<OntimeGroup, 'id'> = {
|
||||
note: '',
|
||||
entries: [],
|
||||
targetDuration: null,
|
||||
useGroupTimer: false,
|
||||
timerType: TimerType.CountDown,
|
||||
colour: '',
|
||||
custom: {},
|
||||
// !==== RUNTIME METADATA ====! //
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import type { OntimeDelay, OntimeEvent, OntimeGroup, OntimeMilestone } from 'ontime-types';
|
||||
import { SupportedEntry, TimeStrategy } from 'ontime-types';
|
||||
import { SupportedEntry, TimeStrategy, TimerType } from 'ontime-types';
|
||||
|
||||
import { generateId } from '../generate-id/generateId.js';
|
||||
import { validateEndAction, validateTimerType } from '../validate-events/validateEvent.js';
|
||||
@@ -67,6 +67,8 @@ export function createGroup(patch?: Partial<OntimeGroup>): OntimeGroup {
|
||||
note: patch.note ?? '',
|
||||
entries: patch.entries ?? [],
|
||||
targetDuration: patch.targetDuration ?? null,
|
||||
useGroupTimer: patch.useGroupTimer === true,
|
||||
timerType: validateGroupTimerType(patch.timerType),
|
||||
colour: makeString(patch.colour, ''),
|
||||
custom: patch.custom ?? {},
|
||||
revision: 0,
|
||||
@@ -77,6 +79,16 @@ export function createGroup(patch?: Partial<OntimeGroup>): OntimeGroup {
|
||||
};
|
||||
}
|
||||
|
||||
export function validateGroupTimerType(
|
||||
value: unknown,
|
||||
fallback: unknown = TimerType.CountDown,
|
||||
): TimerType.CountDown | TimerType.CountUp {
|
||||
if (value === TimerType.CountDown || value === TimerType.CountUp) {
|
||||
return value;
|
||||
}
|
||||
return fallback === TimerType.CountUp ? TimerType.CountUp : TimerType.CountDown;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new milestone from an optional patch
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user