mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-20 14:39:06 +00:00
Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| b59dc796cf | |||
| d70d7f2fd8 | |||
| 469d83dc0b | |||
| 59bff62f76 | |||
| 38e3ab979d | |||
| 2f29060fa4 | |||
| 2f7909ccc3 |
@@ -95,6 +95,22 @@ export const useAuxTimersTime = createSelector((state: RuntimeStore) => {
|
|||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
export const useAuxTimersName = createSelector((state: RuntimeStore) => {
|
||||||
|
return {
|
||||||
|
aux1: state.auxtimer1.name,
|
||||||
|
aux2: state.auxtimer2.name,
|
||||||
|
aux3: state.auxtimer3.name,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
export const useAuxTimersActive = createSelector((state: RuntimeStore) => {
|
||||||
|
return (
|
||||||
|
state.auxtimer1.playback === SimplePlayback.Start ||
|
||||||
|
state.auxtimer2.playback === SimplePlayback.Start ||
|
||||||
|
state.auxtimer3.playback === SimplePlayback.Start
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
export const useAuxTimerTime = (index: number) =>
|
export const useAuxTimerTime = (index: number) =>
|
||||||
createSelector((state: RuntimeStore) => {
|
createSelector((state: RuntimeStore) => {
|
||||||
if (index === 1) return state.auxtimer1.current;
|
if (index === 1) return state.auxtimer1.current;
|
||||||
@@ -108,15 +124,18 @@ export const useAuxTimerControl = (index: number) =>
|
|||||||
return {
|
return {
|
||||||
playback: state.auxtimer1.playback,
|
playback: state.auxtimer1.playback,
|
||||||
direction: state.auxtimer1.direction,
|
direction: state.auxtimer1.direction,
|
||||||
|
name: state.auxtimer1.name,
|
||||||
};
|
};
|
||||||
if (index === 2)
|
if (index === 2)
|
||||||
return {
|
return {
|
||||||
playback: state.auxtimer2.playback,
|
playback: state.auxtimer2.playback,
|
||||||
direction: state.auxtimer2.direction,
|
direction: state.auxtimer2.direction,
|
||||||
|
name: state.auxtimer2.name,
|
||||||
};
|
};
|
||||||
return {
|
return {
|
||||||
playback: state.auxtimer3.playback,
|
playback: state.auxtimer3.playback,
|
||||||
direction: state.auxtimer3.direction,
|
direction: state.auxtimer3.direction,
|
||||||
|
name: state.auxtimer3.name,
|
||||||
};
|
};
|
||||||
})();
|
})();
|
||||||
|
|
||||||
|
|||||||
@@ -6,4 +6,5 @@ export const ontimePlaceholderSettings: Settings = {
|
|||||||
operatorKey: null,
|
operatorKey: null,
|
||||||
timeFormat: '24',
|
timeFormat: '24',
|
||||||
language: 'en',
|
language: 'en',
|
||||||
|
auxTimerNames: ['', '', ''],
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ type EditorSettingsStore = {
|
|||||||
defaultTimerType: TimerType;
|
defaultTimerType: TimerType;
|
||||||
defaultEndAction: EndAction;
|
defaultEndAction: EndAction;
|
||||||
inheritGroupColour: boolean;
|
inheritGroupColour: boolean;
|
||||||
|
auxTimersCollapsed: boolean;
|
||||||
setDefaultDuration: (defaultDuration: string) => void;
|
setDefaultDuration: (defaultDuration: string) => void;
|
||||||
setLinkPrevious: (linkPrevious: boolean) => void;
|
setLinkPrevious: (linkPrevious: boolean) => void;
|
||||||
setInheritGroupColour: (inheritGroupColour: boolean) => void;
|
setInheritGroupColour: (inheritGroupColour: boolean) => void;
|
||||||
@@ -21,6 +22,7 @@ type EditorSettingsStore = {
|
|||||||
setDangerTime: (dangerTime: string) => void;
|
setDangerTime: (dangerTime: string) => void;
|
||||||
setDefaultTimerType: (defaultTimerType: TimerType) => void;
|
setDefaultTimerType: (defaultTimerType: TimerType) => void;
|
||||||
setDefaultEndAction: (defaultEndAction: EndAction) => void;
|
setDefaultEndAction: (defaultEndAction: EndAction) => void;
|
||||||
|
setAuxTimersCollapsed: (auxTimersCollapsed: boolean) => void;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const editorSettingsDefaults = {
|
export const editorSettingsDefaults = {
|
||||||
@@ -32,6 +34,7 @@ export const editorSettingsDefaults = {
|
|||||||
timerType: TimerType.CountDown,
|
timerType: TimerType.CountDown,
|
||||||
endAction: EndAction.None,
|
endAction: EndAction.None,
|
||||||
inheritGroupColour: false,
|
inheritGroupColour: false,
|
||||||
|
auxTimersCollapsed: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
enum EditorSettingsKeys {
|
enum EditorSettingsKeys {
|
||||||
@@ -43,6 +46,7 @@ enum EditorSettingsKeys {
|
|||||||
DefaultTimerType = 'ontime-default-timer-type',
|
DefaultTimerType = 'ontime-default-timer-type',
|
||||||
DefaultEndAction = 'ontime-default-end-action',
|
DefaultEndAction = 'ontime-default-end-action',
|
||||||
InheritGroupColour = 'ontime-inherit-group-colour',
|
InheritGroupColour = 'ontime-inherit-group-colour',
|
||||||
|
AuxTimersCollapsed = 'ontime-aux-timers-collapsed',
|
||||||
}
|
}
|
||||||
|
|
||||||
export const useEditorSettings = create<EditorSettingsStore>((set) => {
|
export const useEditorSettings = create<EditorSettingsStore>((set) => {
|
||||||
@@ -67,6 +71,10 @@ export const useEditorSettings = create<EditorSettingsStore>((set) => {
|
|||||||
EditorSettingsKeys.InheritGroupColour,
|
EditorSettingsKeys.InheritGroupColour,
|
||||||
editorSettingsDefaults.inheritGroupColour,
|
editorSettingsDefaults.inheritGroupColour,
|
||||||
),
|
),
|
||||||
|
auxTimersCollapsed: booleanFromLocalStorage(
|
||||||
|
EditorSettingsKeys.AuxTimersCollapsed,
|
||||||
|
editorSettingsDefaults.auxTimersCollapsed,
|
||||||
|
),
|
||||||
|
|
||||||
setDefaultDuration: (defaultDuration) =>
|
setDefaultDuration: (defaultDuration) =>
|
||||||
set(() => {
|
set(() => {
|
||||||
@@ -110,5 +118,10 @@ export const useEditorSettings = create<EditorSettingsStore>((set) => {
|
|||||||
localStorage.setItem(EditorSettingsKeys.InheritGroupColour, String(inheritGroupColour));
|
localStorage.setItem(EditorSettingsKeys.InheritGroupColour, String(inheritGroupColour));
|
||||||
return { inheritGroupColour };
|
return { inheritGroupColour };
|
||||||
}),
|
}),
|
||||||
|
setAuxTimersCollapsed: (auxTimersCollapsed) =>
|
||||||
|
set(() => {
|
||||||
|
localStorage.setItem(EditorSettingsKeys.AuxTimersCollapsed, String(auxTimersCollapsed));
|
||||||
|
return { auxTimersCollapsed };
|
||||||
|
}),
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -0,0 +1,10 @@
|
|||||||
|
export function getAuxTimerLabel(name: string | undefined, fallback: string): string {
|
||||||
|
const custom = name?.trim();
|
||||||
|
return custom ? custom : fallback;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Combines the aux timer's index with its custom name, eg. "Aux 1: Speaker" */
|
||||||
|
export function getAuxTimerIndexedLabel(name: string | undefined, index: number): string {
|
||||||
|
const custom = name?.trim();
|
||||||
|
return custom ? `Aux ${index}: ${custom}` : `Aux ${index}`;
|
||||||
|
}
|
||||||
@@ -0,0 +1,95 @@
|
|||||||
|
import { Settings } from 'ontime-types';
|
||||||
|
import { auxTimerNameMaxLength } from 'ontime-utils';
|
||||||
|
import { useEffect } from 'react';
|
||||||
|
import { useForm } from 'react-hook-form';
|
||||||
|
|
||||||
|
import { postSettings } from '../../../../common/api/settings';
|
||||||
|
import { maybeAxiosError } from '../../../../common/api/utils';
|
||||||
|
import Button from '../../../../common/components/buttons/Button';
|
||||||
|
import Info from '../../../../common/components/info/Info';
|
||||||
|
import Input from '../../../../common/components/input/input/Input';
|
||||||
|
import useSettings from '../../../../common/hooks-query/useSettings';
|
||||||
|
import { preventEscape } from '../../../../common/utils/keyEvent';
|
||||||
|
import * as Panel from '../../panel-utils/PanelUtils';
|
||||||
|
|
||||||
|
export default function AuxTimerSettings() {
|
||||||
|
const { data, status, refetch } = useSettings();
|
||||||
|
const {
|
||||||
|
handleSubmit,
|
||||||
|
register,
|
||||||
|
reset,
|
||||||
|
setError,
|
||||||
|
formState: { isSubmitting, isDirty, errors },
|
||||||
|
} = useForm<Settings>({
|
||||||
|
defaultValues: data,
|
||||||
|
resetOptions: {
|
||||||
|
keepDirtyValues: true,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (data) {
|
||||||
|
reset(data);
|
||||||
|
}
|
||||||
|
}, [data, reset]);
|
||||||
|
|
||||||
|
const onSubmit = async (formData: Settings) => {
|
||||||
|
try {
|
||||||
|
await postSettings(formData);
|
||||||
|
} catch (error) {
|
||||||
|
const message = maybeAxiosError(error);
|
||||||
|
setError('root', { message });
|
||||||
|
} finally {
|
||||||
|
await refetch();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const onReset = () => {
|
||||||
|
reset(data);
|
||||||
|
};
|
||||||
|
|
||||||
|
const isLoading = status === 'pending';
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Panel.Section
|
||||||
|
as='form'
|
||||||
|
onSubmit={handleSubmit(onSubmit)}
|
||||||
|
onKeyDown={(event) => preventEscape(event, onReset)}
|
||||||
|
id='aux-timer-settings'
|
||||||
|
>
|
||||||
|
<Panel.Card>
|
||||||
|
<Panel.SubHeader>
|
||||||
|
Aux timers
|
||||||
|
<Panel.InlineElements>
|
||||||
|
<Button disabled={!isDirty || isSubmitting} variant='ghosted' onClick={onReset}>
|
||||||
|
Revert to saved
|
||||||
|
</Button>
|
||||||
|
<Button type='submit' loading={isSubmitting} disabled={!isDirty} variant='primary'>
|
||||||
|
Save
|
||||||
|
</Button>
|
||||||
|
</Panel.InlineElements>
|
||||||
|
</Panel.SubHeader>
|
||||||
|
<Panel.Divider />
|
||||||
|
<Panel.Section>
|
||||||
|
<Info>Give the aux timers custom names. Names are shown across the editor controls and views.</Info>
|
||||||
|
<Panel.Loader isLoading={isLoading} />
|
||||||
|
<Panel.Error>{errors.root?.message}</Panel.Error>
|
||||||
|
<Panel.ListGroup>
|
||||||
|
<Panel.ListItem>
|
||||||
|
<Panel.Field title='Aux timer 1' description='Custom name for aux timer 1' />
|
||||||
|
<Input maxLength={auxTimerNameMaxLength} placeholder='Aux 1' {...register('auxTimerNames.0')} />
|
||||||
|
</Panel.ListItem>
|
||||||
|
<Panel.ListItem>
|
||||||
|
<Panel.Field title='Aux timer 2' description='Custom name for aux timer 2' />
|
||||||
|
<Input maxLength={auxTimerNameMaxLength} placeholder='Aux 2' {...register('auxTimerNames.1')} />
|
||||||
|
</Panel.ListItem>
|
||||||
|
<Panel.ListItem>
|
||||||
|
<Panel.Field title='Aux timer 3' description='Custom name for aux timer 3' />
|
||||||
|
<Input maxLength={auxTimerNameMaxLength} placeholder='Aux 3' {...register('auxTimerNames.2')} />
|
||||||
|
</Panel.ListItem>
|
||||||
|
</Panel.ListGroup>
|
||||||
|
</Panel.Section>
|
||||||
|
</Panel.Card>
|
||||||
|
</Panel.Section>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -3,6 +3,7 @@ import { isDocker } from '../../../../externals';
|
|||||||
import type { PanelBaseProps } from '../../panel-list/PanelList';
|
import type { PanelBaseProps } from '../../panel-list/PanelList';
|
||||||
import * as Panel from '../../panel-utils/PanelUtils';
|
import * as Panel from '../../panel-utils/PanelUtils';
|
||||||
import CustomViews from '../manage-panel/CustomViews';
|
import CustomViews from '../manage-panel/CustomViews';
|
||||||
|
import AuxTimerSettings from './AuxTimerSettings';
|
||||||
import GeneralSettings from './GeneralSettings';
|
import GeneralSettings from './GeneralSettings';
|
||||||
import McpSection from './McpSection';
|
import McpSection from './McpSection';
|
||||||
import ProjectData from './ProjectData';
|
import ProjectData from './ProjectData';
|
||||||
@@ -12,6 +13,7 @@ import ViewSettings from './ViewSettings';
|
|||||||
export default function SettingsPanel({ location }: PanelBaseProps) {
|
export default function SettingsPanel({ location }: PanelBaseProps) {
|
||||||
const dataRef = useScrollIntoView<HTMLDivElement>('data', location);
|
const dataRef = useScrollIntoView<HTMLDivElement>('data', location);
|
||||||
const generalRef = useScrollIntoView<HTMLDivElement>('general', location);
|
const generalRef = useScrollIntoView<HTMLDivElement>('general', location);
|
||||||
|
const auxTimersRef = useScrollIntoView<HTMLDivElement>('aux-timers', location);
|
||||||
const viewRef = useScrollIntoView<HTMLDivElement>('view', location);
|
const viewRef = useScrollIntoView<HTMLDivElement>('view', location);
|
||||||
const customViewsRef = useScrollIntoView<HTMLDivElement>('custom-views', location);
|
const customViewsRef = useScrollIntoView<HTMLDivElement>('custom-views', location);
|
||||||
const mcpRef = useScrollIntoView<HTMLDivElement>('mcp', location);
|
const mcpRef = useScrollIntoView<HTMLDivElement>('mcp', location);
|
||||||
@@ -26,6 +28,9 @@ export default function SettingsPanel({ location }: PanelBaseProps) {
|
|||||||
<div ref={generalRef}>
|
<div ref={generalRef}>
|
||||||
<GeneralSettings />
|
<GeneralSettings />
|
||||||
</div>
|
</div>
|
||||||
|
<div ref={auxTimersRef}>
|
||||||
|
<AuxTimerSettings />
|
||||||
|
</div>
|
||||||
<div ref={viewRef}>
|
<div ref={viewRef}>
|
||||||
<ViewSettings />
|
<ViewSettings />
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ const staticOptions = [
|
|||||||
secondary: [
|
secondary: [
|
||||||
{ id: 'settings__data', label: 'Project data' },
|
{ id: 'settings__data', label: 'Project data' },
|
||||||
{ id: 'settings__general', label: 'General settings' },
|
{ id: 'settings__general', label: 'General settings' },
|
||||||
|
{ id: 'settings__aux-timers', label: 'Aux timers' },
|
||||||
{ id: 'settings__view', label: 'View settings' },
|
{ id: 'settings__view', label: 'View settings' },
|
||||||
{ id: 'settings__custom-views', label: 'Custom views' },
|
{ id: 'settings__custom-views', label: 'Custom views' },
|
||||||
{ id: 'settings__mcp', label: 'MCP Server' },
|
{ id: 'settings__mcp', label: 'MCP Server' },
|
||||||
|
|||||||
@@ -3,6 +3,34 @@
|
|||||||
margin: 0 auto;
|
margin: 0 auto;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.auxHeader {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: space-between;
|
||||||
|
margin-top: 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.label {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 0.5rem;
|
||||||
|
font-size: $inner-section-text-size;
|
||||||
|
color: $label-gray;
|
||||||
|
}
|
||||||
|
|
||||||
|
.auxHeaderButtons {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 0.25rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.activeIndicator {
|
||||||
|
width: 0.5rem;
|
||||||
|
height: 0.5rem;
|
||||||
|
border-radius: 50%;
|
||||||
|
background-color: $active-indicator;
|
||||||
|
}
|
||||||
|
|
||||||
.auxTimers {
|
.auxTimers {
|
||||||
display: grid;
|
display: grid;
|
||||||
grid-template-columns: 1fr 1fr 1fr;
|
grid-template-columns: 1fr 1fr 1fr;
|
||||||
|
|||||||
@@ -1,4 +1,10 @@
|
|||||||
import { usePlaybackControl } from '../../../common/hooks/useSocket';
|
import { IoChevronDown, IoChevronUp, IoSettingsOutline } from 'react-icons/io5';
|
||||||
|
|
||||||
|
import IconButton from '../../../common/components/buttons/IconButton';
|
||||||
|
import Tooltip from '../../../common/components/tooltip/Tooltip';
|
||||||
|
import { useAuxTimersActive, usePlaybackControl } from '../../../common/hooks/useSocket';
|
||||||
|
import { useEditorSettings } from '../../../common/stores/editorSettings';
|
||||||
|
import useAppSettingsNavigation from '../../app-settings/useAppSettingsNavigation';
|
||||||
import AddTime from './add-time/AddTime';
|
import AddTime from './add-time/AddTime';
|
||||||
import { AuxTimer } from './aux-timer/AuxTimer';
|
import { AuxTimer } from './aux-timer/AuxTimer';
|
||||||
import PlaybackButtons from './playback-buttons/PlaybackButtons';
|
import PlaybackButtons from './playback-buttons/PlaybackButtons';
|
||||||
@@ -8,6 +14,9 @@ import style from './PlaybackControl.module.scss';
|
|||||||
|
|
||||||
export default function PlaybackControl() {
|
export default function PlaybackControl() {
|
||||||
const data = usePlaybackControl();
|
const data = usePlaybackControl();
|
||||||
|
const { setLocation } = useAppSettingsNavigation();
|
||||||
|
const { auxTimersCollapsed, setAuxTimersCollapsed } = useEditorSettings();
|
||||||
|
const isAuxTimerActive = useAuxTimersActive();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={style.mainContainer}>
|
<div className={style.mainContainer}>
|
||||||
@@ -20,11 +29,42 @@ export default function PlaybackControl() {
|
|||||||
selectedEventIndex={data.selectedEventIndex}
|
selectedEventIndex={data.selectedEventIndex}
|
||||||
timerPhase={data.timerPhase}
|
timerPhase={data.timerPhase}
|
||||||
/>
|
/>
|
||||||
<div className={style.auxTimers}>
|
<div className={style.auxHeader}>
|
||||||
<AuxTimer index={1} />
|
<span className={style.label}>
|
||||||
<AuxTimer index={2} />
|
Aux timers
|
||||||
<AuxTimer index={3} />
|
{auxTimersCollapsed && isAuxTimerActive && <span className={style.activeIndicator} />}
|
||||||
|
</span>
|
||||||
|
<div className={style.auxHeaderButtons}>
|
||||||
|
<Tooltip
|
||||||
|
text='Name aux timers'
|
||||||
|
render={
|
||||||
|
<IconButton
|
||||||
|
size='small'
|
||||||
|
variant='subtle-white'
|
||||||
|
aria-label='Name aux timers'
|
||||||
|
onClick={() => setLocation('settings__aux-timers')}
|
||||||
|
/>
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<IoSettingsOutline />
|
||||||
|
</Tooltip>
|
||||||
|
<IconButton
|
||||||
|
size='small'
|
||||||
|
variant='subtle-white'
|
||||||
|
aria-label={auxTimersCollapsed ? 'Expand aux timers' : 'Collapse aux timers'}
|
||||||
|
onClick={() => setAuxTimersCollapsed(!auxTimersCollapsed)}
|
||||||
|
>
|
||||||
|
{auxTimersCollapsed ? <IoChevronUp /> : <IoChevronDown />}
|
||||||
|
</IconButton>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
{!auxTimersCollapsed && (
|
||||||
|
<div className={style.auxTimers}>
|
||||||
|
<AuxTimer index={1} />
|
||||||
|
<AuxTimer index={2} />
|
||||||
|
<AuxTimer index={3} />
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,18 @@
|
|||||||
.label {
|
.label {
|
||||||
display: block;
|
display: block;
|
||||||
margin-top: 1rem;
|
margin-top: 1rem;
|
||||||
|
// aux timers sit in a 3 column grid, without this a long name would grow its column
|
||||||
|
// instead of shrinking to it, breaking the equal column layout
|
||||||
|
min-width: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.labelText {
|
||||||
|
display: block;
|
||||||
font-size: $inner-section-text-size;
|
font-size: $inner-section-text-size;
|
||||||
color: $label-gray;
|
color: $label-gray;
|
||||||
|
white-space: nowrap;
|
||||||
|
overflow: hidden;
|
||||||
|
text-overflow: ellipsis;
|
||||||
}
|
}
|
||||||
|
|
||||||
.controls {
|
.controls {
|
||||||
|
|||||||
@@ -3,7 +3,9 @@ import { millisToString, parseUserTime } from 'ontime-utils';
|
|||||||
import { IoArrowDown, IoArrowUp, IoPause, IoPlay, IoStop } from 'react-icons/io5';
|
import { IoArrowDown, IoArrowUp, IoPause, IoPlay, IoStop } from 'react-icons/io5';
|
||||||
|
|
||||||
import TimeInput from '../../../../common/components/input/time-input/TimeInput';
|
import TimeInput from '../../../../common/components/input/time-input/TimeInput';
|
||||||
|
import Tooltip from '../../../../common/components/tooltip/Tooltip';
|
||||||
import { setAuxTimer, useAuxTimerControl, useAuxTimerTime } from '../../../../common/hooks/useSocket';
|
import { setAuxTimer, useAuxTimerControl, useAuxTimerTime } from '../../../../common/hooks/useSocket';
|
||||||
|
import { getAuxTimerIndexedLabel } from '../../../../common/utils/auxTimerUtils';
|
||||||
import TapButton from '../tap-button/TapButton';
|
import TapButton from '../tap-button/TapButton';
|
||||||
|
|
||||||
import style from './AuxTimer.module.scss';
|
import style from './AuxTimer.module.scss';
|
||||||
@@ -13,10 +15,12 @@ interface AuxTimerProps {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function AuxTimer({ index }: AuxTimerProps) {
|
export function AuxTimer({ index }: AuxTimerProps) {
|
||||||
const { playback, direction } = useAuxTimerControl(index);
|
const { playback, direction, name } = useAuxTimerControl(index);
|
||||||
|
|
||||||
const { stop, setDirection } = setAuxTimer;
|
const { stop, setDirection } = setAuxTimer;
|
||||||
|
|
||||||
|
const label = getAuxTimerIndexedLabel(name, index);
|
||||||
|
|
||||||
const toggleDirection = () => {
|
const toggleDirection = () => {
|
||||||
const newDirection = direction === SimpleDirection.CountDown ? SimpleDirection.CountUp : SimpleDirection.CountDown;
|
const newDirection = direction === SimpleDirection.CountDown ? SimpleDirection.CountUp : SimpleDirection.CountDown;
|
||||||
setDirection(index, newDirection);
|
setDirection(index, newDirection);
|
||||||
@@ -27,10 +31,12 @@ export function AuxTimer({ index }: AuxTimerProps) {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<label className={style.label}>
|
<label className={style.label}>
|
||||||
Aux Timer {index}
|
<Tooltip text={label} render={<span />} className={style.labelText}>
|
||||||
|
{label}
|
||||||
|
</Tooltip>
|
||||||
<div className={style.controls}>
|
<div className={style.controls}>
|
||||||
<div className={style.input}>
|
<div className={style.input}>
|
||||||
<AuxTimerInput index={index} isActive={isActive} />
|
<AuxTimerInput index={index} isActive={isActive} placeholder={`Aux ${index}`} />
|
||||||
<TapButton onClick={toggleDirection} aspect='tight' disabled={isActive}>
|
<TapButton onClick={toggleDirection} aspect='tight' disabled={isActive}>
|
||||||
{direction === SimpleDirection.CountDown && <IoArrowDown data-testid={`aux-timer-direction-${index}`} />}
|
{direction === SimpleDirection.CountDown && <IoArrowDown data-testid={`aux-timer-direction-${index}`} />}
|
||||||
{direction === SimpleDirection.CountUp && <IoArrowUp data-testid={`aux-timer-direction-${index}`} />}
|
{direction === SimpleDirection.CountUp && <IoArrowUp data-testid={`aux-timer-direction-${index}`} />}
|
||||||
@@ -50,9 +56,10 @@ export function AuxTimer({ index }: AuxTimerProps) {
|
|||||||
interface AuxTimerInputProps {
|
interface AuxTimerInputProps {
|
||||||
index: number;
|
index: number;
|
||||||
isActive: boolean;
|
isActive: boolean;
|
||||||
|
placeholder: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
function AuxTimerInput({ index, isActive }: AuxTimerInputProps) {
|
function AuxTimerInput({ index, isActive, placeholder }: AuxTimerInputProps) {
|
||||||
const newTimeInMs = useAuxTimerTime(index);
|
const newTimeInMs = useAuxTimerTime(index);
|
||||||
const { setDuration } = setAuxTimer;
|
const { setDuration } = setAuxTimer;
|
||||||
|
|
||||||
@@ -70,7 +77,7 @@ function AuxTimerInput({ index, isActive }: AuxTimerInputProps) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<TimeInput submitHandler={handleTimeUpdate} name={`aux${index}`} time={newTimeInMs} placeholder={`Aux ${index}`} />
|
<TimeInput submitHandler={handleTimeUpdate} name={`aux${index}`} time={newTimeInMs} placeholder={placeholder} />
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
import { Playback, TimerPhase, ViewSettings } from 'ontime-types';
|
import { Playback, TimerPhase, ViewSettings } from 'ontime-types';
|
||||||
import { millisToString } from 'ontime-utils';
|
import { millisToString } from 'ontime-utils';
|
||||||
|
|
||||||
import { useAuxTimersTime, useStudioTimersSocket } from '../../common/hooks/useSocket';
|
import { useAuxTimersName, useAuxTimersTime, useStudioTimersSocket } from '../../common/hooks/useSocket';
|
||||||
|
import { getAuxTimerLabel } from '../../common/utils/auxTimerUtils';
|
||||||
import { getOffsetState } from '../../common/utils/offset';
|
import { getOffsetState } from '../../common/utils/offset';
|
||||||
import { cx } from '../../common/utils/styleUtils';
|
import { cx } from '../../common/utils/styleUtils';
|
||||||
import { useTranslation } from '../../translation/TranslationProvider';
|
import { useTranslation } from '../../translation/TranslationProvider';
|
||||||
@@ -121,22 +122,23 @@ export default function StudioTimers({ viewSettings }: StudioTimersProps) {
|
|||||||
|
|
||||||
function StudioTimersAux() {
|
function StudioTimersAux() {
|
||||||
const auxTimer = useAuxTimersTime();
|
const auxTimer = useAuxTimersTime();
|
||||||
|
const auxName = useAuxTimersName();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className='card' id='card-aux'>
|
<div className='card' id='card-aux'>
|
||||||
<div className='card__row'>
|
<div className='card__row'>
|
||||||
<div>
|
<div>
|
||||||
<div className='label'>Aux 1</div>
|
<div className='label'>{getAuxTimerLabel(auxName.aux1, 'Aux 1')}</div>
|
||||||
<div className='extra'>{millisToString(auxTimer.aux1)}</div>
|
<div className='extra'>{millisToString(auxTimer.aux1)}</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<div className='label center'>Aux 2</div>
|
<div className='label center'>{getAuxTimerLabel(auxName.aux2, 'Aux 2')}</div>
|
||||||
<div className='extra center'>{millisToString(auxTimer.aux2)}</div>
|
<div className='extra center'>{millisToString(auxTimer.aux2)}</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<div className='label right'>Aux 3</div>
|
<div className='label right'>{getAuxTimerLabel(auxName.aux3, 'Aux 3')}</div>
|
||||||
<div className='extra right'>{millisToString(auxTimer.aux3)}</div>
|
<div className='extra right'>{millisToString(auxTimer.aux3)}</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -90,4 +90,14 @@ describe('test parseDatabaseModel() edge cases', () => {
|
|||||||
// @ts-expect-error -- we know this is wrong, testing imports outside domain
|
// @ts-expect-error -- we know this is wrong, testing imports outside domain
|
||||||
expect(() => parseDatabaseModel('some random dataset')).toThrow();
|
expect(() => parseDatabaseModel('some random dataset')).toThrow();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('creates the aux timer names when importing a project file which predates the feature', () => {
|
||||||
|
const oldProject = structuredClone(demoDb);
|
||||||
|
// @ts-expect-error -- simulating a project file saved before aux timer naming existed
|
||||||
|
delete oldProject.settings.auxTimerNames;
|
||||||
|
|
||||||
|
const { data } = parseDatabaseModel(oldProject);
|
||||||
|
|
||||||
|
expect(data.settings.auxTimerNames).toStrictEqual(['', '', '']);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -74,7 +74,15 @@ export function migrateSettings(jsonData: object): (Settings & { serverPort: num
|
|||||||
const { serverPort, editorKey, operatorKey, timeFormat, language } = structuredClone(
|
const { serverPort, editorKey, operatorKey, timeFormat, language } = structuredClone(
|
||||||
jsonData.settings,
|
jsonData.settings,
|
||||||
) as old_Settings;
|
) as old_Settings;
|
||||||
return { version: '4.0.0', serverPort, editorKey, operatorKey, timeFormat, language };
|
return {
|
||||||
|
version: '4.0.0',
|
||||||
|
serverPort,
|
||||||
|
editorKey,
|
||||||
|
operatorKey,
|
||||||
|
timeFormat,
|
||||||
|
language,
|
||||||
|
auxTimerNames: ['', '', ''],
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import { DatabaseModel, Settings } from 'ontime-types';
|
import { DatabaseModel, Settings } from 'ontime-types';
|
||||||
|
import { sanitiseAuxTimerNames } from 'ontime-utils';
|
||||||
|
|
||||||
import { is } from '../../../utils/is.js';
|
import { is } from '../../../utils/is.js';
|
||||||
|
|
||||||
@@ -23,6 +24,7 @@ export function migrateServerPort(jsonData: Partial<DatabaseModel>): {
|
|||||||
const operatorKey = settings?.operatorKey;
|
const operatorKey = settings?.operatorKey;
|
||||||
const timeFormat = settings?.timeFormat;
|
const timeFormat = settings?.timeFormat;
|
||||||
const language = settings?.language;
|
const language = settings?.language;
|
||||||
|
const auxTimerNames = sanitiseAuxTimerNames(settings?.auxTimerNames);
|
||||||
const version = '4.5.0';
|
const version = '4.5.0';
|
||||||
db.settings = {
|
db.settings = {
|
||||||
version,
|
version,
|
||||||
@@ -30,6 +32,7 @@ export function migrateServerPort(jsonData: Partial<DatabaseModel>): {
|
|||||||
operatorKey,
|
operatorKey,
|
||||||
timeFormat,
|
timeFormat,
|
||||||
language,
|
language,
|
||||||
|
auxTimerNames,
|
||||||
app: 'ontime',
|
app: 'ontime',
|
||||||
} as Settings;
|
} as Settings;
|
||||||
return { db, serverPort: settings?.serverPort };
|
return { db, serverPort: settings?.serverPort };
|
||||||
|
|||||||
@@ -184,6 +184,7 @@ describe('v3 to v4', () => {
|
|||||||
operatorKey: null,
|
operatorKey: null,
|
||||||
timeFormat: '24',
|
timeFormat: '24',
|
||||||
language: 'en',
|
language: 'en',
|
||||||
|
auxTimerNames: ['', '', ''],
|
||||||
};
|
};
|
||||||
const newSettings = v3.migrateSettings(oldDb);
|
const newSettings = v3.migrateSettings(oldDb);
|
||||||
expect(newSettings).toEqual(expectSettings);
|
expect(newSettings).toEqual(expectSettings);
|
||||||
|
|||||||
@@ -16,6 +16,36 @@ describe('parseSettings()', () => {
|
|||||||
operatorKey: null,
|
operatorKey: null,
|
||||||
timeFormat: '24',
|
timeFormat: '24',
|
||||||
language: 'en',
|
language: 'en',
|
||||||
|
auxTimerNames: ['', '', ''],
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('carries custom aux timer names through and pads to a length-3 array', () => {
|
||||||
|
const result = parseSettings({
|
||||||
|
settings: { version: '1', auxTimerNames: ['Speaker'] } as unknown as Settings,
|
||||||
|
});
|
||||||
|
expect(result.auxTimerNames).toStrictEqual(['Speaker', '', '']);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('falls back to defaults when aux timer names are missing or malformed', () => {
|
||||||
|
const result = parseSettings({
|
||||||
|
settings: { version: '1', auxTimerNames: 'not-an-array' } as unknown as Settings,
|
||||||
|
});
|
||||||
|
expect(result.auxTimerNames).toStrictEqual(['', '', '']);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('creates the aux timer names for project files made before the feature existed', () => {
|
||||||
|
const oldSettings = {
|
||||||
|
version: '4.5.0',
|
||||||
|
editorKey: null,
|
||||||
|
operatorKey: null,
|
||||||
|
timeFormat: '24',
|
||||||
|
language: 'en',
|
||||||
|
};
|
||||||
|
|
||||||
|
const result = parseSettings({ settings: oldSettings as Settings });
|
||||||
|
|
||||||
|
expect(result.auxTimerNames).toStrictEqual(['', '', '']);
|
||||||
|
expect(result).toMatchObject({ timeFormat: '24', language: 'en' });
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import { DatabaseModel, Settings } from 'ontime-types';
|
import { DatabaseModel, Settings } from 'ontime-types';
|
||||||
|
import { sanitiseAuxTimerNames } from 'ontime-utils';
|
||||||
|
|
||||||
import { getPartialProject } from '../../models/dataModel.js';
|
import { getPartialProject } from '../../models/dataModel.js';
|
||||||
|
|
||||||
@@ -22,5 +23,7 @@ export function parseSettings(data: Partial<DatabaseModel>): Settings {
|
|||||||
operatorKey: data.settings.operatorKey ?? defaultSettings.operatorKey,
|
operatorKey: data.settings.operatorKey ?? defaultSettings.operatorKey,
|
||||||
timeFormat: data.settings.timeFormat ?? defaultSettings.timeFormat,
|
timeFormat: data.settings.timeFormat ?? defaultSettings.timeFormat,
|
||||||
language: data.settings.language ?? defaultSettings.language,
|
language: data.settings.language ?? defaultSettings.language,
|
||||||
|
// older project files predate this property
|
||||||
|
auxTimerNames: sanitiseAuxTimerNames(data.settings.auxTimerNames),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import { sendRefetch } from '../../adapters/WebsocketAdapter.js';
|
|||||||
import { getDataProvider } from '../../classes/data-provider/DataProvider.js';
|
import { getDataProvider } from '../../classes/data-provider/DataProvider.js';
|
||||||
import { portManager } from '../../classes/port-manager/PortManager.js';
|
import { portManager } from '../../classes/port-manager/PortManager.js';
|
||||||
import * as appState from '../../services/app-state-service/AppStateService.js';
|
import * as appState from '../../services/app-state-service/AppStateService.js';
|
||||||
|
import { auxTimerService } from '../../services/aux-timer-service/AuxTimerService.js';
|
||||||
import { validateSettings, validateWelcomeDialog, validateServerPort } from './settings.validation.js';
|
import { validateSettings, validateWelcomeDialog, validateServerPort } from './settings.validation.js';
|
||||||
|
|
||||||
export const router: Router = express.Router();
|
export const router: Router = express.Router();
|
||||||
@@ -41,6 +42,10 @@ router.post('/', validateSettings, async (req: Request, res: Response<Settings |
|
|||||||
|
|
||||||
if (!deepEqual(data, settings)) {
|
if (!deepEqual(data, settings)) {
|
||||||
await getDataProvider().setSettings(data);
|
await getDataProvider().setSettings(data);
|
||||||
|
// keep the runtime aux timers in sync so consumers get the new names live
|
||||||
|
if (!deepEqual(data.auxTimerNames, settings.auxTimerNames)) {
|
||||||
|
auxTimerService.loadNames(data.auxTimerNames);
|
||||||
|
}
|
||||||
sendRefetch(RefetchKey.Settings);
|
sendRefetch(RefetchKey.Settings);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import { body } from 'express-validator';
|
import { body } from 'express-validator';
|
||||||
|
import { sanitiseAuxTimerNames } from 'ontime-utils';
|
||||||
|
|
||||||
import { requestValidationFunction } from '../validation-utils/validationFunction.js';
|
import { requestValidationFunction } from '../validation-utils/validationFunction.js';
|
||||||
|
|
||||||
@@ -27,6 +28,7 @@ export const validateSettings = [
|
|||||||
pinValidator('operatorKey'),
|
pinValidator('operatorKey'),
|
||||||
body('timeFormat').isString().isIn(['12', '24']).withMessage('Time format can only be "12" or "24"'),
|
body('timeFormat').isString().isIn(['12', '24']).withMessage('Time format can only be "12" or "24"'),
|
||||||
body('language').isString().trim().notEmpty(),
|
body('language').isString().trim().notEmpty(),
|
||||||
|
body('auxTimerNames').isArray().withMessage('auxTimerNames must be an array').customSanitizer(sanitiseAuxTimerNames),
|
||||||
|
|
||||||
requestValidationFunction,
|
requestValidationFunction,
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import cookieParser from 'cookie-parser';
|
|||||||
import cors from 'cors';
|
import cors from 'cors';
|
||||||
import express from 'express';
|
import express from 'express';
|
||||||
import { LogOrigin, SimpleDirection, SimplePlayback, runtimeStorePlaceholder } from 'ontime-types';
|
import { LogOrigin, SimpleDirection, SimplePlayback, runtimeStorePlaceholder } from 'ontime-types';
|
||||||
|
import { sanitiseAuxTimerNames } from 'ontime-utils';
|
||||||
import serverTiming from 'server-timing';
|
import serverTiming from 'server-timing';
|
||||||
|
|
||||||
import { oscServer } from './adapters/OscAdapter.js';
|
import { oscServer } from './adapters/OscAdapter.js';
|
||||||
@@ -26,6 +27,7 @@ import { bodyParser } from './middleware/bodyParser.js';
|
|||||||
import { compressedStatic } from './middleware/staticGZip.js';
|
import { compressedStatic } from './middleware/staticGZip.js';
|
||||||
import { ONTIME_VERSION } from './ONTIME_VERSION.js';
|
import { ONTIME_VERSION } from './ONTIME_VERSION.js';
|
||||||
import { getShowWelcomeDialog } from './services/app-state-service/AppStateService.js';
|
import { getShowWelcomeDialog } from './services/app-state-service/AppStateService.js';
|
||||||
|
import { auxTimerService } from './services/aux-timer-service/AuxTimerService.js';
|
||||||
import * as messageService from './services/message-service/message.service.js';
|
import * as messageService from './services/message-service/message.service.js';
|
||||||
import { initialiseProject } from './services/project-service/ProjectService.js';
|
import { initialiseProject } from './services/project-service/ProjectService.js';
|
||||||
import { restoreService } from './services/restore-service/restore.service.js';
|
import { restoreService } from './services/restore-service/restore.service.js';
|
||||||
@@ -204,6 +206,7 @@ export const startServer = async (): Promise<{ message: string; serverPort: numb
|
|||||||
* Module initialises the services and provides initial payload for the store
|
* Module initialises the services and provides initial payload for the store
|
||||||
*/
|
*/
|
||||||
const state = getState();
|
const state = getState();
|
||||||
|
const [auxName1, auxName2, auxName3] = sanitiseAuxTimerNames(getDataProvider().getSettings().auxTimerNames);
|
||||||
eventStore.init({
|
eventStore.init({
|
||||||
clock: state.clock,
|
clock: state.clock,
|
||||||
timer: state.timer,
|
timer: state.timer,
|
||||||
@@ -219,22 +222,28 @@ export const startServer = async (): Promise<{ message: string; serverPort: numb
|
|||||||
current: timerConfig.auxTimerDefault,
|
current: timerConfig.auxTimerDefault,
|
||||||
playback: SimplePlayback.Stop,
|
playback: SimplePlayback.Stop,
|
||||||
direction: SimpleDirection.CountDown,
|
direction: SimpleDirection.CountDown,
|
||||||
|
name: auxName1,
|
||||||
},
|
},
|
||||||
auxtimer2: {
|
auxtimer2: {
|
||||||
duration: timerConfig.auxTimerDefault,
|
duration: timerConfig.auxTimerDefault,
|
||||||
current: timerConfig.auxTimerDefault,
|
current: timerConfig.auxTimerDefault,
|
||||||
playback: SimplePlayback.Stop,
|
playback: SimplePlayback.Stop,
|
||||||
direction: SimpleDirection.CountDown,
|
direction: SimpleDirection.CountDown,
|
||||||
|
name: auxName2,
|
||||||
},
|
},
|
||||||
auxtimer3: {
|
auxtimer3: {
|
||||||
duration: timerConfig.auxTimerDefault,
|
duration: timerConfig.auxTimerDefault,
|
||||||
current: timerConfig.auxTimerDefault,
|
current: timerConfig.auxTimerDefault,
|
||||||
playback: SimplePlayback.Stop,
|
playback: SimplePlayback.Stop,
|
||||||
direction: SimpleDirection.CountDown,
|
direction: SimpleDirection.CountDown,
|
||||||
|
name: auxName3,
|
||||||
},
|
},
|
||||||
ping: 1,
|
ping: 1,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// AuxTimerService owns its own SimpleTimer instances, so the store above doesn't update them
|
||||||
|
auxTimerService.loadNames(getDataProvider().getSettings().auxTimerNames);
|
||||||
|
|
||||||
// initialise message service
|
// initialise message service
|
||||||
messageService.init(eventStore.set, eventStore.get);
|
messageService.init(eventStore.set, eventStore.get);
|
||||||
|
|
||||||
|
|||||||
@@ -81,6 +81,7 @@ describe('safeMerge', () => {
|
|||||||
editorKey: null,
|
editorKey: null,
|
||||||
timeFormat: baseDb.settings.timeFormat,
|
timeFormat: baseDb.settings.timeFormat,
|
||||||
language: 'pt',
|
language: 'pt',
|
||||||
|
auxTimerNames: baseDb.settings.auxTimerNames,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ export class SimpleTimer {
|
|||||||
current: 0,
|
current: 0,
|
||||||
playback: SimplePlayback.Stop,
|
playback: SimplePlayback.Stop,
|
||||||
direction: SimpleDirection.CountDown,
|
direction: SimpleDirection.CountDown,
|
||||||
|
name: '',
|
||||||
};
|
};
|
||||||
private startedAt: number | null = null;
|
private startedAt: number | null = null;
|
||||||
private pausedAt: number | null = null;
|
private pausedAt: number | null = null;
|
||||||
@@ -23,9 +24,16 @@ export class SimpleTimer {
|
|||||||
current: 0,
|
current: 0,
|
||||||
playback: SimplePlayback.Stop,
|
playback: SimplePlayback.Stop,
|
||||||
direction: SimpleDirection.CountDown,
|
direction: SimpleDirection.CountDown,
|
||||||
|
// the name is a persisted configuration, independent of the timer runtime
|
||||||
|
name: this.state.name,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public setName(name: string): SimpleTimerState {
|
||||||
|
this.state.name = name;
|
||||||
|
return this.state;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the duration of the timer
|
* Sets the duration of the timer
|
||||||
* @param time - time in milliseconds
|
* @param time - time in milliseconds
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ describe('SimpleTimer count-down', () => {
|
|||||||
current: initialTime,
|
current: initialTime,
|
||||||
direction: SimpleDirection.CountDown,
|
direction: SimpleDirection.CountDown,
|
||||||
playback: SimplePlayback.Stop,
|
playback: SimplePlayback.Stop,
|
||||||
|
name: '',
|
||||||
};
|
};
|
||||||
expect(newState).toStrictEqual(expected);
|
expect(newState).toStrictEqual(expected);
|
||||||
});
|
});
|
||||||
@@ -27,6 +28,7 @@ describe('SimpleTimer count-down', () => {
|
|||||||
current: initialTime,
|
current: initialTime,
|
||||||
direction: SimpleDirection.CountDown,
|
direction: SimpleDirection.CountDown,
|
||||||
playback: SimplePlayback.Start,
|
playback: SimplePlayback.Start,
|
||||||
|
name: '',
|
||||||
};
|
};
|
||||||
expect(newState).toStrictEqual(expected);
|
expect(newState).toStrictEqual(expected);
|
||||||
});
|
});
|
||||||
@@ -38,6 +40,7 @@ describe('SimpleTimer count-down', () => {
|
|||||||
current: initialTime - 100,
|
current: initialTime - 100,
|
||||||
direction: SimpleDirection.CountDown,
|
direction: SimpleDirection.CountDown,
|
||||||
playback: SimplePlayback.Start,
|
playback: SimplePlayback.Start,
|
||||||
|
name: '',
|
||||||
};
|
};
|
||||||
expect(newState).toStrictEqual(expected);
|
expect(newState).toStrictEqual(expected);
|
||||||
|
|
||||||
@@ -58,6 +61,7 @@ describe('SimpleTimer count-down', () => {
|
|||||||
current: initialTime - 1500,
|
current: initialTime - 1500,
|
||||||
direction: SimpleDirection.CountDown,
|
direction: SimpleDirection.CountDown,
|
||||||
playback: SimplePlayback.Pause,
|
playback: SimplePlayback.Pause,
|
||||||
|
name: '',
|
||||||
};
|
};
|
||||||
expect(newState).toStrictEqual(expected);
|
expect(newState).toStrictEqual(expected);
|
||||||
|
|
||||||
@@ -83,6 +87,7 @@ describe('SimpleTimer count-down', () => {
|
|||||||
current: initialTime,
|
current: initialTime,
|
||||||
direction: SimpleDirection.CountDown,
|
direction: SimpleDirection.CountDown,
|
||||||
playback: SimplePlayback.Stop,
|
playback: SimplePlayback.Stop,
|
||||||
|
name: '',
|
||||||
};
|
};
|
||||||
expect(newState).toStrictEqual(expected);
|
expect(newState).toStrictEqual(expected);
|
||||||
});
|
});
|
||||||
@@ -97,6 +102,7 @@ describe('SimpleTimer count-down', () => {
|
|||||||
current: initialTime,
|
current: initialTime,
|
||||||
direction: SimpleDirection.CountUp,
|
direction: SimpleDirection.CountUp,
|
||||||
playback: SimplePlayback.Start,
|
playback: SimplePlayback.Start,
|
||||||
|
name: '',
|
||||||
};
|
};
|
||||||
|
|
||||||
newState = timer.update(100);
|
newState = timer.update(100);
|
||||||
@@ -127,6 +133,7 @@ describe('SimpleTimer count-down', () => {
|
|||||||
current: 1000,
|
current: 1000,
|
||||||
direction: SimpleDirection.CountUp,
|
direction: SimpleDirection.CountUp,
|
||||||
playback: SimplePlayback.Start,
|
playback: SimplePlayback.Start,
|
||||||
|
name: '',
|
||||||
});
|
});
|
||||||
|
|
||||||
newState = timer.update(100);
|
newState = timer.update(100);
|
||||||
@@ -135,6 +142,7 @@ describe('SimpleTimer count-down', () => {
|
|||||||
current: initialTime + 100,
|
current: initialTime + 100,
|
||||||
direction: SimpleDirection.CountUp,
|
direction: SimpleDirection.CountUp,
|
||||||
playback: SimplePlayback.Start,
|
playback: SimplePlayback.Start,
|
||||||
|
name: '',
|
||||||
});
|
});
|
||||||
|
|
||||||
newState = timer.update(500);
|
newState = timer.update(500);
|
||||||
@@ -143,6 +151,7 @@ describe('SimpleTimer count-down', () => {
|
|||||||
current: 1500,
|
current: 1500,
|
||||||
direction: SimpleDirection.CountUp,
|
direction: SimpleDirection.CountUp,
|
||||||
playback: SimplePlayback.Start,
|
playback: SimplePlayback.Start,
|
||||||
|
name: '',
|
||||||
});
|
});
|
||||||
|
|
||||||
newState = timer.setDirection(SimpleDirection.CountDown, 600);
|
newState = timer.setDirection(SimpleDirection.CountDown, 600);
|
||||||
@@ -151,6 +160,7 @@ describe('SimpleTimer count-down', () => {
|
|||||||
current: 1500,
|
current: 1500,
|
||||||
direction: SimpleDirection.CountDown,
|
direction: SimpleDirection.CountDown,
|
||||||
playback: SimplePlayback.Start,
|
playback: SimplePlayback.Start,
|
||||||
|
name: '',
|
||||||
});
|
});
|
||||||
|
|
||||||
newState = timer.update(700);
|
newState = timer.update(700);
|
||||||
@@ -159,6 +169,7 @@ describe('SimpleTimer count-down', () => {
|
|||||||
current: 1400,
|
current: 1400,
|
||||||
direction: SimpleDirection.CountDown,
|
direction: SimpleDirection.CountDown,
|
||||||
playback: SimplePlayback.Start,
|
playback: SimplePlayback.Start,
|
||||||
|
name: '',
|
||||||
});
|
});
|
||||||
|
|
||||||
newState = timer.setDirection(SimpleDirection.CountUp, 700);
|
newState = timer.setDirection(SimpleDirection.CountUp, 700);
|
||||||
@@ -167,6 +178,7 @@ describe('SimpleTimer count-down', () => {
|
|||||||
current: 1400,
|
current: 1400,
|
||||||
direction: SimpleDirection.CountUp,
|
direction: SimpleDirection.CountUp,
|
||||||
playback: SimplePlayback.Start,
|
playback: SimplePlayback.Start,
|
||||||
|
name: '',
|
||||||
});
|
});
|
||||||
|
|
||||||
newState = timer.update(800);
|
newState = timer.update(800);
|
||||||
@@ -175,6 +187,7 @@ describe('SimpleTimer count-down', () => {
|
|||||||
current: 1500,
|
current: 1500,
|
||||||
direction: SimpleDirection.CountUp,
|
direction: SimpleDirection.CountUp,
|
||||||
playback: SimplePlayback.Start,
|
playback: SimplePlayback.Start,
|
||||||
|
name: '',
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ const dbModel: DatabaseModel = {
|
|||||||
operatorKey: null,
|
operatorKey: null,
|
||||||
timeFormat: '24',
|
timeFormat: '24',
|
||||||
language: 'en',
|
language: 'en',
|
||||||
|
auxTimerNames: ['', '', ''],
|
||||||
},
|
},
|
||||||
viewSettings: {
|
viewSettings: {
|
||||||
overrideStyles: false,
|
overrideStyles: false,
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ export const demoDb: DatabaseModel = {
|
|||||||
operatorKey: null,
|
operatorKey: null,
|
||||||
timeFormat: '24',
|
timeFormat: '24',
|
||||||
language: 'en',
|
language: 'en',
|
||||||
|
auxTimerNames: ['', '', ''],
|
||||||
},
|
},
|
||||||
viewSettings: {
|
viewSettings: {
|
||||||
dangerColor: '#ff7300',
|
dangerColor: '#ff7300',
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import { RuntimeStore, SimpleDirection, SimplePlayback } from 'ontime-types';
|
import { RuntimeStore, SimpleDirection, SimplePlayback } from 'ontime-types';
|
||||||
|
import { sanitiseAuxTimerNames } from 'ontime-utils';
|
||||||
|
|
||||||
import { SimpleTimer } from '../../classes/simple-timer/SimpleTimer.js';
|
import { SimpleTimer } from '../../classes/simple-timer/SimpleTimer.js';
|
||||||
import { timerConfig } from '../../setup/config.js';
|
import { timerConfig } from '../../setup/config.js';
|
||||||
@@ -24,6 +25,20 @@ export class AuxTimerService {
|
|||||||
this.getTime = getTime;
|
this.getTime = getTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called at bootstrap and whenever the loaded project's settings change,
|
||||||
|
* so the running timers reflect the current project's aux timer names.
|
||||||
|
*/
|
||||||
|
loadNames(names?: string[]) {
|
||||||
|
const [name1, name2, name3] = sanitiseAuxTimerNames(names);
|
||||||
|
const patch: AuxTimerStateUpdate = {
|
||||||
|
auxtimer1: this.aux1.setName(name1),
|
||||||
|
auxtimer2: this.aux2.setName(name2),
|
||||||
|
auxtimer3: this.aux3.setName(name3),
|
||||||
|
};
|
||||||
|
this.emit(patch);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Whether any of the aux timers are currently running
|
* Whether any of the aux timers are currently running
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -0,0 +1,53 @@
|
|||||||
|
import { RuntimeStore } from 'ontime-types';
|
||||||
|
|
||||||
|
import { AuxTimerService } from '../AuxTimerService.js';
|
||||||
|
|
||||||
|
describe('AuxTimerService', () => {
|
||||||
|
describe('loadNames()', () => {
|
||||||
|
it('applies the names to each aux timer and broadcasts them', () => {
|
||||||
|
const emit = vi.fn();
|
||||||
|
const service = new AuxTimerService(emit, () => 0);
|
||||||
|
|
||||||
|
service.loadNames(['Speaker', 'Break', 'Q&A']);
|
||||||
|
|
||||||
|
const patch = emit.mock.calls.at(-1)?.[0] as Partial<RuntimeStore>;
|
||||||
|
expect(patch.auxtimer1?.name).toBe('Speaker');
|
||||||
|
expect(patch.auxtimer2?.name).toBe('Break');
|
||||||
|
expect(patch.auxtimer3?.name).toBe('Q&A');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('defaults missing names to an empty string', () => {
|
||||||
|
const emit = vi.fn();
|
||||||
|
const service = new AuxTimerService(emit, () => 0);
|
||||||
|
|
||||||
|
service.loadNames(['only-one']);
|
||||||
|
|
||||||
|
const patch = emit.mock.calls.at(-1)?.[0] as Partial<RuntimeStore>;
|
||||||
|
expect(patch.auxtimer1?.name).toBe('only-one');
|
||||||
|
expect(patch.auxtimer2?.name).toBe('');
|
||||||
|
expect(patch.auxtimer3?.name).toBe('');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('handles names missing from a project file', () => {
|
||||||
|
const emit = vi.fn();
|
||||||
|
const service = new AuxTimerService(emit, () => 0);
|
||||||
|
|
||||||
|
expect(() => service.loadNames(undefined)).not.toThrow();
|
||||||
|
|
||||||
|
const patch = emit.mock.calls.at(-1)?.[0] as Partial<RuntimeStore>;
|
||||||
|
expect(patch.auxtimer1?.name).toBe('');
|
||||||
|
expect(patch.auxtimer2?.name).toBe('');
|
||||||
|
expect(patch.auxtimer3?.name).toBe('');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('keeps the name on the timer through subsequent commands', () => {
|
||||||
|
const emit = vi.fn();
|
||||||
|
const service = new AuxTimerService(emit, () => 0);
|
||||||
|
|
||||||
|
service.loadNames(['Speaker', '', '']);
|
||||||
|
const started = service.start(1);
|
||||||
|
|
||||||
|
expect(started.name).toBe('Speaker');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -1,9 +1,10 @@
|
|||||||
import { copyFile } from 'fs/promises';
|
import { copyFile } from 'fs/promises';
|
||||||
import { join } from 'path';
|
import { join } from 'path';
|
||||||
|
|
||||||
import { DatabaseModel, LogOrigin, ProjectFileListResponse } from 'ontime-types';
|
import { DatabaseModel, LogOrigin, ProjectFileListResponse, RefetchKey } from 'ontime-types';
|
||||||
import { getErrorMessage, getFirstRundown } from 'ontime-utils';
|
import { getErrorMessage, getFirstRundown } from 'ontime-utils';
|
||||||
|
|
||||||
|
import { sendRefetch } from '../../adapters/WebsocketAdapter.js';
|
||||||
import { parseCustomFields } from '../../api-data/custom-fields/customFields.parser.js';
|
import { parseCustomFields } from '../../api-data/custom-fields/customFields.parser.js';
|
||||||
import { parseDatabaseModel } from '../../api-data/db/db.parser.js';
|
import { parseDatabaseModel } from '../../api-data/db/db.parser.js';
|
||||||
import { getCurrentRundown } from '../../api-data/rundown/rundown.dao.js';
|
import { getCurrentRundown } from '../../api-data/rundown/rundown.dao.js';
|
||||||
@@ -28,6 +29,7 @@ import {
|
|||||||
removeFileExtension,
|
removeFileExtension,
|
||||||
} from '../../utils/fileManagement.js';
|
} from '../../utils/fileManagement.js';
|
||||||
import { getLastLoaded, isLastLoadedProject, setLastLoaded } from '../app-state-service/AppStateService.js';
|
import { getLastLoaded, isLastLoadedProject, setLastLoaded } from '../app-state-service/AppStateService.js';
|
||||||
|
import { auxTimerService } from '../aux-timer-service/AuxTimerService.js';
|
||||||
import { runtimeService } from '../runtime-service/runtime.service.js';
|
import { runtimeService } from '../runtime-service/runtime.service.js';
|
||||||
import {
|
import {
|
||||||
doesProjectExist,
|
doesProjectExist,
|
||||||
@@ -88,12 +90,16 @@ async function loadProject(projectData: DatabaseModel, fileName: string, rundown
|
|||||||
// stop the runtime service
|
// stop the runtime service
|
||||||
runtimeService.stop();
|
runtimeService.stop();
|
||||||
|
|
||||||
|
// AuxTimerService holds its own state, independent of the loaded project, so it needs to be updated explicitly
|
||||||
|
auxTimerService.loadNames(projectData.settings.auxTimerNames);
|
||||||
|
|
||||||
// load the rundown given by key otherwise load the first in the project
|
// load the rundown given by key otherwise load the first in the project
|
||||||
const rundown =
|
const rundown =
|
||||||
rundownId && rundownId in projectData.rundowns
|
rundownId && rundownId in projectData.rundowns
|
||||||
? projectData.rundowns[rundownId]
|
? projectData.rundowns[rundownId]
|
||||||
: getFirstRundown(projectData.rundowns);
|
: getFirstRundown(projectData.rundowns);
|
||||||
|
|
||||||
|
// initialising the rundown with reload sends a refetch to the clients
|
||||||
await initRundown(rundown, projectData.customFields, true);
|
await initRundown(rundown, projectData.customFields, true);
|
||||||
|
|
||||||
// persist the project selection
|
// persist the project selection
|
||||||
@@ -346,6 +352,12 @@ export async function patchCurrentProject(data: Partial<DatabaseModel>) {
|
|||||||
// we can pass some stuff straight to the data provider
|
// we can pass some stuff straight to the data provider
|
||||||
await getDataProvider().mergeIntoData(rest);
|
await getDataProvider().mergeIntoData(rest);
|
||||||
|
|
||||||
|
// AuxTimerService holds its own state, so a settings patch needs to be applied to it explicitly
|
||||||
|
if (rest.settings) {
|
||||||
|
auxTimerService.loadNames(getDataProvider().getSettings().auxTimerNames);
|
||||||
|
sendRefetch(RefetchKey.Settings);
|
||||||
|
}
|
||||||
|
|
||||||
// the rundown depends on custom fields
|
// the rundown depends on custom fields
|
||||||
// so custom fields needs to be checked first
|
// so custom fields needs to be checked first
|
||||||
if (customFields) {
|
if (customFields) {
|
||||||
|
|||||||
@@ -6,4 +6,9 @@ export type Settings = {
|
|||||||
operatorKey: null | string;
|
operatorKey: null | string;
|
||||||
timeFormat: TimeFormat;
|
timeFormat: TimeFormat;
|
||||||
language: string;
|
language: string;
|
||||||
|
/**
|
||||||
|
* Custom names for the aux timers, one entry per aux timer in order (index 0 is aux timer 1).
|
||||||
|
* An empty string means the timer is unnamed and consumers show the default label
|
||||||
|
*/
|
||||||
|
auxTimerNames: string[];
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -14,4 +14,6 @@ export type SimpleTimerState = {
|
|||||||
current: number;
|
current: number;
|
||||||
playback: SimplePlayback;
|
playback: SimplePlayback;
|
||||||
direction: SimpleDirection;
|
direction: SimpleDirection;
|
||||||
|
/** Custom name for the aux timer. Empty string when unnamed */
|
||||||
|
name: string;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -53,18 +53,21 @@ export const runtimeStorePlaceholder: Readonly<RuntimeStore> = {
|
|||||||
direction: SimpleDirection.CountUp,
|
direction: SimpleDirection.CountUp,
|
||||||
duration: 0,
|
duration: 0,
|
||||||
playback: SimplePlayback.Stop,
|
playback: SimplePlayback.Stop,
|
||||||
|
name: '',
|
||||||
},
|
},
|
||||||
auxtimer2: {
|
auxtimer2: {
|
||||||
current: 0,
|
current: 0,
|
||||||
direction: SimpleDirection.CountUp,
|
direction: SimpleDirection.CountUp,
|
||||||
duration: 0,
|
duration: 0,
|
||||||
playback: SimplePlayback.Stop,
|
playback: SimplePlayback.Stop,
|
||||||
|
name: '',
|
||||||
},
|
},
|
||||||
auxtimer3: {
|
auxtimer3: {
|
||||||
current: 0,
|
current: 0,
|
||||||
direction: SimpleDirection.CountUp,
|
direction: SimpleDirection.CountUp,
|
||||||
duration: 0,
|
duration: 0,
|
||||||
playback: SimplePlayback.Stop,
|
playback: SimplePlayback.Stop,
|
||||||
|
name: '',
|
||||||
},
|
},
|
||||||
ping: 1,
|
ping: 1,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -99,6 +99,9 @@ export {
|
|||||||
|
|
||||||
export { isPlaybackActive } from './src/playback-utils/playbackstate.js';
|
export { isPlaybackActive } from './src/playback-utils/playbackstate.js';
|
||||||
|
|
||||||
|
// aux timers
|
||||||
|
export { auxTimerNameMaxLength, sanitiseAuxTimerNames } from './src/aux-timer-utils/auxTimerUtils.js';
|
||||||
|
|
||||||
//Colour
|
//Colour
|
||||||
export {
|
export {
|
||||||
colourToHex,
|
colourToHex,
|
||||||
|
|||||||
@@ -0,0 +1,30 @@
|
|||||||
|
import { auxTimerNameMaxLength, sanitiseAuxTimerNames } from './auxTimerUtils.js';
|
||||||
|
|
||||||
|
describe('sanitiseAuxTimerNames()', () => {
|
||||||
|
it('generates the default value when given nothing', () => {
|
||||||
|
expect(sanitiseAuxTimerNames()).toStrictEqual(['', '', '']);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('always returns exactly three entries', () => {
|
||||||
|
expect(sanitiseAuxTimerNames(['a', 'b', 'c', 'extra'])).toStrictEqual(['a', 'b', 'c']);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('pads missing entries with an empty string', () => {
|
||||||
|
expect(sanitiseAuxTimerNames(['Speaker'])).toStrictEqual(['Speaker', '', '']);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('trims whitespace', () => {
|
||||||
|
expect(sanitiseAuxTimerNames([' Speaker ', '', ''])).toStrictEqual(['Speaker', '', '']);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('caps the name length', () => {
|
||||||
|
const tooLong = 'a'.repeat(auxTimerNameMaxLength + 10);
|
||||||
|
expect(sanitiseAuxTimerNames([tooLong])[0]).toHaveLength(auxTimerNameMaxLength);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('falls back to defaults for malformed data', () => {
|
||||||
|
expect(sanitiseAuxTimerNames('not-an-array')).toStrictEqual(['', '', '']);
|
||||||
|
expect(sanitiseAuxTimerNames(null)).toStrictEqual(['', '', '']);
|
||||||
|
expect(sanitiseAuxTimerNames([42, {}, undefined])).toStrictEqual(['', '', '']);
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
/** Maximum length of a user given aux timer name */
|
||||||
|
export const auxTimerNameMaxLength = 30;
|
||||||
|
|
||||||
|
function sanitiseAuxTimerName(value: unknown): string {
|
||||||
|
return typeof value === 'string' ? value.trim().slice(0, auxTimerNameMaxLength) : '';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ontime has three aux timers. Given whatever was found on disk or in a request body,
|
||||||
|
* returns a name for each of them, so callers never need to deal with a missing
|
||||||
|
* or malformed auxTimerNames (eg. a project file saved before this feature existed).
|
||||||
|
*/
|
||||||
|
export function sanitiseAuxTimerNames(names?: unknown): [string, string, string] {
|
||||||
|
const source = Array.isArray(names) ? names : [];
|
||||||
|
return [sanitiseAuxTimerName(source[0]), sanitiseAuxTimerName(source[1]), sanitiseAuxTimerName(source[2])];
|
||||||
|
}
|
||||||
@@ -342,6 +342,7 @@ export const demoDb: DatabaseModel = {
|
|||||||
operatorKey: null,
|
operatorKey: null,
|
||||||
timeFormat: '24',
|
timeFormat: '24',
|
||||||
language: 'en',
|
language: 'en',
|
||||||
|
auxTimerNames: ['', '', ''],
|
||||||
},
|
},
|
||||||
viewSettings: {
|
viewSettings: {
|
||||||
dangerColor: '#ff7300',
|
dangerColor: '#ff7300',
|
||||||
|
|||||||
Reference in New Issue
Block a user