fix: quiz submission
This commit is contained in:
@@ -6,8 +6,11 @@
|
|||||||
"engine": "InnoDB",
|
"engine": "InnoDB",
|
||||||
"field_order": [
|
"field_order": [
|
||||||
"member",
|
"member",
|
||||||
|
"member_name",
|
||||||
|
"column_break_3",
|
||||||
"quiz",
|
"quiz",
|
||||||
"score",
|
"score",
|
||||||
|
"section_break_6",
|
||||||
"result"
|
"result"
|
||||||
],
|
],
|
||||||
"fields": [
|
"fields": [
|
||||||
@@ -38,12 +41,26 @@
|
|||||||
"in_standard_filter": 1,
|
"in_standard_filter": 1,
|
||||||
"label": "Member",
|
"label": "Member",
|
||||||
"options": "User"
|
"options": "User"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fetch_from": "member.full_name",
|
||||||
|
"fieldname": "member_name",
|
||||||
|
"fieldtype": "Data",
|
||||||
|
"label": "Member Name"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldname": "column_break_3",
|
||||||
|
"fieldtype": "Column Break"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldname": "section_break_6",
|
||||||
|
"fieldtype": "Section Break"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"in_create": 1,
|
"in_create": 1,
|
||||||
"index_web_pages_for_search": 1,
|
"index_web_pages_for_search": 1,
|
||||||
"links": [],
|
"links": [],
|
||||||
"modified": "2022-06-20 10:13:23.013802",
|
"modified": "2022-10-10 18:57:42.813738",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "LMS",
|
"module": "LMS",
|
||||||
"name": "LMS Quiz Submission",
|
"name": "LMS Quiz Submission",
|
||||||
@@ -65,5 +82,6 @@
|
|||||||
"sort_field": "modified",
|
"sort_field": "modified",
|
||||||
"sort_order": "DESC",
|
"sort_order": "DESC",
|
||||||
"states": [],
|
"states": [],
|
||||||
|
"title_field": "member_name",
|
||||||
"track_changes": 1
|
"track_changes": 1
|
||||||
}
|
}
|
||||||
@@ -573,7 +573,7 @@ input[type=checkbox] {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.lesson-content-card {
|
.lesson-content-card {
|
||||||
margin: 2rem 0 3rem;
|
margin-top: 2rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
.lesson-content-card .alert-dismissible .close {
|
.lesson-content-card .alert-dismissible .close {
|
||||||
@@ -599,9 +599,10 @@ input[type=checkbox] {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.lesson-pagination {
|
.lesson-pagination {
|
||||||
display: flex;
|
display: flex;
|
||||||
justify-content: space-between;
|
justify-content: space-between;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
|
margin-top: 2rem
|
||||||
}
|
}
|
||||||
|
|
||||||
.lesson-pagination-parent {
|
.lesson-pagination-parent {
|
||||||
|
|||||||
@@ -1,80 +1,105 @@
|
|||||||
{% if attempts_exceeded %}
|
{% if attempts_exceeded %}
|
||||||
<div class="text-center">
|
<div class="">
|
||||||
<div class="font-weight-bold mb-4" style="font-size: var(--text-lg);">{{ quiz.title }}</div>
|
<div class="font-weight-bold mb-4" style="font-size: var(--text-lg);">{{ quiz.title }}</div>
|
||||||
<div> {{ _("You have already exceeded the maximum number of attempts allowed for this quiz.") }} </div>
|
<div class="alert alert-info medium mb-0">
|
||||||
<div> {{ _("Your latest score is {0}.").format(last_attempt_score) }} </div>
|
{{ _("You have already exceeded the maximum number of attempts allowed for this quiz.") }}
|
||||||
|
{{ _("Your latest score is {0}.").format(last_attempt_score) }}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
{% else %}
|
{% else %}
|
||||||
<div id="quiz-title" class="hide" data-name="{{ quiz.name }}"
|
<div id="quiz-title" class="hide" data-name="{{ quiz.name }}" data-max-attempts="{{ quiz.max_attempts }}">
|
||||||
data-max-attempts="{{ quiz.max_attempts }}">{{ quiz.title }}</div>
|
{{ quiz.title }}
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="">
|
<div class="">
|
||||||
<div id="start-banner" class="text-center">
|
<div id="start-banner">
|
||||||
<div class="font-weight-bold mb-3" style="font-size: var(--text-lg);"> {{ quiz.title }} </div>
|
<div class="font-weight-bold mb-5" style="font-size: var(--text-lg);"> {{ quiz.title }} </div>
|
||||||
<div class="mb-3">{{ _("There are {0} questions in this quiz.").format(quiz.questions | length) }}{% if quiz.max_attempts %}
|
<div class="alert alert-info medium mb-5">
|
||||||
{% set suffix = "times" if quiz.max_attempts > 1 else "time" %} {{ _("This quiz can only be taken {0} {1}. If you attempt the quiz and leave the page before submitting, the quiz will be automatically submitted.").format(quiz.max_attempts, suffix) }}{% endif %}
|
{{ _("This quiz consists of {0} questions.").format(quiz.questions | length) }}
|
||||||
{% if quiz.time %}{{ _("The quiz has a time limit. Each question will be given {0} seconds.").format(quiz.time) }}{% endif %}
|
{% if quiz.max_attempts %}
|
||||||
|
{% set suffix = "times" if quiz.max_attempts > 1 else "time" %}
|
||||||
|
{{ _("This quiz can only be taken {0} {1}. If you attempt the quiz but leave the page before submitting,
|
||||||
|
the quiz will be automatically submitted.").format(quiz.max_attempts, suffix) }}
|
||||||
|
{% endif %}
|
||||||
|
{% if quiz.time %}
|
||||||
|
{{ _("The quiz has a time limit. For each question you will be given {0} seconds.").format(quiz.time) }}
|
||||||
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<button class="button is-default m-auto btn-start-quiz"> {{ _("Start") }} </bu>
|
<button class="btn btn-secondary m-auto btn-start-quiz"> {{ _("Start the Quiz") }} </bu>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<form id="quiz-form" class="hide">
|
<form id="quiz-form" class="hide">
|
||||||
<div class="questions">
|
<div class="questions">
|
||||||
{% for question in quiz.questions %}
|
{% for question in quiz.questions %}
|
||||||
{% set instruction = _("Choose all answers that apply") if question.multiple else _("Choose 1 answer") %}
|
{% set instruction = _("Choose all answers that apply") if question.multiple else _("Choose 1 answer") %}
|
||||||
<div class="question hide"
|
|
||||||
data-question="{{ question.question }}" data-multi="{{ question.multiple }}" data-qt-index="{{ loop.index }}">
|
<div class="question hide"
|
||||||
<div class="question-header">
|
data-question="{{ question.question }}" data-multi="{{ question.multiple }}" data-qt-index="{{ loop.index }}">
|
||||||
<div class="question-number">{{ loop.index }}. </div>
|
<div class="question-header">
|
||||||
<div class="question-text">
|
<div class="question-number">{{ loop.index }}. </div>
|
||||||
{{ frappe.utils.md_to_html(question.question) }}
|
<div class="question-text">
|
||||||
|
{{ frappe.utils.md_to_html(question.question) }}
|
||||||
|
</div>
|
||||||
|
<div class="small"> {{ instruction }} </div>
|
||||||
</div>
|
</div>
|
||||||
<div class="small"> {{ instruction }} </div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{% set options = [question.option_1, question.option_2, question.option_3, question.option_4] %}
|
{% set options = [question.option_1, question.option_2, question.option_3, question.option_4] %}
|
||||||
{% for option in options %}
|
{% for option in options %}
|
||||||
{% if option %}
|
{% if option %}
|
||||||
<div class="mb-2">
|
<div class="mb-2">
|
||||||
<div class="custom-checkbox">
|
<div class="custom-checkbox">
|
||||||
<label class="quiz-label">
|
<label class="quiz-label">
|
||||||
<div class="course-meta font-weight-bold"> {{ convert_number_to_character(loop.index - 1) }}</div>
|
<div class="course-meta font-weight-bold"> {{ convert_number_to_character(loop.index - 1) }}</div>
|
||||||
<input class="option" value="{{ option | urlencode }}"
|
<input class="option" value="{{ option | urlencode }}"
|
||||||
data-correct="{{ question['is_correct_' + loop.index | string] }}" {% if question.multiple %}
|
data-correct="{{ question['is_correct_' + loop.index | string] }}" {% if question.multiple %}
|
||||||
type="checkbox" {% else %} type="radio" name="{{ question.question | urlencode }}" {% endif %}>
|
type="checkbox" {% else %} type="radio" name="{{ question.question | urlencode }}" {% endif %}>
|
||||||
<div class="option-text">{{ frappe.utils.md_to_html(option) }}</div>
|
<div class="option-text">{{ frappe.utils.md_to_html(option) }}</div>
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{% set explanation = question['explanation_' + loop.index | string] %}
|
||||||
|
{% if explanation %}
|
||||||
|
<small class="explanation ml-10 hide">{{ explanation }}</small>
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
{% endfor %}
|
||||||
|
|
||||||
{% set explanation = question['explanation_' + loop.index | string] %}
|
|
||||||
{% if explanation %}
|
|
||||||
<small class="explanation ml-10 hide">{{ explanation }}</small>
|
|
||||||
{% endif %}
|
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
</div>
|
||||||
|
|
||||||
</div>
|
<div class="quiz-footer">
|
||||||
{% endfor %}
|
<span class="font-weight-bold"> <span class="current-question">1</span> of {{ quiz.questions | length }}</span>
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="quiz-footer">
|
{% if quiz.time %}
|
||||||
<span class="font-weight-bold"> <span class="current-question">1</span> of {{ quiz.questions | length }}</span>
|
<div class="progress timer w-75" data-time="{{ quiz.time }}">
|
||||||
|
<div class="progress-bar" role="progressbar" aria-valuenow="100" aria-valuemin="0"
|
||||||
|
aria-valuemax="100"style="width:100%">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
{% if quiz.time %}
|
|
||||||
<div class="progress timer w-75" data-time="{{ quiz.time }}">
|
<button class="button pull-right is-default" id="check" disabled>
|
||||||
<div class="progress-bar" role="progressbar" aria-valuenow="100" aria-valuemin="0" aria-valuemax="100" style="width:100%">
|
{{ _("Check") }}
|
||||||
|
</button>
|
||||||
|
<div class="button is-secondary hide" id="next">
|
||||||
|
{{ _("Next Question") }}
|
||||||
|
</div>
|
||||||
|
<div class="button is-secondary is-default hide" id="summary">
|
||||||
|
{{ _("Submit") }}
|
||||||
|
</div>
|
||||||
|
<small id="submission-message" class="font-weight-bold hide">
|
||||||
|
{{ _("Please join the course to submit the Quiz.") }}
|
||||||
|
</small>
|
||||||
|
<div class="button is-secondary hide" id="try-again">
|
||||||
|
{{ _("Try Again") }}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
</form>
|
||||||
|
|
||||||
<button class="button pull-right is-default" id="check" disabled>{{ _("Check") }}</button>
|
|
||||||
<div class="button is-secondary hide" id="next">{{ _("Next Question") }}</div>
|
|
||||||
<div class="button is-secondary is-default hide" id="summary">{{ _("Submit") }}</div>
|
|
||||||
<small id="submission-message" class="font-weight-bold hide"> {{ _("Please join the course to submit the Quiz.") }} </small>
|
|
||||||
<div class="button is-secondary hide" id="try-again">{{ _("Try Again") }}</div>
|
|
||||||
</div>
|
|
||||||
</form>
|
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|||||||
@@ -114,7 +114,7 @@
|
|||||||
{% if show_lesson %}
|
{% if show_lesson %}
|
||||||
|
|
||||||
{% if is_instructor and not lesson.include_in_preview and not lesson.edit_mode %}
|
{% if is_instructor and not lesson.include_in_preview and not lesson.edit_mode %}
|
||||||
<div class="small alert alert-secondary alert-dismissible mb-4">
|
<div class="medium alert alert-info alert-dismissible mb-4">
|
||||||
{{ _("This lesson is not available for preview. As you are the Instructor of the course only you can see it.") }}
|
{{ _("This lesson is not available for preview. As you are the Instructor of the course only you can see it.") }}
|
||||||
<a href="#" class="close" data-dismiss="alert" aria-label="close">×</a>
|
<a href="#" class="close" data-dismiss="alert" aria-label="close">×</a>
|
||||||
</div>
|
</div>
|
||||||
@@ -127,13 +127,11 @@
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{% else %}
|
{% else %}
|
||||||
{% set course_link = "<a class='join-batch' data-course=" + course.name | urlencode + " href=''>" + _('here') + "</a>" %}
|
{% set course_link = "<a class='join-batch' data-course=" + course.name | urlencode + " href=''>" + _('here') + "</a>" %}
|
||||||
<div class="">
|
<div class="alert alert-info medium mb-0">
|
||||||
<div>
|
{{ _("There is no preview available for this lesson.
|
||||||
{{ _("There is no preview available for this lesson.
|
Please join the course to access it.
|
||||||
Please join the course to access it.
|
Click {0} to enroll.").format(course_link) }}
|
||||||
Click {0} to enroll.").format(course_link) }}
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
@@ -148,6 +146,7 @@
|
|||||||
|
|
||||||
<!-- Pagination -->
|
<!-- Pagination -->
|
||||||
{% macro pagination(prev_url, next_url) %}
|
{% macro pagination(prev_url, next_url) %}
|
||||||
|
{% if prev_url or next_url %}
|
||||||
<div class="lesson-pagination">
|
<div class="lesson-pagination">
|
||||||
{% if prev_url %}
|
{% if prev_url %}
|
||||||
<div>
|
<div>
|
||||||
@@ -165,6 +164,7 @@
|
|||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
|
{% endif %}
|
||||||
{% endmacro %}
|
{% endmacro %}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
frappe.ready(() => {
|
frappe.ready(() => {
|
||||||
|
|
||||||
this.marked_as_complete = false;
|
this.marked_as_complete = false;
|
||||||
|
this.quiz_submitted = false;
|
||||||
|
|
||||||
localStorage.removeItem($("#quiz-title").data("name"));
|
localStorage.removeItem($("#quiz-title").data("name"));
|
||||||
|
|
||||||
@@ -76,9 +77,12 @@ frappe.ready(() => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if ($("#quiz-title").data("max-attempts")) {
|
if ($("#quiz-title").data("max-attempts")) {
|
||||||
|
let self = this;
|
||||||
window.addEventListener("beforeunload", (e) => {
|
window.addEventListener("beforeunload", (e) => {
|
||||||
e.returnValue = "";
|
e.returnValue = "";
|
||||||
$(".active-question").length && quiz_summary();
|
if ($(".active-question").length && !self.quiz_submitted) {
|
||||||
|
quiz_summary();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -157,6 +161,7 @@ const quiz_summary = (e=undefined) => {
|
|||||||
e && e.preventDefault();
|
e && e.preventDefault();
|
||||||
let quiz_name = $("#quiz-title").data("name");
|
let quiz_name = $("#quiz-title").data("name");
|
||||||
let total_questions = $(".question").length;
|
let total_questions = $(".question").length;
|
||||||
|
let self = this;
|
||||||
|
|
||||||
frappe.call({
|
frappe.call({
|
||||||
method: "lms.lms.doctype.lms_quiz.lms_quiz.quiz_summary",
|
method: "lms.lms.doctype.lms_quiz.lms_quiz.quiz_summary",
|
||||||
@@ -169,9 +174,12 @@ const quiz_summary = (e=undefined) => {
|
|||||||
$(".question").addClass("hide");
|
$(".question").addClass("hide");
|
||||||
$("#summary").addClass("hide");
|
$("#summary").addClass("hide");
|
||||||
$("#quiz-form").parent().prepend(
|
$("#quiz-form").parent().prepend(
|
||||||
`<div class="text-center summary"><h2> ${message} </h2>
|
`<div class="text-center summary">
|
||||||
<div class="font-weight-bold">${data.message}/${total_questions}</div></div>`);
|
<h2> ${message} </h2>
|
||||||
|
<div class="font-weight-bold"> ${data.message}/${total_questions} </div>
|
||||||
|
</div>`);
|
||||||
$("#try-again").removeClass("hide");
|
$("#try-again").removeClass("hide");
|
||||||
|
self.quiz_submitted = true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@@ -232,7 +240,7 @@ const add_icon = (element, icon) => {
|
|||||||
let label = $(element).siblings(".option-text").text();
|
let label = $(element).siblings(".option-text").text();
|
||||||
$(element).siblings(".option-text").html(`
|
$(element).siblings(".option-text").html(`
|
||||||
<div>
|
<div>
|
||||||
<img class="mr-3" src="/assets/lms/icons/${icon}.svg">
|
<img class="d-inline mr-3" src="/assets/lms/icons/${icon}.svg">
|
||||||
${label}
|
${label}
|
||||||
</div>
|
</div>
|
||||||
`);
|
`);
|
||||||
|
|||||||
Reference in New Issue
Block a user