-
Notifications
You must be signed in to change notification settings - Fork 0
/
openAndSave.js
40 lines (32 loc) · 1.2 KB
/
openAndSave.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
let downloadBtn = document.querySelector(".download");
let uploadBtn = document.querySelector(".upload");
//download task
downloadBtn.addEventListener("click", (e) => {
let jsonData = JSON.stringify([sheetDB, graphComponentMatrix]);
let file = new Blob([jsonData], { type: "application/json"});
let a = document.createElement("a");
a.href = URL.createObjectURL(file);
a.download = "SheetData.json";
a.click();
})
//upload task
uploadBtn.addEventListener("click", (e) => {
// opens file explorer
let input = document.createElement("input");
input.setAttribute("type", "file");
input.click();
input.addEventListener("change", (e) => {
let fr = new FileReader();
let fileObj = input.files[0];
fr.readAsText(fileObj);
fr.addEventListener("load", (e) => {
let readSheetData = JSON.parse(fr.result);
addSheetBtn.click();
sheetDB = readSheetData[0];
graphComponentMatrix = readSheetData[1];
collectedSheetDB[collectedSheetDB.length - 1] = sheetDB;
collectedGraphComponent[collectedGraphComponent - 1] = graphComponentMatrix;
handleSheetProperties();
})
})
})