improve answer submission
This commit is contained in:
@@ -7,3 +7,5 @@ img/*
|
|||||||
.htaccess
|
.htaccess
|
||||||
|
|
||||||
node_modules
|
node_modules
|
||||||
|
|
||||||
|
config.js
|
||||||
+15
-2
@@ -112,9 +112,22 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="dialog-text">
|
<div class="dialog-text">
|
||||||
Click to start exam.
|
Click to start exam.
|
||||||
<p>You will have <input type='number' size=2 id='exam-time'></input> minutes.</p>
|
<p>You will have <input type='number' size=2 class='exam-time'></input> minutes.</p>
|
||||||
</div>
|
</div>
|
||||||
<button id="start-packet-button" class="navigation dialog-yes">Start</button>
|
<button class="start-packet-button navigation dialog-yes">Start</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div id="start-dialog-exam" class="dialog modal no-close">
|
||||||
|
<h3 class="dialog-title">Start exam</h3>
|
||||||
|
<div class="dialog-text">
|
||||||
|
Click to start exam.
|
||||||
|
<p>You will have <input type='number' size=2 class='exam-time'></input> minutes.</p>
|
||||||
|
</div>
|
||||||
|
<div class="dialog-text">
|
||||||
|
Check your below candidate number is correct.
|
||||||
|
<input type='number' size=10 id='candidate-number2'></input>
|
||||||
|
</div>
|
||||||
|
<button class="start-packet-button navigation dialog-yes">Start</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div id="time-up-dialog" class="dialog modal">
|
<div id="time-up-dialog" class="dialog modal">
|
||||||
|
|||||||
+106
-11
@@ -1,6 +1,7 @@
|
|||||||
/* global Dexie, cornerstone, cornerstoneTools, cornerstoneBase64ImageLoader, cornerstoneWebImageLoader, cornerstoneWADOImageLoader */
|
/* global Dexie, cornerstone, cornerstoneTools, cornerstoneBase64ImageLoader, cornerstoneWebImageLoader, cornerstoneWADOImageLoader */
|
||||||
import * as helper from "./helpers.js";
|
import * as helper from "./helpers.js";
|
||||||
import * as viewer from "./viewer.js";
|
import * as viewer from "./viewer.js";
|
||||||
|
import * as config from "./config.js";
|
||||||
// const { v4: uuidv4 } = require('uuid');
|
// const { v4: uuidv4 } = require('uuid');
|
||||||
|
|
||||||
// cid = null;
|
// cid = null;
|
||||||
@@ -11,6 +12,7 @@ window.eid = 5678;
|
|||||||
window.exam_mode = false;
|
window.exam_mode = false;
|
||||||
|
|
||||||
window.packet_list = [];
|
window.packet_list = [];
|
||||||
|
window.exams = [];
|
||||||
|
|
||||||
window.packet_name = null;
|
window.packet_name = null;
|
||||||
window.questions = null;
|
window.questions = null;
|
||||||
@@ -30,6 +32,8 @@ window.timer = null;
|
|||||||
|
|
||||||
//window.dfile = null;
|
//window.dfile = null;
|
||||||
|
|
||||||
|
window.config = config;
|
||||||
|
|
||||||
retrievePacketList();
|
retrievePacketList();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -38,13 +42,29 @@ retrievePacketList();
|
|||||||
* and then fallback to packets.json
|
* and then fallback to packets.json
|
||||||
*/
|
*/
|
||||||
function retrievePacketList() {
|
function retrievePacketList() {
|
||||||
$.getJSON("packets/", function (data) {
|
let url = "packets/";
|
||||||
loadPacketList(data);
|
|
||||||
|
console.log(window.config.exam_query_url)
|
||||||
|
|
||||||
|
if (window.config.exam_query_url != undefined) {
|
||||||
|
url = window.config.exam_query_url;
|
||||||
|
}
|
||||||
|
|
||||||
|
$.getJSON(url, 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) {
|
||||||
loadPacketList(data);
|
if (data.hasOwnProperty("exams")) {
|
||||||
|
loadExamList(data);
|
||||||
|
} else {
|
||||||
|
loadPacketList(data);
|
||||||
|
}
|
||||||
}).fail(function (jqXHR, textStatus, errorThrown) {
|
}).fail(function (jqXHR, textStatus, errorThrown) {
|
||||||
console.log(jqXHR);
|
console.log(jqXHR);
|
||||||
console.log(textStatus);
|
console.log(textStatus);
|
||||||
@@ -56,6 +76,65 @@ function retrievePacketList() {
|
|||||||
.always(function () {});
|
.always(function () {});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generate a list of exams that are available to be loaded
|
||||||
|
* this is based on the subsequant function but gives less options
|
||||||
|
*
|
||||||
|
* @param {JSON} data - json containing available exams
|
||||||
|
*/
|
||||||
|
async function loadExamList(data) {
|
||||||
|
let sessions = await window.db.session.toArray().catch(function (error) {
|
||||||
|
console.log("Error loading session", error);
|
||||||
|
$("#database-error").text(
|
||||||
|
"Error loading the database, schema has probably changed and needs updating. You will probably need to delete the local database."
|
||||||
|
);
|
||||||
|
let delete_button = $("<button>Delete local database</button>").click(
|
||||||
|
() => {
|
||||||
|
window.indexedDB.deleteDatabase("answers_database");
|
||||||
|
location.reload();
|
||||||
|
}
|
||||||
|
);
|
||||||
|
$("#database-error").append(delete_button);
|
||||||
|
$("#database-error").show();
|
||||||
|
});
|
||||||
|
// db.session
|
||||||
|
// .where("packet")
|
||||||
|
// .equals()
|
||||||
|
let exams_started = [];
|
||||||
|
let exams_completed = [];
|
||||||
|
sessions.forEach((s) => {
|
||||||
|
if (s.status == "active") {
|
||||||
|
exams_started.push(s.packet);
|
||||||
|
} else {
|
||||||
|
exams_completed.push(s.packet);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (data != null) {
|
||||||
|
window.exam_list = data.exams;
|
||||||
|
}
|
||||||
|
$("#packet-list").empty();
|
||||||
|
window.exam_list.forEach(function (exam) {
|
||||||
|
let name = exam["name"];
|
||||||
|
let url = exam["url"];
|
||||||
|
let c = "";
|
||||||
|
if (exams_started.indexOf(name) > -1) {
|
||||||
|
c = " session-started";
|
||||||
|
}
|
||||||
|
if (exams_completed.indexOf(name) > -1) {
|
||||||
|
c = " session-completed";
|
||||||
|
}
|
||||||
|
$("#packet-list").append(
|
||||||
|
$(`<div class='packet-button${c}' title='Load packet'></div>`)
|
||||||
|
.text(name)
|
||||||
|
.click(function () {
|
||||||
|
loadPacketFromAjax(url);
|
||||||
|
})
|
||||||
|
);
|
||||||
|
});
|
||||||
|
$("#options-panel").show();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generate a list of the packets that are available to be loaded
|
* Generate a list of the packets that are available to be loaded
|
||||||
*
|
*
|
||||||
@@ -200,13 +279,25 @@ function setUpQuestions(load_previous) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$("#exam-time")
|
$(".exam-time")
|
||||||
.val(window.exam_time / 60)
|
.val(window.exam_time / 60)
|
||||||
.change(() => {
|
.change(() => {
|
||||||
window.exam_time = $("#exam-time").val() * 60;
|
window.exam_time = $(".exam-time").val() * 60;
|
||||||
});
|
});
|
||||||
|
|
||||||
$("#start-dialog").modal();
|
if (window.exam_mode) {
|
||||||
|
$("#candidate-number2").val(window.cid).change(() => {
|
||||||
|
window.cid = parseInt($("#candidate-number2").val());
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
$("#start-dialog-exam").modal( {closeExisting: false, // Close existing modals. Set this to false if you need to stack multiple modal instances.
|
||||||
|
escapeClose: false, // Allows the user to close the modal by pressing `ESC`
|
||||||
|
clickClose: false, // Allows the user to close the modal by clicking the overlay
|
||||||
|
showClose: false} );
|
||||||
|
} else {
|
||||||
|
$("#start-dialog").modal();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set up cornerstone (the dicom viewer)
|
// Set up cornerstone (the dicom viewer)
|
||||||
@@ -1037,13 +1128,17 @@ function getJsonAnswers() {
|
|||||||
* @param {*} ans - json representation of answers
|
* @param {*} ans - json representation of answers
|
||||||
*/
|
*/
|
||||||
function postAnswers(ans) {
|
function postAnswers(ans) {
|
||||||
console.log(ans);
|
$("#progress").html(`Submitting answers...`);
|
||||||
// ans = {"test" : 1}
|
// ans = {"test" : 1}
|
||||||
$.post("http://localhost:8000/submit_answers", JSON.stringify(ans)).done(
|
$.post(window.config.exam_submit_url, JSON.stringify(ans)).done(
|
||||||
(data) => {
|
(data) => {
|
||||||
console.log(data);
|
console.log(data)
|
||||||
|
if (data.success) {
|
||||||
|
alert("Answers sucessfully submitted.");
|
||||||
|
} else {
|
||||||
|
alert(`Error submitting answers: ${data.error}`);
|
||||||
}
|
}
|
||||||
);
|
});
|
||||||
// $.post( "http://localhost:8000/submit_answers", JSON.stringify(ans));
|
// $.post( "http://localhost:8000/submit_answers", JSON.stringify(ans));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1640,7 +1735,7 @@ $("#start-exam-button").click(function (evt) {
|
|||||||
$.modal.close();
|
$.modal.close();
|
||||||
});
|
});
|
||||||
|
|
||||||
$("#start-packet-button").click(function (evt) {
|
$(".start-packet-button").click(function (evt) {
|
||||||
if (window.timer != null) {
|
if (window.timer != null) {
|
||||||
window.timer.stop();
|
window.timer.stop();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user