-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSidebar.html
More file actions
269 lines (229 loc) · 8.2 KB
/
Copy pathSidebar.html
File metadata and controls
269 lines (229 loc) · 8.2 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
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
<!DOCTYPE html>
<html>
<head>
<base target="_top">
<link rel="stylesheet" href="https://ssl.gstatic.com/docs/script/css/add-ons1.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/1.4.6/socket.io.min.js"></script>
<!-- The CSS package above applies Google styling to buttons and other elements. -->
<style>
.branding-below {
bottom: 56px;
top: 0;
}
.branding-text {
left: 7px;
position: relative;
top: 3px;
}
.col-contain {
overflow: hidden;
}
.col-one {
float: left;
width: 50%;
}
.logo {
vertical-align: middle;
}
.radio-spacer {
height: 20px;
}
.width-100 {
width: 100%;
}
body {
background-color: #34352E
}
.terminals {
color: #fff;
}
.terminals textarea {
background-color: #34352E;
color: #fff;
}
</style>
</head>
<body>
<div class="sidebar branding-below">
<div>
<select id="language">
<option value="JavaScript">JavaScript</option>
<option value="Java">Java</option>
<option value="R">R</option>
<option value="Python2">Python 2</option>
<option value="Python3">Python 3</option>
<option value="Ruby">Ruby</option>
</select>
<button id="run">Run</button>
</div>
<div class="terminals block form-group">
<label><b>Terminal</b></label>
<textarea class="width-100" id="terminal-text" rows="10" readonly></textarea>
<label><b>Errors</b></label>
<textarea class="width-100" id="errors-text" rows="10" readonly></textarea>
</div>
</div>
<!--
<div class="sidebar bottom">
<img alt="Add-on logo" class="logo" src="https://googledrive.com/host/0B0G1UdyJGrY6XzdjQWF4a1JYY1k/translate-logo-small.png" width="27" height="27">
<span class="gray branding-text">Translate sample by Google</span>
</div>-->
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js">
</script>
<script>
var URL_SERVER = 'https://159.203.247.240:4000';
var socket = io.connect(URL_SERVER);
var javaClass;
/**
* On document load, assign click handlers to each button and try to load the
* user's origin and destination language preferences if previously set.
*/
$(function() {
var language;
$('#run').click(function(){
var languageSelect = document.getElementById('language');
var language = languageSelect.options[languageSelect.selectedIndex].value;
google.script.run
.withSuccessHandler(function(text) {
$("#terminal-text").text("");
$("#errors-text").text("");
if( language == 'Java' ) {
javaClass = prompt("What class's main are you running?", javaClass);
socket.emit('compile', {id:docid, language:language, input:text, javaClass:javaClass});
/*
google.script.run
.withSuccessHandler(function(data){
if (data != -1){
var javaClass = data;
socket.emit('compile', {id:docid, language:language, input:text, javaClass:javaClass});
}
})
.withFailureHandler(function(err) {
console.log(new Error(err));
})
.askJavaClass();
*/
}else{
socket.emit('compile', {id:docid, language:language, input:text});
}
/*$.ajax({
type: "POST",
url: "159.203.247.240:3000/run",
data: {
language: language,
input: text,
id: docid
},
success: function(data) {
}
})//*/
})
.withFailureHandler(function(err) {
console.error(new Error(err));
})
.getDocumentText();
});
$('#language').on('change', function() {
var languageSelect = document.getElementById('language');
language = languageSelect.options[languageSelect.selectedIndex].value;
})
google.script.run.withSuccessHandler(loadPreferences)
.withFailureHandler(showError).getPreferences();
setInterval(function(){
google.script.run.everySecond(language);
}, 1000)
var docid;
google.script.run.withSuccessHandler(function(id) {
socket.on(id, function(data){
if (data.type == "stdout") {
$("#terminal-text").append(data.body);
} else {
$("#errors-text").append(data.body);
}
console.log(data);
});
console.log('now listening!');
console.log(id);
docid = id;
}).getDocId();
/*
var doPoll = function() {
$.get('https://159.203.247.240:3000/out/' + docid + '.out', function(data) {
$('#terminal-text').text(data);
setTimeout(doPoll,5000);
});
}
doPoll();*/
});
/**
* Callback function that populates the origin and destination selection
* boxes with user preferences from the server.
*
* @param {Object} languagePrefs The saved origin and destination languages.
*/
function loadPreferences(languagePrefs) {
$('input:radio[name="origin"]')
.filter('[value=' + languagePrefs.originLang + ']')
.attr('checked', true);
$('input:radio[name="dest"]')
.filter('[value=' + languagePrefs.destLang + ']')
.attr('checked', true);
}
/**
* Runs a server-side function to translate the user-selected text and update
* the sidebar UI with the resulting translation.
*/
function runTranslation() {
this.disabled = true;
$('#error').remove();
var origin = $('input[name=origin]:checked').val();
var dest = $('input[name=dest]:checked').val();
var savePrefs = $('#save-prefs').is(':checked');
google.script.run
.withSuccessHandler(
function(translatedText, element) {
$('#translated-text').val(translatedText);
element.disabled = false;
})
.withFailureHandler(
function(msg, element) {
showError(msg, $('#button-bar'));
element.disabled = false;
})
.withUserObject(this)
.runTranslation(origin, dest, savePrefs);
}
/**
* Runs a server-side function to insert the translated text into the document
* at the user's cursor or selection.
*/
function insertText() {
this.disabled = true;
$('#error').remove();
google.script.run
.withSuccessHandler(
function(returnSuccess, element) {
element.disabled = false;
})
.withFailureHandler(
function(msg, element) {
showError(msg, $('#button-bar'));
element.disabled = false;
})
.withUserObject(this)
.insertText($('#translated-text').val());
}
/**
* Inserts a div that contains an error message after a given element.
*
* @param msg The error message to display.
* @param element The element after which to display the error.
*/
function showError(msg, element) {
var div = $('<div id="error" class="error">' + msg + '</div>');
$(element).after(div);
}
//doPoll();
</script>
</body>
</html>