From 469c06c88e815005f4fc8644fcf68177e1db2c16 Mon Sep 17 00:00:00 2001 From: Ross Date: Mon, 8 Feb 2021 12:36:31 +0000 Subject: [PATCH 1/7] add captions (new field image_titles) --- js/main.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/js/main.js b/js/main.js index 9990670..dcaeaf9 100644 --- a/js/main.js +++ b/js/main.js @@ -586,10 +586,13 @@ function loadQuestion(n, section = 1, force_reload = false) { 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( - '
...
' + `
${caption}
` ); // const thumbnail = $(".figure .thumbnail").get(id); From b2c4f2b33ceb8bdbd82dc0b5d78d933f9bd1efab Mon Sep 17 00:00:00 2001 From: Ross Date: Sun, 28 Feb 2021 15:17:39 +0000 Subject: [PATCH 2/7] add support for seperate qusetion requests --- js/interact.js | 29 +++++++++++++++++++- js/main.js | 73 +++++++++++++++++++++++++++++++++++++++++--------- 2 files changed, 89 insertions(+), 13 deletions(-) diff --git a/js/interact.js b/js/interact.js index d74e8c1..884ccda 100644 --- a/js/interact.js +++ b/js/interact.js @@ -1,3 +1,4 @@ +import * as helper from "./helpers.js"; /** * Submits answers */ @@ -67,7 +68,7 @@ export function postAnswers(ans) { alert(`${data.question_count} answers sucessfully submitted.`); } } else { - submissionError(data, ans); + submissionError(data, ans); } }) .fail((e) => { @@ -108,3 +109,29 @@ function submissionError(data, ans) { "z-index": 5000, }); } + +// TODO: async request +export function getQuestion(url, question_number, question_total) { + console.log("Downloading ", url, question_number, question_total); + return $.ajax({ + dataType: "json", + url: url, + progress: function (e) { + console.log(e); + if (e.lengthComputable) { + var completedPercentage = Math.round((e.loaded * 100) / e.total); + + $("#progress").html( + `Downloading [${question_number}/${question_total}]${completedPercentage}%
${helper.formatBytes( + e.total + )}` + ); + } + }, + //success: function (data) { + // strReturn = data; + //}, + //async: false, + }); + +} diff --git a/js/main.js b/js/main.js index 4753842..ca37c29 100644 --- a/js/main.js +++ b/js/main.js @@ -53,13 +53,18 @@ function retrievePacketList() { url = window.config.exam_query_url; } - $.ajax({dataType: "json", cache: false, url: url, success : function (data) { - if (data.hasOwnProperty("exams")) { - loadExamList(data); - } else { - loadPacketList(data); - } - },}) + $.ajax({ + dataType: "json", + cache: false, + url: url, + success: function (data) { + if (data.hasOwnProperty("exams")) { + loadExamList(data); + } else { + loadPacketList(data); + } + }, + }) .done(function () {}) .fail(function () { $.getJSON("packets/packets.json", function (data) { @@ -133,12 +138,14 @@ async function loadExamList(data) { if ($(`#packet-list .${exam.type}`).length) { list = $(`#packet-list .${exam.type}`); } else { - list = $("#packet-list").append(`
${exam.type}
`); + list = $("#packet-list").append( + `
${exam.type}
` + ); } } else { list = $("#packet-list"); } - + list.append( $(`
`) .text(name) @@ -204,7 +211,9 @@ async function loadPacketList(data) { if ($(`#packet-list .${packet.type}`)) { list = $(`#packet-list .${packet.type}`); } else { - list = $(`
${packet.type}
`); + list = $( + `
${packet.type}
` + ); $("#packet-list").append(list); } } else { @@ -259,7 +268,8 @@ function loadPacketFromAjax(path) { }, }) .done(function (data) { - setUpPacket(data, path.split("/").pop()); + //setUpPacket(data, path.split("/").pop()); + setUpPacket(data, path); $("#options-panel").hide(); }) .fail(function () { @@ -393,7 +403,8 @@ window.db = db; * Will then call setUpQuestions() to load the packet * @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) if (data.hasOwnProperty("exam_name")) { packet_name = data.exam_name; @@ -427,6 +438,44 @@ function setUpPacket(data, packet_name) { 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 + 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 request = interact.getQuestion( + question_url, + question_number, + question_total + ); + + requests.push(request) + request_numbers.push(n) + //data["questions"][n] = question_json; + } + + $.when.apply($,requests).then(function(){ + console.log(arguments); //array of responses [0][data, status, xhrObj],[1][data, status, xhrObj]... + }) + + } else { + // Just carry on loading + loadSession(); + } +} + +function loadSession() { // Either continue session or create a new one db.session // .where("status") From 112109d07c1ed1d7dcb4bda338b843e26119af7a Mon Sep 17 00:00:00 2001 From: Ross Date: Sun, 28 Feb 2021 16:18:56 +0000 Subject: [PATCH 3/7] . --- js/main.js | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/js/main.js b/js/main.js index 0080592..6f94611 100644 --- a/js/main.js +++ b/js/main.js @@ -448,26 +448,37 @@ function setUpPacket(data, path) { 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 request = interact.getQuestion( + const question_json = await interact.getQuestion( question_url, question_number, question_total ); - requests.push(request) - request_numbers.push(n) - //data["questions"][n] = question_json; + //requests.push(request) + //request_numbers.push(n) + data["questions"][n] = question_json; } + loadSession(); + })() - $.when.apply($,requests).then(function(){ - console.log(arguments); //array of responses [0][data, status, xhrObj],[1][data, status, xhrObj]... - }) + + //(async () => { + // for(let f of requests){ + // var json = await f; + // console.log(json) + //}; + //})() + + //$.when.apply($,requests).then(function(){ + // console.log(arguments); //array of responses [0][data, status, xhrObj],[1][data, status, xhrObj]... + //}) } else { // Just carry on loading From c8a3aa1549a99654f07c259146f8f9bf1573b7e0 Mon Sep 17 00:00:00 2001 From: Ross Date: Sun, 28 Feb 2021 22:56:41 +0000 Subject: [PATCH 4/7] . --- js/interact.js | 6 ++---- js/main.js | 13 +------------ 2 files changed, 3 insertions(+), 16 deletions(-) diff --git a/js/interact.js b/js/interact.js index 884ccda..59aa93b 100644 --- a/js/interact.js +++ b/js/interact.js @@ -110,19 +110,17 @@ function submissionError(data, ans) { }); } -// TODO: async request export function getQuestion(url, question_number, question_total) { - console.log("Downloading ", url, question_number, question_total); + console.log("Downloading question ", url, question_number, question_total); return $.ajax({ dataType: "json", url: url, progress: function (e) { - console.log(e); if (e.lengthComputable) { var completedPercentage = Math.round((e.loaded * 100) / e.total); $("#progress").html( - `Downloading [${question_number}/${question_total}]${completedPercentage}%
${helper.formatBytes( + `Downloading question [${question_number}/${question_total}]
${completedPercentage}%
${helper.formatBytes( e.total )}` ); diff --git a/js/main.js b/js/main.js index 6f94611..29d012b 100644 --- a/js/main.js +++ b/js/main.js @@ -465,21 +465,10 @@ function setUpPacket(data, path) { //request_numbers.push(n) data["questions"][n] = question_json; } + // Once all questions have been downloaded we carry on loading loadSession(); })() - - //(async () => { - // for(let f of requests){ - // var json = await f; - // console.log(json) - //}; - //})() - - //$.when.apply($,requests).then(function(){ - // console.log(arguments); //array of responses [0][data, status, xhrObj],[1][data, status, xhrObj]... - //}) - } else { // Just carry on loading loadSession(); From 865cd9b1a6fbb9d880ddb1e2a902a65c1fcbd2a8 Mon Sep 17 00:00:00 2001 From: Ross Date: Mon, 1 Mar 2021 08:42:16 +0000 Subject: [PATCH 5/7] load screen should only be hidden once all requests are complete --- js/main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/main.js b/js/main.js index 29d012b..94e3f1d 100644 --- a/js/main.js +++ b/js/main.js @@ -1982,7 +1982,7 @@ $(document).ajaxStart(function () { $("#loading").show(); }); -$(document).ajaxComplete(function () { +$(document).ajaxStop(function () { $("#loading").hide(); }); From c2dba555ec5cde8e1384d79d1a10326554a1cc17 Mon Sep 17 00:00:00 2001 From: Ross Date: Mon, 1 Mar 2021 08:51:19 +0000 Subject: [PATCH 6/7] . --- js/interact.js | 2 ++ js/main.js | 1 + 2 files changed, 3 insertions(+) diff --git a/js/interact.js b/js/interact.js index 59aa93b..9498f81 100644 --- a/js/interact.js +++ b/js/interact.js @@ -116,6 +116,8 @@ export function getQuestion(url, question_number, question_total) { dataType: "json", url: url, progress: function (e) { + $("#progress").html( + `Downloading question [${question_number}/${question_total}]
This file is compressed (no size available)` if (e.lengthComputable) { var completedPercentage = Math.round((e.loaded * 100) / e.total); diff --git a/js/main.js b/js/main.js index 94e3f1d..e630fa1 100644 --- a/js/main.js +++ b/js/main.js @@ -259,6 +259,7 @@ function loadPacketFromAjax(path) { url: path, progress: function (e) { if (e.lengthComputable) { + console.log("1") var completedPercentage = Math.round((e.loaded * 100) / e.total); $("#progress").html( From b826484c39d3ba95421214a094a5ae82efd20a20 Mon Sep 17 00:00:00 2001 From: Ross Date: Mon, 1 Mar 2021 08:51:47 +0000 Subject: [PATCH 7/7] . --- js/interact.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/interact.js b/js/interact.js index 9498f81..afc2402 100644 --- a/js/interact.js +++ b/js/interact.js @@ -117,7 +117,7 @@ export function getQuestion(url, question_number, question_total) { url: url, progress: function (e) { $("#progress").html( - `Downloading question [${question_number}/${question_total}]
This file is compressed (no size available)` + `Downloading question [${question_number}/${question_total}]
This file is compressed (no size available)`) if (e.lengthComputable) { var completedPercentage = Math.round((e.loaded * 100) / e.total);