diff --git a/js/main.js b/js/main.js index ea33433..cf03fb4 100644 --- a/js/main.js +++ b/js/main.js @@ -89,11 +89,11 @@ function retrievePacketList() { //console.log(config.exam_query_url); try { - if (config.exam_query_url != undefined) { - url = config.exam_query_url; - } + if (config.exam_query_url != undefined) { + url = config.exam_query_url; + } } catch (e) { - // + // } $.ajax({ @@ -272,7 +272,10 @@ async function loadExamList(data) { ); //question_db.saved_exams.where("eid").equals(saved_exam.eid).delete(); - question_db.question_data.where(["qid", "type"]).equals([q, saved_exam.exam_type]).delete(); + question_db.question_data + .where(["qid", "type"]) + .equals([q, saved_exam.exam_type]) + .delete(); } d = null; }) @@ -289,8 +292,10 @@ async function loadExamList(data) { ); //question_db.saved_exams.where("eid").equals(saved_exam.eid).delete(); - question_db.question_data.where(["qid", "type"]).equals([q, saved_exam.exam_type]).delete(); - + question_db.question_data + .where(["qid", "type"]) + .equals([q, saved_exam.exam_type]) + .delete(); }); } } @@ -298,15 +303,33 @@ async function loadExamList(data) { }); // Sort different lists - $('.packet-list.rapid div').sort(function(a,b) { - return a.dataset.eid > b.dataset.eid ? 1 : (a.dataset.eid < b.dataset.eid ? -1 : 0);; - }).appendTo('.packet-list.rapid'); - $('.packet-list.anatomy div').sort(function(a,b) { - return a.dataset.eid > b.dataset.eid ? 1 : (a.dataset.eid < b.dataset.eid ? -1 : 0);; - }).appendTo('.packet-list.anatomy'); - $('.packet-list.long div').sort(function(a,b) { - return a.dataset.eid > b.dataset.eid ? 1 : (a.dataset.eid < b.dataset.eid ? -1 : 0);; - }).appendTo('.packet-list.long'); + $(".packet-list.rapid div") + .sort(function (a, b) { + return a.dataset.eid > b.dataset.eid + ? 1 + : a.dataset.eid < b.dataset.eid + ? -1 + : 0; + }) + .appendTo(".packet-list.rapid"); + $(".packet-list.anatomy div") + .sort(function (a, b) { + return a.dataset.eid > b.dataset.eid + ? 1 + : a.dataset.eid < b.dataset.eid + ? -1 + : 0; + }) + .appendTo(".packet-list.anatomy"); + $(".packet-list.long div") + .sort(function (a, b) { + return a.dataset.eid > b.dataset.eid + ? 1 + : a.dataset.eid < b.dataset.eid + ? -1 + : 0; + }) + .appendTo(".packet-list.long"); $("#options-panel").show(); } @@ -497,28 +520,28 @@ function setUpPacket(data, path) { if (data.hasOwnProperty("exam_order")) { exam_details.question_order = data.exam_order; } else { - exam_details.question_order = []; - Object.keys(questions).forEach(function (e) { - exam_details.question_order.push(e); + exam_details.question_order = []; + Object.keys(questions).forEach(function (e) { + exam_details.question_order.push(e); - // Make sure answers are arrays - if (!Array.isArray(questions[e]["answers"])) { - questions[e]["answers"] = [questions[e]["answers"]]; - } - }); + // Make sure answers are arrays + if (!Array.isArray(questions[e]["answers"])) { + questions[e]["answers"] = [questions[e]["answers"]]; + } + }); - let randomise_order = true; - if (config.randomise_order != undefined) { - randomise_order = config.randomise_order; - } - if (randomise_order) { - exam_details.question_order = helper.shuffleArray( - exam_details.question_order - ); - } - // We add this here so the question order is maintained - // when loading from cache - data["exam_order"] = exam_details.question_order + let randomise_order = true; + if (config.randomise_order != undefined) { + randomise_order = config.randomise_order; + } + if (randomise_order) { + exam_details.question_order = helper.shuffleArray( + exam_details.question_order + ); + } + // We add this here so the question order is maintained + // when loading from cache + data["exam_order"] = exam_details.question_order; } if (data.hasOwnProperty("exam_time")) { @@ -541,7 +564,10 @@ function setUpPacket(data, path) { } // If question_requests is set we need to do a request for each question - if (data.hasOwnProperty("question_requests") && (Object.keys(data["question_requests"]).length > 0)) { + if ( + data.hasOwnProperty("question_requests") && + Object.keys(data["question_requests"]).length > 0 + ) { // Will happen if loading from cache //if (data["questions"] == "cached") { // let a = {}; @@ -564,12 +590,14 @@ function setUpPacket(data, path) { for (const n in data["question_requests"]) { question_number++; - let obj = {qid: n, type: question_type}; + let obj = { qid: n, type: question_type }; let question_in_db = await question_db.question_data.get(obj); // If the question is in the db we can load // invalid questions should have already been removed - if (question_in_db != undefined) {continue} + if (question_in_db != undefined) { + continue; + } const question_url = `${path}/${n}`; @@ -832,7 +860,6 @@ async function loadQuestion(n, section = 1, force_reload = false) { const question_data = return_data.data; return_data = null; - loaded_question = n; // Set up question navigation @@ -1236,12 +1263,12 @@ async function loadQuestion(n, section = 1, force_reload = false) { for (let qidn_count = 1; qidn_count < 6; qidn_count++) { let obj = { - aid: aid, - cid: cid, - eid: eid, - qid: qid, - qidn: qidn_count.toString(), - } + aid: aid, + cid: cid, + eid: eid, + qid: qid, + qidn: qidn_count.toString(), + }; db.answers .get(obj) .then(function (answer) { @@ -1614,12 +1641,14 @@ function reviewQuestions() { let incorrectcall_number = 0; exam_details.question_order.forEach(async function (qid, n) { const q_object = { qid: qid, type: question_type }; - let question = await question_db.question_data.get(q_object) + let question = await question_db.question_data.get(q_object); question = question.data; if (question_type == "long") { $("#review-answer-table").append( $( - `