mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-07 00:13:53 +00:00
lint
This commit is contained in:
@@ -239,10 +239,7 @@ export const uploadSheetClientFile = async (file: File) => {
|
||||
.post(`${ontimeURL}/sheet-clientsecrect`, formData, {
|
||||
headers: {
|
||||
'Content-Type': 'multipart/form-data',
|
||||
},
|
||||
onUploadProgress: (progressEvent) => {
|
||||
const complete = progressEvent?.total ? Math.round((progressEvent.loaded * 100) / progressEvent.total) : 0;
|
||||
},
|
||||
}
|
||||
})
|
||||
.then((response) => response.data.id);
|
||||
};
|
||||
|
||||
@@ -11,21 +11,21 @@ import {
|
||||
ModalOverlay,
|
||||
} from '@chakra-ui/react';
|
||||
import { useQueryClient } from '@tanstack/react-query';
|
||||
import { OntimeRundown, ProjectData, UserFields } from 'ontime-types';
|
||||
|
||||
import { PROJECT_DATA, RUNDOWN, USERFIELDS } from '../../../common/api/apiConstants';
|
||||
import { maybeAxiosError } from '../../../common/api/apiUtils';
|
||||
import {
|
||||
getSheetsAuthStatus,
|
||||
getSheetsAuthUrl,
|
||||
postPreviewSheet,
|
||||
uploadSheetClientFile,
|
||||
patchData,
|
||||
postPreviewSheet,
|
||||
postPushSheet,
|
||||
uploadSheetClientFile,
|
||||
} from '../../../common/api/ontimeApi';
|
||||
import { OntimeRundown, ProjectData, UserFields } from 'ontime-types';
|
||||
|
||||
import PreviewExcel from '../upload-modal/preview/PreviewExcel';
|
||||
import { projectDataPlaceholder } from '../../../common/models/ProjectData';
|
||||
import { userFieldsPlaceholder } from '../../../common/models/UserFields';
|
||||
import { PROJECT_DATA, RUNDOWN, USERFIELDS } from '../../../common/api/apiConstants';
|
||||
import { maybeAxiosError } from '../../../common/api/apiUtils';
|
||||
import PreviewExcel from '../upload-modal/preview/PreviewExcel';
|
||||
|
||||
interface SheetsModalProps {
|
||||
onClose: () => void;
|
||||
@@ -35,7 +35,6 @@ interface SheetsModalProps {
|
||||
export default function SheetsModal(props: SheetsModalProps) {
|
||||
const { isOpen, onClose } = props;
|
||||
const fileInputRef = useRef<HTMLInputElement>(null);
|
||||
const [file, setFile] = useState<File | null>(null);
|
||||
const [authState, setAuthState] = useState<boolean>(true);
|
||||
|
||||
const [rundown, setRundown] = useState<OntimeRundown | null>(null);
|
||||
@@ -59,12 +58,10 @@ export default function SheetsModal(props: SheetsModalProps) {
|
||||
const handleFile = (event: ChangeEvent<HTMLInputElement>) => {
|
||||
const selectedFile = event?.target?.files?.[0];
|
||||
if (!selectedFile) {
|
||||
setFile(null);
|
||||
return;
|
||||
} else {
|
||||
uploadSheetClientFile(selectedFile);
|
||||
}
|
||||
setFile(selectedFile);
|
||||
};
|
||||
|
||||
//TODO: do smoething better here
|
||||
@@ -75,8 +72,7 @@ export default function SheetsModal(props: SheetsModalProps) {
|
||||
const handleAuthenticate = () => {
|
||||
getSheetsAuthUrl().then((data) => {
|
||||
console.log(data);
|
||||
if (data == 'bad') {
|
||||
} else {
|
||||
if (data != 'bad') {
|
||||
window.open(data, '_blank', 'noreferrer');
|
||||
}
|
||||
});
|
||||
|
||||
@@ -413,7 +413,7 @@ export async function previewSheet(req, res) {
|
||||
*/
|
||||
export async function pushSheet(req, res) {
|
||||
try {
|
||||
const data = await Sheet.push(req.body.sheetid, req.body.worksheet);
|
||||
await Sheet.push(req.body.sheetid, req.body.worksheet);
|
||||
res.status(200).send('ok');
|
||||
} catch (error) {
|
||||
res.status(500).send({ message: error.toString() });
|
||||
|
||||
@@ -46,8 +46,8 @@ export const JSON_MIME = 'application/json';
|
||||
* @returns {object} - parsed object
|
||||
*/
|
||||
export const parseExcel = (excelData: unknown[][], options?: Partial<ExcelImportMap>) => {
|
||||
let projectMetadata = {};
|
||||
let rundownMetadata = {};
|
||||
const projectMetadata = {};
|
||||
const rundownMetadata = {};
|
||||
const importMap: ExcelImportMap = { ...defaultExcelImportMap, ...options };
|
||||
const projectData: Partial<ProjectData> = {
|
||||
title: '',
|
||||
|
||||
@@ -6,7 +6,7 @@ import { URL } from 'url';
|
||||
import { logger } from '../classes/Logger.js';
|
||||
import { getAppDataPath } from '../setup.js';
|
||||
import { DatabaseModel, LogOrigin, OntimeRundownEntry, isOntimeEvent } from 'ontime-types';
|
||||
import { ExcelImportOptions, isExcelImportMap, defaultExcelImportMap, millisToString } from 'ontime-utils';
|
||||
import { isExcelImportMap, defaultExcelImportMap, millisToString } from 'ontime-utils';
|
||||
import { parseExcel } from './parser.js';
|
||||
import { parseProject, parseRundown, parseUserFields } from './parserFunctions.js';
|
||||
import { ensureDirectory } from './fileManagement.js';
|
||||
@@ -81,7 +81,8 @@ class sheet {
|
||||
range: worksheet + '!A:Z', //FIXME: this is an abitrary range
|
||||
});
|
||||
if (rq.status === 200) {
|
||||
const { projectMetadata, rundownMetadata } = parseExcel(rq.data.values, options);
|
||||
//TODO: projectMetadata
|
||||
const { rundownMetadata } = parseExcel(rq.data.values, options);
|
||||
const rundown = DataProvider.getRundown();
|
||||
const titleRow = Object.values(rundownMetadata)[0]['row'];
|
||||
|
||||
@@ -184,9 +185,9 @@ class sheet {
|
||||
|
||||
/**
|
||||
* saves Object to appdata path as client_secret.json
|
||||
* @param {Object} secrets
|
||||
* @param {} secrets
|
||||
*/
|
||||
public async saveClientSecrets(secrets: Object) {
|
||||
public async saveClientSecrets(secrets) {
|
||||
ensureDirectory(this.sheetsFolder);
|
||||
logger.info(LogOrigin.Server, 'Sheets: got new client_secret');
|
||||
//TODO: test that this is actualy a client file?
|
||||
@@ -236,7 +237,9 @@ class sheet {
|
||||
if (response?.credentials) {
|
||||
return true;
|
||||
}
|
||||
} catch (_) {}
|
||||
} catch (_) {
|
||||
logger.info(LogOrigin.Server, 'Sheets token expired');
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -250,12 +253,13 @@ class sheet {
|
||||
metadata,
|
||||
titleCol: number,
|
||||
): sheets_v4.Schema$Request {
|
||||
let r: sheets_v4.Schema$CellData[] = [];
|
||||
const tmp = Object.entries(metadata)
|
||||
.filter(([key, value]) => value !== undefined)
|
||||
.sort(([aKey, a], [bKey, b]) => a['col'] - b['col']);
|
||||
|
||||
tmp.forEach(([key, value], index, arr) => {
|
||||
const r: sheets_v4.Schema$CellData[] = [];
|
||||
const tmp = Object.entries(metadata)
|
||||
.filter(([_, value]) => value !== undefined)
|
||||
.sort(([_a, a], [_b, b]) => a['col'] - b['col']);
|
||||
|
||||
tmp.forEach(([_, value], index, arr) => {
|
||||
if (index != 0) {
|
||||
if (arr[index - 1][1]['col'] + 1 < value['col']) {
|
||||
arr.splice(index, 0, ['blank', { col: arr[index - 1][1]['col'] + 1 }]);
|
||||
@@ -263,7 +267,7 @@ class sheet {
|
||||
}
|
||||
});
|
||||
|
||||
tmp.forEach(([key, value]) => {
|
||||
tmp.forEach(([key, _]) => {
|
||||
if (isOntimeEvent(event)) {
|
||||
if (key === 'blank') {
|
||||
r.push({});
|
||||
@@ -430,29 +434,4 @@ your keyfile, and add a 'redirect_uris' section. For example:
|
||||
]
|
||||
`;
|
||||
|
||||
function hexToRgb(hex: string) {
|
||||
if (hex === '' || hex[0] !== '#') {
|
||||
return { red: 1, green: 1, blue: 1 };
|
||||
}
|
||||
const bigint = parseInt(hex.slice(1), 16);
|
||||
const r = ((bigint >> 16) & 255) / 255;
|
||||
const g = ((bigint >> 8) & 255) / 255;
|
||||
const b = (bigint & 255) / 255;
|
||||
return { red: r, green: g, blue: b };
|
||||
}
|
||||
|
||||
type sheetPos = {
|
||||
row: number;
|
||||
col: number;
|
||||
};
|
||||
|
||||
function isEqualPartial<T>(a: T, b: Partial<T>) {
|
||||
for (const [key, value] of Object.entries(a)) {
|
||||
if (b[key] !== undefined && value !== b[key]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
export const Sheet = new sheet();
|
||||
|
||||
Reference in New Issue
Block a user