mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-13 19:33:46 +00:00
refactor: add rundown summary to import preview
This commit is contained in:
committed by
Carlos Valente
parent
3918664945
commit
e6070e6efd
@@ -1,6 +1,6 @@
|
||||
import express from 'express';
|
||||
import type { Request, Response } from 'express';
|
||||
import { CustomFields, ErrorResponse, Rundown } from 'ontime-types';
|
||||
import { CustomFields, ErrorResponse, Rundown, RundownSummary } from 'ontime-types';
|
||||
|
||||
import { getDataProvider } from '../../classes/data-provider/DataProvider.js';
|
||||
|
||||
@@ -32,7 +32,10 @@ router.post(
|
||||
router.post(
|
||||
'/preview',
|
||||
validateImportMapOptions,
|
||||
(req: Request, res: Response<{ rundown: Rundown; customFields: CustomFields } | ErrorResponse>) => {
|
||||
(
|
||||
req: Request,
|
||||
res: Response<{ rundown: Rundown; customFields: CustomFields; summary: RundownSummary } | ErrorResponse>,
|
||||
) => {
|
||||
try {
|
||||
const { options } = req.body;
|
||||
const data = generateRundownPreview(options);
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* Google Sheets
|
||||
*/
|
||||
|
||||
import { CustomFields, Rundown } from 'ontime-types';
|
||||
import { CustomFields, Rundown, RundownSummary } from 'ontime-types';
|
||||
import { type ImportMap } from 'ontime-utils';
|
||||
|
||||
import { extname } from 'path';
|
||||
@@ -14,7 +14,7 @@ import type { WorkBook } from 'xlsx';
|
||||
import { deleteFile } from '../../utils/fileManagement.js';
|
||||
|
||||
import { parseRundown } from '../rundown/rundown.parser.js';
|
||||
import { getProjectCustomFields } from '../rundown/rundown.dao.js';
|
||||
import { getProjectCustomFields, processRundown } from '../rundown/rundown.dao.js';
|
||||
import { parseCustomFields } from '../custom-fields/customFields.parser.js';
|
||||
|
||||
import { parseExcel } from './excel.parser.js';
|
||||
@@ -43,7 +43,11 @@ export async function readExcelFile(filePath: string): Promise<string[]> {
|
||||
return excelData.SheetNames;
|
||||
}
|
||||
|
||||
export function generateRundownPreview(options: ImportMap): { rundown: Rundown; customFields: CustomFields } {
|
||||
export function generateRundownPreview(options: ImportMap): {
|
||||
rundown: Rundown;
|
||||
summary: RundownSummary;
|
||||
customFields: CustomFields;
|
||||
} {
|
||||
const data = excelData.Sheets[options.worksheet];
|
||||
|
||||
if (!data) {
|
||||
@@ -59,9 +63,25 @@ export function generateRundownPreview(options: ImportMap): { rundown: Rundown;
|
||||
|
||||
// we run the parsed data through an extra step to ensure the objects shape
|
||||
const customFields = parseCustomFields(dataFromExcel);
|
||||
const rundown = parseRundown(dataFromExcel.rundown, customFields);
|
||||
const parsedRundown = parseRundown(dataFromExcel.rundown, customFields);
|
||||
const processedRundown = processRundown(parsedRundown, customFields);
|
||||
|
||||
return { rundown, customFields };
|
||||
return {
|
||||
rundown: {
|
||||
id: parsedRundown.id,
|
||||
title: parsedRundown.title,
|
||||
order: processedRundown.order,
|
||||
flatOrder: processedRundown.flatEntryOrder,
|
||||
entries: processedRundown.entries,
|
||||
revision: 0,
|
||||
},
|
||||
summary: {
|
||||
duration: processedRundown.totalDuration,
|
||||
start: processedRundown.firstStart,
|
||||
end: processedRundown.lastEnd,
|
||||
},
|
||||
customFields,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* Google Sheets
|
||||
*/
|
||||
|
||||
import type { AuthenticationStatus, CustomFields, ErrorResponse, Rundown } from 'ontime-types';
|
||||
import type { AuthenticationStatus, CustomFields, ErrorResponse, Rundown, RundownSummary } from 'ontime-types';
|
||||
import { getErrorMessage } from 'ontime-utils';
|
||||
|
||||
import { Request, Response } from 'express';
|
||||
@@ -86,6 +86,7 @@ export async function readFromSheet(
|
||||
| {
|
||||
rundown: Rundown;
|
||||
customFields: CustomFields;
|
||||
summary: RundownSummary;
|
||||
}
|
||||
| ErrorResponse
|
||||
>,
|
||||
|
||||
@@ -15,6 +15,7 @@ import {
|
||||
MaybeString,
|
||||
OntimeGroup,
|
||||
Rundown,
|
||||
RundownSummary,
|
||||
SupportedEntry,
|
||||
} from 'ontime-types';
|
||||
import { ImportMap, getErrorMessage } from 'ontime-utils';
|
||||
@@ -24,7 +25,7 @@ import { Credentials, OAuth2Client } from 'google-auth-library';
|
||||
|
||||
import { logger } from '../../classes/Logger.js';
|
||||
import { parseRundowns } from '../../api-data/rundown/rundown.parser.js';
|
||||
import { getCurrentRundown, getProjectCustomFields } from '../../api-data/rundown/rundown.dao.js';
|
||||
import { getCurrentRundown, getProjectCustomFields, processRundown } from '../../api-data/rundown/rundown.dao.js';
|
||||
import { parseExcel } from '../../api-data/excel/excel.parser.js';
|
||||
import { parseCustomFields } from '../../api-data/custom-fields/customFields.parser.js';
|
||||
import { consoleSubdued } from '../../utils/console.js';
|
||||
@@ -455,6 +456,7 @@ export async function download(
|
||||
): Promise<{
|
||||
rundown: Rundown;
|
||||
customFields: CustomFields;
|
||||
summary: RundownSummary;
|
||||
}> {
|
||||
if (!currentAuthClient) {
|
||||
throw new Error('Not authenticated');
|
||||
@@ -488,9 +490,9 @@ export async function download(
|
||||
};
|
||||
|
||||
const customFields = parseCustomFields(dataModel);
|
||||
const rundowns = parseRundowns(dataModel, customFields);
|
||||
const parsedRundown = parseRundowns(dataModel, customFields);
|
||||
|
||||
const importedRundown = rundowns[rundownId];
|
||||
const importedRundown = parsedRundown[rundownId];
|
||||
if (!importedRundown) {
|
||||
throw new Error(`Sheet: Rundown with ID ${rundownId} not found in the worksheet`);
|
||||
}
|
||||
@@ -499,5 +501,22 @@ export async function download(
|
||||
throw new Error('Sheet: Could not find data to import in the worksheet');
|
||||
}
|
||||
|
||||
return { rundown: rundowns[rundownId], customFields };
|
||||
const processedRundown = processRundown(importedRundown, customFields);
|
||||
|
||||
return {
|
||||
rundown: {
|
||||
id: importedRundown.id,
|
||||
title: importedRundown.title,
|
||||
order: processedRundown.order,
|
||||
flatOrder: processedRundown.flatEntryOrder,
|
||||
entries: processedRundown.entries,
|
||||
revision: 0,
|
||||
},
|
||||
summary: {
|
||||
duration: processedRundown.totalDuration,
|
||||
start: processedRundown.firstStart,
|
||||
end: processedRundown.lastEnd,
|
||||
},
|
||||
customFields,
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user