fix date comparisons
This commit is contained in:
+49
-26
@@ -236,15 +236,15 @@ async function loadExamList(data) {
|
|||||||
const question_timestamp_hash = exam_generated_map[saved_exam.eid][1];
|
const question_timestamp_hash = exam_generated_map[saved_exam.eid][1];
|
||||||
|
|
||||||
if (
|
if (
|
||||||
Date.parse(saved_exam.generated) !=
|
|
||||||
// Probably better doing this serveside
|
// Probably better doing this serveside
|
||||||
Date.parse(exam_timestamp.split("+")[0])
|
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();
|
||||||
|
|
||||||
$(`li.cache-item[data-eid="${saved_exam.eid}"]`).addClass(
|
console.log("HOL");
|
||||||
"cache-out-of-date"
|
$(`li.cache-item[data-eid="${saved_exam.eid}"]`)
|
||||||
).append(` [out of date (latest: ${exam_timestamp})]`);
|
.addClass("cache-out-of-date")
|
||||||
|
.append(` [out of date (latest: ${exam_timestamp})]`);
|
||||||
} else {
|
} else {
|
||||||
$(`.packet-button[data-eid="${saved_exam.eid}"]`).addClass("cached");
|
$(`.packet-button[data-eid="${saved_exam.eid}"]`).addClass("cached");
|
||||||
}
|
}
|
||||||
@@ -256,7 +256,7 @@ async function loadExamList(data) {
|
|||||||
`<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}`
|
||||||
);
|
);
|
||||||
// If a single question is out of date we invalidate the lot...
|
// If a single question is out of date we invalidate the lot...
|
||||||
const q_object = { qid: q, type: saved_exam.exam_type };
|
const q_object = { qid: parseInt(q), type: saved_exam.exam_type };
|
||||||
question_db.question_data
|
question_db.question_data
|
||||||
.get(q_object)
|
.get(q_object)
|
||||||
.then((d) => {
|
.then((d) => {
|
||||||
@@ -264,7 +264,7 @@ async function loadExamList(data) {
|
|||||||
// 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 == undefined ||
|
||||||
Date.parse(d.data.generated) != Date.parse(new_timestamp)
|
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"
|
||||||
@@ -285,6 +285,8 @@ async function loadExamList(data) {
|
|||||||
d = null;
|
d = null;
|
||||||
})
|
})
|
||||||
.catch((e) => {
|
.catch((e) => {
|
||||||
|
console.log(e);
|
||||||
|
console.log("1234", saved_exam.eid);
|
||||||
// If the question isn't found in the cache...
|
// If the question isn't found in the cache...
|
||||||
$(`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"
|
||||||
@@ -430,10 +432,8 @@ function loadPacketFromAjax(path, eid, generated) {
|
|||||||
question_db.saved_exams
|
question_db.saved_exams
|
||||||
.get(eid)
|
.get(eid)
|
||||||
.then((exam) => {
|
.then((exam) => {
|
||||||
if (
|
if (exam == undefined || compareDates(exam["generated"], generated))
|
||||||
exam == undefined ||
|
{
|
||||||
(Date.parse(exam["generated"].split("+")[0]) != Date.parse(generated.split("+")[0]))
|
|
||||||
) {
|
|
||||||
console.log("AjaxRequestPacket:", eid);
|
console.log("AjaxRequestPacket:", eid);
|
||||||
ajaxRequestionPacket(true);
|
ajaxRequestionPacket(true);
|
||||||
} else {
|
} else {
|
||||||
@@ -860,13 +860,12 @@ async function loadQuestion(n, section = 1, force_reload = false) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.log(exam_details, n);
|
||||||
console.log(exam_details, n)
|
|
||||||
const qid = exam_details.question_order[n];
|
const qid = exam_details.question_order[n];
|
||||||
|
|
||||||
let q = { qid: qid, type: question_type };
|
let q = { qid: qid, type: question_type };
|
||||||
console.log(q)
|
console.log(q);
|
||||||
console.log(question_db.question_data)
|
console.log(question_db.question_data);
|
||||||
|
|
||||||
let return_data = await question_db.question_data.get(q);
|
let return_data = await question_db.question_data.get(q);
|
||||||
const question_data = return_data.data;
|
const question_data = return_data.data;
|
||||||
@@ -1759,7 +1758,8 @@ function reviewQuestions() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
db.user_answers
|
db.user_answers
|
||||||
.where({ type: question_type, qid: qid }).toArray()
|
.where({ type: question_type, qid: qid })
|
||||||
|
.toArray()
|
||||||
.then(function (answers) {
|
.then(function (answers) {
|
||||||
// Merge the question answers with the user saved answers
|
// Merge the question answers with the user saved answers
|
||||||
let question_answers = question["answers"];
|
let question_answers = question["answers"];
|
||||||
@@ -1967,7 +1967,7 @@ function reviewQuestions() {
|
|||||||
*/
|
*/
|
||||||
function markAnswer(qid, current_question, n) {
|
function markAnswer(qid, current_question, n) {
|
||||||
const type = current_question.type;
|
const type = current_question.type;
|
||||||
console.log("Mark", current_question)
|
console.log("Mark", current_question);
|
||||||
|
|
||||||
let option = null;
|
let option = null;
|
||||||
if (review_mode == true) {
|
if (review_mode == true) {
|
||||||
@@ -2021,22 +2021,35 @@ function markAnswer(qid, current_question, n) {
|
|||||||
|
|
||||||
// Load user saved answers
|
// Load user saved answers
|
||||||
db.user_answers
|
db.user_answers
|
||||||
.where({ type: type, qid: qid }).toArray()
|
.where({ type: type, qid: qid })
|
||||||
|
.toArray()
|
||||||
.then(function (saved_user_answers) {
|
.then(function (saved_user_answers) {
|
||||||
// check if given answer matches a user saved answer
|
// check if given answer matches a user saved answer
|
||||||
if (saved_user_answers != undefined) {
|
if (saved_user_answers != undefined) {
|
||||||
console.log(saved_user_answers)
|
console.log(saved_user_answers);
|
||||||
saved_user_answers.forEach(function (saved_answer_object, n) {
|
saved_user_answers.forEach(function (saved_answer_object, n) {
|
||||||
let saved_answer = saved_answer_object.ans;
|
let saved_answer = saved_answer_object.ans;
|
||||||
console.log("ua", user_answer, saved_answer)
|
console.log("ua", user_answer, saved_answer);
|
||||||
ul.append("<li>" + saved_answer + "</li>");
|
ul.append("<li>" + saved_answer + "</li>");
|
||||||
if (compareString(saved_answer, user_answer)) {
|
if (compareString(saved_answer, user_answer)) {
|
||||||
textarea.removeClass("incorrect").addClass("correct");
|
textarea.removeClass("incorrect").addClass("correct");
|
||||||
}
|
}
|
||||||
if (saved_answer_object.submitted == undefined || saved_answer_object.submitted != true) {
|
if (
|
||||||
ul.append($("<button>Submit Answer</button>").click((e) => {
|
saved_answer_object.submitted == undefined ||
|
||||||
interact.postSavedAnswer(type, qid, saved_answer, e, saved_answer_object, db);
|
saved_answer_object.submitted != true
|
||||||
}));
|
) {
|
||||||
|
ul.append(
|
||||||
|
$("<button>Submit Answer</button>").click((e) => {
|
||||||
|
interact.postSavedAnswer(
|
||||||
|
type,
|
||||||
|
qid,
|
||||||
|
saved_answer,
|
||||||
|
e,
|
||||||
|
saved_answer_object,
|
||||||
|
db
|
||||||
|
);
|
||||||
|
})
|
||||||
|
);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -2082,7 +2095,7 @@ function markAnswer(qid, current_question, n) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function addFeedback(current_question, qid) {
|
function addFeedback(current_question, qid) {
|
||||||
console.log(current_question)
|
console.log(current_question);
|
||||||
if (
|
if (
|
||||||
current_question.hasOwnProperty("feedback") &&
|
current_question.hasOwnProperty("feedback") &&
|
||||||
current_question.feedback.length > 0
|
current_question.feedback.length > 0
|
||||||
@@ -2119,7 +2132,12 @@ function markCorrect(qid, user_answer, type) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
db.user_answers.put({ type: type, qid: qid, ans: user_answer, submitted: false });
|
db.user_answers.put({
|
||||||
|
type: type,
|
||||||
|
qid: qid,
|
||||||
|
ans: user_answer,
|
||||||
|
submitted: false,
|
||||||
|
});
|
||||||
//db.user_answers
|
//db.user_answers
|
||||||
// .get({ type: type, qid: qid })
|
// .get({ type: type, qid: qid })
|
||||||
// .then(function (answers) {
|
// .then(function (answers) {
|
||||||
@@ -2465,3 +2483,8 @@ function refreshDatabaseSettings() {
|
|||||||
$(document).on("saveSessionEvent", {}, (evt, review) => {
|
$(document).on("saveSessionEvent", {}, (evt, review) => {
|
||||||
saveSession(review);
|
saveSession(review);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Helper to compare dates
|
||||||
|
function compareDates(d1, d2) {
|
||||||
|
return Date.parse(d1.split("+")[0]) != Date.parse(d2.split("+")[0]);
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user