From 49615e5a24ecfdd0b22bae080e7f9bb2507bbfd7 Mon Sep 17 00:00:00 2001 From: prathamesh Date: Mon, 14 Aug 2017 14:51:39 +0530 Subject: To handle unknown status response from code server --- yaksh/static/yaksh/js/requesthandler.js | 15 +++++++++++---- yaksh/templates/yaksh/question.html | 7 +++++-- yaksh/views.py | 7 ++++--- 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/yaksh/static/yaksh/js/requesthandler.js b/yaksh/static/yaksh/js/requesthandler.js index 9d023cc..b637928 100644 --- a/yaksh/static/yaksh/js/requesthandler.js +++ b/yaksh/static/yaksh/js/requesthandler.js @@ -3,9 +3,15 @@ function submitRequest(){ document.forms["code"].submit(); } -function check_state(state, uid, success) { - if (state == "running") { +function check_state(state, uid) { + if (state == "running" || state == "not started") { setTimeout(get_result(uid), 2000); + } else if (state == "unknown") { + request_status = "initial"; + var $notice = document.getElementById("notification"); + $notice.classList.add("alert"); + $notice.classList.add("alert-success"); + $notice.innerHTML = "Your are requesting for a wrong data"; } } @@ -24,7 +30,7 @@ function get_result(uid){ } else if(content_type.includes("application/json")) { res = JSON.parse(data); request_status = res.status; - check_state(request_status, uid, res.success); + check_state(request_status, uid); } } }); @@ -74,6 +80,7 @@ $(document).ready(function(){ success: function(data, status, xhr) { content_type = xhr.getResponseHeader("content-type"); if(content_type.includes("text/html")) { + request_status = "initial" document.open(); document.write(data); document.close(); @@ -81,7 +88,7 @@ $(document).ready(function(){ res = JSON.parse(data); var uid = res.uid; request_status = res.state; - check_state(request_status, uid, false); + check_state(request_status, uid); } } }); diff --git a/yaksh/templates/yaksh/question.html b/yaksh/templates/yaksh/question.html index 9df2fef..9789d25 100644 --- a/yaksh/templates/yaksh/question.html +++ b/yaksh/templates/yaksh/question.html @@ -101,14 +101,17 @@ lang = "{{ question.language }}"

{% if notification %} {% if question.type == "code" %} -