Skip to content

Commit

Permalink
feat: parse timeToEnd from excel
Browse files Browse the repository at this point in the history
  • Loading branch information
cpvalente committed Dec 16, 2024
1 parent b88c2a6 commit 9813643
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export const namedImportMap = {
Duration: 'duration',
Cue: 'cue',
Title: 'title',
'Time to end': 'time to end',
'Is Public': 'public',
Skip: 'skip',
Note: 'notes',
Expand Down Expand Up @@ -47,6 +48,7 @@ export function convertToImportMap(namedImportMap: NamedImportMap): ImportMap {
duration: namedImportMap.Duration,
cue: namedImportMap.Cue,
title: namedImportMap.Title,
isTimeToEnd: namedImportMap['Time to end'],
isPublic: namedImportMap['Is Public'],
skip: namedImportMap.Skip,
note: namedImportMap.Note,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export default function PreviewRundown(props: PreviewRundownProps) {
<th>Duration</th>
<th>Warning Time</th>
<th>Danger Time</th>
<th>Is Time to End</th>
<th>Is Public</th>
<th>Skip</th>
<th>Colour</th>
Expand Down Expand Up @@ -71,6 +72,7 @@ export default function PreviewRundown(props: PreviewRundownProps) {
}
eventIndex += 1;
const colour = event.colour ? getAccessibleColour(event.colour) : {};
const isTimeToEnd = booleanToText(event.isTimeToEnd);
const isPublic = booleanToText(event.isPublic);
const skip = booleanToText(event.skip);

Expand All @@ -93,6 +95,7 @@ export default function PreviewRundown(props: PreviewRundownProps) {
<td>{millisToString(event.duration)}</td>
<td>{millisToString(event.timeWarning)}</td>
<td>{millisToString(event.timeDanger)}</td>
<td className={style.center}>{isTimeToEnd && <Tag>{isTimeToEnd}</Tag>}</td>
<td className={style.center}>{isPublic && <Tag>{isPublic}</Tag>}</td>
<td>{skip && <Tag>{skip}</Tag>}</td>
<td style={{ ...colour }}>{event.colour}</td>
Expand Down
24 changes: 18 additions & 6 deletions apps/server/src/utils/__tests__/parser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -775,6 +775,7 @@ describe('getCustomFieldData()', () => {
duration: 'duration',
cue: 'cue',
title: 'title',
isTimeToEnd: 'time to end',
isPublic: 'public',
skip: 'skip',
note: 'notes',
Expand Down Expand Up @@ -825,6 +826,7 @@ describe('getCustomFieldData()', () => {
duration: 'duration',
cue: 'cue',
title: 'title',
isTimeToEnd: 'time to end',
isPublic: 'public',
skip: 'skip',
note: 'notes',
Expand Down Expand Up @@ -884,6 +886,7 @@ describe('parseExcel()', () => {
'Title',
'End Action',
'Timer type',
'Time to end',
'Public',
'Skip',
'Notes',
Expand All @@ -906,7 +909,8 @@ describe('parseExcel()', () => {
'Guest Welcome',
'',
'',
'x',
'x', // <-- time to end
'x', // <-- public
'',
'Ballyhoo',
'a0',
Expand All @@ -928,7 +932,8 @@ describe('parseExcel()', () => {
'A song from the hearth',
'load-next',
'clock',
'',
'x', // <-- time to end
'', // <-- public
'x',
'Rainbow chase',
'b0',
Expand Down Expand Up @@ -972,6 +977,7 @@ describe('parseExcel()', () => {
timerType: 'count-down',
endAction: 'none',
isPublic: true,
isTimeToEnd: true,
skip: false,
note: 'Ballyhoo',
custom: {
Expand All @@ -995,6 +1001,7 @@ describe('parseExcel()', () => {
timeEnd: 30600000,
title: 'A song from the hearth',
timerType: 'clock',
isTimeToEnd: true,
endAction: 'load-next',
isPublic: false,
skip: true,
Expand Down Expand Up @@ -1455,12 +1462,17 @@ describe('parseExcel()', () => {
timeDanger: 'danger time',
custom: {},
};

const result = parseExcel(testdata, {}, importMap);
expect(result.rundown.length).toBe(2);
expect((result.rundown.at(0) as OntimeEvent).type).toBe(SupportedEvent.Event);
expect((result.rundown.at(0) as OntimeEvent).timerType).toBe(TimerType.CountDown);
expect((result.rundown.at(1) as OntimeEvent).type).toBe(SupportedEvent.Event);
expect((result.rundown.at(1) as OntimeEvent).timerType).toBe(TimerType.CountDown);
expect(result.rundown[0]).toMatchObject({
type: SupportedEvent.Event,
timerType: TimerType.CountDown,
});
expect(result.rundown[1]).toMatchObject({
type: SupportedEvent.Event,
timerType: TimerType.CountDown,
});
});

it('imports as events if timer type is empty or has whitespace', () => {
Expand Down
8 changes: 7 additions & 1 deletion apps/server/src/utils/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ export const parseExcel = (
// options: booleans
let isPublicIndex: number | null = null;
let skipIndex: number | null = null;
let isTimeToEndIndex: number | null = null;

let linkStartIndex: number | null = null;

Expand Down Expand Up @@ -159,6 +160,10 @@ export const parseExcel = (
titleIndex = col;
rundownMetadata['title'] = { row, col };
},
[importMap.isTimeToEnd]: (row: number, col: number) => {
isTimeToEndIndex = col;
rundownMetadata['isTimeToEnd'] = { row, col };
},
[importMap.isPublic]: (row: number, col: number) => {
isPublicIndex = col;
rundownMetadata['isPublic'] = { row, col };
Expand Down Expand Up @@ -226,6 +231,8 @@ export const parseExcel = (
event.duration = parseExcelDate(column);
} else if (j === cueIndex) {
event.cue = makeString(column, '');
} else if (j === isTimeToEndIndex) {
event.isTimeToEnd = parseBooleanString(column);
} else if (j === isPublicIndex) {
event.isPublic = parseBooleanString(column);
} else if (j === skipIndex) {
Expand Down Expand Up @@ -271,7 +278,6 @@ export const parseExcel = (

// if any data was found in row, push to array
const keysFound = Object.keys(event).length + Object.keys(eventCustomFields).length;
console.log('keys found ---->', event)
if (keysFound > 0) {
// if it is a Block type drop all other filed
if (isOntimeBlock(event)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ describe('isImportMap()', () => {
duration: 'duration',
cue: 'cue',
title: 'title',
isTimeToEnd: 'time to end',
isPublic: 'public',
skip: 'skip',
note: 'notes',
Expand All @@ -34,6 +35,7 @@ describe('isImportMap()', () => {
duration: 'duration',
cue: 'cue',
title: 'title',
isTimeToEnd: 'time to end',
isPublic: 'public',
skip: 'skip',
note: 'notes',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export const defaultImportMap = {
duration: 'duration',
cue: 'cue',
title: 'title',
isTimeToEnd: 'time to end',
isPublic: 'public',
skip: 'skip',
note: 'notes',
Expand Down

0 comments on commit 9813643

Please sign in to comment.