-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
287 lines (254 loc) · 10.2 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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
<!DOCTYPE html>
<html>
<head>
<link rel='stylesheet' href='styles.css' Content-Type='text/css'>
<script type="text/javascript" src="http://platform.linkedin.com/in.js">
api_key: 868 tt52riovazz
onLoad: onLinkedInLoad
authorize: true
</script>
<script type="text/javascript">
var LOGGEDIN = false ;
function onLinkedInLoad() {
IN.Event.on(IN, "auth", onLinkedInAuth);
}
function onLinkedInAuth() {
if ( LOGGEDIN ) {
return ;
}
IN.API.Profile("me").fields("first-name", "last-name", "email-address", "public-profile-url", "id").result(function(data) {
//console.log(JSON.stringify(data));
var fields = data.values["0"];
var login = new XMLHttpRequest();
login.open('POST', '/login', true);
login.send(JSON.stringify(fields));
var id = fields.id;
document.getElementById('identification').innerHTML = id;
document.getElementById('login_screen').style.display = 'none';
var mkdir = new XMLHttpRequest();
mkdir.open('POST', '/mkdir', true);
mkdir.send(id);
open_file ("/run.tcl", id);
LOGGEDIN = true ;
}).error(function(data) {
console.log(data);
});
//Create/Open User's Directory Here
}
</script>
</head>
<title>Guna, by Paripath</title>
<body>
<p id='identification' style='display: none'></p>
<div id="login_screen">
<div id="login_button">
<script type="in/Login"></script>
</div>
</div>
<div id='sidenav'>
<center>
<a href="http://www.paripath.com/" target=_blank>
<img src="logo.jpg" style="width: 80px; height: 80px;" alt="paripath.com">
</a>
<hr id='break' />
<div id='icons'>
<button id='run-button'></button>
<button id='save-button'></button>
<button id='exit-button' onclick="window.location.href='http://www.paripath.com'"></button>
</div>
<hr id='break' />
</center>
<!--INSERT BUTTONS HERE-->
</div>
<textarea id='current-file' name='file-name' readonly></textarea>
<div id="workspace">
<textarea id='editor' name='content' class='content'></textarea>
<div id="workspace_separator"></div>
<pre><textarea readonly id='terminal'>
Guna Explorer (Community Edition), v55.18. (c) Paripath Inc.
------------------------------------------------------------
To characterize available cells/IPs:
1. Open run.tcl.
2. Add, Delete available cells.
3. Click Run.
4. See your results in main.lib.
</textarea></pre>
</div>
</body>
<script>
//changes title of current-file header to filename and changes content of editor to contents of filename
function open_file(filename, id) {
document.getElementById('current-file').value = filename;
var file = 'client/' + id + filename;
httpGetAsync(file,
function(text) {
document.getElementById('editor').value = text;
}
);
}
/*Handling directory click*/
var id;
var dropdown = document.getElementsByClassName('dir');
for (var i = 0; i < dropdown.length; i++) {
dropdown[i].addEventListener('click', function() {
var this_ddc = this.nextElementSibling;
if (this_ddc == null) {
document.getElementById('editor').value = 'NO CONTENT HERE';
} else {
if (this_ddc.style.display === 'block') {
this.classList.remove('active');
this_ddc.style.display = 'none';
} else {
var dropdown = document.getElementsByClassName('dir');
for (var j = 0; j < dropdown.length; j++) {
dropdown[j].classList.remove('active');
var ind_ddc = dropdown[j].nextElementSibling;
if (ind_ddc != null) {
ind_ddc.style.display = 'none';
}
}
this.classList.toggle('active');
this_ddc.style.display = 'block';
}
}
});
}
/*handling file click*/
var file = document.getElementsByClassName('file');
for (var i = 0; i < file.length; i++) {
file[i].addEventListener('click',
function() {
var name = this.name;
save(
function() {
id = document.getElementById('identification').innerHTML;
document.getElementById('current-file').value = name;
var file = name.substr(0,1)=="/"?'client/' + id + name:'client/' + id + "/" + name;
httpGetAsync(file,
function(text) {
document.getElementById('editor').value = text;
}
);
}
);
}
);
}
//Adding event listener to save button that calls function save
document.getElementById('save-button').addEventListener('click', function() {
save(function() {
return;
});
});
//Sends get request to server with parameters of file name and content
// Only saves .tcl and .cfg files on the server.
function save(callback) {
var currentfile = document.getElementById('current-file').value.substr(0,1)=="/"?document.getElementById('identification').innerHTML + document.getElementById('current-file').value:document.getElementById('identification').innerHTML + "/" + document.getElementById('current-file').value;
var fext = currentfile.slice((currentfile.lastIndexOf(".") - 1 >>> 0) + 2);
if (currentfile != "" && (fext == 'cfg' || fext == 'tcl')) {
var content = document.getElementById('editor').value;
if ( content != "" ) {
var http = new XMLHttpRequest();
http.open('POST', '/save', true);
http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
var params = currentfile;
params += "&" + content;
http.send(params);
}
}
callback();
}
document.getElementById('exit-button').addEventListener('click', function() {
alert("Thank you for using Guna Explorer!");
});
var exited = false;
function exit_callback(text) {
if (exited == false) {
document.write(text);
alert("Thank you for using Guna Explorer!");
exited = true;
}
}
document.getElementById('run-button').addEventListener('click', function() {
save(function() {
id = document.getElementById('identification').innerHTML;
httpGetAsync('/run/' + id, update);
alert("Running characterization on the server(s).");
});
});
var DISABLED = false;
function update(text) {
var id = document.getElementById('identification').innerHTML;
var terminal = document.getElementById('terminal');
terminal.value = text;
if (text.includes("ENDOFFILE") == true) {
if (DISABLED) {
document.getElementById('editor').style.cursor = "auto";
document.getElementById('terminal').style.cursor = "auto";
document.getElementById('run-button').style.cursor = "auto";
document.getElementById('run-button').disabled = false;
document.getElementById('save-button').style.cursor = "auto";
document.getElementById('save-button').disabled = false;
document.getElementById('exit-button').style.cursor = "auto";
document.getElementById('exit-button').disabled = false;
document.getElementById("editor").disabled = false;
var dropdown = document.getElementsByClassName('dir');
for (var i = 0; i < dropdown.length; i++) {
dropdown[i].style.cursor = "auto";
dropdown[i].disabled = false;
}
var file = document.getElementsByClassName('file');
for (var i = 0; i < file.length; i++) {
file[i].style.cursor = "auto";
file[i].disabled = false;
}
DISABLED = false;
console.log("IS DISABLED: " + DISABLED);
}
open_file("/main.lib", id);
terminal.value = text.replace("ENDOFFILE", "");
} else {
if (!DISABLED) {
document.getElementById('editor').style.cursor = "wait";
document.getElementById('terminal').style.cursor = "wait";
document.getElementById('run-button').style.cursor = "wait";
document.getElementById('run-button').disabled = true;
document.getElementById('save-button').style.cursor = "wait";
document.getElementById('save-button').disabled = true;
document.getElementById('exit-button').style.cursor = "wait";
document.getElementById('exit-button').disabled = true;
document.getElementById("editor").disabled = true;
var dropdown = document.getElementsByClassName('dir');
for (var i = 0; i < dropdown.length; i++) {
dropdown[i].style.cursor = "wait";
dropdown[i].disabled = true;
}
var file = document.getElementsByClassName('file');
for (var i = 0; i < file.length; i++) {
file[i].style.cursor = "wait";
file[i].disabled = true;
}
DISABLED = true;
console.log("IS DISABLED: " + DISABLED);
}
}
}
//This function slows everything down
function httpGetAsync(theUrl, callback) {
console.log(' httpGet: ' + theUrl);
var xmlHttp = new XMLHttpRequest();
xmlHttp.onreadystatechange = function() {
console.log ('httpStateChange: ' + theUrl + "readyState: " + xmlHttp.readyState);
//Things slow down here
if ((xmlHttp.readyState == 4 || xmlHttp.readyState == 3) && xmlHttp.status == 200) {
callback(xmlHttp.responseText);
} else {
//console.log("readyState: " + xmlHttp.readyState);
//console.log("status: " + xmlHttp.status);
}
}
xmlHttp.open("GET", theUrl, true); // true --> asynchronous
xmlHttp.send(null);
}
</script>
</html>