mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-31 20:09:11 +00:00
refactor: update timers (#729)
* refactor: remove duplication * refactor: previous times * refactor: event patching
This commit is contained in:
@@ -4,22 +4,18 @@ import { millisToString } from 'ontime-utils';
|
|||||||
|
|
||||||
import { useEmitLog } from '../../../stores/logger';
|
import { useEmitLog } from '../../../stores/logger';
|
||||||
import { forgivingStringToMillis } from '../../../utils/dateConfig';
|
import { forgivingStringToMillis } from '../../../utils/dateConfig';
|
||||||
import { TimeEntryField } from '../../../utils/timesManager';
|
|
||||||
|
|
||||||
import style from './TimeInput.module.scss';
|
import style from './TimeInput.module.scss';
|
||||||
interface TimeInputProps {
|
interface TimeInputProps<T extends string> {
|
||||||
id?: TimeEntryField;
|
name: T;
|
||||||
name: TimeEntryField;
|
submitHandler: (field: T, value: string) => void;
|
||||||
submitHandler: (field: TimeEntryField, value: number) => void;
|
|
||||||
time?: number;
|
time?: number;
|
||||||
delay?: number;
|
|
||||||
placeholder: string;
|
placeholder: string;
|
||||||
previousEnd?: number;
|
|
||||||
className?: string;
|
className?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function TimeInput(props: TimeInputProps) {
|
export default function TimeInput<T extends string>(props: TimeInputProps<T>) {
|
||||||
const { id, name, submitHandler, time = 0, delay = 0, placeholder, previousEnd = 0, className } = props;
|
const { name, submitHandler, time = 0, placeholder, className } = props;
|
||||||
const { emitError } = useEmitLog();
|
const { emitError } = useEmitLog();
|
||||||
const inputRef = useRef<HTMLInputElement | null>(null);
|
const inputRef = useRef<HTMLInputElement | null>(null);
|
||||||
const [value, setValue] = useState<string>('');
|
const [value, setValue] = useState<string>('');
|
||||||
@@ -55,32 +51,20 @@ export default function TimeInput(props: TimeInputProps) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
let newValMillis = 0;
|
// we dont know the values in the rundown, escalate to handler
|
||||||
|
if (newValue.startsWith('p') || newValue.startsWith('+')) {
|
||||||
// check for known aliases
|
submitHandler(name, newValue);
|
||||||
if (newValue === 'p' || newValue === 'prev' || newValue === 'previous') {
|
|
||||||
// string to pass should be the time of the end before
|
|
||||||
if (previousEnd != null) {
|
|
||||||
newValMillis = previousEnd;
|
|
||||||
}
|
|
||||||
} else if (newValue.startsWith('+') || newValue.startsWith('p+') || newValue.startsWith('p +')) {
|
|
||||||
// string to pass should add to the end before
|
|
||||||
const val = newValue.substring(1);
|
|
||||||
newValMillis = previousEnd + forgivingStringToMillis(val);
|
|
||||||
} else {
|
|
||||||
// convert entered value to milliseconds
|
|
||||||
newValMillis = forgivingStringToMillis(newValue);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// check if time is different from before
|
const valueInMillis = forgivingStringToMillis(newValue);
|
||||||
if (newValMillis === time) return false;
|
if (valueInMillis === time) {
|
||||||
|
return false;
|
||||||
// update entry
|
}
|
||||||
submitHandler(name, newValMillis);
|
|
||||||
|
|
||||||
|
submitHandler(name, newValue);
|
||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
[name, previousEnd, submitHandler, time],
|
[name, submitHandler, time],
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -90,15 +74,11 @@ export default function TimeInput(props: TimeInputProps) {
|
|||||||
const validateAndSubmit = useCallback(
|
const validateAndSubmit = useCallback(
|
||||||
(newValue: string) => {
|
(newValue: string) => {
|
||||||
const success = handleSubmit(newValue);
|
const success = handleSubmit(newValue);
|
||||||
if (success) {
|
if (!success) {
|
||||||
const ms = forgivingStringToMillis(newValue);
|
|
||||||
const delayed = name === 'timeEnd' ? Math.max(0, ms + delay) : Math.max(0, ms + delay);
|
|
||||||
setValue(millisToString(delayed));
|
|
||||||
} else {
|
|
||||||
resetValue();
|
resetValue();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
[delay, handleSubmit, name, resetValue],
|
[handleSubmit, resetValue],
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -144,7 +124,6 @@ export default function TimeInput(props: TimeInputProps) {
|
|||||||
<Input
|
<Input
|
||||||
size='sm'
|
size='sm'
|
||||||
ref={inputRef}
|
ref={inputRef}
|
||||||
id={id}
|
|
||||||
data-testid={`time-input-${name}`}
|
data-testid={`time-input-${name}`}
|
||||||
className={timeInputClass}
|
className={timeInputClass}
|
||||||
type='text'
|
type='text'
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
$input-font-size: 15px;
|
$input-font-size: 15px;
|
||||||
$input-delayed-border-color: #E69056;
|
$input-delayed-border-color: $ontime-delay-text;
|
||||||
|
|
||||||
.timeInput {
|
.timeInput {
|
||||||
width: fit-content !important;
|
width: fit-content;
|
||||||
|
|
||||||
.inputLeft {
|
&.delayed {
|
||||||
max-width: fit-content;
|
border: 1px solid $input-delayed-border-color;
|
||||||
}
|
}
|
||||||
|
|
||||||
.inputLeft,
|
.inputLeft,
|
||||||
@@ -20,16 +20,7 @@ $input-delayed-border-color: #E69056;
|
|||||||
padding: 0 0 0 2.6em;
|
padding: 0 0 0 2.6em;
|
||||||
}
|
}
|
||||||
|
|
||||||
.warn {
|
.inputButton {
|
||||||
&::after {
|
border-radius: 2px 0 0 2px;
|
||||||
content: "*";
|
|
||||||
color: $warning-orange;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
&.delayed {
|
|
||||||
.inputField {
|
|
||||||
border: 1px solid $input-delayed-border-color;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,83 +1,39 @@
|
|||||||
import { useMemo } from 'react';
|
|
||||||
import { Button, InputGroup, InputLeftElement, Tooltip } from '@chakra-ui/react';
|
import { Button, InputGroup, InputLeftElement, Tooltip } from '@chakra-ui/react';
|
||||||
|
|
||||||
import { tooltipDelayFast } from '../../../../ontimeConfig';
|
import { tooltipDelayFast } from '../../../../ontimeConfig';
|
||||||
import { cx } from '../../../utils/styleUtils';
|
import { cx } from '../../../utils/styleUtils';
|
||||||
import { TimeEntryField } from '../../../utils/timesManager';
|
|
||||||
|
|
||||||
import TimeInput from './TimeInput';
|
import TimeInput from './TimeInput';
|
||||||
|
|
||||||
import style from './TimeInputWithButton.module.scss';
|
import style from './TimeInputWithButton.module.scss';
|
||||||
|
|
||||||
interface TimeInputProps {
|
interface TimeInputWithButtonProps<T extends string> {
|
||||||
id?: TimeEntryField;
|
name: T;
|
||||||
name: TimeEntryField;
|
submitHandler: (field: T, value: string) => void;
|
||||||
submitHandler: (field: TimeEntryField, value: number) => void;
|
|
||||||
time?: number;
|
time?: number;
|
||||||
delay?: number;
|
hasDelay?: boolean;
|
||||||
placeholder: string;
|
placeholder: string;
|
||||||
previousEnd?: number;
|
|
||||||
warning?: string;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function ButtonInitial(name: TimeEntryField) {
|
export default function TimeInputWithButton<T extends string>(props: TimeInputWithButtonProps<T>) {
|
||||||
if (name === 'timeStart') return 'S';
|
const { name, submitHandler, time, hasDelay, placeholder } = props;
|
||||||
if (name === 'timeEnd') return 'E';
|
|
||||||
if (name === 'durationOverride') return 'D';
|
|
||||||
if (name === 'timeWarning') return 'Wa';
|
|
||||||
if (name === 'timeDanger') return 'Da';
|
|
||||||
return '';
|
|
||||||
}
|
|
||||||
|
|
||||||
function ButtonTooltip(name: TimeEntryField, warning?: string) {
|
const inputClasses = cx([style.timeInput, hasDelay ? style.delayed : null]);
|
||||||
if (name === 'timeStart') return `Start${warning ? `: ${warning}` : ''}`;
|
|
||||||
if (name === 'timeEnd') return `End${warning ? `: ${warning}` : ''}`;
|
|
||||||
if (name === 'durationOverride') return `Duration${warning ? `: ${warning}` : ''}`;
|
|
||||||
if (name === 'timeWarning') return `Warning${warning ? `: ${warning}` : ''}`;
|
|
||||||
if (name === 'timeDanger') return `Danger${warning ? `: ${warning}` : ''}`;
|
|
||||||
return '';
|
|
||||||
}
|
|
||||||
|
|
||||||
export default function TimeInputWithButton(props: TimeInputProps) {
|
|
||||||
const { id, name, submitHandler, time = 0, delay = 0, placeholder, previousEnd = 0, warning } = props;
|
|
||||||
|
|
||||||
const isDelayed = delay !== 0;
|
|
||||||
const inputClasses = cx([style.timeInput, isDelayed ? style.delayed : null]);
|
|
||||||
const buttonClasses = cx([style.inputButton, isDelayed ? style.delayed : null, warning ? style.warn : null]);
|
|
||||||
|
|
||||||
const TooltipLabel = useMemo(() => {
|
|
||||||
return ButtonTooltip(name, warning);
|
|
||||||
}, [name, warning]);
|
|
||||||
|
|
||||||
const ButtonText = useMemo(() => {
|
|
||||||
return ButtonInitial(name);
|
|
||||||
}, [name]);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<InputGroup size='sm' className={inputClasses}>
|
<InputGroup size='sm' className={inputClasses}>
|
||||||
<InputLeftElement className={style.inputLeft}>
|
<InputLeftElement className={style.inputLeft}>
|
||||||
<Tooltip label={TooltipLabel} openDelay={tooltipDelayFast} variant='ontime-ondark'>
|
<Tooltip label={placeholder} openDelay={tooltipDelayFast} variant='ontime-ondark'>
|
||||||
<Button
|
<Button size='sm' variant='ontime-subtle-white' className={style.inputButton} tabIndex={-1}>
|
||||||
size='sm'
|
{placeholder.charAt(0)}
|
||||||
variant='ontime-subtle-white'
|
|
||||||
className={buttonClasses}
|
|
||||||
tabIndex={-1}
|
|
||||||
border={isDelayed ? '1px solid #E69056' : '1px solid transparent'}
|
|
||||||
borderRight='1px solid transparent'
|
|
||||||
borderRadius='2px 0 0 2px'
|
|
||||||
>
|
|
||||||
{ButtonText}
|
|
||||||
</Button>
|
</Button>
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
</InputLeftElement>
|
</InputLeftElement>
|
||||||
<TimeInput
|
<TimeInput<T>
|
||||||
id={id}
|
|
||||||
name={name}
|
name={name}
|
||||||
submitHandler={submitHandler}
|
submitHandler={submitHandler}
|
||||||
time={time}
|
time={time}
|
||||||
delay={delay}
|
|
||||||
placeholder={placeholder}
|
placeholder={placeholder}
|
||||||
previousEnd={previousEnd}
|
|
||||||
className={style.inputField}
|
className={style.inputField}
|
||||||
/>
|
/>
|
||||||
</InputGroup>
|
</InputGroup>
|
||||||
|
|||||||
+1
-1
@@ -30,7 +30,7 @@ export default function RenameClientModal({ isOpen, onClose }: RenameClientModal
|
|||||||
|
|
||||||
const handleRename = async () => {
|
const handleRename = async () => {
|
||||||
if (newName) {
|
if (newName) {
|
||||||
await setClientName(newName);
|
setClientName(newName);
|
||||||
persistName(newName);
|
persistName(newName);
|
||||||
onClose();
|
onClose();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { useCallback } from 'react';
|
import { useCallback } from 'react';
|
||||||
import { useMutation, useQueryClient } from '@tanstack/react-query';
|
import { useMutation, useQueryClient } from '@tanstack/react-query';
|
||||||
import { GetRundownCached, isOntimeEvent, OntimeRundownEntry } from 'ontime-types';
|
import { GetRundownCached, isOntimeEvent, OntimeRundownEntry } from 'ontime-types';
|
||||||
import { getCueCandidate, swapOntimeEvents } from 'ontime-utils';
|
import { getPreviousEvent, swapOntimeEvents } from 'ontime-utils';
|
||||||
|
|
||||||
import { RUNDOWN } from '../api/apiConstants';
|
import { RUNDOWN } from '../api/apiConstants';
|
||||||
import { logAxiosError } from '../api/apiUtils';
|
import { logAxiosError } from '../api/apiUtils';
|
||||||
@@ -18,6 +18,7 @@ import {
|
|||||||
SwapEntry,
|
SwapEntry,
|
||||||
} from '../api/eventsApi';
|
} from '../api/eventsApi';
|
||||||
import { useEditorSettings } from '../stores/editorSettings';
|
import { useEditorSettings } from '../stores/editorSettings';
|
||||||
|
import { forgivingStringToMillis } from '../utils/dateConfig';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description Set of utilities for events
|
* @description Set of utilities for events
|
||||||
@@ -70,19 +71,9 @@ export const useEventAction = () => {
|
|||||||
|
|
||||||
const rundown = queryClient.getQueryData<GetRundownCached>(RUNDOWN)?.rundown ?? [];
|
const rundown = queryClient.getQueryData<GetRundownCached>(RUNDOWN)?.rundown ?? [];
|
||||||
|
|
||||||
if (newEvent?.cue === undefined) {
|
|
||||||
newEvent.cue = getCueCandidate(rundown, options?.after);
|
|
||||||
}
|
|
||||||
|
|
||||||
// hard coding duration value to be as expected for now
|
|
||||||
// this until timeOptions gets implemented
|
|
||||||
if (newEvent?.timeStart !== undefined && newEvent.timeEnd !== undefined) {
|
|
||||||
newEvent.duration = Math.max(0, newEvent?.timeEnd - newEvent?.timeStart) || 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (applicationOptions.startTimeIsLastEnd && applicationOptions?.lastEventId) {
|
if (applicationOptions.startTimeIsLastEnd && applicationOptions?.lastEventId) {
|
||||||
const previousEvent = rundown.find((event) => event.id === applicationOptions.lastEventId);
|
const previousEvent = rundown.find((event) => event.id === applicationOptions.lastEventId);
|
||||||
if (previousEvent !== undefined && previousEvent.type === 'event') {
|
if (isOntimeEvent(previousEvent)) {
|
||||||
newEvent.timeStart = previousEvent.timeEnd;
|
newEvent.timeStart = previousEvent.timeEnd;
|
||||||
newEvent.timeEnd = previousEvent.timeEnd;
|
newEvent.timeEnd = previousEvent.timeEnd;
|
||||||
}
|
}
|
||||||
@@ -120,7 +111,6 @@ export const useEventAction = () => {
|
|||||||
await queryClient.cancelQueries({ queryKey: RUNDOWN });
|
await queryClient.cancelQueries({ queryKey: RUNDOWN });
|
||||||
|
|
||||||
// Snapshot the previous value
|
// Snapshot the previous value
|
||||||
|
|
||||||
const previousData = queryClient.getQueryData<GetRundownCached>(RUNDOWN);
|
const previousData = queryClient.getQueryData<GetRundownCached>(RUNDOWN);
|
||||||
|
|
||||||
if (previousData) {
|
if (previousData) {
|
||||||
@@ -164,6 +154,50 @@ export const useEventAction = () => {
|
|||||||
[_updateEventMutation],
|
[_updateEventMutation],
|
||||||
);
|
);
|
||||||
|
|
||||||
|
type TimeField = 'timeStart' | 'timeEnd' | 'duration';
|
||||||
|
/**
|
||||||
|
* Updates time of existing event
|
||||||
|
*/
|
||||||
|
const updateTimer = useCallback(
|
||||||
|
async (eventId: string, field: TimeField, value: string) => {
|
||||||
|
const getPreviousEnd = (): number => {
|
||||||
|
const rundown = queryClient.getQueryData<GetRundownCached>(RUNDOWN)?.rundown ?? [];
|
||||||
|
if (rundown) {
|
||||||
|
const { previousEvent } = getPreviousEvent(rundown, eventId);
|
||||||
|
if (previousEvent) {
|
||||||
|
return previousEvent.timeEnd;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
let newValMillis = 0;
|
||||||
|
|
||||||
|
// check for previous keyword
|
||||||
|
if (value === 'p' || value === 'prev' || value === 'previous') {
|
||||||
|
newValMillis = getPreviousEnd();
|
||||||
|
|
||||||
|
// check for adding time keyword
|
||||||
|
} else if (value.startsWith('+') || value.startsWith('p+') || value.startsWith('p +')) {
|
||||||
|
const remainingString = value.substring(1);
|
||||||
|
newValMillis = getPreviousEnd() + forgivingStringToMillis(remainingString);
|
||||||
|
} else {
|
||||||
|
newValMillis = forgivingStringToMillis(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
const newEvent = {
|
||||||
|
id: eventId,
|
||||||
|
[field]: newValMillis,
|
||||||
|
};
|
||||||
|
try {
|
||||||
|
await _updateEventMutation.mutateAsync(newEvent);
|
||||||
|
} catch (error) {
|
||||||
|
logAxiosError('Error updating event', error);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
[_updateEventMutation, queryClient],
|
||||||
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calls mutation to edit multiple events
|
* Calls mutation to edit multiple events
|
||||||
* @private
|
* @private
|
||||||
@@ -392,9 +426,9 @@ export const useEventAction = () => {
|
|||||||
async (eventId: string, from: number, to: number) => {
|
async (eventId: string, from: number, to: number) => {
|
||||||
try {
|
try {
|
||||||
const reorderObject: ReorderEntry = {
|
const reorderObject: ReorderEntry = {
|
||||||
eventId: eventId,
|
eventId,
|
||||||
from: from,
|
from,
|
||||||
to: to,
|
to,
|
||||||
};
|
};
|
||||||
await _reorderEventMutation.mutateAsync(reorderObject);
|
await _reorderEventMutation.mutateAsync(reorderObject);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -461,12 +495,13 @@ export const useEventAction = () => {
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
addEvent,
|
addEvent,
|
||||||
updateEvent,
|
applyDelay,
|
||||||
|
batchUpdateEvents,
|
||||||
deleteEvent,
|
deleteEvent,
|
||||||
deleteAllEvents,
|
deleteAllEvents,
|
||||||
applyDelay,
|
|
||||||
reorderEvent,
|
reorderEvent,
|
||||||
swapEvents,
|
swapEvents,
|
||||||
batchUpdateEvents,
|
updateEvent,
|
||||||
|
updateTimer,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -8,13 +8,12 @@ import { OntimeEvent, SupportedEvent } from 'ontime-types';
|
|||||||
*/
|
*/
|
||||||
type ClonedEvent = Omit<
|
type ClonedEvent = Omit<
|
||||||
OntimeEvent,
|
OntimeEvent,
|
||||||
'id' | 'user0' | 'user1' | 'user2' | 'user3' | 'user4' | 'user5' | 'user6' | 'user7' | 'user8' | 'user9'
|
'id' | 'cue' | 'user0' | 'user1' | 'user2' | 'user3' | 'user4' | 'user5' | 'user6' | 'user7' | 'user8' | 'user9'
|
||||||
>;
|
>;
|
||||||
export const cloneEvent = (event: OntimeEvent, after?: string): ClonedEvent => {
|
export const cloneEvent = (event: OntimeEvent, after?: string): ClonedEvent => {
|
||||||
return {
|
return {
|
||||||
type: SupportedEvent.Event,
|
type: SupportedEvent.Event,
|
||||||
title: event.title,
|
title: event.title,
|
||||||
cue: event.cue,
|
|
||||||
subtitle: event.subtitle,
|
subtitle: event.subtitle,
|
||||||
presenter: event.presenter,
|
presenter: event.presenter,
|
||||||
note: event.note,
|
note: event.note,
|
||||||
@@ -26,7 +25,7 @@ export const cloneEvent = (event: OntimeEvent, after?: string): ClonedEvent => {
|
|||||||
isPublic: event.isPublic,
|
isPublic: event.isPublic,
|
||||||
skip: event.skip,
|
skip: event.skip,
|
||||||
colour: event.colour,
|
colour: event.colour,
|
||||||
after: after,
|
after,
|
||||||
revision: 0,
|
revision: 0,
|
||||||
timeWarning: event.timeWarning,
|
timeWarning: event.timeWarning,
|
||||||
timeDanger: event.timeDanger,
|
timeDanger: event.timeDanger,
|
||||||
|
|||||||
@@ -1,44 +0,0 @@
|
|||||||
export type TimeEntryField = 'timeStart' | 'timeEnd' | 'durationOverride' | 'timeWarning' | 'timeDanger';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @description Checks which field the value relates to
|
|
||||||
*/
|
|
||||||
export const handleTimeEntry = (
|
|
||||||
field: TimeEntryField,
|
|
||||||
val: number,
|
|
||||||
timeStart: number,
|
|
||||||
timeEnd: number,
|
|
||||||
): { start: number; end: number; durationOverride: boolean } => {
|
|
||||||
let start = timeStart;
|
|
||||||
let end = timeEnd;
|
|
||||||
let durationOverride = false;
|
|
||||||
|
|
||||||
if (field === 'timeStart') {
|
|
||||||
start = val;
|
|
||||||
} else if (field === 'timeEnd') {
|
|
||||||
end = val;
|
|
||||||
} else {
|
|
||||||
durationOverride = field === 'durationOverride';
|
|
||||||
}
|
|
||||||
return { start, end, durationOverride };
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @description Validates time entry
|
|
||||||
*/
|
|
||||||
export const validateEntry = (
|
|
||||||
field: TimeEntryField,
|
|
||||||
value: number,
|
|
||||||
timeStart: number,
|
|
||||||
timeEnd: number,
|
|
||||||
): { value: boolean; warnings: { start?: string; end?: string; duration?: string } } => {
|
|
||||||
const validate = { value: true, warnings: { start: '', end: '', duration: '' } };
|
|
||||||
|
|
||||||
const { start, end } = handleTimeEntry(field, value, timeStart, timeEnd);
|
|
||||||
|
|
||||||
if (end < start) {
|
|
||||||
validate.warnings.start = 'Start time later than end time';
|
|
||||||
}
|
|
||||||
|
|
||||||
return validate;
|
|
||||||
};
|
|
||||||
@@ -2,7 +2,6 @@
|
|||||||
height: calc(100% - 1.5rem);
|
height: calc(100% - 1.5rem);
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
padding-top: 0.5rem;
|
padding-top: 0.5rem;
|
||||||
flex: 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.eventContainer {
|
.eventContainer {
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { Fragment, lazy, useCallback, useEffect, useRef, useState } from 'react';
|
import { Fragment, lazy, useCallback, useEffect, useRef, useState } from 'react';
|
||||||
import { closestCenter, DndContext, DragEndEvent, PointerSensor, useSensor, useSensors } from '@dnd-kit/core';
|
import { closestCenter, DndContext, DragEndEvent, PointerSensor, useSensor, useSensors } from '@dnd-kit/core';
|
||||||
import { arrayMove, SortableContext, verticalListSortingStrategy } from '@dnd-kit/sortable';
|
import { arrayMove, SortableContext, verticalListSortingStrategy } from '@dnd-kit/sortable';
|
||||||
import { OntimeRundown, Playback, SupportedEvent } from 'ontime-types';
|
import { isOntimeBlock, isOntimeDelay, isOntimeEvent, OntimeRundown, Playback, SupportedEvent } from 'ontime-types';
|
||||||
import { getFirst, getNext, getPrevious } from 'ontime-utils';
|
import { getFirst, getNext, getPrevious } from 'ontime-utils';
|
||||||
|
|
||||||
import { useEventAction } from '../../common/hooks/useEventAction';
|
import { useEventAction } from '../../common/hooks/useEventAction';
|
||||||
@@ -38,7 +38,7 @@ export default function Rundown(props: RundownProps) {
|
|||||||
const viewFollowsCursor = appMode === AppMode.Run;
|
const viewFollowsCursor = appMode === AppMode.Run;
|
||||||
const cursorRef = useRef<HTMLDivElement | null>(null);
|
const cursorRef = useRef<HTMLDivElement | null>(null);
|
||||||
const scrollRef = useRef<HTMLDivElement | null>(null);
|
const scrollRef = useRef<HTMLDivElement | null>(null);
|
||||||
useFollowComponent({ followRef: cursorRef, scrollRef: scrollRef, doFollow: true });
|
useFollowComponent({ followRef: cursorRef, scrollRef, doFollow: true });
|
||||||
|
|
||||||
// DND KIT
|
// DND KIT
|
||||||
const sensors = useSensors(useSensor(PointerSensor));
|
const sensors = useSensors(useSensor(PointerSensor));
|
||||||
@@ -66,8 +66,8 @@ export default function Rundown(props: RundownProps) {
|
|||||||
type: SupportedEvent.Event,
|
type: SupportedEvent.Event,
|
||||||
};
|
};
|
||||||
const options = {
|
const options = {
|
||||||
defaultPublic: defaultPublic,
|
defaultPublic,
|
||||||
startTimeIsLastEnd: startTimeIsLastEnd,
|
startTimeIsLastEnd,
|
||||||
lastEventId: cursor,
|
lastEventId: cursor,
|
||||||
after: cursor,
|
after: cursor,
|
||||||
};
|
};
|
||||||
@@ -197,7 +197,7 @@ export default function Rundown(props: RundownProps) {
|
|||||||
return <RundownEmpty handleAddNew={() => insertAtCursor(SupportedEvent.Event, null)} />;
|
return <RundownEmpty handleAddNew={() => insertAtCursor(SupportedEvent.Event, null)} />;
|
||||||
}
|
}
|
||||||
|
|
||||||
let previousEnd = 0;
|
let previousEnd: null | number = null;
|
||||||
let thisEnd = 0;
|
let thisEnd = 0;
|
||||||
let previousEventId: string | undefined;
|
let previousEventId: string | undefined;
|
||||||
let eventIndex = 0;
|
let eventIndex = 0;
|
||||||
@@ -213,10 +213,13 @@ export default function Rundown(props: RundownProps) {
|
|||||||
eventIndex = 0;
|
eventIndex = 0;
|
||||||
}
|
}
|
||||||
let isFirstEvent = false;
|
let isFirstEvent = false;
|
||||||
if (entry.type === SupportedEvent.Event) {
|
if (isOntimeEvent(entry)) {
|
||||||
isFirstEvent = eventIndex === 0;
|
isFirstEvent = eventIndex === 0;
|
||||||
|
// event indexes are 1 based in frontend
|
||||||
eventIndex++;
|
eventIndex++;
|
||||||
previousEnd = thisEnd;
|
if (!isFirstEvent) {
|
||||||
|
previousEnd = thisEnd;
|
||||||
|
}
|
||||||
thisEnd = entry.timeEnd;
|
thisEnd = entry.timeEnd;
|
||||||
previousEventId = entry.id;
|
previousEventId = entry.id;
|
||||||
}
|
}
|
||||||
@@ -236,7 +239,6 @@ export default function Rundown(props: RundownProps) {
|
|||||||
<RundownEntry
|
<RundownEntry
|
||||||
type={entry.type}
|
type={entry.type}
|
||||||
isPast={isPast}
|
isPast={isPast}
|
||||||
isFirstEvent={isFirstEvent}
|
|
||||||
eventIndex={eventIndex}
|
eventIndex={eventIndex}
|
||||||
data={entry}
|
data={entry}
|
||||||
selected={isSelected}
|
selected={isSelected}
|
||||||
@@ -255,8 +257,8 @@ export default function Rundown(props: RundownProps) {
|
|||||||
showKbd={hasCursor}
|
showKbd={hasCursor}
|
||||||
eventId={entry.id}
|
eventId={entry.id}
|
||||||
previousEventId={previousEventId}
|
previousEventId={previousEventId}
|
||||||
disableAddDelay={entry.type === SupportedEvent.Delay}
|
disableAddDelay={isOntimeDelay(entry)}
|
||||||
disableAddBlock={entry.type === SupportedEvent.Block}
|
disableAddBlock={isOntimeBlock(entry)}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
</Fragment>
|
</Fragment>
|
||||||
|
|||||||
@@ -2,12 +2,12 @@ import { useCallback } from 'react';
|
|||||||
import {
|
import {
|
||||||
GetRundownCached,
|
GetRundownCached,
|
||||||
isOntimeEvent,
|
isOntimeEvent,
|
||||||
|
MaybeNumber,
|
||||||
OntimeEvent,
|
OntimeEvent,
|
||||||
OntimeRundownEntry,
|
OntimeRundownEntry,
|
||||||
Playback,
|
Playback,
|
||||||
SupportedEvent,
|
SupportedEvent,
|
||||||
} from 'ontime-types';
|
} from 'ontime-types';
|
||||||
import { calculateDuration, getCueCandidate } from 'ontime-utils';
|
|
||||||
|
|
||||||
import { RUNDOWN } from '../../common/api/apiConstants';
|
import { RUNDOWN } from '../../common/api/apiConstants';
|
||||||
import { useEventAction } from '../../common/hooks/useEventAction';
|
import { useEventAction } from '../../common/hooks/useEventAction';
|
||||||
@@ -28,17 +28,16 @@ export type EventItemActions = 'set-cursor' | 'event' | 'delay' | 'block' | 'del
|
|||||||
interface RundownEntryProps {
|
interface RundownEntryProps {
|
||||||
type: SupportedEvent;
|
type: SupportedEvent;
|
||||||
isPast: boolean;
|
isPast: boolean;
|
||||||
isFirstEvent: boolean;
|
|
||||||
data: OntimeRundownEntry;
|
data: OntimeRundownEntry;
|
||||||
selected: boolean;
|
selected: boolean;
|
||||||
eventIndex: number;
|
eventIndex: number;
|
||||||
hasCursor: boolean;
|
hasCursor: boolean;
|
||||||
next: boolean;
|
next: boolean;
|
||||||
previousEnd: number;
|
previousEnd: MaybeNumber;
|
||||||
previousEventId?: string;
|
previousEventId?: string;
|
||||||
playback?: Playback; // we only care about this if this event is playing
|
playback?: Playback; // we only care about this if this event is playing
|
||||||
isRolling: boolean; // we need to know even if not related to this event
|
isRolling: boolean; // we need to know even if not related to this event
|
||||||
disableEdit: boolean; // we disable edit when the window is extracted
|
disableEdit: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function RundownEntry(props: RundownEntryProps) {
|
export default function RundownEntry(props: RundownEntryProps) {
|
||||||
@@ -53,7 +52,6 @@ export default function RundownEntry(props: RundownEntryProps) {
|
|||||||
playback,
|
playback,
|
||||||
isRolling,
|
isRolling,
|
||||||
disableEdit,
|
disableEdit,
|
||||||
isFirstEvent,
|
|
||||||
eventIndex,
|
eventIndex,
|
||||||
} = props;
|
} = props;
|
||||||
const { emitError } = useEmitLog();
|
const { emitError } = useEmitLog();
|
||||||
@@ -111,9 +109,7 @@ export default function RundownEntry(props: RundownEntryProps) {
|
|||||||
}
|
}
|
||||||
case 'clone': {
|
case 'clone': {
|
||||||
const newEvent = cloneEvent(data as OntimeEvent, data.id);
|
const newEvent = cloneEvent(data as OntimeEvent, data.id);
|
||||||
const rundown = ontimeQueryClient.getQueryData<GetRundownCached>(RUNDOWN)?.rundown ?? [];
|
addEvent(newEvent, { after: data.id });
|
||||||
newEvent.cue = getCueCandidate(rundown, data.id);
|
|
||||||
addEvent(newEvent);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 'update': {
|
case 'update': {
|
||||||
@@ -139,26 +135,6 @@ export default function RundownEntry(props: RundownEntryProps) {
|
|||||||
batchUpdateEvents(changes, eventIds);
|
batchUpdateEvents(changes, eventIds);
|
||||||
return clearSelectedEvents();
|
return clearSelectedEvents();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (field === 'durationOverride' && data.type === SupportedEvent.Event) {
|
|
||||||
// duration defines timeEnd
|
|
||||||
newData.duration = value as number;
|
|
||||||
newData.timeEnd = data.timeStart + (value as number);
|
|
||||||
return updateEvent(newData);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (field === 'timeStart' && data.type === SupportedEvent.Event) {
|
|
||||||
newData.duration = calculateDuration(value as number, data.timeEnd);
|
|
||||||
newData.timeStart = value as number;
|
|
||||||
return updateEvent(newData);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (field === 'timeEnd' && data.type === SupportedEvent.Event) {
|
|
||||||
newData.duration = calculateDuration(data.timeStart, value as number);
|
|
||||||
newData.timeEnd = value as number;
|
|
||||||
return updateEvent(newData);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (field in data) {
|
if (field in data) {
|
||||||
// @ts-expect-error not sure how to type this
|
// @ts-expect-error not sure how to type this
|
||||||
newData[field] = value;
|
newData[field] = value;
|
||||||
@@ -186,7 +162,7 @@ export default function RundownEntry(props: RundownEntryProps) {
|
|||||||
timerType={data.timerType}
|
timerType={data.timerType}
|
||||||
title={data.title}
|
title={data.title}
|
||||||
note={data.note}
|
note={data.note}
|
||||||
delay={data.delay || 0}
|
delay={data.delay ?? 0}
|
||||||
previousEnd={previousEnd}
|
previousEnd={previousEnd}
|
||||||
colour={data.colour}
|
colour={data.colour}
|
||||||
isPast={isPast}
|
isPast={isPast}
|
||||||
@@ -198,7 +174,6 @@ export default function RundownEntry(props: RundownEntryProps) {
|
|||||||
isRolling={isRolling}
|
isRolling={isRolling}
|
||||||
actionHandler={actionHandler}
|
actionHandler={actionHandler}
|
||||||
disableEdit={disableEdit}
|
disableEdit={disableEdit}
|
||||||
isFirstEvent={isFirstEvent}
|
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
} else if (data.type === SupportedEvent.Block) {
|
} else if (data.type === SupportedEvent.Block) {
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ $skip-opacity: 0.1;
|
|||||||
grid-template-areas:
|
grid-template-areas:
|
||||||
'binder ... ... ...'
|
'binder ... ... ...'
|
||||||
'binder pb-actions times actions'
|
'binder pb-actions times actions'
|
||||||
'binder pb-actions title next-ind'
|
'binder pb-actions title next'
|
||||||
'binder pb-actions estatus estatus'
|
'binder pb-actions estatus estatus'
|
||||||
'binder ... ... ...';
|
'binder ... ... ...';
|
||||||
|
|
||||||
@@ -53,7 +53,7 @@ $skip-opacity: 0.1;
|
|||||||
|
|
||||||
/* we stop the eventActions from having opacity to fix issue with dropdown drawing order */
|
/* we stop the eventActions from having opacity to fix issue with dropdown drawing order */
|
||||||
&.past:not(.skip) {
|
&.past:not(.skip) {
|
||||||
.delayNote,
|
.timerNote,
|
||||||
.statusElements,
|
.statusElements,
|
||||||
.eventTitle,
|
.eventTitle,
|
||||||
.eventNote,
|
.eventNote,
|
||||||
@@ -68,7 +68,7 @@ $skip-opacity: 0.1;
|
|||||||
&.skip {
|
&.skip {
|
||||||
border: 1px solid $white-3;
|
border: 1px solid $white-3;
|
||||||
|
|
||||||
.delayNote,
|
.timerNote,
|
||||||
.eventTitle,
|
.eventTitle,
|
||||||
.eventNote,
|
.eventNote,
|
||||||
.binder,
|
.binder,
|
||||||
@@ -127,10 +127,12 @@ $skip-opacity: 0.1;
|
|||||||
gap: $block-clearance;
|
gap: $block-clearance;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
|
|
||||||
.delayNote {
|
.timerNote {
|
||||||
font-size: 0.75rem;
|
display: grid;
|
||||||
line-height: 0.8rem;
|
place-content: center;
|
||||||
color: $ontime-delay-text;
|
color: $blue-500;
|
||||||
|
margin-right: 0.5em;
|
||||||
|
font-size: 1.5em;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -189,7 +191,7 @@ $skip-opacity: 0.1;
|
|||||||
}
|
}
|
||||||
|
|
||||||
.nextTag {
|
.nextTag {
|
||||||
grid-area: next-ind;
|
grid-area: next;
|
||||||
font-size: 1rem;
|
font-size: 1rem;
|
||||||
color: $orange-500;
|
color: $orange-500;
|
||||||
letter-spacing: 0.03px;
|
letter-spacing: 0.03px;
|
||||||
@@ -197,31 +199,6 @@ $skip-opacity: 0.1;
|
|||||||
text-align: right;
|
text-align: right;
|
||||||
}
|
}
|
||||||
|
|
||||||
.indicators {
|
|
||||||
grid-area: next-ind;
|
|
||||||
display: flex;
|
|
||||||
justify-content: flex-end;
|
|
||||||
align-items: center;
|
|
||||||
gap: 0.5rem;
|
|
||||||
|
|
||||||
.indicator {
|
|
||||||
background-color: transparent;
|
|
||||||
margin: 0.4rem;
|
|
||||||
margin-right: 0;
|
|
||||||
border-radius: 0.7rem;
|
|
||||||
width: 0.7rem;
|
|
||||||
height: 0.7rem;
|
|
||||||
}
|
|
||||||
.indicator.delay {
|
|
||||||
background-color: $ontime-delay;
|
|
||||||
}
|
|
||||||
.indicator.nextDay,
|
|
||||||
.indicator.overlap,
|
|
||||||
.indicator.spacing {
|
|
||||||
background-color: $gray-600;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.eventStatus {
|
.eventStatus {
|
||||||
grid-area: status;
|
grid-area: status;
|
||||||
display: flex;
|
display: flex;
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import { IoPeople } from '@react-icons/all-files/io5/IoPeople';
|
|||||||
import { IoPeopleOutline } from '@react-icons/all-files/io5/IoPeopleOutline';
|
import { IoPeopleOutline } from '@react-icons/all-files/io5/IoPeopleOutline';
|
||||||
import { IoReorderTwo } from '@react-icons/all-files/io5/IoReorderTwo';
|
import { IoReorderTwo } from '@react-icons/all-files/io5/IoReorderTwo';
|
||||||
import { IoSwapVertical } from '@react-icons/all-files/io5/IoSwapVertical';
|
import { IoSwapVertical } from '@react-icons/all-files/io5/IoSwapVertical';
|
||||||
import { EndAction, OntimeEvent, Playback, TimerType } from 'ontime-types';
|
import { EndAction, MaybeNumber, OntimeEvent, Playback, TimerType } from 'ontime-types';
|
||||||
|
|
||||||
import { useContextMenu } from '../../../common/hooks/useContextMenu';
|
import { useContextMenu } from '../../../common/hooks/useContextMenu';
|
||||||
import useRundown from '../../../common/hooks-query/useRundown';
|
import useRundown from '../../../common/hooks-query/useRundown';
|
||||||
@@ -19,6 +19,7 @@ import { useEventIdSwapping } from '../useEventIdSwapping';
|
|||||||
import { EditMode, useEventSelection } from '../useEventSelection';
|
import { EditMode, useEventSelection } from '../useEventSelection';
|
||||||
|
|
||||||
import EventBlockInner from './EventBlockInner';
|
import EventBlockInner from './EventBlockInner';
|
||||||
|
import RundownIndicators from './RundownIndicators';
|
||||||
|
|
||||||
import style from './EventBlock.module.scss';
|
import style from './EventBlock.module.scss';
|
||||||
|
|
||||||
@@ -47,7 +48,7 @@ interface EventBlockProps {
|
|||||||
title: string;
|
title: string;
|
||||||
note: string;
|
note: string;
|
||||||
delay: number;
|
delay: number;
|
||||||
previousEnd: number;
|
previousEnd: MaybeNumber;
|
||||||
colour: string;
|
colour: string;
|
||||||
isPast: boolean;
|
isPast: boolean;
|
||||||
next: boolean;
|
next: boolean;
|
||||||
@@ -66,7 +67,6 @@ interface EventBlockProps {
|
|||||||
},
|
},
|
||||||
) => void;
|
) => void;
|
||||||
disableEdit: boolean;
|
disableEdit: boolean;
|
||||||
isFirstEvent: boolean;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function EventBlock(props: EventBlockProps) {
|
export default function EventBlock(props: EventBlockProps) {
|
||||||
@@ -94,7 +94,6 @@ export default function EventBlock(props: EventBlockProps) {
|
|||||||
isRolling,
|
isRolling,
|
||||||
actionHandler,
|
actionHandler,
|
||||||
disableEdit,
|
disableEdit,
|
||||||
isFirstEvent,
|
|
||||||
} = props;
|
} = props;
|
||||||
const { selectedEventId, setSelectedEventId, clearSelectedEventId } = useEventIdSwapping();
|
const { selectedEventId, setSelectedEventId, clearSelectedEventId } = useEventIdSwapping();
|
||||||
const { selectedEvents, setSelectedEvents } = useEventSelection();
|
const { selectedEvents, setSelectedEvents } = useEventSelection();
|
||||||
@@ -253,12 +252,15 @@ export default function EventBlock(props: EventBlockProps) {
|
|||||||
onContextMenu={onContextMenu}
|
onContextMenu={onContextMenu}
|
||||||
id='event-block'
|
id='event-block'
|
||||||
>
|
>
|
||||||
|
<RundownIndicators timeStart={timeStart} previousEnd={previousEnd} delay={delay} />
|
||||||
|
|
||||||
<div className={style.binder} style={{ ...binderColours }} tabIndex={-1}>
|
<div className={style.binder} style={{ ...binderColours }} tabIndex={-1}>
|
||||||
<span className={style.drag} ref={handleRef} {...dragAttributes} {...dragListeners}>
|
<span className={style.drag} ref={handleRef} {...dragAttributes} {...dragListeners}>
|
||||||
<IoReorderTwo />
|
<IoReorderTwo />
|
||||||
</span>
|
</span>
|
||||||
<span className={style.cue}>{cue}</span>
|
<span className={style.cue}>{cue}</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{isVisible && (
|
{isVisible && (
|
||||||
<EventBlockInner
|
<EventBlockInner
|
||||||
timeStart={timeStart}
|
timeStart={timeStart}
|
||||||
@@ -272,7 +274,6 @@ export default function EventBlock(props: EventBlockProps) {
|
|||||||
title={title}
|
title={title}
|
||||||
note={note}
|
note={note}
|
||||||
delay={delay}
|
delay={delay}
|
||||||
previousEnd={previousEnd}
|
|
||||||
next={next}
|
next={next}
|
||||||
skip={skip}
|
skip={skip}
|
||||||
selected={selected}
|
selected={selected}
|
||||||
@@ -280,7 +281,6 @@ export default function EventBlock(props: EventBlockProps) {
|
|||||||
isRolling={isRolling}
|
isRolling={isRolling}
|
||||||
actionHandler={actionHandler}
|
actionHandler={actionHandler}
|
||||||
disableEdit={disableEdit}
|
disableEdit={disableEdit}
|
||||||
isFirstEvent={isFirstEvent}
|
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -11,10 +11,8 @@ import { IoPlaySkipForward } from '@react-icons/all-files/io5/IoPlaySkipForward'
|
|||||||
import { IoStop } from '@react-icons/all-files/io5/IoStop';
|
import { IoStop } from '@react-icons/all-files/io5/IoStop';
|
||||||
import { IoTime } from '@react-icons/all-files/io5/IoTime';
|
import { IoTime } from '@react-icons/all-files/io5/IoTime';
|
||||||
import { EndAction, Playback, TimerType } from 'ontime-types';
|
import { EndAction, Playback, TimerType } from 'ontime-types';
|
||||||
import { millisToString } from 'ontime-utils';
|
|
||||||
|
|
||||||
import TooltipActionBtn from '../../../common/components/buttons/TooltipActionBtn';
|
import TooltipActionBtn from '../../../common/components/buttons/TooltipActionBtn';
|
||||||
import { millisToDelayString } from '../../../common/utils/dateConfig';
|
|
||||||
import { tooltipDelayMid } from '../../../ontimeConfig';
|
import { tooltipDelayMid } from '../../../ontimeConfig';
|
||||||
import EditableBlockTitle from '../common/EditableBlockTitle';
|
import EditableBlockTitle from '../common/EditableBlockTitle';
|
||||||
import { EventItemActions } from '../RundownEntry';
|
import { EventItemActions } from '../RundownEntry';
|
||||||
@@ -47,7 +45,6 @@ interface EventBlockInnerProps {
|
|||||||
title: string;
|
title: string;
|
||||||
note: string;
|
note: string;
|
||||||
delay: number;
|
delay: number;
|
||||||
previousEnd: number;
|
|
||||||
next: boolean;
|
next: boolean;
|
||||||
skip: boolean;
|
skip: boolean;
|
||||||
selected: boolean;
|
selected: boolean;
|
||||||
@@ -55,7 +52,6 @@ interface EventBlockInnerProps {
|
|||||||
isRolling: boolean;
|
isRolling: boolean;
|
||||||
actionHandler: (action: EventItemActions, payload?: any) => void;
|
actionHandler: (action: EventItemActions, payload?: any) => void;
|
||||||
disableEdit: boolean;
|
disableEdit: boolean;
|
||||||
isFirstEvent: boolean;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const EventBlockInner = (props: EventBlockInnerProps) => {
|
const EventBlockInner = (props: EventBlockInnerProps) => {
|
||||||
@@ -70,7 +66,6 @@ const EventBlockInner = (props: EventBlockInnerProps) => {
|
|||||||
title,
|
title,
|
||||||
note,
|
note,
|
||||||
delay,
|
delay,
|
||||||
previousEnd,
|
|
||||||
next,
|
next,
|
||||||
skip = false,
|
skip = false,
|
||||||
selected,
|
selected,
|
||||||
@@ -78,7 +73,6 @@ const EventBlockInner = (props: EventBlockInnerProps) => {
|
|||||||
isRolling,
|
isRolling,
|
||||||
actionHandler,
|
actionHandler,
|
||||||
disableEdit,
|
disableEdit,
|
||||||
isFirstEvent,
|
|
||||||
} = props;
|
} = props;
|
||||||
|
|
||||||
const [renderInner, setRenderInner] = useState(false);
|
const [renderInner, setRenderInner] = useState(false);
|
||||||
@@ -111,59 +105,14 @@ const EventBlockInner = (props: EventBlockInnerProps) => {
|
|||||||
playBtnStyles._hover = {};
|
playBtnStyles._hover = {};
|
||||||
}
|
}
|
||||||
|
|
||||||
const delayedStart = Math.max(0, timeStart + delay);
|
|
||||||
const newTime = millisToString(delayedStart);
|
|
||||||
const delayTime = delay !== 0 ? millisToDelayString(delay) : null;
|
|
||||||
|
|
||||||
const overlap = previousEnd - timeStart;
|
|
||||||
const overlapTime = !isFirstEvent
|
|
||||||
? overlap > 0
|
|
||||||
? `Overlapping ${millisToDelayString(overlap)}`
|
|
||||||
: overlap < 0
|
|
||||||
? `Spacing ${millisToDelayString(overlap)}`
|
|
||||||
: null
|
|
||||||
: null;
|
|
||||||
|
|
||||||
return !renderInner ? null : (
|
return !renderInner ? null : (
|
||||||
<>
|
<>
|
||||||
<EventBlockTimers
|
<EventBlockTimers eventId={eventId} timeStart={timeStart} timeEnd={timeEnd} duration={duration} delay={delay} />
|
||||||
eventId={eventId}
|
|
||||||
timeStart={timeStart}
|
|
||||||
timeEnd={timeEnd}
|
|
||||||
duration={duration}
|
|
||||||
delay={delay}
|
|
||||||
previousEnd={previousEnd}
|
|
||||||
/>
|
|
||||||
<EditableBlockTitle title={title} eventId={eventId} placeholder='Event title' className={style.eventTitle} />
|
<EditableBlockTitle title={title} eventId={eventId} placeholder='Event title' className={style.eventTitle} />
|
||||||
{next ? (
|
{next && (
|
||||||
<Tooltip label='Next event' {...tooltipProps}>
|
<Tooltip label='Next event' {...tooltipProps}>
|
||||||
<span className={style.nextTag}>UP NEXT</span>
|
<span className={style.nextTag}>UP NEXT</span>
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
) : (
|
|
||||||
<span className={style.indicators}>
|
|
||||||
{delayTime && (
|
|
||||||
<Tooltip
|
|
||||||
label={
|
|
||||||
<div>
|
|
||||||
{delayTime} <br />
|
|
||||||
New Time: {newTime}
|
|
||||||
</div>
|
|
||||||
}
|
|
||||||
>
|
|
||||||
<div className={`${style.indicator} ${style.delay}`} />
|
|
||||||
</Tooltip>
|
|
||||||
)}
|
|
||||||
{overlapTime && (
|
|
||||||
<Tooltip label={overlapTime}>
|
|
||||||
<div className={`${style.indicator} ${overlap > 0 ? style.overlap : style.spacing}`} />
|
|
||||||
</Tooltip>
|
|
||||||
)}
|
|
||||||
{timeStart > timeEnd && (
|
|
||||||
<Tooltip label='Start time is later than end'>
|
|
||||||
<div className={`${style.indicator} ${style.nextDay}`} />
|
|
||||||
</Tooltip>
|
|
||||||
)}
|
|
||||||
</span>
|
|
||||||
)}
|
)}
|
||||||
<EventBlockPlayback
|
<EventBlockPlayback
|
||||||
eventId={eventId}
|
eventId={eventId}
|
||||||
|
|||||||
@@ -0,0 +1,25 @@
|
|||||||
|
.indicators {
|
||||||
|
font-size: calc(1rem - 5px);
|
||||||
|
position: absolute;
|
||||||
|
top: -1em;
|
||||||
|
z-index: 2;
|
||||||
|
margin: 0 20%;
|
||||||
|
width: 60%;
|
||||||
|
|
||||||
|
display: flex;
|
||||||
|
gap: 0.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
@mixin indicator($bg-colour) {
|
||||||
|
padding: 0 0.5rem;
|
||||||
|
border-radius: 2px;
|
||||||
|
background-color: $bg-colour;
|
||||||
|
}
|
||||||
|
|
||||||
|
.delay {
|
||||||
|
@include indicator($ontime-delay);
|
||||||
|
}
|
||||||
|
|
||||||
|
.gap {
|
||||||
|
@include indicator($blue-500);
|
||||||
|
}
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
import { millisToString, removeLeadingZero, removeTrailingZero } from 'ontime-utils';
|
||||||
|
|
||||||
|
import style from './RundownIndicators.module.scss';
|
||||||
|
|
||||||
|
interface RundownIndicatorProps {
|
||||||
|
timeStart: number;
|
||||||
|
previousEnd: number | null;
|
||||||
|
delay: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
function formatDelay(timeStart: number, delay: number): string | undefined {
|
||||||
|
if (!delay) return;
|
||||||
|
|
||||||
|
const delayedStart = Math.max(0, timeStart + delay);
|
||||||
|
const timeTag = removeTrailingZero(millisToString(delayedStart));
|
||||||
|
return `New start: ${timeTag}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
function formatOverlap(previousEnd: number | null, timeStart: number): string | undefined {
|
||||||
|
if (previousEnd === null) return;
|
||||||
|
|
||||||
|
const overlap = previousEnd - timeStart;
|
||||||
|
if (overlap === 0) return;
|
||||||
|
|
||||||
|
const overlapString = removeLeadingZero(millisToString(Math.abs(overlap)));
|
||||||
|
|
||||||
|
return `${overlap > 0 ? 'Overlap' : 'Gap'}: ${overlapString}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function RundownIndicators(props: RundownIndicatorProps) {
|
||||||
|
const { timeStart, previousEnd, delay } = props;
|
||||||
|
|
||||||
|
const hasOverlap = formatOverlap(previousEnd, timeStart);
|
||||||
|
const hasDelay = formatDelay(timeStart, delay);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className={style.indicators}>
|
||||||
|
{hasDelay && <div className={style.delay}>{hasDelay}</div>}
|
||||||
|
{hasOverlap && <div className={style.gap}>{hasOverlap}</div>}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -1,10 +1,12 @@
|
|||||||
import { memo } from 'react';
|
import { memo } from 'react';
|
||||||
|
import { Tooltip } from '@chakra-ui/react';
|
||||||
|
import { IoAlertCircleOutline } from '@react-icons/all-files/io5/IoAlertCircleOutline';
|
||||||
import { OntimeEvent } from 'ontime-types';
|
import { OntimeEvent } from 'ontime-types';
|
||||||
import { calculateDuration, millisToString } from 'ontime-utils';
|
|
||||||
|
|
||||||
import TimeInputWithButton from '../../../../common/components/input/time-input/TimeInputWithButton';
|
import TimeInputWithButton from '../../../../common/components/input/time-input/TimeInputWithButton';
|
||||||
import { useEventAction } from '../../../../common/hooks/useEventAction';
|
import { useEventAction } from '../../../../common/hooks/useEventAction';
|
||||||
import { millisToDelayString } from '../../../../common/utils/dateConfig';
|
import { forgivingStringToMillis } from '../../../../common/utils/dateConfig';
|
||||||
|
import { tooltipDelayFast } from '../../../../ontimeConfig';
|
||||||
|
|
||||||
import style from '../EventBlock.module.scss';
|
import style from '../EventBlock.module.scss';
|
||||||
|
|
||||||
@@ -14,73 +16,64 @@ interface EventBlockTimerProps {
|
|||||||
timeEnd: number;
|
timeEnd: number;
|
||||||
duration: number;
|
duration: number;
|
||||||
delay: number;
|
delay: number;
|
||||||
previousEnd: number;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type TimeActions = 'timeStart' | 'timeEnd' | 'durationOverride' | 'timeWarning' | 'timeDanger';
|
type TimeActions = 'timeStart' | 'timeEnd' | 'durationOverride'; // we call it durationOverride to stop from passing as a duration value
|
||||||
|
|
||||||
const EventBlockTimers = (props: EventBlockTimerProps) => {
|
const EventBlockTimers = (props: EventBlockTimerProps) => {
|
||||||
const { eventId, timeStart, timeEnd, duration, delay, previousEnd } = props;
|
const { eventId, timeStart, timeEnd, duration, delay } = props;
|
||||||
const { updateEvent } = useEventAction();
|
const { updateEvent, updateTimer } = useEventAction();
|
||||||
|
|
||||||
const handleSubmit = (field: TimeActions, value: number) => {
|
// In sync with EventEditorTimes
|
||||||
const newEventData: Partial<OntimeEvent> = { id: eventId };
|
const handleSubmit = (field: TimeActions, value: string) => {
|
||||||
switch (field) {
|
if (field === 'timeStart' || field === 'timeEnd') {
|
||||||
case 'durationOverride': {
|
updateTimer(eventId, field, value);
|
||||||
// duration defines timeEnd
|
return;
|
||||||
newEventData.duration = value;
|
}
|
||||||
newEventData.timeEnd = timeStart + value;
|
|
||||||
break;
|
if (field === 'durationOverride') {
|
||||||
}
|
const timeInMillis = forgivingStringToMillis(value);
|
||||||
case 'timeStart': {
|
const newEventData: Partial<OntimeEvent> = { id: eventId, timeEnd: timeStart + timeInMillis };
|
||||||
newEventData.duration = calculateDuration(value, timeEnd);
|
updateEvent(newEventData);
|
||||||
newEventData.timeStart = value;
|
return;
|
||||||
break;
|
|
||||||
}
|
|
||||||
case 'timeEnd': {
|
|
||||||
newEventData.duration = calculateDuration(timeStart, value);
|
|
||||||
newEventData.timeEnd = value;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
updateEvent(newEventData);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const delayedStart = Math.max(0, timeStart + delay);
|
const overMidnight = timeStart > timeEnd;
|
||||||
const newTime = millisToString(delayedStart);
|
const hasDelay = delay !== 0;
|
||||||
const delayTime = delay !== 0 ? millisToDelayString(delay) : null;
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={style.eventTimers}>
|
<div className={style.eventTimers}>
|
||||||
<TimeInputWithButton
|
<TimeInputWithButton<TimeActions>
|
||||||
name='timeStart'
|
name='timeStart'
|
||||||
submitHandler={handleSubmit}
|
submitHandler={handleSubmit}
|
||||||
time={timeStart}
|
time={timeStart}
|
||||||
delay={delay}
|
hasDelay={hasDelay}
|
||||||
placeholder='Start'
|
placeholder='Start'
|
||||||
previousEnd={previousEnd}
|
|
||||||
/>
|
/>
|
||||||
<TimeInputWithButton
|
<TimeInputWithButton<TimeActions>
|
||||||
name='timeEnd'
|
name='timeEnd'
|
||||||
submitHandler={handleSubmit}
|
submitHandler={handleSubmit}
|
||||||
time={timeEnd}
|
time={timeEnd}
|
||||||
delay={delay}
|
hasDelay={hasDelay}
|
||||||
placeholder='End'
|
placeholder='End'
|
||||||
previousEnd={previousEnd}
|
|
||||||
/>
|
/>
|
||||||
<TimeInputWithButton
|
<TimeInputWithButton<TimeActions>
|
||||||
name='durationOverride'
|
name='durationOverride'
|
||||||
submitHandler={handleSubmit}
|
submitHandler={handleSubmit}
|
||||||
time={duration}
|
time={duration}
|
||||||
delay={0}
|
|
||||||
placeholder='Duration'
|
placeholder='Duration'
|
||||||
previousEnd={previousEnd}
|
|
||||||
/>
|
/>
|
||||||
{delayTime && (
|
{overMidnight && (
|
||||||
<div className={style.delayNote}>
|
<div className={style.timerNote}>
|
||||||
{delayTime}
|
<Tooltip
|
||||||
<br />
|
label='End timer before start'
|
||||||
{`New start: ${newTime}`}
|
openDelay={tooltipDelayFast}
|
||||||
|
variant='ontime-ondark'
|
||||||
|
shouldWrapChildren
|
||||||
|
>
|
||||||
|
<IoAlertCircleOutline />
|
||||||
|
</Tooltip>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ export default function EventEditor() {
|
|||||||
);
|
);
|
||||||
|
|
||||||
if (!event) {
|
if (!event) {
|
||||||
return <span>Loading...</span>;
|
return <span data-testid='editor-container'>Loading...</span>;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compositing user fields by hand
|
// Compositing user fields by hand
|
||||||
@@ -80,7 +80,7 @@ export default function EventEditor() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={style.eventEditor}>
|
<div className={style.eventEditor} data-testid='editor-container'>
|
||||||
<div>HEADER ACTIONS?</div>
|
<div>HEADER ACTIONS?</div>
|
||||||
<div className={style.content}>
|
<div className={style.content}>
|
||||||
<EventEditorTimes
|
<EventEditorTimes
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
import { memo } from 'react';
|
import { memo } from 'react';
|
||||||
import { Select, Switch } from '@chakra-ui/react';
|
import { Select, Switch } from '@chakra-ui/react';
|
||||||
import { EndAction, OntimeEvent, TimerType } from 'ontime-types';
|
import { EndAction, OntimeEvent, TimerType } from 'ontime-types';
|
||||||
import { calculateDuration, millisToString } from 'ontime-utils';
|
import { millisToString } from 'ontime-utils';
|
||||||
|
|
||||||
import TimeInput from '../../../../common/components/input/time-input/TimeInput';
|
import TimeInput from '../../../../common/components/input/time-input/TimeInput';
|
||||||
import TimeInputWithButton from '../../../../common/components/input/time-input/TimeInputWithButton';
|
import TimeInputWithButton from '../../../../common/components/input/time-input/TimeInputWithButton';
|
||||||
import { useEventAction } from '../../../../common/hooks/useEventAction';
|
import { useEventAction } from '../../../../common/hooks/useEventAction';
|
||||||
import { millisToDelayString } from '../../../../common/utils/dateConfig';
|
import { forgivingStringToMillis, millisToDelayString } from '../../../../common/utils/dateConfig';
|
||||||
import { cx } from '../../../../common/utils/styleUtils';
|
import { cx } from '../../../../common/utils/styleUtils';
|
||||||
|
|
||||||
import style from '../EventEditor.module.scss';
|
import style from '../EventEditor.module.scss';
|
||||||
@@ -24,60 +24,52 @@ interface EventEditorTimesProps {
|
|||||||
timeDanger: number;
|
timeDanger: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
type TimeActions =
|
type HandledActions = 'timerType' | 'endAction' | 'isPublic' | 'timeWarning' | 'timeDanger';
|
||||||
| 'timeStart'
|
type TimeActions = 'timeStart' | 'timeEnd' | 'durationOverride'; // we call it durationOverride to stop from passing as a duration value
|
||||||
| 'timeEnd'
|
|
||||||
| 'durationOverride'
|
|
||||||
| 'timerType'
|
|
||||||
| 'endAction'
|
|
||||||
| 'isPublic'
|
|
||||||
| 'timeWarning'
|
|
||||||
| 'timeDanger';
|
|
||||||
|
|
||||||
const EventEditorTimes = (props: EventEditorTimesProps) => {
|
const EventEditorTimes = (props: EventEditorTimesProps) => {
|
||||||
const { eventId, timeStart, timeEnd, duration, delay, isPublic, endAction, timerType, timeWarning, timeDanger } =
|
const { eventId, timeStart, timeEnd, duration, delay, isPublic, endAction, timerType, timeWarning, timeDanger } =
|
||||||
props;
|
props;
|
||||||
const { updateEvent } = useEventAction();
|
const { updateEvent, updateTimer } = useEventAction();
|
||||||
|
|
||||||
const handleSubmit = (field: TimeActions, value: number | string | boolean) => {
|
// In sync with EventBlockTimers
|
||||||
const newEventData: Partial<OntimeEvent> = { id: eventId };
|
const handleTimeSubmit = (field: TimeActions, value: string) => {
|
||||||
switch (field) {
|
if (field === 'timeStart' || field === 'timeEnd') {
|
||||||
case 'durationOverride': {
|
updateTimer(eventId, field, value);
|
||||||
// duration defines timeEnd
|
return;
|
||||||
newEventData.duration = value as number;
|
}
|
||||||
newEventData.timeEnd = timeStart + (value as number);
|
|
||||||
break;
|
if (field === 'durationOverride') {
|
||||||
}
|
const timeInMillis = forgivingStringToMillis(value);
|
||||||
case 'timeStart': {
|
const newEventData: Partial<OntimeEvent> = { id: eventId, timeEnd: timeStart + timeInMillis };
|
||||||
newEventData.duration = calculateDuration(value as number, timeEnd);
|
updateEvent(newEventData);
|
||||||
newEventData.timeStart = value as number;
|
return;
|
||||||
break;
|
|
||||||
}
|
|
||||||
case 'timeEnd': {
|
|
||||||
newEventData.duration = calculateDuration(timeStart, value as number);
|
|
||||||
newEventData.timeEnd = value as number;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case 'isPublic': {
|
|
||||||
updateEvent({ id: eventId, isPublic: !(value as boolean) });
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
default: {
|
|
||||||
if (field === 'timerType' || field === 'endAction' || field === 'timeWarning' || field === 'timeDanger') {
|
|
||||||
// @ts-expect-error -- not sure how to typecheck here
|
|
||||||
newEventData[field as keyof OntimeEvent] = value as string;
|
|
||||||
} else {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
updateEvent(newEventData);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const delayTime = delay !== 0 ? millisToDelayString(delay) : null;
|
const handleSubmit = (field: HandledActions, value: string | boolean) => {
|
||||||
const startLabel = delayTime ? `New start ${millisToString(timeStart + delay)}` : 'Start time';
|
if (field === 'isPublic') {
|
||||||
const endLabel = delayTime ? `New end ${millisToString(timeEnd + delay)}` : 'End time';
|
updateEvent({ id: eventId, isPublic: !(value as boolean) });
|
||||||
const inputTimeLabels = cx([style.inputLabel, delayTime ? style.delayLabel : null]);
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (field === 'timeWarning' || field === 'timeDanger') {
|
||||||
|
const newTime = forgivingStringToMillis(value as string);
|
||||||
|
updateEvent({ id: eventId, [field]: newTime });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (field === 'timerType' || field === 'endAction') {
|
||||||
|
updateEvent({ id: eventId, [field]: value });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const hasDelay = delay !== 0;
|
||||||
|
const delayTime = hasDelay ? millisToDelayString(delay) : null;
|
||||||
|
const startLabel = delayTime ? `New Start ${millisToString(timeStart + delay)}` : 'Start time';
|
||||||
|
const endLabel = delayTime ? `New End ${millisToString(timeEnd + delay)}` : 'End time';
|
||||||
|
const inputTimeLabels = cx([style.inputLabel, hasDelay ? style.delayLabel : null]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={style.column}>
|
<div className={style.column}>
|
||||||
@@ -87,11 +79,10 @@ const EventEditorTimes = (props: EventEditorTimesProps) => {
|
|||||||
{startLabel}
|
{startLabel}
|
||||||
</label>
|
</label>
|
||||||
<TimeInputWithButton
|
<TimeInputWithButton
|
||||||
id='timeStart'
|
|
||||||
name='timeStart'
|
name='timeStart'
|
||||||
submitHandler={handleSubmit}
|
submitHandler={handleTimeSubmit}
|
||||||
time={timeStart}
|
time={timeStart}
|
||||||
delay={delay}
|
hasDelay={hasDelay}
|
||||||
placeholder='Start'
|
placeholder='Start'
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
@@ -100,11 +91,10 @@ const EventEditorTimes = (props: EventEditorTimesProps) => {
|
|||||||
{endLabel}
|
{endLabel}
|
||||||
</label>
|
</label>
|
||||||
<TimeInputWithButton
|
<TimeInputWithButton
|
||||||
id='timeEnd'
|
|
||||||
name='timeEnd'
|
name='timeEnd'
|
||||||
submitHandler={handleSubmit}
|
submitHandler={handleTimeSubmit}
|
||||||
time={timeEnd}
|
time={timeEnd}
|
||||||
delay={delay}
|
hasDelay={hasDelay}
|
||||||
placeholder='End'
|
placeholder='End'
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
@@ -113,9 +103,8 @@ const EventEditorTimes = (props: EventEditorTimesProps) => {
|
|||||||
Duration
|
Duration
|
||||||
</label>
|
</label>
|
||||||
<TimeInputWithButton
|
<TimeInputWithButton
|
||||||
id='durationOverride'
|
|
||||||
name='durationOverride'
|
name='durationOverride'
|
||||||
submitHandler={handleSubmit}
|
submitHandler={handleTimeSubmit}
|
||||||
time={duration}
|
time={duration}
|
||||||
placeholder='Duration'
|
placeholder='Duration'
|
||||||
/>
|
/>
|
||||||
@@ -123,18 +112,14 @@ const EventEditorTimes = (props: EventEditorTimesProps) => {
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className={style.splitTwo}>
|
<div className={style.splitTwo}>
|
||||||
<label className={style.inputLabel} htmlFor='timeWarning'>
|
<div>
|
||||||
Warning Time
|
<label className={style.inputLabel} htmlFor='timeWarning'>
|
||||||
<TimeInput
|
Warning Time
|
||||||
id='timeWarning'
|
</label>
|
||||||
name='timeWarning'
|
<TimeInput name='timeWarning' submitHandler={handleSubmit} time={timeWarning} placeholder='Duration' />
|
||||||
submitHandler={handleSubmit}
|
</div>
|
||||||
time={timeWarning}
|
<div>
|
||||||
placeholder='Duration'
|
<label className={style.inputLabel}>Timer Type</label>
|
||||||
/>
|
|
||||||
</label>
|
|
||||||
<label className={style.inputLabel}>
|
|
||||||
Timer Type
|
|
||||||
<Select
|
<Select
|
||||||
size='sm'
|
size='sm'
|
||||||
name='timerType'
|
name='timerType'
|
||||||
@@ -147,19 +132,15 @@ const EventEditorTimes = (props: EventEditorTimesProps) => {
|
|||||||
<option value={TimerType.TimeToEnd}>Time to end</option>
|
<option value={TimerType.TimeToEnd}>Time to end</option>
|
||||||
<option value={TimerType.Clock}>Clock</option>
|
<option value={TimerType.Clock}>Clock</option>
|
||||||
</Select>
|
</Select>
|
||||||
</label>
|
</div>
|
||||||
<label className={style.inputLabel} htmlFor='timeDanger'>
|
<div>
|
||||||
Danger Time
|
<label className={style.inputLabel} htmlFor='timeDanger'>
|
||||||
<TimeInput
|
Danger Time
|
||||||
id='timeDanger'
|
</label>
|
||||||
name='timeDanger'
|
<TimeInput name='timeDanger' submitHandler={handleSubmit} time={timeDanger} placeholder='Duration' />
|
||||||
submitHandler={handleSubmit}
|
</div>
|
||||||
time={timeDanger}
|
<div>
|
||||||
placeholder='Duration'
|
<label className={style.inputLabel}>End Action</label>
|
||||||
/>
|
|
||||||
</label>
|
|
||||||
<label className={style.inputLabel}>
|
|
||||||
End Action
|
|
||||||
<Select
|
<Select
|
||||||
size='sm'
|
size='sm'
|
||||||
name='endAction'
|
name='endAction'
|
||||||
@@ -172,11 +153,11 @@ const EventEditorTimes = (props: EventEditorTimesProps) => {
|
|||||||
<option value={EndAction.LoadNext}>Load Next</option>
|
<option value={EndAction.LoadNext}>Load Next</option>
|
||||||
<option value={EndAction.PlayNext}>Play Next</option>
|
<option value={EndAction.PlayNext}>Play Next</option>
|
||||||
</Select>
|
</Select>
|
||||||
</label>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<span className={style.inputLabel}>Event visibility</span>
|
<span className={style.inputLabel}>Event Visibility</span>
|
||||||
<label className={style.switchLabel}>
|
<label className={style.switchLabel}>
|
||||||
<Switch isChecked={isPublic} onChange={() => handleSubmit('isPublic', isPublic)} variant='ontime' />
|
<Switch isChecked={isPublic} onChange={() => handleSubmit('isPublic', isPublic)} variant='ontime' />
|
||||||
{isPublic ? 'Public' : 'Private'}
|
{isPublic ? 'Public' : 'Private'}
|
||||||
|
|||||||
@@ -31,8 +31,10 @@ const EventEditorTitles = (props: EventEditorLeftProps) => {
|
|||||||
return (
|
return (
|
||||||
<div className={style.column}>
|
<div className={style.column}>
|
||||||
<div className={style.splitTwo}>
|
<div className={style.splitTwo}>
|
||||||
<label className={style.inputLabel} htmlFor='eventId'>
|
<div>
|
||||||
Event ID (read only)
|
<label className={style.inputLabel} htmlFor='eventId'>
|
||||||
|
Event ID (read only)
|
||||||
|
</label>
|
||||||
<Input
|
<Input
|
||||||
id='eventId'
|
id='eventId'
|
||||||
size='sm'
|
size='sm'
|
||||||
@@ -41,7 +43,7 @@ const EventEditorTitles = (props: EventEditorLeftProps) => {
|
|||||||
value={eventId}
|
value={eventId}
|
||||||
readOnly
|
readOnly
|
||||||
/>
|
/>
|
||||||
</label>
|
</div>
|
||||||
<EventTextInput field='cue' label='Cue' initialValue={cue} submitHandler={cueSubmitHandler} maxLength={10} />
|
<EventTextInput field='cue' label='Cue' initialValue={cue} submitHandler={cueSubmitHandler} maxLength={10} />
|
||||||
</div>
|
</div>
|
||||||
<EventTextInput field='title' label='Title' initialValue={title} submitHandler={handleSubmit} />
|
<EventTextInput field='title' label='Title' initialValue={title} submitHandler={handleSubmit} />
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ export default function CountdownSelect(props: CountdownSelectProps) {
|
|||||||
) as OntimeEvent[];
|
) as OntimeEvent[];
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className='event-select' data-testid='countdown-select'>
|
<div className='event-select' data-testid='countdown__select'>
|
||||||
<span className='event-select__title'>{getLocalizedString('countdown.select_event')}</span>
|
<span className='event-select__title'>{getLocalizedString('countdown.select_event')}</span>
|
||||||
<ul className='event-select__events'>
|
<ul className='event-select__events'>
|
||||||
{!events.length ? (
|
{!events.length ? (
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { LogOrigin, OntimeBaseEvent, OntimeBlock, OntimeDelay, OntimeEvent, SupportedEvent } from 'ontime-types';
|
import { LogOrigin, OntimeBaseEvent, OntimeBlock, OntimeDelay, OntimeEvent, SupportedEvent, isOntimeEvent } from 'ontime-types';
|
||||||
import { generateId, getCueCandidate } from 'ontime-utils';
|
import { generateId, getCueCandidate } from 'ontime-utils';
|
||||||
import { DataProvider } from '../../classes/data-provider/DataProvider.js';
|
import { DataProvider } from '../../classes/data-provider/DataProvider.js';
|
||||||
import { block as blockDef, delay as delayDef } from '../../models/eventsDefinition.js';
|
import { block as blockDef, delay as delayDef } from '../../models/eventsDefinition.js';
|
||||||
@@ -18,7 +18,7 @@ import {
|
|||||||
delayedRundownCacheKey,
|
delayedRundownCacheKey,
|
||||||
} from './delayedRundown.utils.js';
|
} from './delayedRundown.utils.js';
|
||||||
import { logger } from '../../classes/Logger.js';
|
import { logger } from '../../classes/Logger.js';
|
||||||
import { validateEvent } from '../../utils/parser.js';
|
import { createEvent } from '../../utils/parser.js';
|
||||||
import { stateMutations } from '../../state.js';
|
import { stateMutations } from '../../state.js';
|
||||||
import { runtimeService } from '../runtime-service/RuntimeService.js';
|
import { runtimeService } from '../runtime-service/RuntimeService.js';
|
||||||
|
|
||||||
@@ -56,7 +56,7 @@ export async function addEvent(eventData: Partial<OntimeEvent> | Partial<OntimeD
|
|||||||
|
|
||||||
switch (eventData.type) {
|
switch (eventData.type) {
|
||||||
case SupportedEvent.Event: {
|
case SupportedEvent.Event: {
|
||||||
newEvent = validateEvent(eventData, getCueCandidate(DataProvider.getRundown(), eventData?.after)) as OntimeEvent;
|
newEvent = createEvent(eventData, getCueCandidate(DataProvider.getRundown(), eventData?.after)) as OntimeEvent;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case SupportedEvent.Delay:
|
case SupportedEvent.Delay:
|
||||||
@@ -80,7 +80,7 @@ export async function addEvent(eventData: Partial<OntimeEvent> | Partial<OntimeD
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function editEvent(eventData: Partial<OntimeEvent> | Partial<OntimeBlock> | Partial<OntimeDelay>) {
|
export async function editEvent(eventData: Partial<OntimeEvent> | Partial<OntimeBlock> | Partial<OntimeDelay>) {
|
||||||
if (eventData.type === SupportedEvent.Event && eventData?.cue === '') {
|
if (isOntimeEvent(eventData) && eventData?.cue === '') {
|
||||||
throw new Error('Cue value invalid');
|
throw new Error('Cue value invalid');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ import { getCached, runtimeCacheStore } from '../../stores/cachingStore.js';
|
|||||||
import { isProduction } from '../../setup.js';
|
import { isProduction } from '../../setup.js';
|
||||||
import { deleteAtIndex, insertAtIndex, reorderArray } from '../../utils/arrayUtils.js';
|
import { deleteAtIndex, insertAtIndex, reorderArray } from '../../utils/arrayUtils.js';
|
||||||
import { _applyDelay } from '../delayUtils.js';
|
import { _applyDelay } from '../delayUtils.js';
|
||||||
|
import { createPatch } from '../../utils/parser.js';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Keep incremental revision number of rundown for runtime
|
* Keep incremental revision number of rundown for runtime
|
||||||
@@ -109,6 +110,16 @@ export async function cachedEdit(
|
|||||||
eventId: string,
|
eventId: string,
|
||||||
patchObject: Partial<OntimeEvent> | Partial<OntimeBlock> | Partial<OntimeDelay>,
|
patchObject: Partial<OntimeEvent> | Partial<OntimeBlock> | Partial<OntimeDelay>,
|
||||||
) {
|
) {
|
||||||
|
const makeEvent = (eventFromRundown: OntimeRundownEntry): OntimeRundownEntry => {
|
||||||
|
if (isOntimeEvent(eventFromRundown)) {
|
||||||
|
const newEvent = createPatch(eventFromRundown, patchObject as OntimeEvent);
|
||||||
|
newEvent.revision++;
|
||||||
|
return newEvent;
|
||||||
|
}
|
||||||
|
|
||||||
|
return { ...eventFromRundown, ...patchObject } as OntimeRundownEntry;
|
||||||
|
};
|
||||||
|
|
||||||
const indexInMemory = DataProvider.getIndexOf(eventId);
|
const indexInMemory = DataProvider.getIndexOf(eventId);
|
||||||
if (indexInMemory < 0) {
|
if (indexInMemory < 0) {
|
||||||
throw new Error('No event with ID found');
|
throw new Error('No event with ID found');
|
||||||
@@ -125,10 +136,7 @@ export async function cachedEdit(
|
|||||||
return eventFromRundown;
|
return eventFromRundown;
|
||||||
}
|
}
|
||||||
|
|
||||||
const newEvent = { ...eventFromRundown, ...patchObject } as OntimeRundownEntry;
|
const newEvent = makeEvent(eventFromRundown);
|
||||||
if (isOntimeEvent(newEvent)) {
|
|
||||||
newEvent.revision++;
|
|
||||||
}
|
|
||||||
updatedRundown[indexInMemory] = newEvent;
|
updatedRundown[indexInMemory] = newEvent;
|
||||||
|
|
||||||
let newDelayedRundown = getDelayedRundown();
|
let newDelayedRundown = getDelayedRundown();
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import { vi } from 'vitest';
|
|||||||
import { EndAction, OntimeEvent, TimerType } from 'ontime-types';
|
import { EndAction, OntimeEvent, TimerType } from 'ontime-types';
|
||||||
|
|
||||||
import { dbModel } from '../../models/dataModel.js';
|
import { dbModel } from '../../models/dataModel.js';
|
||||||
import { parseExcel, parseJson, validateEvent } from '../parser.js';
|
import { parseExcel, parseJson, createEvent } from '../parser.js';
|
||||||
import { makeString } from '../parserUtils.js';
|
import { makeString } from '../parserUtils.js';
|
||||||
import { parseAliases, parseUserFields, parseViewSettings } from '../parserFunctions.js';
|
import { parseAliases, parseUserFields, parseViewSettings } from '../parserFunctions.js';
|
||||||
|
|
||||||
@@ -340,7 +340,7 @@ describe('test parser edge cases', () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const parseResponse = await parseJson(testData);
|
const parseResponse = await parseJson(testData);
|
||||||
expect(console.log).toHaveBeenCalledWith('ERROR: undefined event type, skipping');
|
expect(console.log).toHaveBeenCalledWith('ERROR: unkown event type, skipping');
|
||||||
expect(parseResponse?.rundown.length).toBe(0);
|
expect(parseResponse?.rundown.length).toBe(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -464,7 +464,7 @@ describe('test event validator', () => {
|
|||||||
const event = {
|
const event = {
|
||||||
title: 'test',
|
title: 'test',
|
||||||
};
|
};
|
||||||
const validated = validateEvent(event, 'test');
|
const validated = createEvent(event, 'test');
|
||||||
|
|
||||||
expect(validated).toEqual(
|
expect(validated).toEqual(
|
||||||
expect.objectContaining({
|
expect.objectContaining({
|
||||||
@@ -497,7 +497,7 @@ describe('test event validator', () => {
|
|||||||
|
|
||||||
it('fails an empty object', () => {
|
it('fails an empty object', () => {
|
||||||
const event = {};
|
const event = {};
|
||||||
const validated = validateEvent(event, 'none');
|
const validated = createEvent(event, 'none');
|
||||||
expect(validated).toEqual(null);
|
expect(validated).toEqual(null);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -509,7 +509,7 @@ describe('test event validator', () => {
|
|||||||
note: '1899-12-30T08:00:10.000Z',
|
note: '1899-12-30T08:00:10.000Z',
|
||||||
};
|
};
|
||||||
// @ts-expect-error -- we know this is wrong, testing imports outside domain
|
// @ts-expect-error -- we know this is wrong, testing imports outside domain
|
||||||
const validated = validateEvent(event, 'not-used');
|
const validated = createEvent(event, 'not-used');
|
||||||
expect(typeof validated.title).toEqual('string');
|
expect(typeof validated.title).toEqual('string');
|
||||||
expect(typeof validated.subtitle).toEqual('string');
|
expect(typeof validated.subtitle).toEqual('string');
|
||||||
expect(typeof validated.presenter).toEqual('string');
|
expect(typeof validated.presenter).toEqual('string');
|
||||||
@@ -522,7 +522,7 @@ describe('test event validator', () => {
|
|||||||
timeEnd: '2',
|
timeEnd: '2',
|
||||||
};
|
};
|
||||||
// @ts-expect-error -- we know this is wrong, testing imports outside domain
|
// @ts-expect-error -- we know this is wrong, testing imports outside domain
|
||||||
const validated = validateEvent(event);
|
const validated = createEvent(event);
|
||||||
expect(typeof validated.timeStart).toEqual('number');
|
expect(typeof validated.timeStart).toEqual('number');
|
||||||
expect(validated.timeStart).toEqual(0);
|
expect(validated.timeStart).toEqual(0);
|
||||||
expect(typeof validated.timeEnd).toEqual('number');
|
expect(typeof validated.timeEnd).toEqual('number');
|
||||||
@@ -534,7 +534,7 @@ describe('test event validator', () => {
|
|||||||
title: {},
|
title: {},
|
||||||
};
|
};
|
||||||
// @ts-expect-error -- we know this is wrong, testing imports outside domain
|
// @ts-expect-error -- we know this is wrong, testing imports outside domain
|
||||||
const validated = validateEvent(event);
|
const validated = createEvent(event);
|
||||||
expect(typeof validated.title).toEqual('string');
|
expect(typeof validated.title).toEqual('string');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -43,20 +43,25 @@ import { coerceBoolean } from './coerceType.js';
|
|||||||
export const EXCEL_MIME = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet';
|
export const EXCEL_MIME = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet';
|
||||||
export const JSON_MIME = 'application/json';
|
export const JSON_MIME = 'application/json';
|
||||||
|
|
||||||
|
type ExcelData = Pick<DatabaseModel, 'rundown' | 'project' | 'userFields'> & {
|
||||||
|
projectMetadata: Record<string, { row: number; col: number }>;
|
||||||
|
rundownMetadata: Record<string, { row: number; col: number }>;
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description Excel array parser
|
* @description Excel array parser
|
||||||
* @param {array} excelData - array with excel sheet
|
* @param {array} excelData - array with excel sheet
|
||||||
* @param {ExcelImportOptions} options - an object that contains the import map
|
* @param {ExcelImportOptions} options - an object that contains the import map
|
||||||
* @returns {object} - parsed object
|
* @returns {object} - parsed object
|
||||||
*/
|
*/
|
||||||
export const parseExcel = (excelData: unknown[][], options?: Partial<ExcelImportMap>) => {
|
export const parseExcel = (excelData: unknown[][], options?: Partial<ExcelImportMap>): ExcelData => {
|
||||||
const projectMetadata = {};
|
const projectMetadata = {};
|
||||||
const rundownMetadata = {};
|
const rundownMetadata = {};
|
||||||
const importMap: ExcelImportMap = { ...defaultExcelImportMap, ...options };
|
const importMap: ExcelImportMap = { ...defaultExcelImportMap, ...options };
|
||||||
for (const [key, value] of Object.entries(importMap)) {
|
for (const [key, value] of Object.entries(importMap)) {
|
||||||
importMap[key] = value.toLocaleLowerCase();
|
importMap[key] = value.toLocaleLowerCase();
|
||||||
}
|
}
|
||||||
const projectData: Partial<ProjectData> = {
|
const projectData: ProjectData = {
|
||||||
title: '',
|
title: '',
|
||||||
description: '',
|
description: '',
|
||||||
publicUrl: '',
|
publicUrl: '',
|
||||||
@@ -64,7 +69,7 @@ export const parseExcel = (excelData: unknown[][], options?: Partial<ExcelImport
|
|||||||
backstageUrl: '',
|
backstageUrl: '',
|
||||||
backstageInfo: '',
|
backstageInfo: '',
|
||||||
};
|
};
|
||||||
const customUserFields: Partial<UserFields> = {
|
const customUserFields: UserFields = {
|
||||||
user0: importMap.user0,
|
user0: importMap.user0,
|
||||||
user1: importMap.user1,
|
user1: importMap.user1,
|
||||||
user2: importMap.user2,
|
user2: importMap.user2,
|
||||||
@@ -350,10 +355,6 @@ export const parseExcel = (excelData: unknown[][], options?: Partial<ExcelImport
|
|||||||
return {
|
return {
|
||||||
rundown,
|
rundown,
|
||||||
project: projectData,
|
project: projectData,
|
||||||
settings: {
|
|
||||||
app: 'ontime',
|
|
||||||
version: '2.0.0',
|
|
||||||
},
|
|
||||||
userFields: customUserFields,
|
userFields: customUserFields,
|
||||||
projectMetadata,
|
projectMetadata,
|
||||||
rundownMetadata,
|
rundownMetadata,
|
||||||
@@ -393,61 +394,66 @@ export const parseJson = async (jsonData): Promise<DatabaseModel | null> => {
|
|||||||
return returnData as DatabaseModel;
|
return returnData as DatabaseModel;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export function createPatch(originalEvent: OntimeEvent, patchEvent: Partial<OntimeEvent>): OntimeEvent {
|
||||||
|
if (Object.keys(patchEvent).length === 0) {
|
||||||
|
return originalEvent;
|
||||||
|
}
|
||||||
|
|
||||||
|
const { timeStart, timeEnd, duration } = validateTimes(
|
||||||
|
patchEvent?.timeStart ?? originalEvent.timeStart,
|
||||||
|
patchEvent?.timeEnd ?? originalEvent.timeEnd,
|
||||||
|
patchEvent?.duration ?? originalEvent.duration,
|
||||||
|
);
|
||||||
|
|
||||||
|
return {
|
||||||
|
id: originalEvent.id,
|
||||||
|
type: SupportedEvent.Event,
|
||||||
|
title: makeString(patchEvent.title, originalEvent.title),
|
||||||
|
subtitle: makeString(patchEvent.subtitle, originalEvent.subtitle),
|
||||||
|
presenter: makeString(patchEvent.presenter, originalEvent.presenter),
|
||||||
|
timeStart,
|
||||||
|
timeEnd,
|
||||||
|
duration,
|
||||||
|
endAction: validateEndAction(patchEvent.endAction, EndAction.None),
|
||||||
|
timerType: validateTimerType(patchEvent.timerType, TimerType.CountDown),
|
||||||
|
isPublic: typeof patchEvent.isPublic === 'boolean' ? patchEvent.isPublic : originalEvent.isPublic,
|
||||||
|
skip: typeof patchEvent.skip === 'boolean' ? patchEvent.skip : originalEvent.skip,
|
||||||
|
note: makeString(patchEvent.note, originalEvent.note),
|
||||||
|
user0: makeString(patchEvent.user0, originalEvent.user0),
|
||||||
|
user1: makeString(patchEvent.user1, originalEvent.user1),
|
||||||
|
user2: makeString(patchEvent.user2, originalEvent.user2),
|
||||||
|
user3: makeString(patchEvent.user3, originalEvent.user3),
|
||||||
|
user4: makeString(patchEvent.user4, originalEvent.user4),
|
||||||
|
user5: makeString(patchEvent.user5, originalEvent.user5),
|
||||||
|
user6: makeString(patchEvent.user6, originalEvent.user6),
|
||||||
|
user7: makeString(patchEvent.user7, originalEvent.user7),
|
||||||
|
user8: makeString(patchEvent.user8, originalEvent.user8),
|
||||||
|
user9: makeString(patchEvent.user9, originalEvent.user9),
|
||||||
|
colour: makeString(patchEvent.colour, originalEvent.colour),
|
||||||
|
cue: makeString(patchEvent.cue, originalEvent.cue),
|
||||||
|
revision: originalEvent.revision,
|
||||||
|
timeWarning: patchEvent.timeWarning,
|
||||||
|
timeDanger: patchEvent.timeDanger,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description Enforces formatting for events
|
* @description Enforces formatting for events
|
||||||
* @param {object} eventArgs - attributes of event
|
* @param {object} eventArgs - attributes of event
|
||||||
* @param cueFallback
|
* @param cueFallback
|
||||||
* @returns {object|null} - formatted object or null in case is invalid
|
* @returns {object|null} - formatted object or null in case is invalid
|
||||||
*/
|
*/
|
||||||
|
export const createEvent = (eventArgs: Partial<OntimeEvent>, cueFallback: string): OntimeEvent | null => {
|
||||||
export const validateEvent = (eventArgs: Partial<OntimeEvent>, cueFallback: string) => {
|
if (Object.keys(eventArgs).length === 0) {
|
||||||
// ensure id is defined and unique
|
return null;
|
||||||
const id = eventArgs.id || generateId();
|
|
||||||
|
|
||||||
let event = null;
|
|
||||||
|
|
||||||
// return if object is empty
|
|
||||||
if (Object.keys(eventArgs).length > 0) {
|
|
||||||
// make sure all properties exits
|
|
||||||
// dont load any extra properties than the ones known
|
|
||||||
|
|
||||||
const e = eventArgs;
|
|
||||||
const d = eventDef;
|
|
||||||
|
|
||||||
const { timeStart, timeEnd, duration } = validateTimes(e.timeStart, e.timeEnd, e.duration);
|
|
||||||
|
|
||||||
event = {
|
|
||||||
...d,
|
|
||||||
title: makeString(e.title, d.title),
|
|
||||||
subtitle: makeString(e.subtitle, d.subtitle),
|
|
||||||
presenter: makeString(e.presenter, d.presenter),
|
|
||||||
timeStart,
|
|
||||||
timeEnd,
|
|
||||||
duration,
|
|
||||||
endAction: validateEndAction(e.endAction, EndAction.None),
|
|
||||||
timerType: validateTimerType(e.timerType, TimerType.CountDown),
|
|
||||||
isPublic: typeof e.isPublic === 'boolean' ? e.isPublic : d.isPublic,
|
|
||||||
skip: typeof e.skip === 'boolean' ? e.skip : d.skip,
|
|
||||||
note: makeString(e.note, d.note),
|
|
||||||
user0: makeString(e.user0, d.user0),
|
|
||||||
user1: makeString(e.user1, d.user1),
|
|
||||||
user2: makeString(e.user2, d.user2),
|
|
||||||
user3: makeString(e.user3, d.user3),
|
|
||||||
user4: makeString(e.user4, d.user4),
|
|
||||||
user5: makeString(e.user5, d.user5),
|
|
||||||
user6: makeString(e.user6, d.user6),
|
|
||||||
user7: makeString(e.user7, d.user7),
|
|
||||||
user8: makeString(e.user8, d.user8),
|
|
||||||
user9: makeString(e.user9, d.user9),
|
|
||||||
colour: makeString(e.colour, d.colour),
|
|
||||||
cue: makeString(e.cue, cueFallback),
|
|
||||||
id,
|
|
||||||
type: 'event',
|
|
||||||
timeWarning: e.timeWarning,
|
|
||||||
timeDanger: e.timeDanger,
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const baseEvent = {
|
||||||
|
id: eventArgs?.id ?? generateId(),
|
||||||
|
cue: cueFallback,
|
||||||
|
...eventDef,
|
||||||
|
};
|
||||||
|
const event = createPatch(baseEvent, eventArgs);
|
||||||
return event;
|
return event;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -497,7 +503,6 @@ export const fileHandler = async (file: string, options: ExcelImportOptions): Pr
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (file.endsWith('.json')) {
|
if (file.endsWith('.json')) {
|
||||||
// if json check version
|
|
||||||
const rawdata = fs.readFileSync(file).toString();
|
const rawdata = fs.readFileSync(file).toString();
|
||||||
let uploadedJson = null;
|
let uploadedJson = null;
|
||||||
|
|
||||||
|
|||||||
@@ -13,11 +13,15 @@ import {
|
|||||||
HttpSubscription,
|
HttpSubscription,
|
||||||
OscSubscriptionOptions,
|
OscSubscriptionOptions,
|
||||||
HttpSubscriptionOptions,
|
HttpSubscriptionOptions,
|
||||||
|
DatabaseModel,
|
||||||
|
isOntimeEvent,
|
||||||
|
isOntimeDelay,
|
||||||
|
isOntimeBlock,
|
||||||
} from 'ontime-types';
|
} from 'ontime-types';
|
||||||
|
|
||||||
import { block as blockDef, delay as delayDef } from '../models/eventsDefinition.js';
|
import { block as blockDef, delay as delayDef } from '../models/eventsDefinition.js';
|
||||||
import { dbModel } from '../models/dataModel.js';
|
import { dbModel } from '../models/dataModel.js';
|
||||||
import { validateEvent } from './parser.js';
|
import { createEvent } from './parser.js';
|
||||||
import { MAX_EVENTS } from '../settings.js';
|
import { MAX_EVENTS } from '../settings.js';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -25,7 +29,7 @@ import { MAX_EVENTS } from '../settings.js';
|
|||||||
* @param {object} data - data object
|
* @param {object} data - data object
|
||||||
* @returns {object} - event object data
|
* @returns {object} - event object data
|
||||||
*/
|
*/
|
||||||
export const parseRundown = (data): OntimeRundown => {
|
export const parseRundown = (data: Partial<DatabaseModel>): OntimeRundown => {
|
||||||
let newRundown: OntimeRundown = [];
|
let newRundown: OntimeRundown = [];
|
||||||
if ('rundown' in data) {
|
if ('rundown' in data) {
|
||||||
console.log('Found rundown definition, importing...');
|
console.log('Found rundown definition, importing...');
|
||||||
@@ -33,7 +37,7 @@ export const parseRundown = (data): OntimeRundown => {
|
|||||||
try {
|
try {
|
||||||
let eventIndex = 0;
|
let eventIndex = 0;
|
||||||
const ids = [];
|
const ids = [];
|
||||||
for (const e of data.rundown) {
|
for (const event of data.rundown) {
|
||||||
// cap number of events
|
// cap number of events
|
||||||
if (rundown.length >= MAX_EVENTS) {
|
if (rundown.length >= MAX_EVENTS) {
|
||||||
console.log(`ERROR: Reached limit number of ${MAX_EVENTS} events`);
|
console.log(`ERROR: Reached limit number of ${MAX_EVENTS} events`);
|
||||||
@@ -41,28 +45,28 @@ export const parseRundown = (data): OntimeRundown => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// double check unique ids
|
// double check unique ids
|
||||||
if (ids.includes(e?.id)) {
|
if (ids.includes(event?.id)) {
|
||||||
console.log('ERROR: ID collision on import, skipping');
|
console.log('ERROR: ID collision on import, skipping');
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (e.type === 'event') {
|
if (isOntimeEvent(event)) {
|
||||||
eventIndex += 1;
|
eventIndex += 1;
|
||||||
const event = validateEvent(e, eventIndex.toString());
|
const parsedEvent = createEvent(event, eventIndex.toString());
|
||||||
if (event != null) {
|
if (event != null) {
|
||||||
rundown.push(event);
|
rundown.push(parsedEvent);
|
||||||
ids.push(event.id);
|
ids.push(parsedEvent.id);
|
||||||
}
|
}
|
||||||
} else if (e.type === 'delay') {
|
} else if (isOntimeDelay(event)) {
|
||||||
rundown.push({
|
rundown.push({
|
||||||
...delayDef,
|
...delayDef,
|
||||||
duration: e.duration,
|
duration: event.duration,
|
||||||
id: e.id || generateId(),
|
id: event.id || generateId(),
|
||||||
});
|
});
|
||||||
} else if (e.type === 'block') {
|
} else if (isOntimeBlock(event)) {
|
||||||
rundown.push({ ...blockDef, title: e.title, id: e.id || generateId() });
|
rundown.push({ ...blockDef, title: event.title, id: event.id || generateId() });
|
||||||
} else {
|
} else {
|
||||||
console.log('ERROR: undefined event type, skipping');
|
console.log('ERROR: unkown event type, skipping');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -112,16 +116,16 @@ export const parseSettings = (data): Settings => {
|
|||||||
const s = data.settings;
|
const s = data.settings;
|
||||||
|
|
||||||
// skip if file definition is missing
|
// skip if file definition is missing
|
||||||
if (s.app == null || s.version == null) {
|
if (s?.app !== 'ontime' || s?.version == null) {
|
||||||
console.log('ERROR: unknown app version, skipping');
|
console.log('ERROR: unknown app version, skipping');
|
||||||
} else {
|
} else {
|
||||||
const settings = {
|
const settings = {
|
||||||
version: dbModel.settings.version,
|
version: dbModel.settings.version,
|
||||||
serverPort: s.serverPort || dbModel.settings.serverPort,
|
serverPort: s.serverPort ?? dbModel.settings.serverPort,
|
||||||
editorKey: s.editorKey || null,
|
editorKey: s.editorKey ?? null,
|
||||||
operatorKey: s.operatorKey || null,
|
operatorKey: s.operatorKey ?? null,
|
||||||
timeFormat: s.timeFormat || '24',
|
timeFormat: s.timeFormat ?? '24',
|
||||||
language: s.language || 'en',
|
language: s.language ?? 'en',
|
||||||
};
|
};
|
||||||
|
|
||||||
// write to db
|
// write to db
|
||||||
@@ -287,15 +291,15 @@ export const parseAliases = (data): Alias[] => {
|
|||||||
if ('aliases' in data) {
|
if ('aliases' in data) {
|
||||||
console.log('Found Aliases definition, importing...');
|
console.log('Found Aliases definition, importing...');
|
||||||
try {
|
try {
|
||||||
for (const a of data.aliases) {
|
for (const alias of data.aliases) {
|
||||||
const newAlias = {
|
const newAlias = {
|
||||||
enabled: a.enabled || false,
|
enabled: alias.enabled ?? false,
|
||||||
alias: a.alias || '',
|
alias: alias.alias ?? '',
|
||||||
pathAndParams: a.pathAndParams || '',
|
pathAndParams: alias.pathAndParams ?? '',
|
||||||
};
|
};
|
||||||
newAliases.push(newAlias);
|
newAliases.push(newAlias);
|
||||||
}
|
}
|
||||||
console.log(`Uploaded ${newAliases?.length || 0} alias(es)`);
|
console.log(`Uploaded ${newAliases.length} alias(es)`);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(`Error: ${error}`);
|
console.log(`Error: ${error}`);
|
||||||
}
|
}
|
||||||
@@ -328,4 +332,4 @@ export const parseUserFields = (data): UserFields => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return { ...newUserFields };
|
return { ...newUserFields };
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -8,8 +8,7 @@ test.describe('pages routes are available', () => {
|
|||||||
await page.goto('http://localhost:4001/editor');
|
await page.goto('http://localhost:4001/editor');
|
||||||
|
|
||||||
await expect(page).toHaveTitle(/ontime/);
|
await expect(page).toHaveTitle(/ontime/);
|
||||||
// TODO (v3): not ready yet
|
await expect(page.getByTestId('editor-container')).toBeVisible();
|
||||||
// await expect(page.getByTestId('editor-container')).toBeVisible();
|
|
||||||
await expect(page.getByTestId('panel-rundown')).toBeVisible();
|
await expect(page.getByTestId('panel-rundown')).toBeVisible();
|
||||||
await expect(page.getByTestId('panel-timer-control')).toBeVisible();
|
await expect(page.getByTestId('panel-timer-control')).toBeVisible();
|
||||||
await expect(page.getByTestId('panel-messages-control')).toBeVisible();
|
await expect(page.getByTestId('panel-messages-control')).toBeVisible();
|
||||||
|
|||||||
@@ -25,12 +25,7 @@ test('test project file upload', async ({ page }) => {
|
|||||||
await page.getByPlaceholder('Start').first().click();
|
await page.getByPlaceholder('Start').first().click();
|
||||||
await page.getByText('First test event').click();
|
await page.getByText('First test event').click();
|
||||||
await page.getByTestId('delay-input').click();
|
await page.getByTestId('delay-input').click();
|
||||||
await page
|
await page.getByText('New start: 10:10').click();
|
||||||
.locator('div')
|
|
||||||
.filter({ hasText: /^SED\+10 minNew start: 10:10:00$/ })
|
|
||||||
.getByPlaceholder('Start')
|
|
||||||
.click();
|
|
||||||
await page.getByText('+10 minNew start: 10:10:00').click();
|
|
||||||
await page.getByText('Second test event').click();
|
await page.getByText('Second test event').click();
|
||||||
await page.getByText('Lunch').click();
|
await page.getByText('Lunch').click();
|
||||||
await page.getByText('Third test event').click();
|
await page.getByText('Third test event').click();
|
||||||
|
|||||||
@@ -25,11 +25,11 @@ test('delay blocks add time to events', async ({ page }) => {
|
|||||||
await page.getByTestId('delay-input').click();
|
await page.getByTestId('delay-input').click();
|
||||||
await page.getByTestId('delay-input').fill('2m');
|
await page.getByTestId('delay-input').fill('2m');
|
||||||
await page.getByTestId('delay-input').press('Enter');
|
await page.getByTestId('delay-input').press('Enter');
|
||||||
await page.getByText('+2 minNew start: 00:12:00').click();
|
await page.getByText('New start: 00:12').click();
|
||||||
|
|
||||||
// make negative delay
|
// make negative delay
|
||||||
await page.getByText('Subtract time').click();
|
await page.getByText('Subtract time').click();
|
||||||
await page.getByText('-2 minNew start: 00:08:00').click();
|
await page.getByText('New start: 00:08').click();
|
||||||
|
|
||||||
// apply delay
|
// apply delay
|
||||||
await page.getByRole('button', { name: 'Apply' }).click();
|
await page.getByRole('button', { name: 'Apply' }).click();
|
||||||
@@ -42,12 +42,12 @@ test('delay blocks add time to events', async ({ page }) => {
|
|||||||
await page.getByTestId('delay-input').click();
|
await page.getByTestId('delay-input').click();
|
||||||
await page.getByTestId('delay-input').fill('10m');
|
await page.getByTestId('delay-input').fill('10m');
|
||||||
await page.getByTestId('delay-input').press('Enter');
|
await page.getByTestId('delay-input').press('Enter');
|
||||||
await page.getByText('+10 minNew start: 00:18:00').click();
|
await page.getByText('New start: 00:18').click();
|
||||||
|
|
||||||
// cancel delay
|
// cancel delay
|
||||||
await page.getByRole('button', { name: 'Cancel' }).click();
|
await page.getByRole('button', { name: 'Cancel' }).click();
|
||||||
await expect(page.getByTestId('rundown').getByTestId('time-input-timeStart')).toHaveValue('00:08:00');
|
await expect(page.getByTestId('rundown').getByTestId('time-input-timeStart')).toHaveValue('00:08:00');
|
||||||
await expect(page.getByText('+10 minNew start: 00:18:00')).toHaveCount(0);
|
await expect(page.getByText('New start: 00:18')).toHaveCount(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('delays are show correctly', async ({ page }) => {
|
test('delays are show correctly', async ({ page }) => {
|
||||||
@@ -79,7 +79,7 @@ test('delays are show correctly', async ({ page }) => {
|
|||||||
await page.getByTestId('delay-input').press('Enter');
|
await page.getByTestId('delay-input').press('Enter');
|
||||||
|
|
||||||
// delay is shown in the editor
|
// delay is shown in the editor
|
||||||
await page.getByText('+1 minNew start: 00:11:00').click();
|
await page.getByText('New start: 00:11').click();
|
||||||
|
|
||||||
// delay is shown in the cuesheet
|
// delay is shown in the cuesheet
|
||||||
await page.goto('http://localhost:4001/cuesheet');
|
await page.goto('http://localhost:4001/cuesheet');
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { test, expect } from '@playwright/test';
|
import { test } from '@playwright/test';
|
||||||
|
|
||||||
test('test aliases feature, it should redirect to given alias', async ({ page }) => {
|
test('test aliases feature, it should redirect to given alias', async ({ page }) => {
|
||||||
await page.goto('http://localhost:4001/editor');
|
await page.goto('http://localhost:4001/editor');
|
||||||
@@ -17,5 +17,5 @@ test('test aliases feature, it should redirect to given alias', async ({ page })
|
|||||||
|
|
||||||
// make sure alias works
|
// make sure alias works
|
||||||
await page.goto('http://localhost:4001/testing');
|
await page.goto('http://localhost:4001/testing');
|
||||||
await page.getByText('Select an event to follow').click();
|
await page.getByTestId('countdown__select').click();
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ export { calculateDuration } from './src/validate-events/validateEvent.js';
|
|||||||
export { sanitiseCue } from './src/cue-utils/cueUtils.js';
|
export { sanitiseCue } from './src/cue-utils/cueUtils.js';
|
||||||
export { getCueCandidate } from './src/cue-utils/cueUtils.js';
|
export { getCueCandidate } from './src/cue-utils/cueUtils.js';
|
||||||
export { generateId } from './src/generate-id/generateId.js';
|
export { generateId } from './src/generate-id/generateId.js';
|
||||||
export { swapOntimeEvents } from './src/rundown-utils/rundownUtils.js';
|
export { getPreviousEvent, swapOntimeEvents } from './src/rundown-utils/rundownUtils.js';
|
||||||
|
|
||||||
// format utils
|
// format utils
|
||||||
export {
|
export {
|
||||||
@@ -20,7 +20,13 @@ export {
|
|||||||
millisToSeconds,
|
millisToSeconds,
|
||||||
} from './src/date-utils/conversionUtils.js';
|
} from './src/date-utils/conversionUtils.js';
|
||||||
export { isTimeString } from './src/date-utils/isTimeString.js';
|
export { isTimeString } from './src/date-utils/isTimeString.js';
|
||||||
export { formatFromMillis, millisToString, removeLeadingZero, removeSeconds } from './src/date-utils/timeFormatting.js';
|
export {
|
||||||
|
formatFromMillis,
|
||||||
|
millisToString,
|
||||||
|
removeLeadingZero,
|
||||||
|
removeSeconds,
|
||||||
|
removeTrailingZero,
|
||||||
|
} from './src/date-utils/timeFormatting.js';
|
||||||
export { isColourHex } from './src/regex-utils/isColourHex.js';
|
export { isColourHex } from './src/regex-utils/isColourHex.js';
|
||||||
|
|
||||||
// time utils
|
// time utils
|
||||||
|
|||||||
@@ -52,6 +52,17 @@ export function removeLeadingZero(timer: string): string {
|
|||||||
return timer;
|
return timer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Receives a string such as 00:10:10 and removes the seconds field if it is 00
|
||||||
|
* @param timer
|
||||||
|
*/
|
||||||
|
export function removeTrailingZero(timer: string): string {
|
||||||
|
if (timer.endsWith(':00')) {
|
||||||
|
return timer.slice(0, -3);
|
||||||
|
}
|
||||||
|
return timer;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Receives a string such as 00:10:10 and removes the seconds field
|
* Receives a string such as 00:10:10 and removes the seconds field
|
||||||
* @param timer
|
* @param timer
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import { dayInMs } from '../timeConstants.js';
|
|||||||
* @param {EndAction} maybeAction
|
* @param {EndAction} maybeAction
|
||||||
* @param {EndAction} [fallback]
|
* @param {EndAction} [fallback]
|
||||||
*/
|
*/
|
||||||
export function validateEndAction(maybeAction: unknown, fallback = EndAction.None) {
|
export function validateEndAction(maybeAction: unknown, fallback = EndAction.None): EndAction {
|
||||||
return Object.values(EndAction).includes(maybeAction as EndAction) ? (maybeAction as EndAction) : fallback;
|
return Object.values(EndAction).includes(maybeAction as EndAction) ? (maybeAction as EndAction) : fallback;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -16,7 +16,7 @@ export function validateEndAction(maybeAction: unknown, fallback = EndAction.Non
|
|||||||
* @param {TimerType} maybeTimerType
|
* @param {TimerType} maybeTimerType
|
||||||
* @param {TimerType} [fallback]
|
* @param {TimerType} [fallback]
|
||||||
*/
|
*/
|
||||||
export function validateTimerType(maybeTimerType: unknown, fallback = TimerType.CountDown) {
|
export function validateTimerType(maybeTimerType: unknown, fallback = TimerType.CountDown): TimerType {
|
||||||
return Object.values(TimerType).includes(maybeTimerType as TimerType) ? (maybeTimerType as TimerType) : fallback;
|
return Object.values(TimerType).includes(maybeTimerType as TimerType) ? (maybeTimerType as TimerType) : fallback;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -51,7 +51,11 @@ function convertToInteger(value: unknown): number {
|
|||||||
* @param _end
|
* @param _end
|
||||||
* @param _duration
|
* @param _duration
|
||||||
*/
|
*/
|
||||||
export function validateTimes(_start?: unknown, _end?: unknown, _duration?: unknown) {
|
export function validateTimes(
|
||||||
|
_start?: unknown,
|
||||||
|
_end?: unknown,
|
||||||
|
_duration?: unknown,
|
||||||
|
): { timeStart: number; duration: number; timeEnd: number } {
|
||||||
const timeStart = convertToInteger(_start);
|
const timeStart = convertToInteger(_start);
|
||||||
const timeEnd = convertToInteger(_end);
|
const timeEnd = convertToInteger(_end);
|
||||||
const duration = convertToInteger(_duration);
|
const duration = convertToInteger(_duration);
|
||||||
|
|||||||
Reference in New Issue
Block a user