mirror of
https://github.com/cpvalente/ontime.git
synced 2026-07-26 10:38:55 +00:00
dont save
This commit is contained in:
@@ -11,7 +11,6 @@ import {
|
||||
UserFields,
|
||||
Alias,
|
||||
Settings,
|
||||
Sheet,
|
||||
} from 'ontime-types';
|
||||
|
||||
import { data, db } from '../../modules/loadDb.js';
|
||||
@@ -59,15 +58,6 @@ export class DataProvider {
|
||||
await this.persist();
|
||||
}
|
||||
|
||||
static getSheet() {
|
||||
return data.sheet;
|
||||
}
|
||||
|
||||
static async setSheet(newData: Sheet) {
|
||||
data.sheet = { ...newData };
|
||||
await this.persist();
|
||||
}
|
||||
|
||||
static getOsc() {
|
||||
return data.osc;
|
||||
}
|
||||
|
||||
@@ -6,13 +6,12 @@ import { DatabaseModel } from 'ontime-types';
|
||||
* @param {object} newData
|
||||
*/
|
||||
export function safeMerge(existing: DatabaseModel, newData: Partial<DatabaseModel>) {
|
||||
const { rundown, project, settings, sheet, viewSettings, osc, aliases, userFields } = newData || {};
|
||||
const { rundown, project, settings, viewSettings, osc, aliases, userFields } = newData || {};
|
||||
return {
|
||||
...existing,
|
||||
rundown: rundown ?? existing.rundown,
|
||||
project: { ...existing.project, ...project },
|
||||
settings: { ...existing.settings, ...settings },
|
||||
sheet: { ...existing.sheet, ...sheet },
|
||||
viewSettings: { ...existing.viewSettings, ...viewSettings },
|
||||
aliases: aliases ?? existing.aliases,
|
||||
userFields: {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Alias, DatabaseModel, Sheet, OntimeRundown, Settings } from 'ontime-types';
|
||||
import { Alias, DatabaseModel, OntimeRundown, Settings } from 'ontime-types';
|
||||
import { safeMerge } from '../DataProvider.utils.js';
|
||||
|
||||
describe('safeMerge', () => {
|
||||
@@ -21,10 +21,6 @@ describe('safeMerge', () => {
|
||||
timeFormat: '24',
|
||||
language: 'en',
|
||||
},
|
||||
sheet: {
|
||||
worksheet: '1',
|
||||
id: '2',
|
||||
},
|
||||
viewSettings: {
|
||||
overrideStyles: false,
|
||||
endMessage: 'existing endMessage',
|
||||
@@ -101,21 +97,6 @@ describe('safeMerge', () => {
|
||||
language: 'pt',
|
||||
});
|
||||
});
|
||||
|
||||
it('merges the sheet key', () => {
|
||||
const newData = {
|
||||
sheet: {
|
||||
id: '4',
|
||||
worksheet: '5',
|
||||
} as Sheet,
|
||||
};
|
||||
const mergedData = safeMerge(existing, newData);
|
||||
expect(mergedData.sheet).toEqual({
|
||||
id: '4',
|
||||
worksheet: '5',
|
||||
});
|
||||
});
|
||||
|
||||
it('merges the osc key', () => {
|
||||
const newData = {
|
||||
osc: {
|
||||
|
||||
@@ -464,7 +464,8 @@ export const postNew: RequestHandler = async (req, res) => {
|
||||
*/
|
||||
export async function previewSheet(req, res) {
|
||||
try {
|
||||
const data = await Sheet.pull();
|
||||
const { id, worksheet } = req.data;
|
||||
const data = await Sheet.pull(id, worksheet);
|
||||
res.status(200).send(data);
|
||||
} catch (error) {
|
||||
res.status(500).send({ message: error.toString() });
|
||||
@@ -474,10 +475,12 @@ export async function previewSheet(req, res) {
|
||||
/**
|
||||
* downloads and parses an sheet
|
||||
* @returns parsed result
|
||||
* @method POST
|
||||
*/
|
||||
export async function pushSheet(req, res) {
|
||||
try {
|
||||
await Sheet.push();
|
||||
const { id, worksheet } = req.data;
|
||||
await Sheet.push(id, worksheet);
|
||||
res.status(200).send('ok');
|
||||
} catch (error) {
|
||||
res.status(500).send({ message: error.toString() });
|
||||
@@ -487,6 +490,7 @@ export async function pushSheet(req, res) {
|
||||
/**
|
||||
* uploads Client secrets file
|
||||
* @returns parsed result
|
||||
* @method POST
|
||||
*/
|
||||
export async function uploadSheetClientFile(req, res) {
|
||||
if (!req.file.path) {
|
||||
@@ -519,40 +523,11 @@ export async function sheetAuthUrl(req, res) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Get s sheet Settings
|
||||
* @method GET
|
||||
*/
|
||||
export const getSheetSettings = async (req, res) => {
|
||||
const sheet = await DataProvider.getSheet();
|
||||
res.status(200).send(sheet);
|
||||
};
|
||||
|
||||
/**
|
||||
* @description Change view Settings
|
||||
* @method POST
|
||||
*/
|
||||
export const postSheetSettings = async (req, res) => {
|
||||
if (failEmptyObjects(req.body, res)) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const newData = {
|
||||
id: req.body.id,
|
||||
worksheet: req.body.worksheet,
|
||||
};
|
||||
await DataProvider.setSheet(newData);
|
||||
res.status(200).send(newData);
|
||||
} catch (error) {
|
||||
res.status(400).send({ message: error.toString() });
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @description Get sheet state
|
||||
* @method GET
|
||||
*/
|
||||
export const getSheetState = async (req, res) => {
|
||||
res.status(200).send(await Sheet.getSheetState());
|
||||
const { id, worksheet } = req.data;
|
||||
res.status(200).send(await Sheet.getSheetState(id, worksheet));
|
||||
};
|
||||
|
||||
@@ -164,13 +164,3 @@ export const validateSheetPreview = [
|
||||
next();
|
||||
},
|
||||
];
|
||||
|
||||
export const validateSheetSettings = [
|
||||
body('id').isString().optional({ nullable: false }),
|
||||
body('worksheet').isString().optional({ nullable: false }),
|
||||
(req, res, next) => {
|
||||
const errors = validationResult(req);
|
||||
if (!errors.isEmpty()) return res.status(422).json({ errors: errors.array() });
|
||||
next();
|
||||
},
|
||||
];
|
||||
|
||||
@@ -20,10 +20,6 @@ export const dbModel: DatabaseModel = {
|
||||
timeFormat: '24',
|
||||
language: 'en',
|
||||
},
|
||||
sheet: {
|
||||
id: '',
|
||||
worksheet: '',
|
||||
},
|
||||
viewSettings: {
|
||||
overrideStyles: false,
|
||||
normalColor: '#ffffffcc',
|
||||
|
||||
@@ -25,14 +25,11 @@ import {
|
||||
uploadSheetClientFile,
|
||||
previewSheet,
|
||||
pushSheet,
|
||||
getSheetSettings,
|
||||
postSheetSettings,
|
||||
getSheetState,
|
||||
} from '../controllers/ontimeController.js';
|
||||
|
||||
import {
|
||||
validateAliases,
|
||||
validateSheetSettings,
|
||||
validateOSC,
|
||||
validatePatchProjectFile,
|
||||
validateSettings,
|
||||
@@ -118,11 +115,5 @@ router.post('/sheet-preview', validateSheetPreview, previewSheet);
|
||||
// create route between controller and '/ontime/preview-sheet' endpoint
|
||||
router.post('/sheet-push', pushSheet);
|
||||
|
||||
// create route between controller and '/ontime/sheet-settings' endpoint
|
||||
router.get('/sheet-settings', getSheetSettings);
|
||||
|
||||
// create route between controller and '/ontime/sheet-settings' endpoint
|
||||
router.post('/sheet-settings', validateSheetSettings, postSheetSettings);
|
||||
|
||||
// create route between controller and '/ontime/sheet-state' endpoint
|
||||
router.get('/sheet-state', getSheetState);
|
||||
|
||||
@@ -34,7 +34,6 @@ import {
|
||||
parseSettings,
|
||||
parseUserFields,
|
||||
parseViewSettings,
|
||||
parseSheet,
|
||||
} from './parserFunctions.js';
|
||||
import { parseExcelDate } from './time.js';
|
||||
import { coerceBoolean } from './coerceType.js';
|
||||
@@ -371,8 +370,6 @@ export const parseJson = async (jsonData): Promise<DatabaseModel | null> => {
|
||||
returnData.osc = parseOsc(jsonData) ?? dbModel.osc;
|
||||
// Import HTTP settings if any
|
||||
returnData.http = parseHttp(jsonData) ?? dbModel.http;
|
||||
// Import Sheet settings if any
|
||||
returnData.sheet = parseSheet(jsonData, true);
|
||||
|
||||
return returnData as DatabaseModel;
|
||||
};
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import { generateId } from 'ontime-utils';
|
||||
import {
|
||||
Alias,
|
||||
Sheet,
|
||||
OntimeRundown,
|
||||
HttpSettings,
|
||||
OSCSettings,
|
||||
@@ -332,25 +331,4 @@ export const parseUserFields = (data): UserFields => {
|
||||
}
|
||||
}
|
||||
return { ...newUserFields };
|
||||
};
|
||||
|
||||
/**
|
||||
* Parse Sheet portion of an entry
|
||||
* @param {object} data - data object
|
||||
* @param {boolean} enforce - whether to create a definition if one is missing
|
||||
* @returns {object} - event object data
|
||||
*/
|
||||
export const parseSheet = (data, enforce) => {
|
||||
const newSheet: Sheet = {
|
||||
id: '',
|
||||
worksheet: '',
|
||||
};
|
||||
if ('sheet' in data) {
|
||||
console.log('Found Sheet definition, importing...');
|
||||
newSheet.id ??= data.sheet?.id;
|
||||
newSheet.worksheet ??= data.sheet?.worksheet;
|
||||
return newSheet;
|
||||
} else if (enforce) {
|
||||
return newSheet;
|
||||
}
|
||||
};
|
||||
};
|
||||
@@ -41,7 +41,7 @@ class sheet {
|
||||
}
|
||||
}
|
||||
|
||||
public async getSheetState(): Promise<SheetState> {
|
||||
public async getSheetState(id: string, worksheet: string): Promise<SheetState> {
|
||||
const ret: SheetState = {
|
||||
secret: false,
|
||||
auth: false,
|
||||
@@ -65,11 +65,10 @@ class sheet {
|
||||
if (!ret.auth) {
|
||||
return ret;
|
||||
}
|
||||
const settings = DataProvider.getSheet();
|
||||
if (settings.id != '') {
|
||||
if (id != '') {
|
||||
const spreadsheets = await sheets({ version: 'v4', auth: sheet.client })
|
||||
.spreadsheets.get({
|
||||
spreadsheetId: settings.id,
|
||||
spreadsheetId: id,
|
||||
includeGridData: false,
|
||||
})
|
||||
.catch((err) => {
|
||||
@@ -80,7 +79,7 @@ class sheet {
|
||||
}
|
||||
ret.id = true;
|
||||
ret.worksheetOptions = spreadsheets.data.sheets.map((i) => i.properties.title);
|
||||
if (ret.worksheetOptions.indexOf(settings.worksheet) < 0) {
|
||||
if (ret.worksheetOptions.indexOf(worksheet) < 0) {
|
||||
return ret;
|
||||
}
|
||||
ret.worksheet = true;
|
||||
@@ -118,8 +117,7 @@ class sheet {
|
||||
* push sheet
|
||||
* @throws
|
||||
*/
|
||||
public async push() {
|
||||
const { id, worksheet } = DataProvider.getSheet();
|
||||
public async push(id: string, worksheet: string) {
|
||||
const { worksheetId, range } = await this.exist(id, worksheet);
|
||||
|
||||
const rq = await sheets({ version: 'v4', auth: sheet.client }).spreadsheets.values.get({
|
||||
@@ -197,8 +195,7 @@ class sheet {
|
||||
* @returns {Promise<Partial<ResponseOK>>}
|
||||
* @throws
|
||||
*/
|
||||
public async pull(): Promise<Partial<ResponseOK>> {
|
||||
const { id, worksheet } = DataProvider.getSheet();
|
||||
public async pull(id: string, worksheet: string): Promise<Partial<ResponseOK>> {
|
||||
const { range } = await this.exist(id, worksheet);
|
||||
|
||||
const res: Partial<ResponseOK> = {};
|
||||
|
||||
@@ -5,7 +5,7 @@ import { OSCSettings } from './core/OscSettings.type.js';
|
||||
import { Settings } from './core/Settings.type.js';
|
||||
import { UserFields } from './core/UserFields.type.js';
|
||||
import { ViewSettings } from './core/Views.type.js';
|
||||
import { Sheet, HttpSettings } from '../index.js';
|
||||
import { HttpSettings } from '../index.js';
|
||||
|
||||
export type DatabaseModel = {
|
||||
rundown: OntimeRundown;
|
||||
@@ -14,7 +14,6 @@ export type DatabaseModel = {
|
||||
viewSettings: ViewSettings;
|
||||
aliases: Alias[];
|
||||
userFields: UserFields;
|
||||
sheet: Sheet;
|
||||
osc: OSCSettings;
|
||||
http: HttpSettings;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user