-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathopenSave.js
50 lines (36 loc) · 1.42 KB
/
openSave.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
41
42
43
44
45
46
47
48
49
50
let downloadBtn = document.querySelector(".download");
let uploadBtn = document.querySelector(".upload");
// download
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
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 sheetData = JSON.parse(fr.result);
// basic sheet with default data will be created
addSheetBtn.click();
// sheetDB, graphComponent
sheetDB = sheetData[0];
graphComponentMatrix = sheetData[1];
// override default data
collectedSheetDB[collectedSheetDB.length-1] = sheetDB
collectedGraphComponent[collectedGraphComponent.length-1] = graphComponentMatrix;
// UI (AFTER the data has been changed)
handleSheetProperties();
})
})
})