.
This commit is contained in:
+22
-27
@@ -25,7 +25,7 @@ let exam_time = null;
|
|||||||
let packet_time = null;
|
let packet_time = null;
|
||||||
let date_started = null;
|
let date_started = null;
|
||||||
let score = 0;
|
let score = 0;
|
||||||
let packet_generated = null;
|
let packet_json_id = null;
|
||||||
|
|
||||||
let allow_self_marking = true;
|
let allow_self_marking = true;
|
||||||
|
|
||||||
@@ -69,7 +69,7 @@ db.version(1).stores({
|
|||||||
const question_db = new Dexie("question_database");
|
const question_db = new Dexie("question_database");
|
||||||
question_db.version(1).stores({
|
question_db.version(1).stores({
|
||||||
question_data: "&[qid+type], qid, type",
|
question_data: "&[qid+type], qid, type",
|
||||||
saved_exams: "&eid, type, exam_mode, name, order, time, generated",
|
saved_exams: "&eid, type, exam_mode, name, order, time, exam_json_id",
|
||||||
});
|
});
|
||||||
|
|
||||||
retrievePacketList();
|
retrievePacketList();
|
||||||
@@ -168,14 +168,14 @@ async function loadExamList(data) {
|
|||||||
let name = exam["name"];
|
let name = exam["name"];
|
||||||
let url = exam["url"];
|
let url = exam["url"];
|
||||||
let eid = exam["eid"];
|
let eid = exam["eid"];
|
||||||
let generated = exam["json_creation_time"];
|
let exam_json_id = exam["exam_json_id"];
|
||||||
|
|
||||||
let question_timestamp_hash = {};
|
let question_json_id_hash = {};
|
||||||
|
|
||||||
if (exam.hasOwnProperty("multi_question_json")) {
|
if (exam.hasOwnProperty("multi_question_json")) {
|
||||||
question_timestamp_hash = exam["multi_question_json"];
|
question_json_id_hash = exam["multi_question_json"];
|
||||||
}
|
}
|
||||||
exam_generated_map[eid] = [generated, question_timestamp_hash];
|
exam_generated_map[eid] = [exam_json_id, question_json_id_hash];
|
||||||
|
|
||||||
let c = "";
|
let c = "";
|
||||||
if (exams_started.indexOf(name) > -1) {
|
if (exams_started.indexOf(name) > -1) {
|
||||||
@@ -204,7 +204,7 @@ async function loadExamList(data) {
|
|||||||
)
|
)
|
||||||
.text(name)
|
.text(name)
|
||||||
.click(function () {
|
.click(function () {
|
||||||
loadPacketFromAjax(url, eid, generated);
|
loadPacketFromAjax(url, eid, exam_json_id);
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
@@ -227,30 +227,27 @@ async function loadExamList(data) {
|
|||||||
}
|
}
|
||||||
saved_exams.forEach((saved_exam, n) => {
|
saved_exams.forEach((saved_exam, n) => {
|
||||||
$("#cache-details ul").append(
|
$("#cache-details ul").append(
|
||||||
`<li class="cache-item" data-eid=${saved_exam.eid}>Exam: ${saved_exam.exam_name} [${saved_exam.eid}]: ${saved_exam.generated}`
|
`<li class="cache-item" data-eid=${saved_exam.eid}>Exam: ${saved_exam.exam_name} [${saved_exam.eid}]: ${saved_exam.exam_json_id}`
|
||||||
);
|
);
|
||||||
//Compared saved exams to those available
|
//Compared saved exams to those available
|
||||||
if (exam_generated_map.hasOwnProperty(saved_exam.eid)) {
|
if (exam_generated_map.hasOwnProperty(saved_exam.eid)) {
|
||||||
// If the timestamps differ delete and force a refresh
|
// If the json_id s differ delete and force a refresh
|
||||||
const exam_timestamp = exam_generated_map[saved_exam.eid][0];
|
const exam_json_id = exam_generated_map[saved_exam.eid][0];
|
||||||
const question_timestamp_hash = exam_generated_map[saved_exam.eid][1];
|
const question_json_id_hash = exam_generated_map[saved_exam.eid][1];
|
||||||
|
|
||||||
if (
|
if (saved_exam.exam_json_id != exam_json_id) {
|
||||||
// Probably better doing this serveside
|
|
||||||
compareDates(saved_exam.generated, exam_timestamp)
|
|
||||||
) {
|
|
||||||
question_db.saved_exams.where("eid").equals(saved_exam.eid).delete();
|
question_db.saved_exams.where("eid").equals(saved_exam.eid).delete();
|
||||||
|
|
||||||
console.log("HOL");
|
console.log("HOL");
|
||||||
$(`li.cache-item[data-eid="${saved_exam.eid}"]`)
|
$(`li.cache-item[data-eid="${saved_exam.eid}"]`)
|
||||||
.addClass("cache-out-of-date")
|
.addClass("cache-out-of-date")
|
||||||
.append(` [out of date (latest: ${exam_timestamp})]`);
|
.append(` [out of date (latest: ${exam_json_id})]`);
|
||||||
} else {
|
} else {
|
||||||
$(`.packet-button[data-eid="${saved_exam.eid}"]`).addClass("cached");
|
$(`.packet-button[data-eid="${saved_exam.eid}"]`).addClass("cached");
|
||||||
}
|
}
|
||||||
|
|
||||||
for (let q in question_timestamp_hash) {
|
for (let q in question_json_id_hash) {
|
||||||
let new_timestamp = question_timestamp_hash[q];
|
let new_json_id = question_json_id_hash[q];
|
||||||
//q = q.toString();
|
//q = q.toString();
|
||||||
$("#cache-details ul").append(
|
$("#cache-details ul").append(
|
||||||
`<li class="cache-item" data-qid=${q}>Question (${saved_exam.exam_type}): ${q}`
|
`<li class="cache-item" data-qid=${q}>Question (${saved_exam.exam_type}): ${q}`
|
||||||
@@ -262,10 +259,7 @@ async function loadExamList(data) {
|
|||||||
.then((d) => {
|
.then((d) => {
|
||||||
// d is undefined if the question is not saved
|
// d is undefined if the question is not saved
|
||||||
// we should really just requeue the required question for dowload...
|
// we should really just requeue the required question for dowload...
|
||||||
if (
|
if (d == undefined || d.data.exam_json_id != new_json_id) {
|
||||||
d == undefined ||
|
|
||||||
compareDates(d.data.generated, new_timestamp)
|
|
||||||
) {
|
|
||||||
$(`li.cache-item[data-eid="${saved_exam.eid}"]`).addClass(
|
$(`li.cache-item[data-eid="${saved_exam.eid}"]`).addClass(
|
||||||
"cache-out-of-date"
|
"cache-out-of-date"
|
||||||
);
|
);
|
||||||
@@ -426,13 +420,13 @@ async function loadPacketList(data) {
|
|||||||
* Loads the requisite packet into the quiz system
|
* Loads the requisite packet into the quiz system
|
||||||
* @param {string} path - relative path to the packet json file
|
* @param {string} path - relative path to the packet json file
|
||||||
*/
|
*/
|
||||||
function loadPacketFromAjax(path, eid, generated) {
|
function loadPacketFromAjax(path, eid, exam_json_id) {
|
||||||
if (eid != undefined) {
|
if (eid != undefined) {
|
||||||
// try and load the exam from the local indexedDB
|
// try and load the exam from the local indexedDB
|
||||||
question_db.saved_exams
|
question_db.saved_exams
|
||||||
.get(eid)
|
.get(eid)
|
||||||
.then((exam) => {
|
.then((exam) => {
|
||||||
if (exam == undefined || compareDates(exam["generated"], generated))
|
if (exam == undefined || (exam["exam_json_id"] != exam_json_id))
|
||||||
{
|
{
|
||||||
console.log("AjaxRequestPacket:", eid);
|
console.log("AjaxRequestPacket:", eid);
|
||||||
ajaxRequestionPacket(true);
|
ajaxRequestionPacket(true);
|
||||||
@@ -510,8 +504,8 @@ function setUpPacket(data, path) {
|
|||||||
question_type = data.exam_type;
|
question_type = data.exam_type;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (data.hasOwnProperty("generated")) {
|
if (data.hasOwnProperty("exam_json_id")) {
|
||||||
packet_generated = data.generated;
|
packet_json_id = data.exam_json_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (data.hasOwnProperty("exam_mode")) {
|
if (data.hasOwnProperty("exam_mode")) {
|
||||||
@@ -769,7 +763,7 @@ function setUpQuestions(load_previous) {
|
|||||||
qid: String(e),
|
qid: String(e),
|
||||||
type: questions[e].type,
|
type: questions[e].type,
|
||||||
data: questions[e],
|
data: questions[e],
|
||||||
//timestamp: questions[e]["generated"],
|
//timestamp: questions[e]["exam_json_id"],
|
||||||
};
|
};
|
||||||
|
|
||||||
question_db.question_data.put(d);
|
question_db.question_data.put(d);
|
||||||
@@ -2486,5 +2480,6 @@ $(document).on("saveSessionEvent", {}, (evt, review) => {
|
|||||||
function compareDates(d1, d2) {
|
function compareDates(d1, d2) {
|
||||||
console.log("compare", d1, d2);
|
console.log("compare", d1, d2);
|
||||||
console.log("compare striped", Date.parse(d1.split("+")[0]), Date.parse(d2.split("+")[0]));
|
console.log("compare striped", Date.parse(d1.split("+")[0]), Date.parse(d2.split("+")[0]));
|
||||||
|
console.log("compare striped", Date.parse(d1.split("+")[0]), Date.parse(d2.split("+")[0]));
|
||||||
return Date.parse(d1.split("+")[0]) != Date.parse(d2.split("+")[0]);
|
return Date.parse(d1.split("+")[0]) != Date.parse(d2.split("+")[0]);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user