Skip to content

Commit

Permalink
Load code by submission token.
Browse files Browse the repository at this point in the history
  • Loading branch information
hermanzdosilovic committed Sep 15, 2019
1 parent 963c76a commit 79426e1
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 22 deletions.
1 change: 1 addition & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ <h2>Judge0 IDE</h2>
<option value="41" mode="ruby">Ruby (2.1.9)</option>
<option value="42" mode="rust">Rust (1.20.0)</option>
<option value="43" mode="plaintext">Text (plain text)</option>
<option value="44" mode="plaintext">Executable</option>
</select>
</div>
<div class="item fitted borderless left-padding">
Expand Down
74 changes: 52 additions & 22 deletions js/ide.js
Original file line number Diff line number Diff line change
Expand Up @@ -246,26 +246,49 @@ function downloadSource() {
}

function loadSavedSource() {
$.ajax({
url: pbUrl + "/" + getIdFromURI() + ".json",
type: "GET",
success: function (data, textStatus, jqXHR) {
sourceEditor.setValue(decode(data["source_code"]));
$selectLanguage.dropdown("set selected", data["language_id"]);
stdinEditor.setValue(decode(data["stdin"]));
stdoutEditor.setValue(decode(data["stdout"]));
stderrEditor.setValue(decode(data["stderr"]));
compileOutputEditor.setValue(decode(data["compile_output"]));
sandboxMessageEditor.setValue(decode(data["sandbox_message"]));
$statusLine.html(decode(data["status_line"]));
changeEditorLanguage();
},
error: function (jqXHR, textStatus, errorThrown) {
showError("Not Found", "Code not found!");
window.history.replaceState(null, null, location.origin + location.pathname);
loadRandomLanguage();
}
});
snipped_id = getIdFromURI();

if (snipped_id.length == 36) {
$.ajax({
url: apiUrl + "/submissions/" + snipped_id + "?fields=source_code,language_id,stdin,stdout,stderr,compile_output,message,time,memory,status&base64_encoded=true",
type: "GET",
success: function(data, textStatus, jqXHR) {
sourceEditor.setValue(decode(data["source_code"]));
$selectLanguage.dropdown("set selected", data["language_id"]);
stdinEditor.setValue(decode(data["stdin"]));
stdoutEditor.setValue(decode(data["stdout"]));
stderrEditor.setValue(decode(data["stderr"]));
compileOutputEditor.setValue(decode(data["compile_output"]));
sandboxMessageEditor.setValue(decode(data["message"]));
var time = (data.time === null ? "-" : data.time + "s");
var memory = (data.memory === null ? "-" : data.memory + "KB");
$statusLine.html(`${data.status.description}, ${time}, ${memory}`);
changeEditorLanguage();
},
error: handleRunError
});
} else {
$.ajax({
url: pbUrl + "/" + snipped_id + ".json",
type: "GET",
success: function (data, textStatus, jqXHR) {
sourceEditor.setValue(decode(data["source_code"]));
$selectLanguage.dropdown("set selected", data["language_id"]);
stdinEditor.setValue(decode(data["stdin"]));
stdoutEditor.setValue(decode(data["stdout"]));
stderrEditor.setValue(decode(data["stderr"]));
compileOutputEditor.setValue(decode(data["compile_output"]));
sandboxMessageEditor.setValue(decode(data["sandbox_message"]));
$statusLine.html(decode(data["status_line"]));
changeEditorLanguage();
},
error: function (jqXHR, textStatus, errorThrown) {
showError("Not Found", "Code not found!");
window.history.replaceState(null, null, location.origin + location.pathname);
loadRandomLanguage();
}
});
}
}

function run() {
Expand Down Expand Up @@ -607,6 +630,11 @@ fn main() {\n\

var textSource = "hello, world\n";

var executableSource = "\
#!/bin/bash\n\
echo \"hello, world\"\n\
";

var sources = {
1: bashSource,
2: bashSource,
Expand Down Expand Up @@ -650,7 +678,8 @@ var sources = {
40: rubySource,
41: rubySource,
42: rustSource,
43: textSource
43: textSource,
44: executableSource,
};

var fileNames = {
Expand Down Expand Up @@ -696,5 +725,6 @@ var fileNames = {
40: "main.rb",
41: "main.rb",
42: "main.rs",
43: "source.txt"
43: "source.txt",
44: "a.out"
};

0 comments on commit 79426e1

Please sign in to comment.