-
Notifications
You must be signed in to change notification settings - Fork 0
/
uploadFiles.js
44 lines (35 loc) · 1.33 KB
/
uploadFiles.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
let downloadBtn = document.querySelector(".download");
let openBtn = document.querySelector(".open");
// 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();
})
// Open task (upload)
openBtn.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 files = input.files;
let fileObj = files[0];
fr.readAsText(fileObj);
fr.addEventListener("load", (e) => {
let readSheetData = JSON.parse(fr.result);
// Basic sheet with default data will be created
addSheetBtn.click();
// SheetDB, graphComponent
sheetDB = readSheetData[0];
graphComponentMatrix = readSheetData[1];
collectedSheetDB[collectedSheetDB.length-1] = sheetDB;
collectedGraphComponent[collectedGraphComponent.length-1] = graphComponentMatrix;
handleSheetProperties();
})
})
})