-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathindex.js
More file actions
46 lines (37 loc) · 1.41 KB
/
index.js
File metadata and controls
46 lines (37 loc) · 1.41 KB
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
import "babel-polyfill";
import firebase from "firebase/app";
import "firebase/firestore";
const addData = require("./resources/js/addData");
const logger = require("./resources/js/log");
const checkConfig = require("./resources/js/config").checkConfig
let dataJson;
let configJson;
document.getElementById("data").addEventListener("change", function () {
let fr = new FileReader();
fr.onload = (e) => {
dataJson = JSON.parse(e.target.result);
}
fr.readAsText(this.files[0]);
}, false);
document.getElementById("config").addEventListener("change", function () {
let fr = new FileReader();
fr.onload = (e) => {
configJson = JSON.parse(e.target.result);
}
fr.readAsText(this.files[0]);
}, false);
document.getElementById("add").addEventListener("click", () => {
let checkConfigResult = checkConfig(configJson);
if (checkConfigResult.status === "ERROR") return logger.send(checkConfigResult);
firebase.initializeApp(configJson);
const db = firebase.firestore();
if (window.location.hostname === "localhost" && document.getElementById("local").checked) {
db.settings({
host: "localhost:8080",
ssl: false
});
}
let checkCollections = addData.checkCollections(dataJson, "");
if (checkCollections.status === "ERROR") return logger.send(checkCollections);
addData.parseCollection(dataJson.collection, "", db);
});