mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-13 11:23:50 +00:00
Fix ontime aux actions (#1684)
* switch to base ui * ensure all action types is part of the valitation * update test * atempt to do it in the base-ui way * fix fixing * allow undefide visible on set timer message * fix set time not showing * correct time data for aux set automation --------- Co-authored-by: Carlos Valente <carlosvalente@pm.me>
This commit is contained in:
committed by
GitHub
parent
8d68a4554d
commit
4d359445a7
@@ -46,17 +46,17 @@ describe('parseOutput', () => {
|
||||
it('parses a valid payload', () => {
|
||||
const auxStart = {
|
||||
type: 'ontime',
|
||||
action: 'aux-start',
|
||||
action: 'aux1-start',
|
||||
};
|
||||
expect(parseOutput(auxStart)).toStrictEqual(auxStart);
|
||||
const auxStop = {
|
||||
type: 'ontime',
|
||||
action: 'aux-stop',
|
||||
action: 'aux3-stop',
|
||||
};
|
||||
expect(parseOutput(auxStop)).toStrictEqual(auxStop);
|
||||
const auxPause = {
|
||||
type: 'ontime',
|
||||
action: 'aux-pause',
|
||||
action: 'aux2-pause',
|
||||
};
|
||||
expect(parseOutput(auxPause)).toStrictEqual(auxPause);
|
||||
});
|
||||
@@ -65,12 +65,12 @@ describe('parseOutput', () => {
|
||||
expect(
|
||||
parseOutput({
|
||||
type: 'ontime',
|
||||
action: 'aux-start',
|
||||
action: 'aux1-start',
|
||||
time: 10,
|
||||
}),
|
||||
).toStrictEqual({
|
||||
type: 'ontime',
|
||||
action: 'aux-start',
|
||||
action: 'aux1-start',
|
||||
});
|
||||
});
|
||||
|
||||
@@ -88,7 +88,7 @@ describe('parseOutput', () => {
|
||||
type: 'ontime',
|
||||
action: 'message-set',
|
||||
text: 'test',
|
||||
visible: 'true',
|
||||
visible: true,
|
||||
}),
|
||||
).toMatchObject({
|
||||
text: 'test',
|
||||
@@ -99,7 +99,7 @@ describe('parseOutput', () => {
|
||||
type: 'ontime',
|
||||
action: 'message-set',
|
||||
text: '',
|
||||
visible: 'false',
|
||||
visible: false,
|
||||
}),
|
||||
).toMatchObject({
|
||||
text: undefined,
|
||||
@@ -110,7 +110,6 @@ describe('parseOutput', () => {
|
||||
type: 'ontime',
|
||||
action: 'message-set',
|
||||
text: '',
|
||||
visible: '',
|
||||
}),
|
||||
).toMatchObject({
|
||||
text: undefined,
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { EntryId, FilterRule, isOntimeEvent, MaybeNumber, OntimeAction, Rundown } from 'ontime-types';
|
||||
import { EntryId, FilterRule, isOntimeEvent, MaybeNumber, OntimeAction, ontimeActionKeyValues, Rundown } from 'ontime-types';
|
||||
import { millisToString, removeLeadingZero, splitWhitespace, getPropertyFromPath } from 'ontime-utils';
|
||||
import type { OscArgOrArrayInput, OscArgInput } from 'osc-min';
|
||||
|
||||
@@ -13,7 +13,7 @@ export function isFilterRule(value: string): value is FilterRule {
|
||||
}
|
||||
|
||||
export function isOntimeActionAction(value: string): value is OntimeAction['action'] {
|
||||
return ['aux-start', 'aux-stop', 'aux-pause', 'aux-set', 'message-set', 'message-secondary'].includes(value);
|
||||
return ontimeActionKeyValues.includes(value);
|
||||
}
|
||||
|
||||
function toOscValue(argString: string): OscArgInput {
|
||||
|
||||
@@ -8,7 +8,6 @@ import {
|
||||
SecondarySource,
|
||||
timerLifecycleValues,
|
||||
} from 'ontime-types';
|
||||
import { parseUserTime } from 'ontime-utils';
|
||||
|
||||
import { body, oneOf, param } from 'express-validator';
|
||||
|
||||
@@ -200,20 +199,24 @@ function parseOntimeAction(maybeOntimeAction: object): OntimeAction {
|
||||
return {
|
||||
type: 'ontime',
|
||||
action: maybeOntimeAction.action,
|
||||
time: parseUserTime(maybeOntimeAction.time),
|
||||
time: maybeOntimeAction.time, //TODO:(automation set aux) not sure what way around to have the string and where to have the ms value
|
||||
};
|
||||
}
|
||||
|
||||
if (maybeOntimeAction.action === 'message-set') {
|
||||
assert.hasKeys(maybeOntimeAction, ['text', 'visible']);
|
||||
assert.hasKeys(maybeOntimeAction, ['text']);
|
||||
assert.isString(maybeOntimeAction.text);
|
||||
assert.isString(maybeOntimeAction.visible);
|
||||
let visible: boolean | undefined = undefined;
|
||||
if ('visible' in maybeOntimeAction) {
|
||||
assert.isBoolean(maybeOntimeAction.visible);
|
||||
visible = maybeOntimeAction.visible;
|
||||
}
|
||||
|
||||
return {
|
||||
type: 'ontime',
|
||||
action: 'message-set',
|
||||
text: indeterminateText(maybeOntimeAction.text),
|
||||
visible: indeterminateBooleanString(maybeOntimeAction.visible),
|
||||
visible,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -243,16 +246,6 @@ function indeterminateText(value: string): string | undefined {
|
||||
return value === '' ? undefined : value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function to parse boolean values in transit
|
||||
* "true" -> true
|
||||
* "false" -> false
|
||||
* "" | "null" -> undefined
|
||||
*/
|
||||
function indeterminateBooleanString(value: string): boolean | undefined {
|
||||
return value === '' ? undefined : value === 'true';
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function to validate the secondary source
|
||||
*/
|
||||
|
||||
@@ -3,6 +3,7 @@ import { LogOrigin, OntimeAction } from 'ontime-types';
|
||||
import { logger } from '../../../classes/Logger.js';
|
||||
import { auxTimerService } from '../../../services/aux-timer-service/AuxTimerService.js';
|
||||
import * as messageService from '../../../services/message-service/message.service.js';
|
||||
import { parseUserTime } from 'ontime-utils';
|
||||
|
||||
export function toOntimeAction(action: OntimeAction) {
|
||||
const actionType = action.action;
|
||||
@@ -15,7 +16,8 @@ export function toOntimeAction(action: OntimeAction) {
|
||||
case 'aux1-pause':
|
||||
return auxTimerService.pause(1);
|
||||
case 'aux1-set': {
|
||||
return auxTimerService.setTime(action.time, 1);
|
||||
const time = parseUserTime(action.time);
|
||||
return auxTimerService.setTime(time, 1);
|
||||
}
|
||||
case 'aux2-start':
|
||||
return auxTimerService.start(2);
|
||||
@@ -24,7 +26,8 @@ export function toOntimeAction(action: OntimeAction) {
|
||||
case 'aux2-pause':
|
||||
return auxTimerService.pause(2);
|
||||
case 'aux2-set': {
|
||||
return auxTimerService.setTime(action.time, 2);
|
||||
const time = parseUserTime(action.time);
|
||||
return auxTimerService.setTime(time, 2);
|
||||
}
|
||||
case 'aux3-start':
|
||||
return auxTimerService.start(3);
|
||||
@@ -33,7 +36,8 @@ export function toOntimeAction(action: OntimeAction) {
|
||||
case 'aux3-pause':
|
||||
return auxTimerService.pause(3);
|
||||
case 'aux3-set': {
|
||||
return auxTimerService.setTime(action.time, 3);
|
||||
const time = parseUserTime(action.time);
|
||||
return auxTimerService.setTime(time, 3);
|
||||
}
|
||||
|
||||
// Message actions
|
||||
|
||||
Reference in New Issue
Block a user