You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
WebCAD/src/Add-on/LoadConfig.ts

57 lines
1.8 KiB

import { IndexedDbStore, StoreName } from "../IndexedDb/IndexedDbStore";
import { BoardModalType } from "../UI/Components/Board/BoardModal";
import { Command } from "../Editor/CommandMachine";
import { FileSystem } from "../Common/FileSystem";
import { HotCMD } from "../Hot/HotCommand";
@HotCMD
export class DownLoadDrillConfig implements Command
{
async exec()
{
let dbstore = await IndexedDbStore.CADStore();
let configs = await dbstore.Get(StoreName.ConfigData, BoardModalType.Dr);
if (configs)
{
let data = {};
for (let [k, v] of configs)
{
let obj = {};
for (let [k1, v1] of v.ruleMap)
{
obj[k1] = v1;
}
data[k] = { ruleMap: obj };
}
FileSystem.writeFile("drillconfig.json", JSON.stringify(data));
}
}
}
export class UpLoadDrillConfig implements Command
{
async exec()
{
let dbstore = await IndexedDbStore.CADStore();
FileSystem.chooseFile(async files =>
{
if (files.length === 1)
{
let f = files[0];
let fileData = JSON.parse(await FileSystem.readFileAsText(f));
let config = new Map();
for (let key in fileData)
{
let v = fileData[key];
let rule = new Map();
for (let k1 in v.ruleMap)
{
rule.set(k1, v.ruleMap[k1]);
}
config.set(key, { ruleMap: rule });
}
await dbstore.Put(StoreName.ConfigData, BoardModalType.Dr, config);
}
}, ".json", false);
}
}