Merge pull request #400 from pateljannat/quiz-submission

This commit is contained in:
Jannat Patel
2022-10-11 10:13:18 +05:30
committed by GitHub
5 changed files with 127 additions and 75 deletions

View File

@@ -6,8 +6,11 @@
"engine": "InnoDB",
"field_order": [
"member",
"member_name",
"column_break_3",
"quiz",
"score",
"section_break_6",
"result"
],
"fields": [
@@ -38,12 +41,26 @@
"in_standard_filter": 1,
"label": "Member",
"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,
"index_web_pages_for_search": 1,
"links": [],
"modified": "2022-06-20 10:13:23.013802",
"modified": "2022-10-10 18:57:42.813738",
"modified_by": "Administrator",
"module": "LMS",
"name": "LMS Quiz Submission",
@@ -65,5 +82,6 @@
"sort_field": "modified",
"sort_order": "DESC",
"states": [],
"title_field": "member_name",
"track_changes": 1
}

View File

@@ -573,7 +573,7 @@ input[type=checkbox] {
}
.lesson-content-card {
margin: 2rem 0 3rem;
margin-top: 2rem;
}
.lesson-content-card .alert-dismissible .close {
@@ -599,9 +599,10 @@ input[type=checkbox] {
}
.lesson-pagination {
display: flex;
justify-content: space-between;
align-items: center;
display: flex;
justify-content: space-between;
align-items: center;
margin-top: 2rem
}
.lesson-pagination-parent {

View File

@@ -1,80 +1,105 @@
{% 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> {{ _("You have already exceeded the maximum number of attempts allowed for this quiz.") }} </div>
<div> {{ _("Your latest score is {0}.").format(last_attempt_score) }} </div>
<div class="alert alert-info medium mb-0">
{{ _("You have already exceeded the maximum number of attempts allowed for this quiz.") }}
{{ _("Your latest score is {0}.").format(last_attempt_score) }}
</div>
</div>
{% else %}
<div id="quiz-title" class="hide" data-name="{{ quiz.name }}"
data-max-attempts="{{ quiz.max_attempts }}">{{ quiz.title }}</div>
<div id="quiz-title" class="hide" data-name="{{ quiz.name }}" data-max-attempts="{{ quiz.max_attempts }}">
{{ quiz.title }}
</div>
<div class="">
<div id="start-banner" class="text-center">
<div class="font-weight-bold mb-3" 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 %}
{% 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 %}
{% if quiz.time %}{{ _("The quiz has a time limit. Each question will be given {0} seconds.").format(quiz.time) }}{% endif %}
<div id="start-banner">
<div class="font-weight-bold mb-5" style="font-size: var(--text-lg);"> {{ quiz.title }} </div>
<div class="alert alert-info medium mb-5">
{{ _("This quiz consists of {0} questions.").format(quiz.questions | length) }}
{% 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>
<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>
<form id="quiz-form" class="hide">
<div class="questions">
{% for question in quiz.questions %}
{% 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-header">
<div class="question-number">{{ loop.index }}. </div>
<div class="question-text">
{{ frappe.utils.md_to_html(question.question) }}
<form id="quiz-form" class="hide">
<div class="questions">
{% for question in quiz.questions %}
{% 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-header">
<div class="question-number">{{ loop.index }}. </div>
<div class="question-text">
{{ frappe.utils.md_to_html(question.question) }}
</div>
<div class="small"> {{ instruction }} </div>
</div>
<div class="small"> {{ instruction }} </div>
</div>
{% set options = [question.option_1, question.option_2, question.option_3, question.option_4] %}
{% for option in options %}
{% if option %}
<div class="mb-2">
<div class="custom-checkbox">
<label class="quiz-label">
<div class="course-meta font-weight-bold"> {{ convert_number_to_character(loop.index - 1) }}</div>
<input class="option" value="{{ option | urlencode }}"
data-correct="{{ question['is_correct_' + loop.index | string] }}" {% if question.multiple %}
type="checkbox" {% else %} type="radio" name="{{ question.question | urlencode }}" {% endif %}>
<div class="option-text">{{ frappe.utils.md_to_html(option) }}</div>
</label>
</div>
{% set options = [question.option_1, question.option_2, question.option_3, question.option_4] %}
{% for option in options %}
{% if option %}
<div class="mb-2">
<div class="custom-checkbox">
<label class="quiz-label">
<div class="course-meta font-weight-bold"> {{ convert_number_to_character(loop.index - 1) }}</div>
<input class="option" value="{{ option | urlencode }}"
data-correct="{{ question['is_correct_' + loop.index | string] }}" {% if question.multiple %}
type="checkbox" {% else %} type="radio" name="{{ question.question | urlencode }}" {% endif %}>
<div class="option-text">{{ frappe.utils.md_to_html(option) }}</div>
</label>
</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>
{% endif %}
{% endfor %}
</div>
</div>
{% endfor %}
</div>
<div class="quiz-footer">
<span class="font-weight-bold"> <span class="current-question">1</span> of {{ quiz.questions | length }}</span>
<div class="quiz-footer">
<span class="font-weight-bold"> <span class="current-question">1</span> of {{ quiz.questions | length }}</span>
{% if quiz.time %}
<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 }}">
<div class="progress-bar" role="progressbar" aria-valuenow="100" aria-valuemin="0" aria-valuemax="100" style="width:100%">
<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>
{% endif %}
<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>
</form>
</div>
{% endif %}

View File

@@ -114,7 +114,7 @@
{% if show_lesson %}
{% 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.") }}
<a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a>
</div>
@@ -127,13 +127,11 @@
{% endif %}
{% else %}
{% set course_link = "<a class='join-batch' data-course=" + course.name | urlencode + " href=''>" + _('here') + "</a>" %}
<div class="">
<div>
{{ _("There is no preview available for this lesson.
Please join the course to access it.
Click {0} to enroll.").format(course_link) }}
</div>
{% set course_link = "<a class='join-batch' data-course=" + course.name | urlencode + " href=''>" + _('here') + "</a>" %}
<div class="alert alert-info medium mb-0">
{{ _("There is no preview available for this lesson.
Please join the course to access it.
Click {0} to enroll.").format(course_link) }}
</div>
{% endif %}
</div>
@@ -148,6 +146,7 @@
<!-- Pagination -->
{% macro pagination(prev_url, next_url) %}
{% if prev_url or next_url %}
<div class="lesson-pagination">
{% if prev_url %}
<div>
@@ -165,6 +164,7 @@
</div>
{% endif %}
</div>
{% endif %}
{% endmacro %}

View File

@@ -1,6 +1,7 @@
frappe.ready(() => {
this.marked_as_complete = false;
this.quiz_submitted = false;
localStorage.removeItem($("#quiz-title").data("name"));
@@ -76,9 +77,12 @@ frappe.ready(() => {
});
if ($("#quiz-title").data("max-attempts")) {
let self = this;
window.addEventListener("beforeunload", (e) => {
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();
let quiz_name = $("#quiz-title").data("name");
let total_questions = $(".question").length;
let self = this;
frappe.call({
method: "lms.lms.doctype.lms_quiz.lms_quiz.quiz_summary",
@@ -169,9 +174,12 @@ const quiz_summary = (e=undefined) => {
$(".question").addClass("hide");
$("#summary").addClass("hide");
$("#quiz-form").parent().prepend(
`<div class="text-center summary"><h2> ${message} </h2>
<div class="font-weight-bold">${data.message}/${total_questions}</div></div>`);
`<div class="text-center summary">
<h2> ${message} </h2>
<div class="font-weight-bold"> ${data.message}/${total_questions} </div>
</div>`);
$("#try-again").removeClass("hide");
self.quiz_submitted = true;
}
});
};
@@ -232,7 +240,7 @@ const add_icon = (element, icon) => {
let label = $(element).siblings(".option-text").text();
$(element).siblings(".option-text").html(`
<div>
<img class="mr-3" src="/assets/lms/icons/${icon}.svg">
<img class="d-inline mr-3" src="/assets/lms/icons/${icon}.svg">
${label}
</div>
`);