157 lines
3.5 KiB
JavaScript
157 lines
3.5 KiB
JavaScript
$(document).ready(function () {
|
|
|
|
response = {};
|
|
|
|
response.show = function (action, msg, output) {
|
|
console.log("show issued" + action + msg);
|
|
|
|
html = "";
|
|
|
|
if (action == "test") {
|
|
|
|
} else {
|
|
if (msg.data.grade == "PASS") {
|
|
html = '<div class="alert alert-success" role="alert"><strong>Great!</strong> Your solution is correct.<br/></div>';
|
|
$("#continue").prop( "disabled", false);
|
|
} else if (msg.data.grade == "FAIL") {
|
|
html = '<div class="alert alert-danger" role="alert"><strong>Sorry!</strong> That is not correct.<br/></div>';
|
|
} else {
|
|
// assume test
|
|
//html = msg;
|
|
// a possible message that is generated yb the server to give tips?
|
|
}
|
|
}
|
|
|
|
|
|
console.log(output)
|
|
if ( output == "" ) {
|
|
output = " "
|
|
}
|
|
|
|
if ( output != false) {
|
|
console.log("output is not false")
|
|
$("#output-wrapper").show(500);
|
|
$("#output").html(output);
|
|
}
|
|
|
|
$("#response").hide().html(html).show(500);
|
|
|
|
|
|
$("#submit-test").prop( "disabled", false);
|
|
$("#submit-grade").prop( "disabled", false);
|
|
|
|
}
|
|
|
|
|
|
job = {}
|
|
job.submit = function (action) {
|
|
|
|
console.log("Test submission issued..");
|
|
console.log( $("#c-code").val() );
|
|
|
|
submission = {"solution": cEditor.getValue(), "action": action, "slide": window.data.slide};
|
|
submission_json = JSON.stringify(submission);
|
|
|
|
console.log(submission_json)
|
|
|
|
$.ajax({
|
|
method: "POST",
|
|
url: "/api/rest/job/new/",
|
|
contentType: 'application/json',
|
|
data: submission_json
|
|
})
|
|
.done(function( msg ) {
|
|
console.log("Job submitted: " + msg );
|
|
console.log(msg);
|
|
|
|
job_id = msg['id'];
|
|
|
|
$("#job-control").show(500);
|
|
setTimeout(function(){ job.status(action, job_id); }, 1000);
|
|
|
|
});
|
|
};
|
|
|
|
|
|
job_status_countdown = 5;
|
|
job_status_retries = 1;
|
|
job.status = function (action, job_id) {
|
|
|
|
console.log(action)
|
|
|
|
$("#collect-results-countdown").html("(retry in " + job_status_countdown +" s)");
|
|
|
|
if (job_status_countdown > 0) {
|
|
job_status_countdown--;
|
|
setTimeout(function(){ job.status(action, job_id); }, 1000);
|
|
return;
|
|
}
|
|
|
|
|
|
e = {"dummy": "dummy value"};
|
|
json_data = JSON.stringify(e);
|
|
|
|
$.ajax({
|
|
method: "GET",
|
|
url: "/api/rest/job/" + job_id + "/",
|
|
contentType: 'application/json',
|
|
})
|
|
.done(function( msg ) {
|
|
console.log("Status received: " + msg );
|
|
console.log(msg);
|
|
|
|
if ( msg.status == 'SUCCESS' ) {
|
|
$("#job-control").hide(500);
|
|
job_status_retries = 1;
|
|
response.show(action, msg, msg.data.output);
|
|
} else {
|
|
job_status_countdown = 5 * job_status_retries;
|
|
job_status_retries++;
|
|
//response.show(action, "processing...", false);
|
|
setTimeout(function(){ job.status(action, job_id); }, 1000);
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
$("#submit-test").click(function(event) {
|
|
$("#submit-test").prop( "disabled", true);
|
|
job.submit("test");
|
|
});
|
|
|
|
$("#submit-grade").click(function(event) {
|
|
$("#submit-grade").prop( "disabled", true);
|
|
job.submit("grade");
|
|
});
|
|
|
|
|
|
$("#exercise-choices a.list-group-item").click(function(event) {
|
|
event.preventDefault()
|
|
//$("#submit-test").prop( "disabled", true);
|
|
//job.submit("test");
|
|
|
|
|
|
target = event.target
|
|
|
|
|
|
if ( $(target).is('input') ) {
|
|
target = $(event.target).parent()[0]
|
|
} else {
|
|
// also check/uncheck when clicking surounding
|
|
}
|
|
|
|
//if ( $(target).children("input").attr('type') == 'radio' ) {
|
|
// $(target).parent().children(".list-group-item-success").removeClass("list-group-item-success");
|
|
//}
|
|
|
|
console.log(target)
|
|
$(target).children("input").each(function () { this.checked = !this.checked; console.log(this) });
|
|
//$(target).toggleClass("list-group-item-success");
|
|
|
|
});
|
|
|
|
});
|
|
|