Merge branch 'master' of ssh://161.35.163.87:/home/django/rts
This commit is contained in:
+28
-1
@@ -1,3 +1,4 @@
|
|||||||
|
import * as helper from "./helpers.js";
|
||||||
/**
|
/**
|
||||||
* Submits answers
|
* Submits answers
|
||||||
*/
|
*/
|
||||||
@@ -67,7 +68,7 @@ export function postAnswers(ans) {
|
|||||||
alert(`${data.question_count} answers sucessfully submitted.`);
|
alert(`${data.question_count} answers sucessfully submitted.`);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
submissionError(data, ans);
|
submissionError(data, ans);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.fail((e) => {
|
.fail((e) => {
|
||||||
@@ -108,3 +109,29 @@ function submissionError(data, ans) {
|
|||||||
"z-index": 5000,
|
"z-index": 5000,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function getQuestion(url, question_number, question_total) {
|
||||||
|
console.log("Downloading question ", url, question_number, question_total);
|
||||||
|
return $.ajax({
|
||||||
|
dataType: "json",
|
||||||
|
url: url,
|
||||||
|
progress: function (e) {
|
||||||
|
$("#progress").html(
|
||||||
|
`Downloading question [${question_number}/${question_total}]<br/>This file is compressed (no size available)`)
|
||||||
|
if (e.lengthComputable) {
|
||||||
|
var completedPercentage = Math.round((e.loaded * 100) / e.total);
|
||||||
|
|
||||||
|
$("#progress").html(
|
||||||
|
`Downloading question [${question_number}/${question_total}]<br/>${completedPercentage}%<br/>${helper.formatBytes(
|
||||||
|
e.total
|
||||||
|
)}`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
//success: function (data) {
|
||||||
|
// strReturn = data;
|
||||||
|
//},
|
||||||
|
//async: false,
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|||||||
+69
-16
@@ -53,13 +53,18 @@ function retrievePacketList() {
|
|||||||
url = window.config.exam_query_url;
|
url = window.config.exam_query_url;
|
||||||
}
|
}
|
||||||
|
|
||||||
$.ajax({dataType: "json", cache: false, url: url, success : function (data) {
|
$.ajax({
|
||||||
if (data.hasOwnProperty("exams")) {
|
dataType: "json",
|
||||||
loadExamList(data);
|
cache: false,
|
||||||
} else {
|
url: url,
|
||||||
loadPacketList(data);
|
success: function (data) {
|
||||||
}
|
if (data.hasOwnProperty("exams")) {
|
||||||
},})
|
loadExamList(data);
|
||||||
|
} else {
|
||||||
|
loadPacketList(data);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
})
|
||||||
.done(function () {})
|
.done(function () {})
|
||||||
.fail(function () {
|
.fail(function () {
|
||||||
$.getJSON("packets/packets.json", function (data) {
|
$.getJSON("packets/packets.json", function (data) {
|
||||||
@@ -133,12 +138,14 @@ async function loadExamList(data) {
|
|||||||
if ($(`#packet-list .${exam.type}`).length) {
|
if ($(`#packet-list .${exam.type}`).length) {
|
||||||
list = $(`#packet-list .${exam.type}`);
|
list = $(`#packet-list .${exam.type}`);
|
||||||
} else {
|
} else {
|
||||||
list = $("#packet-list").append(`<div class='packet-list ${exam.type}'><span class='packet-list-title'>${exam.type}</span><br/></div>`);
|
list = $("#packet-list").append(
|
||||||
|
`<div class='packet-list ${exam.type}'><span class='packet-list-title'>${exam.type}</span><br/></div>`
|
||||||
|
);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
list = $("#packet-list");
|
list = $("#packet-list");
|
||||||
}
|
}
|
||||||
|
|
||||||
list.append(
|
list.append(
|
||||||
$(`<div class='packet-button${c}' title='Load packet'></div>`)
|
$(`<div class='packet-button${c}' title='Load packet'></div>`)
|
||||||
.text(name)
|
.text(name)
|
||||||
@@ -204,7 +211,9 @@ async function loadPacketList(data) {
|
|||||||
if ($(`#packet-list .${packet.type}`)) {
|
if ($(`#packet-list .${packet.type}`)) {
|
||||||
list = $(`#packet-list .${packet.type}`);
|
list = $(`#packet-list .${packet.type}`);
|
||||||
} else {
|
} else {
|
||||||
list = $(`<div class='packet-list ${packet.type}'>${packet.type}<br/></div>`);
|
list = $(
|
||||||
|
`<div class='packet-list ${packet.type}'>${packet.type}<br/></div>`
|
||||||
|
);
|
||||||
$("#packet-list").append(list);
|
$("#packet-list").append(list);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -250,6 +259,7 @@ function loadPacketFromAjax(path) {
|
|||||||
url: path,
|
url: path,
|
||||||
progress: function (e) {
|
progress: function (e) {
|
||||||
if (e.lengthComputable) {
|
if (e.lengthComputable) {
|
||||||
|
console.log("1")
|
||||||
var completedPercentage = Math.round((e.loaded * 100) / e.total);
|
var completedPercentage = Math.round((e.loaded * 100) / e.total);
|
||||||
|
|
||||||
$("#progress").html(
|
$("#progress").html(
|
||||||
@@ -259,7 +269,8 @@ function loadPacketFromAjax(path) {
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
.done(function (data) {
|
.done(function (data) {
|
||||||
setUpPacket(data, path.split("/").pop());
|
//setUpPacket(data, path.split("/").pop());
|
||||||
|
setUpPacket(data, path);
|
||||||
$("#options-panel").hide();
|
$("#options-panel").hide();
|
||||||
})
|
})
|
||||||
.fail(function () {
|
.fail(function () {
|
||||||
@@ -393,7 +404,8 @@ window.db = db;
|
|||||||
* Will then call setUpQuestions() to load the packet
|
* Will then call setUpQuestions() to load the packet
|
||||||
* @param {JSON} data
|
* @param {JSON} data
|
||||||
*/
|
*/
|
||||||
function setUpPacket(data, packet_name) {
|
function setUpPacket(data, path) {
|
||||||
|
let packet_name = path;
|
||||||
// Load the exam name from the json packet (if it exists)
|
// Load the exam name from the json packet (if it exists)
|
||||||
if (data.hasOwnProperty("exam_name")) {
|
if (data.hasOwnProperty("exam_name")) {
|
||||||
packet_name = data.exam_name;
|
packet_name = data.exam_name;
|
||||||
@@ -427,6 +439,44 @@ function setUpPacket(data, packet_name) {
|
|||||||
window.exam_time = data.exam_time;
|
window.exam_time = data.exam_time;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If the question_requests is set we need to do a request for each question
|
||||||
|
if (data.hasOwnProperty("question_requests") && data["question_requests"]) {
|
||||||
|
|
||||||
|
const question_total = Object.keys(data["questions"]).length;
|
||||||
|
let question_number = 0;
|
||||||
|
|
||||||
|
var requests = [];
|
||||||
|
var request_numbers = [];
|
||||||
|
|
||||||
|
// For loop to generate requests
|
||||||
|
(async () => {
|
||||||
|
for (const n in data["questions"]) {
|
||||||
|
const question_url = `${path}/${n}`;
|
||||||
|
question_number++;
|
||||||
|
|
||||||
|
console.log("Creating ", question_url, question_number, question_total);
|
||||||
|
//$("#progress").html(`Downloading [${question_number}/${question_total}]`);
|
||||||
|
const question_json = await interact.getQuestion(
|
||||||
|
question_url,
|
||||||
|
question_number,
|
||||||
|
question_total
|
||||||
|
);
|
||||||
|
|
||||||
|
//requests.push(request)
|
||||||
|
//request_numbers.push(n)
|
||||||
|
data["questions"][n] = question_json;
|
||||||
|
}
|
||||||
|
// Once all questions have been downloaded we carry on loading
|
||||||
|
loadSession();
|
||||||
|
})()
|
||||||
|
|
||||||
|
} else {
|
||||||
|
// Just carry on loading
|
||||||
|
loadSession();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function loadSession() {
|
||||||
// Either continue session or create a new one
|
// Either continue session or create a new one
|
||||||
db.session
|
db.session
|
||||||
// .where("status")
|
// .where("status")
|
||||||
@@ -611,10 +661,13 @@ function loadQuestion(n, section = 1, force_reload = false) {
|
|||||||
image = image[0]; // Do we want the middle image?
|
image = image[0]; // Do we want the middle image?
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let caption = "...";
|
||||||
|
if (current_question.image_titles != undefined) {
|
||||||
|
caption = current_question.image_titles[id];
|
||||||
|
}
|
||||||
|
|
||||||
thumbnails.append(
|
thumbnails.append(
|
||||||
'<div class="figure" id="figure-' +
|
`<div class="figure" id="figure-${id}"><div class="figcaption">${caption}</div></div>`
|
||||||
id +
|
|
||||||
'"><div class="figcaption">...</div></div>'
|
|
||||||
);
|
);
|
||||||
|
|
||||||
// const thumbnail = $(".figure .thumbnail").get(id);
|
// const thumbnail = $(".figure .thumbnail").get(id);
|
||||||
@@ -1930,7 +1983,7 @@ $(document).ajaxStart(function () {
|
|||||||
$("#loading").show();
|
$("#loading").show();
|
||||||
});
|
});
|
||||||
|
|
||||||
$(document).ajaxComplete(function () {
|
$(document).ajaxStop(function () {
|
||||||
$("#loading").hide();
|
$("#loading").hide();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user