-
Notifications
You must be signed in to change notification settings - Fork 0
/
data-helper.html
executable file
·72 lines (71 loc) · 1.95 KB
/
data-helper.html
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<!DOCTYPE html>
<html>
<head>
<title>Catalog data helper</title>
<script type="text/javascript">
console.log("Main frame loaded.");
fs = require('fs');
ioutils = require('ioutils');
Catalog = require('catalog');
catalog = null;
function log(msg) {
document.querySelector("#log").innerText += msg + "\n";
}
function loadFromLocal() {
catalog = Catalog.fromLocalStorage();
log("Loaded from local.");
}
function loadFromDir() {
catalog = Catalog.fromDirectory("data");
log("Loaded from directory.");
}
function loadFromJson() {
var obj = JSON.parse(fs.readFileSync(__dirname+'/data/courses.json'));
catalog = Catalog.fromStorage(new ioutils.json_io(obj));
log("Loaded from JSON file.");
}
function writeToLocal() {
catalog.save(localStorage);
log("Saved to local.");
}
function writeToDir() {
var io = new ioutils.fs_io('data');
catalog.save(io);
log("Saved to directory.");
}
function writeToJson() {
var io = new ioutils.json_io();
catalog.save(io);
fs.writeFileSync(__dirname+'/data/courses.json', JSON.stringify(io.data));
log("Saved to JSON file.");
}
function goback() {
location.assign("index.html");
}
console.log("Frame loaded.");
</script>
</head>
<body>
<h1>Catalog data migrator</h1>
<div id="controls">
<button onclick="loadFromLocal()">loadFromLocal</button>
<button onclick="loadFromDir()">loadFromDir</button>
<button onclick="loadFromJson()">loadFromJson</button>
<br />
<button onclick="writeToLocal()">writeToLocal</button>
<button onclick="writeToDir()">writeToDir</button>
<button onclick="writeToJson()">writeToJson</button>
<br />
<button onclick="goback()">Go Back</button>
</div>
<p id="log"></p>
<script type="text/javascript">
if (location.hash == "#autorestore") {
document.querySelector("#controls").style.display="none";
loadFromJson();
writeToLocal();
goback();
}
</script>
</body>
</html>