mirror of
https://github.com/cpvalente/ontime.git
synced 2026-09-10 08:39:34 +00:00
fix: insert group-end where needed
This commit is contained in:
committed by
Alex Christoffer Rasmussen
parent
9d6ec3758b
commit
1af42b766d
@@ -4,7 +4,18 @@
|
|||||||
* @link https://developers.google.com/identity/protocols/oauth2/limited-input-device
|
* @link https://developers.google.com/identity/protocols/oauth2/limited-input-device
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { AuthenticationStatus, CustomFields, DatabaseModel, LogOrigin, MaybeString, Rundown } from 'ontime-types';
|
import {
|
||||||
|
AuthenticationStatus,
|
||||||
|
CustomFields,
|
||||||
|
DatabaseModel,
|
||||||
|
isOntimeEvent,
|
||||||
|
isOntimeMilestone,
|
||||||
|
LogOrigin,
|
||||||
|
MaybeString,
|
||||||
|
OntimeGroup,
|
||||||
|
Rundown,
|
||||||
|
SupportedEntry,
|
||||||
|
} from 'ontime-types';
|
||||||
import { ImportMap, getErrorMessage } from 'ontime-utils';
|
import { ImportMap, getErrorMessage } from 'ontime-utils';
|
||||||
|
|
||||||
import { sheets, type sheets_v4 } from '@googleapis/sheets';
|
import { sheets, type sheets_v4 } from '@googleapis/sheets';
|
||||||
@@ -348,6 +359,21 @@ export async function upload(sheetId: string, options: ImportMap) {
|
|||||||
const { sheetMetadata } = parseExcel(readResponse.data.values, getProjectCustomFields(), 'not-used', options);
|
const { sheetMetadata } = parseExcel(readResponse.data.values, getProjectCustomFields(), 'not-used', options);
|
||||||
const rundown = getCurrentRundown();
|
const rundown = getCurrentRundown();
|
||||||
|
|
||||||
|
const sheetOrder: string[] = [];
|
||||||
|
let prevGroup: string | null = null;
|
||||||
|
for (const id of rundown.flatOrder) {
|
||||||
|
const entry = rundown.entries[id];
|
||||||
|
|
||||||
|
if (isOntimeEvent(entry) || isOntimeMilestone(entry)) {
|
||||||
|
if (prevGroup && entry.parent === null) {
|
||||||
|
// if we were in a group and are now not insert a group end
|
||||||
|
sheetOrder.push(`group-end-${prevGroup}`);
|
||||||
|
}
|
||||||
|
prevGroup = entry.parent;
|
||||||
|
}
|
||||||
|
sheetOrder.push(entry.id);
|
||||||
|
}
|
||||||
|
|
||||||
const titleMetadata = Object.values(sheetMetadata)[0];
|
const titleMetadata = Object.values(sheetMetadata)[0];
|
||||||
if (titleMetadata === undefined) {
|
if (titleMetadata === undefined) {
|
||||||
throw new Error(`Sheet read failed: failed to find title row`);
|
throw new Error(`Sheet read failed: failed to find title row`);
|
||||||
@@ -380,15 +406,19 @@ export async function upload(sheetId: string, options: ImportMap) {
|
|||||||
range: {
|
range: {
|
||||||
dimension: 'ROWS',
|
dimension: 'ROWS',
|
||||||
startIndex: titleRow + 1,
|
startIndex: titleRow + 1,
|
||||||
endIndex: titleRow + rundown.order.length,
|
endIndex: titleRow + sheetOrder.length,
|
||||||
sheetId: worksheetId,
|
sheetId: worksheetId,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
// update the corresponding row with event data
|
// update the corresponding row with event data
|
||||||
rundown.order.forEach((entryId, index) => {
|
sheetOrder.forEach((entryId, index) => {
|
||||||
const entry = rundown.entries[entryId];
|
const isGroupEnd = entryId.startsWith('group-end-');
|
||||||
|
const id = isGroupEnd ? entryId.split('group-end-')[1] : entryId;
|
||||||
|
const entry = isGroupEnd
|
||||||
|
? ({ id: entryId, type: SupportedEntry.Group } as OntimeGroup)
|
||||||
|
: structuredClone(rundown.entries[id]);
|
||||||
updateRundown.push(cellRequestFromEvent(entry, index, worksheetId, sheetMetadata));
|
updateRundown.push(cellRequestFromEvent(entry, index, worksheetId, sheetMetadata));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -91,7 +91,10 @@ export function cellRequestFromEvent(
|
|||||||
): sheets_v4.Schema$Request {
|
): sheets_v4.Schema$Request {
|
||||||
const rowData = Object.entries(metadata) // check what headings are available in the sheet
|
const rowData = Object.entries(metadata) // check what headings are available in the sheet
|
||||||
.filter(([_, value]) => value !== undefined) // drop anything that is undefined
|
.filter(([_, value]) => value !== undefined) // drop anything that is undefined
|
||||||
.sort(([_a, a], [_b, b]) => a['col'] - b['col']) as [keyof OntimeEntry | 'blank', { col: number; row: number }][]; // sort the array by the column index
|
.sort(([_a, a], [_b, b]) => a['col'] - b['col']) as [
|
||||||
|
OntimeEntryCommonKeys | 'blank',
|
||||||
|
{ col: number; row: number },
|
||||||
|
][]; // sort the array by the column index
|
||||||
|
|
||||||
// inset blank data is there is spacing between relevant ontime columns
|
// inset blank data is there is spacing between relevant ontime columns
|
||||||
for (const [index, e] of rowData.entries()) {
|
for (const [index, e] of rowData.entries()) {
|
||||||
@@ -159,7 +162,8 @@ function getCellData(key: OntimeEntryCommonKeys | 'blank', entry: OntimeEntry) {
|
|||||||
|
|
||||||
// we need to remap the event type to timer type in the case of groups and milestones
|
// we need to remap the event type to timer type in the case of groups and milestones
|
||||||
if (key === 'timerType') {
|
if (key === 'timerType') {
|
||||||
if (isOntimeGroup(entry)) return { userEnteredValue: { stringValue: 'group' } };
|
if (isOntimeGroup(entry))
|
||||||
|
return { userEnteredValue: { stringValue: entry.id.startsWith('group-end') ? 'group-end' : 'group' } };
|
||||||
if (isOntimeMilestone(entry)) return { userEnteredValue: { stringValue: 'milestone' } };
|
if (isOntimeMilestone(entry)) return { userEnteredValue: { stringValue: 'milestone' } };
|
||||||
return { userEnteredValue: { stringValue: entry.timerType } };
|
return { userEnteredValue: { stringValue: entry.timerType } };
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user