mirror of
https://github.com/cpvalente/ontime.git
synced 2026-07-26 10:38:55 +00:00
Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 2f29060fa4 | |||
| 2f7909ccc3 |
@@ -95,6 +95,14 @@ 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 useAuxTimerTime = (index: number) =>
|
||||
createSelector((state: RuntimeStore) => {
|
||||
if (index === 1) return state.auxtimer1.current;
|
||||
@@ -108,15 +116,18 @@ export const useAuxTimerControl = (index: number) =>
|
||||
return {
|
||||
playback: state.auxtimer1.playback,
|
||||
direction: state.auxtimer1.direction,
|
||||
name: state.auxtimer1.name,
|
||||
};
|
||||
if (index === 2)
|
||||
return {
|
||||
playback: state.auxtimer2.playback,
|
||||
direction: state.auxtimer2.direction,
|
||||
name: state.auxtimer2.name,
|
||||
};
|
||||
return {
|
||||
playback: state.auxtimer3.playback,
|
||||
direction: state.auxtimer3.direction,
|
||||
name: state.auxtimer3.name,
|
||||
};
|
||||
})();
|
||||
|
||||
|
||||
@@ -6,4 +6,5 @@ export const ontimePlaceholderSettings: Settings = {
|
||||
operatorKey: null,
|
||||
timeFormat: '24',
|
||||
language: 'en',
|
||||
auxTimerNames: ['', '', ''],
|
||||
};
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
/**
|
||||
* Resolves the display label for an aux timer.
|
||||
* Falls back to the provided default when no custom name is set.
|
||||
* @param name - the aux timer's custom name (from the runtime store)
|
||||
* @param fallback - label to use when no custom name is set
|
||||
*/
|
||||
export function getAuxTimerLabel(name: string | undefined, fallback: string): string {
|
||||
const custom = name?.trim();
|
||||
return custom ? custom : fallback;
|
||||
}
|
||||
+12
-12
@@ -51,21 +51,21 @@ export default function OntimeActionForm({
|
||||
}}
|
||||
value={watch(`outputs.${index}.action`)}
|
||||
options={[
|
||||
{ value: 'aux1-pause', label: 'Aux 1: pause' },
|
||||
{ value: 'aux2-pause', label: 'Aux 2: pause' },
|
||||
{ value: 'aux3-pause', label: 'Aux 3: pause' },
|
||||
{ value: 'aux1-pause', label: 'Aux timer 1: pause' },
|
||||
{ value: 'aux2-pause', label: 'Aux timer 2: pause' },
|
||||
{ value: 'aux3-pause', label: 'Aux timer 3: pause' },
|
||||
|
||||
{ value: 'aux1-start', label: 'Aux 1: start' },
|
||||
{ value: 'aux2-start', label: 'Aux 2: start' },
|
||||
{ value: 'aux3-start', label: 'Aux 3: start' },
|
||||
{ value: 'aux1-start', label: 'Aux timer 1: start' },
|
||||
{ value: 'aux2-start', label: 'Aux timer 2: start' },
|
||||
{ value: 'aux3-start', label: 'Aux timer 3: start' },
|
||||
|
||||
{ value: 'aux1-stop', label: 'Aux 1: stop' },
|
||||
{ value: 'aux2-stop', label: 'Aux 2: stop' },
|
||||
{ value: 'aux3-stop', label: 'Aux 3: stop' },
|
||||
{ value: 'aux1-stop', label: 'Aux timer 1: stop' },
|
||||
{ value: 'aux2-stop', label: 'Aux timer 2: stop' },
|
||||
{ value: 'aux3-stop', label: 'Aux timer 3: stop' },
|
||||
|
||||
{ value: 'aux1-set', label: 'Aux 1: set' },
|
||||
{ value: 'aux2-set', label: 'Aux 2: set' },
|
||||
{ value: 'aux3-set', label: 'Aux 3: set' },
|
||||
{ value: 'aux1-set', label: 'Aux timer 1: set' },
|
||||
{ value: 'aux2-set', label: 'Aux timer 2: set' },
|
||||
{ value: 'aux3-set', label: 'Aux timer 3: set' },
|
||||
|
||||
{ value: 'playback-start', label: 'Playback: start' },
|
||||
{ value: 'playback-stop', label: 'Playback: stop' },
|
||||
|
||||
@@ -0,0 +1,91 @@
|
||||
import { Settings } from 'ontime-types';
|
||||
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';
|
||||
|
||||
const auxTimerIndexes = [1, 2, 3];
|
||||
|
||||
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,
|
||||
},
|
||||
});
|
||||
|
||||
// update form if we get new data from server
|
||||
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>
|
||||
{auxTimerIndexes.map((index) => (
|
||||
<Panel.ListItem key={index}>
|
||||
<Panel.Field title={`Aux timer ${index}`} description={`Custom name for aux timer ${index}`} />
|
||||
<Input maxLength={30} placeholder={`Aux ${index}`} {...register(`auxTimerNames.${index - 1}`)} />
|
||||
</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 * as Panel from '../../panel-utils/PanelUtils';
|
||||
import CustomViews from '../manage-panel/CustomViews';
|
||||
import AuxTimerSettings from './AuxTimerSettings';
|
||||
import GeneralSettings from './GeneralSettings';
|
||||
import McpSection from './McpSection';
|
||||
import ProjectData from './ProjectData';
|
||||
@@ -12,6 +13,7 @@ import ViewSettings from './ViewSettings';
|
||||
export default function SettingsPanel({ location }: PanelBaseProps) {
|
||||
const dataRef = useScrollIntoView<HTMLDivElement>('data', location);
|
||||
const generalRef = useScrollIntoView<HTMLDivElement>('general', location);
|
||||
const auxTimersRef = useScrollIntoView<HTMLDivElement>('aux-timers', location);
|
||||
const viewRef = useScrollIntoView<HTMLDivElement>('view', location);
|
||||
const customViewsRef = useScrollIntoView<HTMLDivElement>('custom-views', location);
|
||||
const mcpRef = useScrollIntoView<HTMLDivElement>('mcp', location);
|
||||
@@ -26,6 +28,9 @@ export default function SettingsPanel({ location }: PanelBaseProps) {
|
||||
<div ref={generalRef}>
|
||||
<GeneralSettings />
|
||||
</div>
|
||||
<div ref={auxTimersRef}>
|
||||
<AuxTimerSettings />
|
||||
</div>
|
||||
<div ref={viewRef}>
|
||||
<ViewSettings />
|
||||
</div>
|
||||
|
||||
@@ -17,6 +17,7 @@ const staticOptions = [
|
||||
secondary: [
|
||||
{ id: 'settings__data', label: 'Project data' },
|
||||
{ id: 'settings__general', label: 'General settings' },
|
||||
{ id: 'settings__aux-timers', label: 'Aux timers' },
|
||||
{ id: 'settings__view', label: 'View settings' },
|
||||
{ id: 'settings__custom-views', label: 'Custom views' },
|
||||
{ id: 'settings__mcp', label: 'MCP Server' },
|
||||
|
||||
@@ -5,23 +5,25 @@ import { LuArrowDownToLine } from 'react-icons/lu';
|
||||
import { CornerWithPip } from '../../../common/components/editor-utils/EditorUtils';
|
||||
import Tooltip from '../../../common/components/tooltip/Tooltip';
|
||||
import useViewSettings from '../../../common/hooks-query/useViewSettings';
|
||||
import { useMessagePreview } from '../../../common/hooks/useSocket';
|
||||
import { useAuxTimersName, useMessagePreview } from '../../../common/hooks/useSocket';
|
||||
import { getAuxTimerLabel } from '../../../common/utils/auxTimerUtils';
|
||||
import { handleLinks } from '../../../common/utils/linkUtils';
|
||||
import { cx, timerPlaceholder } from '../../../common/utils/styleUtils';
|
||||
import PipRoot from '../../../views/editor/pip-timer/PipRoot';
|
||||
|
||||
import style from './TimerPreview.module.scss';
|
||||
|
||||
const secondarySourceLabels: Record<string, string> = {
|
||||
aux1: 'Aux 1',
|
||||
aux2: 'Aux 2',
|
||||
aux3: 'Aux 3',
|
||||
secondary: 'Secondary message',
|
||||
};
|
||||
|
||||
export default function TimerPreview() {
|
||||
const { blink, blackout, countToEnd, phase, secondarySource, showTimerMessage, timerType } = useMessagePreview();
|
||||
const { data } = useViewSettings();
|
||||
const auxName = useAuxTimersName();
|
||||
|
||||
const secondarySourceLabels: Record<string, string> = {
|
||||
aux1: getAuxTimerLabel(auxName.aux1, 'Aux 1'),
|
||||
aux2: getAuxTimerLabel(auxName.aux2, 'Aux 2'),
|
||||
aux3: getAuxTimerLabel(auxName.aux3, 'Aux 3'),
|
||||
secondary: 'Secondary message',
|
||||
};
|
||||
|
||||
const main = (() => {
|
||||
if (showTimerMessage) return 'Message';
|
||||
|
||||
@@ -4,7 +4,8 @@ import { useEffect, useState } from 'react';
|
||||
import Button from '../../../common/components/buttons/Button';
|
||||
import * as Editor from '../../../common/components/editor-utils/EditorUtils';
|
||||
import Select from '../../../common/components/select/Select';
|
||||
import { setMessage, useTimerViewControl } from '../../../common/hooks/useSocket';
|
||||
import { setMessage, useAuxTimersName, useTimerViewControl } from '../../../common/hooks/useSocket';
|
||||
import { getAuxTimerLabel } from '../../../common/utils/auxTimerUtils';
|
||||
import TimerPreview from './TimerPreview';
|
||||
|
||||
import style from './TimerViewControl.module.scss';
|
||||
@@ -43,6 +44,7 @@ export default function TimerControlsPreview() {
|
||||
|
||||
function SecondarySourceControl() {
|
||||
const { secondarySource } = useTimerViewControl();
|
||||
const auxName = useAuxTimersName();
|
||||
const [value, setValue] = useState<SecondarySource>('aux1');
|
||||
|
||||
// sync secondary source with external changes
|
||||
@@ -65,9 +67,9 @@ function SecondarySourceControl() {
|
||||
<Select
|
||||
value={value}
|
||||
options={[
|
||||
{ value: 'aux1', label: 'Aux 1' },
|
||||
{ value: 'aux2', label: 'Aux 2' },
|
||||
{ value: 'aux3', label: 'Aux 3' },
|
||||
{ value: 'aux1', label: getAuxTimerLabel(auxName.aux1, 'Aux 1') },
|
||||
{ value: 'aux2', label: getAuxTimerLabel(auxName.aux2, 'Aux 2') },
|
||||
{ value: 'aux3', label: getAuxTimerLabel(auxName.aux3, 'Aux 3') },
|
||||
{ value: 'secondary', label: 'Secondary message' },
|
||||
]}
|
||||
onValueChange={(value: SecondarySource | null) => {
|
||||
|
||||
@@ -3,6 +3,15 @@
|
||||
margin: 0 auto;
|
||||
}
|
||||
|
||||
.auxHeader {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
margin-top: 1rem;
|
||||
font-size: $inner-section-text-size;
|
||||
color: $label-gray;
|
||||
}
|
||||
|
||||
.auxTimers {
|
||||
display: grid;
|
||||
grid-template-columns: 1fr 1fr 1fr;
|
||||
|
||||
@@ -1,4 +1,9 @@
|
||||
import { IoSettingsOutline } from 'react-icons/io5';
|
||||
|
||||
import IconButton from '../../../common/components/buttons/IconButton';
|
||||
import Tooltip from '../../../common/components/tooltip/Tooltip';
|
||||
import { usePlaybackControl } from '../../../common/hooks/useSocket';
|
||||
import useAppSettingsNavigation from '../../app-settings/useAppSettingsNavigation';
|
||||
import AddTime from './add-time/AddTime';
|
||||
import { AuxTimer } from './aux-timer/AuxTimer';
|
||||
import PlaybackButtons from './playback-buttons/PlaybackButtons';
|
||||
@@ -8,6 +13,7 @@ import style from './PlaybackControl.module.scss';
|
||||
|
||||
export default function PlaybackControl() {
|
||||
const data = usePlaybackControl();
|
||||
const { setLocation } = useAppSettingsNavigation();
|
||||
|
||||
return (
|
||||
<div className={style.mainContainer}>
|
||||
@@ -20,6 +26,22 @@ export default function PlaybackControl() {
|
||||
selectedEventIndex={data.selectedEventIndex}
|
||||
timerPhase={data.timerPhase}
|
||||
/>
|
||||
<div className={style.auxHeader}>
|
||||
<span>Aux timers</span>
|
||||
<Tooltip
|
||||
text='Name aux timers'
|
||||
render={
|
||||
<IconButton
|
||||
size='small'
|
||||
variant='subtle'
|
||||
aria-label='Name aux timers'
|
||||
onClick={() => setLocation('settings__aux-timers')}
|
||||
/>
|
||||
}
|
||||
>
|
||||
<IoSettingsOutline />
|
||||
</Tooltip>
|
||||
</div>
|
||||
<div className={style.auxTimers}>
|
||||
<AuxTimer index={1} />
|
||||
<AuxTimer index={2} />
|
||||
|
||||
@@ -4,6 +4,7 @@ import { IoArrowDown, IoArrowUp, IoPause, IoPlay, IoStop } from 'react-icons/io5
|
||||
|
||||
import TimeInput from '../../../../common/components/input/time-input/TimeInput';
|
||||
import { setAuxTimer, useAuxTimerControl, useAuxTimerTime } from '../../../../common/hooks/useSocket';
|
||||
import { getAuxTimerLabel } from '../../../../common/utils/auxTimerUtils';
|
||||
import TapButton from '../tap-button/TapButton';
|
||||
|
||||
import style from './AuxTimer.module.scss';
|
||||
@@ -13,10 +14,12 @@ interface AuxTimerProps {
|
||||
}
|
||||
|
||||
export function AuxTimer({ index }: AuxTimerProps) {
|
||||
const { playback, direction } = useAuxTimerControl(index);
|
||||
const { playback, direction, name } = useAuxTimerControl(index);
|
||||
|
||||
const { stop, setDirection } = setAuxTimer;
|
||||
|
||||
const label = getAuxTimerLabel(name, `Aux Timer ${index}`);
|
||||
|
||||
const toggleDirection = () => {
|
||||
const newDirection = direction === SimpleDirection.CountDown ? SimpleDirection.CountUp : SimpleDirection.CountDown;
|
||||
setDirection(index, newDirection);
|
||||
@@ -27,10 +30,10 @@ export function AuxTimer({ index }: AuxTimerProps) {
|
||||
|
||||
return (
|
||||
<label className={style.label}>
|
||||
Aux Timer {index}
|
||||
{label}
|
||||
<div className={style.controls}>
|
||||
<div className={style.input}>
|
||||
<AuxTimerInput index={index} isActive={isActive} />
|
||||
<AuxTimerInput index={index} isActive={isActive} placeholder={label} />
|
||||
<TapButton onClick={toggleDirection} aspect='tight' disabled={isActive}>
|
||||
{direction === SimpleDirection.CountDown && <IoArrowDown data-testid={`aux-timer-direction-${index}`} />}
|
||||
{direction === SimpleDirection.CountUp && <IoArrowUp data-testid={`aux-timer-direction-${index}`} />}
|
||||
@@ -50,9 +53,10 @@ export function AuxTimer({ index }: AuxTimerProps) {
|
||||
interface AuxTimerInputProps {
|
||||
index: number;
|
||||
isActive: boolean;
|
||||
placeholder: string;
|
||||
}
|
||||
|
||||
function AuxTimerInput({ index, isActive }: AuxTimerInputProps) {
|
||||
function AuxTimerInput({ index, isActive, placeholder }: AuxTimerInputProps) {
|
||||
const newTimeInMs = useAuxTimerTime(index);
|
||||
const { setDuration } = setAuxTimer;
|
||||
|
||||
@@ -70,7 +74,7 @@ function AuxTimerInput({ index, isActive }: AuxTimerInputProps) {
|
||||
}
|
||||
|
||||
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 { 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 { cx } from '../../common/utils/styleUtils';
|
||||
import { useTranslation } from '../../translation/TranslationProvider';
|
||||
@@ -121,22 +122,23 @@ export default function StudioTimers({ viewSettings }: StudioTimersProps) {
|
||||
|
||||
function StudioTimersAux() {
|
||||
const auxTimer = useAuxTimersTime();
|
||||
const auxName = useAuxTimersName();
|
||||
|
||||
return (
|
||||
<div className='card' id='card-aux'>
|
||||
<div className='card__row'>
|
||||
<div>
|
||||
<div className='label'>Aux 1</div>
|
||||
<div className='label'>{getAuxTimerLabel(auxName.aux1, 'Aux 1')}</div>
|
||||
<div className='extra'>{millisToString(auxTimer.aux1)}</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>
|
||||
|
||||
<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>
|
||||
</div>
|
||||
|
||||
@@ -74,7 +74,7 @@ export function migrateSettings(jsonData: object): (Settings & { serverPort: num
|
||||
const { serverPort, editorKey, operatorKey, timeFormat, language } = structuredClone(
|
||||
jsonData.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: ['', '', ''] };
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -23,6 +23,7 @@ export function migrateServerPort(jsonData: Partial<DatabaseModel>): {
|
||||
const operatorKey = settings?.operatorKey;
|
||||
const timeFormat = settings?.timeFormat;
|
||||
const language = settings?.language;
|
||||
const auxTimerNames = settings?.auxTimerNames ?? ['', '', ''];
|
||||
const version = '4.5.0';
|
||||
db.settings = {
|
||||
version,
|
||||
@@ -30,6 +31,7 @@ export function migrateServerPort(jsonData: Partial<DatabaseModel>): {
|
||||
operatorKey,
|
||||
timeFormat,
|
||||
language,
|
||||
auxTimerNames,
|
||||
app: 'ontime',
|
||||
} as Settings;
|
||||
return { db, serverPort: settings?.serverPort };
|
||||
|
||||
@@ -184,6 +184,7 @@ describe('v3 to v4', () => {
|
||||
operatorKey: null,
|
||||
timeFormat: '24',
|
||||
language: 'en',
|
||||
auxTimerNames: ['', '', ''],
|
||||
};
|
||||
const newSettings = v3.migrateSettings(oldDb);
|
||||
expect(newSettings).toEqual(expectSettings);
|
||||
|
||||
@@ -16,6 +16,21 @@ describe('parseSettings()', () => {
|
||||
operatorKey: null,
|
||||
timeFormat: '24',
|
||||
language: 'en',
|
||||
auxTimerNames: ['', '', ''],
|
||||
});
|
||||
});
|
||||
|
||||
it('carries custom aux timer names through and normalises 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(['', '', '']);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -22,5 +22,18 @@ export function parseSettings(data: Partial<DatabaseModel>): Settings {
|
||||
operatorKey: data.settings.operatorKey ?? defaultSettings.operatorKey,
|
||||
timeFormat: data.settings.timeFormat ?? defaultSettings.timeFormat,
|
||||
language: data.settings.language ?? defaultSettings.language,
|
||||
auxTimerNames: sanitiseAuxTimerNames(data.settings.auxTimerNames, defaultSettings.auxTimerNames),
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensures the aux timer names are a fixed-length array of strings
|
||||
* regardless of what is found in the file
|
||||
*/
|
||||
function sanitiseAuxTimerNames(maybeNames: unknown, fallback: string[]): string[] {
|
||||
const source = Array.isArray(maybeNames) ? maybeNames : [];
|
||||
return fallback.map((defaultName, index) => {
|
||||
const value = source[index];
|
||||
return typeof value === 'string' ? value : defaultName;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import { sendRefetch } from '../../adapters/WebsocketAdapter.js';
|
||||
import { getDataProvider } from '../../classes/data-provider/DataProvider.js';
|
||||
import { portManager } from '../../classes/port-manager/PortManager.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';
|
||||
|
||||
export const router: Router = express.Router();
|
||||
@@ -41,6 +42,10 @@ router.post('/', validateSettings, async (req: Request, res: Response<Settings |
|
||||
|
||||
if (!deepEqual(data, settings)) {
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
@@ -27,6 +27,14 @@ export const validateSettings = [
|
||||
pinValidator('operatorKey'),
|
||||
body('timeFormat').isString().isIn(['12', '24']).withMessage('Time format can only be "12" or "24"'),
|
||||
body('language').isString().trim().notEmpty(),
|
||||
body('auxTimerNames')
|
||||
.isArray()
|
||||
.withMessage('auxTimerNames must be an array')
|
||||
.customSanitizer((value: unknown) => {
|
||||
// normalise to a fixed-length array of trimmed strings
|
||||
const source = Array.isArray(value) ? value : [];
|
||||
return [0, 1, 2].map((index) => (typeof source[index] === 'string' ? source[index].trim() : ''));
|
||||
}),
|
||||
|
||||
requestValidationFunction,
|
||||
];
|
||||
|
||||
@@ -26,6 +26,7 @@ import { bodyParser } from './middleware/bodyParser.js';
|
||||
import { compressedStatic } from './middleware/staticGZip.js';
|
||||
import { ONTIME_VERSION } from './ONTIME_VERSION.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 { initialiseProject } from './services/project-service/ProjectService.js';
|
||||
import { restoreService } from './services/restore-service/restore.service.js';
|
||||
@@ -204,6 +205,7 @@ export const startServer = async (): Promise<{ message: string; serverPort: numb
|
||||
* Module initialises the services and provides initial payload for the store
|
||||
*/
|
||||
const state = getState();
|
||||
const { auxTimerNames } = getDataProvider().getSettings();
|
||||
eventStore.init({
|
||||
clock: state.clock,
|
||||
timer: state.timer,
|
||||
@@ -219,22 +221,28 @@ export const startServer = async (): Promise<{ message: string; serverPort: numb
|
||||
current: timerConfig.auxTimerDefault,
|
||||
playback: SimplePlayback.Stop,
|
||||
direction: SimpleDirection.CountDown,
|
||||
name: auxTimerNames[0] ?? '',
|
||||
},
|
||||
auxtimer2: {
|
||||
duration: timerConfig.auxTimerDefault,
|
||||
current: timerConfig.auxTimerDefault,
|
||||
playback: SimplePlayback.Stop,
|
||||
direction: SimpleDirection.CountDown,
|
||||
name: auxTimerNames[1] ?? '',
|
||||
},
|
||||
auxtimer3: {
|
||||
duration: timerConfig.auxTimerDefault,
|
||||
current: timerConfig.auxTimerDefault,
|
||||
playback: SimplePlayback.Stop,
|
||||
direction: SimpleDirection.CountDown,
|
||||
name: auxTimerNames[2] ?? '',
|
||||
},
|
||||
ping: 1,
|
||||
});
|
||||
|
||||
// seed the aux timer names onto the running service so they persist across commands
|
||||
auxTimerService.loadNames(auxTimerNames);
|
||||
|
||||
// initialise message service
|
||||
messageService.init(eventStore.set, eventStore.get);
|
||||
|
||||
|
||||
@@ -81,6 +81,7 @@ describe('safeMerge', () => {
|
||||
editorKey: null,
|
||||
timeFormat: baseDb.settings.timeFormat,
|
||||
language: 'pt',
|
||||
auxTimerNames: baseDb.settings.auxTimerNames,
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ export class SimpleTimer {
|
||||
current: 0,
|
||||
playback: SimplePlayback.Stop,
|
||||
direction: SimpleDirection.CountDown,
|
||||
name: '',
|
||||
};
|
||||
private startedAt: number | null = null;
|
||||
private pausedAt: number | null = null;
|
||||
@@ -23,9 +24,19 @@ export class SimpleTimer {
|
||||
current: 0,
|
||||
playback: SimplePlayback.Stop,
|
||||
direction: SimpleDirection.CountDown,
|
||||
// the name is a persisted configuration, independent of the timer runtime
|
||||
name: this.state.name,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the custom name of the timer
|
||||
*/
|
||||
public setName(name: string): SimpleTimerState {
|
||||
this.state.name = name;
|
||||
return this.state;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the duration of the timer
|
||||
* @param time - time in milliseconds
|
||||
|
||||
@@ -16,6 +16,7 @@ describe('SimpleTimer count-down', () => {
|
||||
current: initialTime,
|
||||
direction: SimpleDirection.CountDown,
|
||||
playback: SimplePlayback.Stop,
|
||||
name: '',
|
||||
};
|
||||
expect(newState).toStrictEqual(expected);
|
||||
});
|
||||
@@ -27,6 +28,7 @@ describe('SimpleTimer count-down', () => {
|
||||
current: initialTime,
|
||||
direction: SimpleDirection.CountDown,
|
||||
playback: SimplePlayback.Start,
|
||||
name: '',
|
||||
};
|
||||
expect(newState).toStrictEqual(expected);
|
||||
});
|
||||
@@ -38,6 +40,7 @@ describe('SimpleTimer count-down', () => {
|
||||
current: initialTime - 100,
|
||||
direction: SimpleDirection.CountDown,
|
||||
playback: SimplePlayback.Start,
|
||||
name: '',
|
||||
};
|
||||
expect(newState).toStrictEqual(expected);
|
||||
|
||||
@@ -58,6 +61,7 @@ describe('SimpleTimer count-down', () => {
|
||||
current: initialTime - 1500,
|
||||
direction: SimpleDirection.CountDown,
|
||||
playback: SimplePlayback.Pause,
|
||||
name: '',
|
||||
};
|
||||
expect(newState).toStrictEqual(expected);
|
||||
|
||||
@@ -83,6 +87,7 @@ describe('SimpleTimer count-down', () => {
|
||||
current: initialTime,
|
||||
direction: SimpleDirection.CountDown,
|
||||
playback: SimplePlayback.Stop,
|
||||
name: '',
|
||||
};
|
||||
expect(newState).toStrictEqual(expected);
|
||||
});
|
||||
@@ -97,6 +102,7 @@ describe('SimpleTimer count-down', () => {
|
||||
current: initialTime,
|
||||
direction: SimpleDirection.CountUp,
|
||||
playback: SimplePlayback.Start,
|
||||
name: '',
|
||||
};
|
||||
|
||||
newState = timer.update(100);
|
||||
@@ -127,6 +133,7 @@ describe('SimpleTimer count-down', () => {
|
||||
current: 1000,
|
||||
direction: SimpleDirection.CountUp,
|
||||
playback: SimplePlayback.Start,
|
||||
name: '',
|
||||
});
|
||||
|
||||
newState = timer.update(100);
|
||||
@@ -135,6 +142,7 @@ describe('SimpleTimer count-down', () => {
|
||||
current: initialTime + 100,
|
||||
direction: SimpleDirection.CountUp,
|
||||
playback: SimplePlayback.Start,
|
||||
name: '',
|
||||
});
|
||||
|
||||
newState = timer.update(500);
|
||||
@@ -143,6 +151,7 @@ describe('SimpleTimer count-down', () => {
|
||||
current: 1500,
|
||||
direction: SimpleDirection.CountUp,
|
||||
playback: SimplePlayback.Start,
|
||||
name: '',
|
||||
});
|
||||
|
||||
newState = timer.setDirection(SimpleDirection.CountDown, 600);
|
||||
@@ -151,6 +160,7 @@ describe('SimpleTimer count-down', () => {
|
||||
current: 1500,
|
||||
direction: SimpleDirection.CountDown,
|
||||
playback: SimplePlayback.Start,
|
||||
name: '',
|
||||
});
|
||||
|
||||
newState = timer.update(700);
|
||||
@@ -159,6 +169,7 @@ describe('SimpleTimer count-down', () => {
|
||||
current: 1400,
|
||||
direction: SimpleDirection.CountDown,
|
||||
playback: SimplePlayback.Start,
|
||||
name: '',
|
||||
});
|
||||
|
||||
newState = timer.setDirection(SimpleDirection.CountUp, 700);
|
||||
@@ -167,6 +178,7 @@ describe('SimpleTimer count-down', () => {
|
||||
current: 1400,
|
||||
direction: SimpleDirection.CountUp,
|
||||
playback: SimplePlayback.Start,
|
||||
name: '',
|
||||
});
|
||||
|
||||
newState = timer.update(800);
|
||||
@@ -175,6 +187,7 @@ describe('SimpleTimer count-down', () => {
|
||||
current: 1500,
|
||||
direction: SimpleDirection.CountUp,
|
||||
playback: SimplePlayback.Start,
|
||||
name: '',
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -30,6 +30,7 @@ const dbModel: DatabaseModel = {
|
||||
operatorKey: null,
|
||||
timeFormat: '24',
|
||||
language: 'en',
|
||||
auxTimerNames: ['', '', ''],
|
||||
},
|
||||
viewSettings: {
|
||||
overrideStyles: false,
|
||||
|
||||
@@ -29,6 +29,7 @@ export const demoDb: DatabaseModel = {
|
||||
operatorKey: null,
|
||||
timeFormat: '24',
|
||||
language: 'en',
|
||||
auxTimerNames: ['', '', ''],
|
||||
},
|
||||
viewSettings: {
|
||||
dangerColor: '#ff7300',
|
||||
|
||||
@@ -24,6 +24,20 @@ export class AuxTimerService {
|
||||
this.getTime = getTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies custom names to the aux timers and broadcasts the change.
|
||||
* Names are indexed by aux timer position (0 -> aux1, 1 -> aux2, 2 -> aux3).
|
||||
* Used to seed the names at bootstrap and to keep them in sync with the settings.
|
||||
*/
|
||||
loadNames(names: string[]) {
|
||||
const patch: AuxTimerStateUpdate = {
|
||||
auxtimer1: this.aux1.setName(names[0] ?? ''),
|
||||
auxtimer2: this.aux2.setName(names[1] ?? ''),
|
||||
auxtimer3: this.aux3.setName(names[2] ?? ''),
|
||||
};
|
||||
this.emit(patch);
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether any of the aux timers are currently running
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
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('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');
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -6,4 +6,6 @@ export type Settings = {
|
||||
operatorKey: null | string;
|
||||
timeFormat: TimeFormat;
|
||||
language: string;
|
||||
/** Custom names for the aux timers, indexed by aux timer (1, 2, 3). Empty string falls back to the default label */
|
||||
auxTimerNames: string[];
|
||||
};
|
||||
|
||||
@@ -14,4 +14,6 @@ export type SimpleTimerState = {
|
||||
current: number;
|
||||
playback: SimplePlayback;
|
||||
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,
|
||||
duration: 0,
|
||||
playback: SimplePlayback.Stop,
|
||||
name: '',
|
||||
},
|
||||
auxtimer2: {
|
||||
current: 0,
|
||||
direction: SimpleDirection.CountUp,
|
||||
duration: 0,
|
||||
playback: SimplePlayback.Stop,
|
||||
name: '',
|
||||
},
|
||||
auxtimer3: {
|
||||
current: 0,
|
||||
direction: SimpleDirection.CountUp,
|
||||
duration: 0,
|
||||
playback: SimplePlayback.Stop,
|
||||
name: '',
|
||||
},
|
||||
ping: 1,
|
||||
};
|
||||
|
||||
@@ -342,6 +342,7 @@ export const demoDb: DatabaseModel = {
|
||||
operatorKey: null,
|
||||
timeFormat: '24',
|
||||
language: 'en',
|
||||
auxTimerNames: ['', '', ''],
|
||||
},
|
||||
viewSettings: {
|
||||
dangerColor: '#ff7300',
|
||||
|
||||
Reference in New Issue
Block a user