-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
168 lines (133 loc) · 4.28 KB
/
index.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
<!DOCTYPE html>
<html>
<head>
<title>Tide Power</title>
<!-- TODO: Export this to external file -->
<style media="screen">
#editor {
position: relative;
width: 80%;
height: 100%;
}
body {
margin: 0px
}
#sidebar {
background: #000;
}
.top {
position: absolute;
left: 0;
right: 0;
height: 20px;
}
.left {
position: absolute;
left: 0;
top: 20px;
bottom: 0;
width: 20%;
color: white;
}
.main {
position: absolute;
left: 20%;
top: 20px;
right: 0;
bottom: 0;
}
</style>
</head>
<body>
<div class="top" id="top-menu">
<button type="button" name="start" onclick="startTest()">Start</button>
<button type="button" name="upload">Upload</button>
<select class="" name="simulator">
<option value="simulate">Simulation</option>
<option value="tingbot">TingBot</option>
</select>
</div>
<div class="left" id="sidebar"></div>
<div class="main" id="editor">some text</div>
<!-- SCRIPTS -->
<script src="bower_components/ace-builds/src/ace.js" type="text/javascript" charset="utf-8"></script>
<script src="bower_components/ace-builds/src/theme-monokai.js" type="text/javascript" charset="utf-8"></script>
<script src="bower_components/ace-builds/src/mode-python.js" type="text/javascript" charset="utf-8"></script>
<script>
window.$ = window.jQuery = require('./bower_components/jquery/dist/jquery.min.js');
</script>
<script>
//TODO: Export this to external file
// Make contact with the rest of the app
const ipcRenderer = require('electron').ipcRenderer;
// Setup our editor
var editor = ace.edit("editor");
editor.setTheme("ace/theme/monokai");
var PythonMode = ace.require("ace/mode/python").Mode;
editor.session.setMode(new PythonMode());
editor.setShowPrintMargin(false);
// Ensures editor is the right size
$('#editor').height(window.innerHeight - $('#top-menu').height());
ipcRenderer.on('resize', function(event, newSize) {
$('#editor').height(window.innerHeight - $('#top-menu').height());
});
// Start implementing UI callbacks
function startTest() {
console.log("Clicked");
console.log(ipcRenderer.send('startTest'));
}
// Start Sidebar control
var holder = document.getElementById('sidebar');
holder.ondragover = function() {
return false;
};
holder.ondragleave = holder.ondragend = function() {
return false;
};
holder.ondrop = function(e) {
e.preventDefault();
var file = e.dataTransfer.files[0];
console.log(file);
console.log('File you dragged here is', file.path);
ipcRenderer.send("fileAdd", file);
return false;
};
// directory stuff
var fs = require('fs');
var current_app = require('temp').path()+".tingapp";
var ncp = require('ncp').ncp;
ncp.limit = 16;
function saveDir(source, destination,cb) {
ncp(source, destination, function(err) {
if (err) {
return console.error(err);
}
console.log(destination);
cb(destination);
});
}
//load specific .tingapp into the view
function loadTingapp(dir) {
//we need to get a look at the files in that folder
fs.readdir(dir, function(err, files) {
for (var i in files) {
if (err) throw err;
console.log(files[i]);
$('#sidebar').append("<dir class='treefile' data-path=" + dir + "/" + files[i] + ">" + files[i] + "</dir>");
}
$('.treefile').on('click', function() {
console.log($(this));
openFile($(this).data("path"));
});
});
}
function openFile(path) { //TODO: Check if image or something other than python
console.log("Opening" + path);
fs.readFile(path, function(err, data) {
editor.setValue(data.toString(), 1);
});
}
saveDir(__dirname + "/default.tingapp", current_app,loadTingapp);
</script>
</body>
</html>