Begin support for posting answers to a json api

This commit is contained in:
ross
2020-03-12 09:50:19 +00:00
parent 3774544004
commit 9793252f3a
3 changed files with 74 additions and 41 deletions
+1
View File
@@ -1,6 +1,7 @@
@charset "UTF-8"; @charset "UTF-8";
@import "./base.css"; @import "./base.css";
@import url("https://fonts.googleapis.com/css?family=Noto+Sans:400,700"); @import url("https://fonts.googleapis.com/css?family=Noto+Sans:400,700");
/* Colourscheme from https://www.materialui.co/colors */
* { * {
-webkit-font-smoothing: antialiased; -webkit-font-smoothing: antialiased;
+1
View File
@@ -17,6 +17,7 @@
<div class="content-panel"> <div class="content-panel">
<div class="nav-bar"> <div class="nav-bar">
<button id="review-button" class="navigation nav-right"><b></b></button> <button id="review-button" class="navigation nav-right"><b></b></button>
<button id="submit-button" class="navigation nav-right"><b>submit</b></button>
<button id="options-button" class="navigation nav-right">options</button> <button id="options-button" class="navigation nav-right">options</button>
<button id="review-overlay-button" class="navigation nav-right">review</button> <button id="review-overlay-button" class="navigation nav-right">review</button>
<!--<button id="logout-button" class="navigation nav-right">logout</button>--> <!--<button id="logout-button" class="navigation nav-right">logout</button>-->
+72 -41
View File
@@ -1,6 +1,8 @@
//cid = null; //cid = null;
cid = 1234; var cid = 1234;
eid = 5678; var eid = 5678;
var exam_mode = false;
//var questions = null //var questions = null
var question_order = []; var question_order = [];
@@ -34,10 +36,15 @@ function setUpQuestions() {
// Horrible way to get type of questions // Horrible way to get type of questions
// We assume they are all of the same type.... // We assume they are all of the same type....
question_type = questions[Object.keys(questions)[0]].type; if (question_type == null) {
question_type = questions[Object.keys(questions)[0]].type;
}
// Make sure answers is an array if (window.exam_mode) {
// $("#options-button, #review-overlay-button").hide();
} else {
$("#submit-button").hide();
}
loadQuestion(0, 1, true); loadQuestion(0, 1, true);
createReviewPanel(); createReviewPanel();
@@ -93,7 +100,33 @@ db.version(1).stores({
user_answers: "qid, ans" user_answers: "qid, ans"
}); });
setUpQuestions(); function setUpPacket(data) {
if (data.hasOwnProperty("exam_name")) {
$(".exam-name").text("Exam: " + data.exam_name);
}
if (data.hasOwnProperty("eid")) {
window.eid = data.eid;
}
if (data.hasOwnProperty("type")) {
window.question_type = data.type;
}
if (data.hasOwnProperty("exam_mode")) {
window.exam_mode = data.exam_mode;
}
if (data.hasOwnProperty("questions")) {
window.questions = data.questions;
} else {
window.questions = data;
}
setUpQuestions();
}
setUpPacket(questions);
function loadQuestion(n, section = 1, force_reload = false) { function loadQuestion(n, section = 1, force_reload = false) {
// Make sure we have an integer // Make sure we have an integer
@@ -991,6 +1024,10 @@ function disableFullscreen(dicom_element) {
// Register Key Event Listener // Register Key Event Listener
window.addEventListener("keydown", keydown_handler); window.addEventListener("keydown", keydown_handler);
$("#submit-button").click(function(evt) {
submitAnswers();
});
$("#review-button").click(function(evt) { $("#review-button").click(function(evt) {
$(".question-list-panel").toggle(); $(".question-list-panel").toggle();
}); });
@@ -1026,36 +1063,22 @@ $("#review-overlay-close").click(function(evt) {
}); });
function getJsonAnswers() { function getJsonAnswers() {
db.answers return db.answers.where({ cid: cid, eid: eid }).toArray();
.where({ cid: cid, eid: eid }) // .then(function(ans) {
.toArray() // console.log(ans);
.then(function(answers) { // submitAnswers(ans);
return; // });
answers.forEach(function(answer, n) { }
$(
"#question-list-item-" +
question_order.indexOf(answer.qid) +
"-" +
answer.qidn
).addClass("question-saved-localdb");
if (question_type == "rapid" && answer.qidn == "1") { function postAnswers(ans) {
if (answer.ans == "Abnormal") { console.log(ans);
$( //ans = {"test" : 1}
"#question-list-item-" + question_order.indexOf(answer.qid) + "-2" $.post("http://localhost:8000/submit_answers", JSON.stringify(ans)).done(
).css("display", "block"); data => {
} else { console.log(data);
$( }
"#question-list-item-" + question_order.indexOf(answer.qid) + "-2" );
).css("display", "none"); //$.post( "http://localhost:8000/submit_answers", JSON.stringify(ans));
}
}
});
//$(".long-answer").text(answer.ans);
})
.catch(function(error) {
console.log("error - ", error);
});
} }
function loadLocalQuestionSet() { function loadLocalQuestionSet() {
@@ -1080,16 +1103,23 @@ function loadLocalQuestionSet() {
fr = new FileReader(); fr = new FileReader();
fr.onload = receivedText; fr.onload = receivedText;
fr.readAsText(file); fr.readAsText(file);
$(".exam-name").text("Exam: " + file.name);
} }
function receivedText(e) { function receivedText(e) {
let lines = e.target.result; let lines = e.target.result;
window.questions = JSON.parse(lines); j = JSON.parse(lines);
setUpQuestions(); setUpPacket(j);
} }
} }
function submitAnswers() {
console.log(
getJsonAnswers().then(a => {
postAnswers(a);
})
);
}
// Displays the review question panel with a summary of marks // Displays the review question panel with a summary of marks
function reviewQuestions() { function reviewQuestions() {
$("#review-overlay").show(); $("#review-overlay").show();
@@ -1456,7 +1486,6 @@ function loadMainImage(image, stack) {
const element = document.getElementById("dicom-image"); const element = document.getElementById("dicom-image");
cornerstone.enable(element); cornerstone.enable(element);
cornerstone.displayImage(element, image); cornerstone.displayImage(element, image);
cornerstoneTools.addStackStateManager(element, ["stack"]); cornerstoneTools.addStackStateManager(element, ["stack"]);
@@ -1521,7 +1550,7 @@ function showLoginDialog() {
} }
$("#start-exam-button").click(function(evt) { $("#start-exam-button").click(function(evt) {
cid = $("#candidate-number").val(); cid = parseInt($("#candidate-number").val());
$.modal.close(); $.modal.close();
}); });
@@ -1561,7 +1590,9 @@ function manualScrollDicom(n) {
c = cornerstone.getEnabledElement(dicom_element); c = cornerstone.getEnabledElement(dicom_element);
max = c.toolStateManager.toolState.stack.data[0].imageIds.length; max = c.toolStateManager.toolState.stack.data[0].imageIds.length;
if (max < 2) { return } if (max < 2) {
return;
}
current_index = current_index =
c.toolStateManager.toolState.stack.data[0].currentImageIdIndex; c.toolStateManager.toolState.stack.data[0].currentImageIdIndex;