feat: update quiz
This commit is contained in:
@@ -21,7 +21,7 @@
|
||||
|
||||
{% macro BreadCrumb(quiz) %}
|
||||
<div class="breadcrumb">
|
||||
<a class="dark-links" href="/courses">{{ _("Quizzes") }}</a>
|
||||
<a class="dark-links" href="/quizzes">{{ _("Quizzes") }}</a>
|
||||
<img class="ml-1 mr-1" src="/assets/lms/icons/chevron-right.svg">
|
||||
<span class="breadcrumb-destination">{{ quiz.title if quiz.title else _("New Quiz") }}</span>
|
||||
</div>
|
||||
@@ -32,42 +32,45 @@
|
||||
<div style="width: 60%;">
|
||||
|
||||
<div class="course-home-headings mb-2" data-placeholder="{{ _('Quiz Title') }}" id="quiz-title"
|
||||
contenteditable="true">{% if quiz.title %}{{ quiz.title }}{% endif %}</div>
|
||||
|
||||
<div class="mt-4">
|
||||
<button class="btn btn-secondary btn-sm btn-question"> {{ _("New Question") }} </button>
|
||||
<button class="btn btn-primary btn-sm btn-save-question ml-2 hide"> {{ _("Save") }} </button>
|
||||
</div>
|
||||
{% if quiz.name %} data-name="{{ quiz.name }}" {% endif %}
|
||||
contenteditable="true" >{% if quiz.title %}{{ quiz.title }}{% endif %}</div>
|
||||
|
||||
|
||||
{% if quiz.question %}
|
||||
{% if quiz.questions %}
|
||||
{% for question in quiz.questions %}
|
||||
<div class="quiz-card">
|
||||
<div contenteditable="true" data-placeholder="{{ _('Question') }}"
|
||||
class="mb-4">{% if question.question %} {{ question.question }} {% endif %}</div>
|
||||
<div contenteditable="true" data-placeholder="{{ _('Question') }}" data-question="{{ question.name }}"
|
||||
class="question mb-4">{% if question.question %} {{ question.question }} {% endif %}</div>
|
||||
|
||||
{% for num in range(1,5) %}
|
||||
{% set option = question["option_" + frappe.utils.cstr(num)] %}
|
||||
{% set explanation = question["explanation_" + frappe.utils.cstr(num)] %}
|
||||
{% for i in range(1,5) %}
|
||||
{% set num = frappe.utils.cstr(i) %}
|
||||
{% set option = question["option_" + num] %}
|
||||
{% set explanation = question["explanation_" + num] %}
|
||||
|
||||
<div class="mt-4">
|
||||
<label class=""> {{ _("Option") }} {{ frappe.utils.cstr(num) }} </label>
|
||||
<div class="d-flex justify-content-between">
|
||||
<label class=""> {{ _("Option") }} {{ num }} </label>
|
||||
<div class="d-flex justify-content-between option-{{ num }}">
|
||||
<div contenteditable="true" data-placeholder="{{ _('Option') }}"
|
||||
class="option-input">{% if option %}{{ option }}{% endif %}</div>
|
||||
<div contenteditable="true" data-placeholder="{{ _('Explanation') }}"
|
||||
class="option-input">{% if explanation %}{{ explanation }}{% endif %}</div>
|
||||
<div class="option-checkbox">
|
||||
<input type="checkbox" {% if question['is_correct_' + frappe.utils.cstr(num)] %} checked {% endif %}>
|
||||
<input type="checkbox" {% if question['is_correct_' + num] %} checked {% endif %}>
|
||||
<label class="mb-0"> {{ _("Is Correct") }} </label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
|
||||
|
||||
<div class="mt-4">
|
||||
<button class="btn btn-secondary btn-sm btn-question"> {{ _("New Question") }} </button>
|
||||
<button class="btn btn-primary btn-sm btn-save-question ml-2
|
||||
{% if not quiz.name %} hide {% endif %}"> {{ _("Save") }} </button>
|
||||
</div>
|
||||
</div>
|
||||
{% endmacro %}
|
||||
|
||||
|
||||
@@ -8,6 +8,8 @@ frappe.ready(() => {
|
||||
save_question(e);
|
||||
});
|
||||
|
||||
get_questions()
|
||||
|
||||
});
|
||||
|
||||
|
||||
@@ -56,7 +58,8 @@ const save_question = (e) => {
|
||||
method: "lms.lms.doctype.lms_quiz.lms_quiz.save_quiz",
|
||||
args: {
|
||||
"quiz_title": $("#quiz-title").text(),
|
||||
"questions": get_questions()
|
||||
"questions": get_questions(),
|
||||
"quiz": $("#quiz-title").data("name") || ""
|
||||
},
|
||||
callback: (data) => {
|
||||
window.location.href = "/quizzes";
|
||||
@@ -69,16 +72,17 @@ const get_questions = () => {
|
||||
let questions = [];
|
||||
|
||||
$(".quiz-card").each((i, el) => {
|
||||
|
||||
if (!$(el).find(".question").text())
|
||||
return;
|
||||
|
||||
let details = {};
|
||||
let one_correct_option = false;
|
||||
details["question"] = $(el).find(".question").text();
|
||||
details["question_name"] = $(el).find(".question").data("question") || "";
|
||||
|
||||
Array.from({length: 4}, (x, i) => {
|
||||
let num = i + 1;
|
||||
|
||||
details[`option_${num}`] = $(el).find(`.option-${num} .option-input:first`).text();
|
||||
details[`explanation_${num}`] = $(el).find(`.option-${num} .option-input:last`).text();
|
||||
|
||||
@@ -89,12 +93,12 @@ const get_questions = () => {
|
||||
details[`is_correct_${num}`] = is_correct;
|
||||
});
|
||||
|
||||
if (!details["option_1"] || !details["option_2"]) {
|
||||
if (!details["option_1"] || !details["option_2"])
|
||||
frappe.throw(__("Each question must have at least two options."))
|
||||
}
|
||||
|
||||
if (!one_correct_option)
|
||||
frappe.throw(__("Each question must have at least one correct option."))
|
||||
|
||||
questions.push(details);
|
||||
});
|
||||
|
||||
|
||||
@@ -8,13 +8,14 @@ def get_context(context):
|
||||
context.quiz = frappe._dict()
|
||||
context.quiz.edit_mode = 1
|
||||
else:
|
||||
fields_arr = []
|
||||
fields_arr = ["name","question"]
|
||||
for num in range(1,5):
|
||||
fields_arr.append("option_" + cstr(num))
|
||||
fields_arr.append("is_correct_" + cstr(num))
|
||||
fields_arr.append("explanation_" + cstr(num))
|
||||
fields_arr.append("question")
|
||||
context.quiz = frappe.db.get_value("LMS Quiz", quizname, ["title"], as_dict=1)
|
||||
|
||||
context.quiz = frappe.db.get_value("LMS Quiz", quizname, ["title", "name"], as_dict=1)
|
||||
context.quiz.questions = frappe.get_all("LMS Quiz Question", {
|
||||
"parent": quizname
|
||||
}, fields_arr)
|
||||
}, fields_arr,
|
||||
order_by="idx")
|
||||
|
||||
@@ -17,13 +17,17 @@
|
||||
<div class="course-home-headings"> {{ _("Quiz List") }} </div>
|
||||
<div class="common-card-style">
|
||||
<table class="table">
|
||||
<tr>
|
||||
<td style="width: 5%;"> {{ _("No.") }} </td>
|
||||
<td> {{ _("Quiz") }} </td>
|
||||
<tr style="background-color: var(--fg-hover-color); font-weight: bold">
|
||||
<td style="width: 10%;"> {{ _("No.") }} </td>
|
||||
<td style="width: 45%;"> {{ _("Title") }} </td>
|
||||
<td> {{ _("ID") }} </td>
|
||||
</tr>
|
||||
{% for quiz in quiz_list %}
|
||||
<tr style="position: relative; color: var(--text-color);">
|
||||
<td> {{ loop.index }} </td>
|
||||
<td>
|
||||
<a class="button-links" href="/quizzes/{{ quiz.name }}">{{ quiz.title }}</a>
|
||||
</td>
|
||||
<td>
|
||||
<a class="button-links" href="/quizzes/{{ quiz.name }}">{{ quiz.name }}</a>
|
||||
</td>
|
||||
|
||||
Reference in New Issue
Block a user