From 85460b7192e5471ad1251ce2687216288b725160 Mon Sep 17 00:00:00 2001 From: viveksantayana Date: Sat, 4 Dec 2021 18:50:09 +0000 Subject: [PATCH] Added question progress bar --- ref-test/quiz/static/js/quiz.js | 36 +++++++++++++++++++++++- ref-test/quiz/templates/quiz/client.html | 5 ++++ 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/ref-test/quiz/static/js/quiz.js b/ref-test/quiz/static/js/quiz.js index b5f101a..cb65e47 100644 --- a/ref-test/quiz/static/js/quiz.js +++ b/ref-test/quiz/static/js/quiz.js @@ -368,6 +368,23 @@ function render_question() { `; } $question_options.html(options_output); + let skipped = count_questions(-1); + let answered = count_questions(2); + let flagged = count_questions(1); + + $progress_skipped.attr('title', `Skipped: ${skipped}`); + $progress_skipped.attr('aria-valuenow', skipped); + $progress_skipped.css('width', `${skipped}%`); + + $progress_flagged.attr('title', `Flagged: ${flagged}`); + $progress_flagged.attr('aria-valuenow', flagged); + $progress_flagged.css('width', `${flagged}%`); + + $progress_answered.attr('title', `Answered: ${answered}`); + $progress_answered.attr('aria-valuenow', answered); + $progress_answered.css('width', `10%`); + console.log(`Answered: ${answered}, Skipped: ${skipped}, Flagged: ${flagged}`); + $question_title.focus(); $(window).scrollTop(0); } @@ -550,6 +567,17 @@ function stop() { $("#btn-toggle-settings").addClass('disabled') } +function count_questions(status) { + output = 0; + for (let i = 0; i < Object.keys(question_status).length; i++) { + key = Object.keys(question_status)[i]; + if (question_status[key] == status){ + output ++; + } + } + return output; +} + // Variable Definitions const _id = window.localStorage.getItem('_id'); @@ -582,7 +610,13 @@ const $question_header = $("#quiz-question-header"); const $question_text = $("#quiz-question-text"); const $question_options = $("#quiz-question-options"); +const $progress_skipped = $("#skipped"); +const $progress_answered = $("#answered"); +const $progress_flagged = $("#flagged"); + // Execution on Load apply_settings(display_settings); -check_started(); \ No newline at end of file +check_started(); + +console.log($progress_answered); \ No newline at end of file diff --git a/ref-test/quiz/templates/quiz/client.html b/ref-test/quiz/templates/quiz/client.html index b9357d6..6dfd261 100644 --- a/ref-test/quiz/templates/quiz/client.html +++ b/ref-test/quiz/templates/quiz/client.html @@ -223,6 +223,11 @@ Exam Console
+
+
+
+
+

Question x.