mirror of
https://github.com/cpvalente/ontime.git
synced 2026-09-08 15:59:16 +00:00
get cell location when from parseExcel
This commit is contained in:
+125
-33
@@ -46,6 +46,8 @@ export const JSON_MIME = 'application/json';
|
|||||||
* @returns {object} - parsed object
|
* @returns {object} - parsed object
|
||||||
*/
|
*/
|
||||||
export const parseExcel = (excelData: unknown[][], options?: Partial<ExcelImportMap>) => {
|
export const parseExcel = (excelData: unknown[][], options?: Partial<ExcelImportMap>) => {
|
||||||
|
let projectMetadata = {};
|
||||||
|
let rundownMetadata = {};
|
||||||
const importMap: ExcelImportMap = { ...defaultExcelImportMap, ...options };
|
const importMap: ExcelImportMap = { ...defaultExcelImportMap, ...options };
|
||||||
const projectData: Partial<ProjectData> = {
|
const projectData: Partial<ProjectData> = {
|
||||||
title: '',
|
title: '',
|
||||||
@@ -102,9 +104,10 @@ export const parseExcel = (excelData: unknown[][], options?: Partial<ExcelImport
|
|||||||
let user8Index: number | null = null;
|
let user8Index: number | null = null;
|
||||||
let user9Index: number | null = null;
|
let user9Index: number | null = null;
|
||||||
|
|
||||||
excelData
|
excelData.forEach((row, rowIndex) => {
|
||||||
.filter((e) => e.length > 0)
|
if (row.length === 0) {
|
||||||
.forEach((row) => {
|
return;
|
||||||
|
}
|
||||||
// these fields contain the data to its right
|
// these fields contain the data to its right
|
||||||
let projectTitleNext = false;
|
let projectTitleNext = false;
|
||||||
let projectDescriptionNext = false;
|
let projectDescriptionNext = false;
|
||||||
@@ -115,39 +118,126 @@ export const parseExcel = (excelData: unknown[][], options?: Partial<ExcelImport
|
|||||||
|
|
||||||
const event: Partial<OntimeEvent> = {};
|
const event: Partial<OntimeEvent> = {};
|
||||||
const handlers = {
|
const handlers = {
|
||||||
[importMap.projectName]: () => (projectTitleNext = true),
|
[importMap.projectName]: (row: number, col: number) => {
|
||||||
[importMap.projectDescription]: () => (projectDescriptionNext = true),
|
projectTitleNext = true;
|
||||||
[importMap.publicUrl]: () => (publicUrlNext = true),
|
projectMetadata['projectName'] = { row: row, col: col };
|
||||||
[importMap.publicInfo]: () => (publicInfoNext = true),
|
},
|
||||||
[importMap.backstageUrl]: () => (backstageUrlNext = true),
|
[importMap.projectDescription]: (row: number, col: number) => {
|
||||||
[importMap.backstageInfo]: () => (backstageInfoNext = true),
|
projectDescriptionNext = true;
|
||||||
|
projectMetadata['projectDescription'] = { row: row, col: col };
|
||||||
|
},
|
||||||
|
[importMap.publicUrl]: (row: number, col: number) => {
|
||||||
|
publicUrlNext = true;
|
||||||
|
projectMetadata['publicUrl'] = { row: row, col: col };
|
||||||
|
},
|
||||||
|
[importMap.publicInfo]: (row: number, col: number) => {
|
||||||
|
publicInfoNext = true;
|
||||||
|
projectMetadata['publicInfo'] = { row: row, col: col };
|
||||||
|
},
|
||||||
|
[importMap.backstageUrl]: (row: number, col: number) => {
|
||||||
|
backstageUrlNext = true;
|
||||||
|
projectMetadata['backstageUrl'] = { row: row, col: col };
|
||||||
|
},
|
||||||
|
[importMap.backstageInfo]: (row: number, col: number) => {
|
||||||
|
backstageInfoNext = true;
|
||||||
|
projectMetadata['backstageInfo'] = { row: row, col: col };
|
||||||
|
},
|
||||||
|
|
||||||
[importMap.timeStart]: (index: number) => (timeStartIndex = index),
|
[importMap.timeStart]: (row: number, col: number) => {
|
||||||
[importMap.timeEnd]: (index: number) => (timeEndIndex = index),
|
timeStartIndex = col;
|
||||||
[importMap.duration]: (index: number) => (durationIndex = index),
|
rundownMetadata['timeStart'] = { row: row, col: col };
|
||||||
|
},
|
||||||
|
[importMap.timeEnd]: (row: number, col: number) => {
|
||||||
|
timeEndIndex = col;
|
||||||
|
rundownMetadata['timeEnd'] = { row: row, col: col };
|
||||||
|
},
|
||||||
|
[importMap.duration]: (row: number, col: number) => {
|
||||||
|
durationIndex = col;
|
||||||
|
rundownMetadata['duration'] = { row: row, col: col };
|
||||||
|
},
|
||||||
|
|
||||||
[importMap.cue]: (index: number) => (cueIndex = index),
|
[importMap.cue]: (row: number, col: number) => {
|
||||||
[importMap.title]: (index: number) => (titleIndex = index),
|
cueIndex = col;
|
||||||
[importMap.presenter]: (index: number) => (presenterIndex = index),
|
rundownMetadata['cue'] = { row: row, col: col };
|
||||||
[importMap.subtitle]: (index: number) => (subtitleIndex = index),
|
},
|
||||||
[importMap.isPublic]: (index: number) => (isPublicIndex = index),
|
[importMap.title]: (row: number, col: number) => {
|
||||||
[importMap.skip]: (index: number) => (skipIndex = index),
|
titleIndex = col;
|
||||||
[importMap.note]: (index: number) => (notesIndex = index),
|
rundownMetadata['title'] = { row: row, col: col };
|
||||||
[importMap.colour]: (index: number) => (colourIndex = index),
|
},
|
||||||
|
[importMap.presenter]: (row: number, col: number) => {
|
||||||
|
presenterIndex = col;
|
||||||
|
rundownMetadata['presenter'] = { row: row, col: col };
|
||||||
|
},
|
||||||
|
[importMap.subtitle]: (row: number, col: number) => {
|
||||||
|
subtitleIndex = col;
|
||||||
|
rundownMetadata['subtitle'] = { row: row, col: col };
|
||||||
|
},
|
||||||
|
[importMap.isPublic]: (row: number, col: number) => {
|
||||||
|
isPublicIndex = col;
|
||||||
|
rundownMetadata['isPublic'] = { row: row, col: col };
|
||||||
|
},
|
||||||
|
[importMap.skip]: (row: number, col: number) => {
|
||||||
|
skipIndex = col;
|
||||||
|
rundownMetadata['skip'] = { row: row, col: col };
|
||||||
|
},
|
||||||
|
[importMap.note]: (row: number, col: number) => {
|
||||||
|
notesIndex = col;
|
||||||
|
rundownMetadata['note'] = { row: row, col: col };
|
||||||
|
},
|
||||||
|
[importMap.colour]: (row: number, col: number) => {
|
||||||
|
colourIndex = col;
|
||||||
|
rundownMetadata['colour'] = { row: row, col: col };
|
||||||
|
},
|
||||||
|
|
||||||
[importMap.endAction]: (index: number) => (endActionIndex = index),
|
[importMap.endAction]: (row: number, col: number) => {
|
||||||
[importMap.timerType]: (index: number) => (timerTypeIndex = index),
|
endActionIndex = col;
|
||||||
|
rundownMetadata['endAction'] = { row: row, col: col };
|
||||||
|
},
|
||||||
|
[importMap.timerType]: (row: number, col: number) => {
|
||||||
|
timerTypeIndex = col;
|
||||||
|
rundownMetadata['timerType'] = { row: row, col: col };
|
||||||
|
},
|
||||||
|
|
||||||
[importMap.user0]: (index: number) => (user0Index = index),
|
[importMap.user0]: (row: number, col: number) => {
|
||||||
[importMap.user1]: (index: number) => (user1Index = index),
|
user0Index = col;
|
||||||
[importMap.user2]: (index: number) => (user2Index = index),
|
rundownMetadata['user0'] = { row: row, col: col };
|
||||||
[importMap.user3]: (index: number) => (user3Index = index),
|
},
|
||||||
[importMap.user4]: (index: number) => (user4Index = index),
|
[importMap.user1]: (row: number, col: number) => {
|
||||||
[importMap.user5]: (index: number) => (user5Index = index),
|
user1Index = col;
|
||||||
[importMap.user6]: (index: number) => (user6Index = index),
|
rundownMetadata['user1'] = { row: row, col: col };
|
||||||
[importMap.user7]: (index: number) => (user7Index = index),
|
},
|
||||||
[importMap.user8]: (index: number) => (user8Index = index),
|
[importMap.user2]: (row: number, col: number) => {
|
||||||
[importMap.user9]: (index: number) => (user9Index = index),
|
user2Index = col;
|
||||||
|
rundownMetadata['user2'] = { row: row, col: col };
|
||||||
|
},
|
||||||
|
[importMap.user3]: (row: number, col: number) => {
|
||||||
|
user3Index = col;
|
||||||
|
rundownMetadata['user3'] = { row: row, col: col };
|
||||||
|
},
|
||||||
|
[importMap.user4]: (row: number, col: number) => {
|
||||||
|
user4Index = col;
|
||||||
|
rundownMetadata['user4'] = { row: row, col: col };
|
||||||
|
},
|
||||||
|
[importMap.user5]: (row: number, col: number) => {
|
||||||
|
user5Index = col;
|
||||||
|
rundownMetadata['user5'] = { row: row, col: col };
|
||||||
|
},
|
||||||
|
[importMap.user6]: (row: number, col: number) => {
|
||||||
|
user6Index = col;
|
||||||
|
rundownMetadata['user6'] = { row: row, col: col };
|
||||||
|
},
|
||||||
|
[importMap.user7]: (row: number, col: number) => {
|
||||||
|
user7Index = col;
|
||||||
|
rundownMetadata['user7'] = { row: row, col: col };
|
||||||
|
},
|
||||||
|
[importMap.user8]: (row: number, col: number) => {
|
||||||
|
user8Index = col;
|
||||||
|
rundownMetadata['user8'] = { row: row, col: col };
|
||||||
|
},
|
||||||
|
[importMap.user9]: (row: number, col: number) => {
|
||||||
|
user9Index = col;
|
||||||
|
rundownMetadata['user9'] = { row: row, col: col };
|
||||||
|
},
|
||||||
} as const;
|
} as const;
|
||||||
|
|
||||||
row.forEach((column, j) => {
|
row.forEach((column, j) => {
|
||||||
@@ -222,7 +312,7 @@ export const parseExcel = (excelData: unknown[][], options?: Partial<ExcelImport
|
|||||||
const col = column.toLowerCase();
|
const col = column.toLowerCase();
|
||||||
|
|
||||||
if (handlers[col]) {
|
if (handlers[col]) {
|
||||||
handlers[col](j);
|
handlers[col](rowIndex, j);
|
||||||
}
|
}
|
||||||
// else. we don't know how to handle this column
|
// else. we don't know how to handle this column
|
||||||
// just ignore it
|
// just ignore it
|
||||||
@@ -244,6 +334,8 @@ export const parseExcel = (excelData: unknown[][], options?: Partial<ExcelImport
|
|||||||
version: 2,
|
version: 2,
|
||||||
},
|
},
|
||||||
userFields: customUserFields,
|
userFields: customUserFields,
|
||||||
|
projectMetadata: projectMetadata,
|
||||||
|
rundownMetadata: rundownMetadata,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user