summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorprathamesh2017-08-14 22:33:02 +0530
committerprathamesh2017-08-14 22:33:02 +0530
commitf730a531cf041620209abb812792080cb2d63b4d (patch)
tree646f54719a76ca06d53da62d817678a4d023644c
parent49615e5a24ecfdd0b22bae080e7f9bb2507bbfd7 (diff)
downloadonline_test-f730a531cf041620209abb812792080cb2d63b4d.tar.gz
online_test-f730a531cf041620209abb812792080cb2d63b4d.tar.bz2
online_test-f730a531cf041620209abb812792080cb2d63b4d.zip
Changes related to front-end
Removed snippet append in the check view as snippet is not posted in request. Added an overlay when an user submits a code, with a status text on it. This is to block user from triggering any other event when JS is running. Overlay disappears when JS complete its execution. On time out a request is posted via JS, it receives a JSON response but cannot display user the error as time is over. So in such case, the django itself handles the result and does not return JSONv response.
-rw-r--r--yaksh/static/yaksh/css/ontop.css20
-rw-r--r--yaksh/static/yaksh/js/requesthandler.js44
-rw-r--r--yaksh/templates/base.html6
-rw-r--r--yaksh/views.py14
4 files changed, 75 insertions, 9 deletions
diff --git a/yaksh/static/yaksh/css/ontop.css b/yaksh/static/yaksh/css/ontop.css
new file mode 100644
index 0000000..fb22066
--- /dev/null
+++ b/yaksh/static/yaksh/css/ontop.css
@@ -0,0 +1,20 @@
+#ontop {
+ position: fixed;
+ display: none;
+ width: 100%;
+ height: 100%;
+ top:0;
+ bottom: 0;
+ left:0;
+ right: 0;
+ background-color: rgba(0,0,0,0.5);
+ z-index: 1001; /* 1001 coz sidebar is 1000. So will be on top of sidebar*/
+}
+
+#state {
+ position: absolute;
+ top: 50%;
+ left: 50%;
+ font-size: 30px;
+ color: white;
+}
diff --git a/yaksh/static/yaksh/js/requesthandler.js b/yaksh/static/yaksh/js/requesthandler.js
index b637928..d463434 100644
--- a/yaksh/static/yaksh/js/requesthandler.js
+++ b/yaksh/static/yaksh/js/requesthandler.js
@@ -8,13 +8,29 @@ function check_state(state, uid) {
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";
+ notify("You are requesting for a wrong data");
+ unlock_screen();
+ } else {
+ request_status = "initial";
+ unlock_screen();
}
}
+function notify(text) {
+ var $notice = document.getElementById("notification");
+ $notice.classList.add("alert");
+ $notice.classList.add("alert-success");
+ $notice.innerHTML = text;
+}
+
+function lock_screen() {
+ document.getElementById("ontop").style.display = "block";
+}
+
+function unlock_screen() {
+ document.getElementById("ontop").style.display = "none";
+}
+
function get_result(uid){
$.ajax({
method: "GET",
@@ -23,7 +39,7 @@ function get_result(uid){
success: function(data, status, xhr) {
content_type = xhr.getResponseHeader("content-type");
if(content_type.includes("text/html")) {
- request_status = "initial";
+ unlock_screen();
document.open();
document.write(data);
document.close();
@@ -31,7 +47,15 @@ function get_result(uid){
res = JSON.parse(data);
request_status = res.status;
check_state(request_status, uid);
+ } else {
+ request_status = "initial";
+ unlock_screen();
}
+ },
+ error: function(xhr, text_status, error_thrown ) {
+ request_status = "initial";
+ unlock_screen();
+ notify("There is some problem. Try later.")
}
});
}
@@ -72,6 +96,7 @@ $(document).ready(function(){
global_editor.editor.clearHistory();
}
$('#code').submit(function(e) {
+ lock_screen();
$.ajax({
type: 'POST',
url: $(this).attr("action"),
@@ -81,6 +106,7 @@ $(document).ready(function(){
content_type = xhr.getResponseHeader("content-type");
if(content_type.includes("text/html")) {
request_status = "initial"
+ unlock_screen();
document.open();
document.write(data);
document.close();
@@ -89,7 +115,15 @@ $(document).ready(function(){
var uid = res.uid;
request_status = res.state;
check_state(request_status, uid);
+ } else {
+ request_status = "initial";
+ unlock_screen();
}
+ },
+ error: function(xhr, text_status, error_thrown ) {
+ request_status = "initial";
+ unlock_screen();
+ notify("There is some problem. Try later.")
}
});
e.preventDefault(); // To stop the default form submission.
diff --git a/yaksh/templates/base.html b/yaksh/templates/base.html
index 35c6976..cbe396f 100644
--- a/yaksh/templates/base.html
+++ b/yaksh/templates/base.html
@@ -19,6 +19,7 @@
<link rel="stylesheet" href="{{ URL_ROOT }}/static/yaksh/css/theme.css" type="text/css" />
<link rel="stylesheet" href="{{ URL_ROOT }}/static/yaksh/css/sticky-footer.css" type="text/css" />
<link rel="stylesheet" href="{{ URL_ROOT }}/static/yaksh/css/dashboard.css" type="text/css" />
+ <link rel="stylesheet" href="{{ URL_ROOT }}/static/yaksh/css/ontop.css" type="text/css" />
{% block meta %}
@@ -36,6 +37,11 @@
</head>
<body {% block onload %} {% endblock %}>
+ <div id="ontop">
+ <div id="state">
+ Checking...
+ </div>
+ </div>
{% block nav %}
{% endblock %}
<div class="container">
diff --git a/yaksh/views.py b/yaksh/views.py
index 0e9835d..fc550ed 100644
--- a/yaksh/views.py
+++ b/yaksh/views.py
@@ -475,7 +475,6 @@ def check(request, q_id, attempt_num=None, questionpaper_id=None):
current_question = get_object_or_404(Question, pk=q_id)
if request.method == 'POST':
- snippet_code = request.POST.get('snippet')
# Add the answer submitted, regardless of it being correct or not.
if current_question.type == 'mcq':
user_answer = request.POST.get('answer')
@@ -532,8 +531,7 @@ def check(request, q_id, attempt_num=None, questionpaper_id=None):
next_q = paper.add_completed_question(current_question.id)
return show_question(request, next_q, paper)
else:
- user_code = request.POST.get('answer')
- user_answer = snippet_code + "\n" + user_code if snippet_code else user_code
+ user_answer = request.POST.get('answer')
if not user_answer:
msg = ["Please submit a valid option or code"]
return show_question(request, current_question, paper, notification=msg)
@@ -552,7 +550,15 @@ def check(request, q_id, attempt_num=None, questionpaper_id=None):
json_data, uid
)
if current_question.type in ['code', 'upload']:
- return JsonResponse(result)
+ if paper.time_left() <= 0:
+ url = 'http://localhost:%s' % SERVER_POOL_PORT
+ result = get_result(url, uid, block=True)
+ result = json.loads(result.get('result'))
+ next_question, error_message, paper = _update_paper(request, uid,
+ result)
+ return show_question(request, next_question, paper, error_message)
+ else:
+ return JsonResponse(result)
else:
next_question, error_message, paper = _update_paper(request, uid, result)
return show_question(request, next_question, paper, error_message)