fix: quiz list in lesson page
This commit is contained in:
@@ -57,7 +57,7 @@
|
|||||||
"index_web_pages_for_search": 1,
|
"index_web_pages_for_search": 1,
|
||||||
"istable": 1,
|
"istable": 1,
|
||||||
"links": [],
|
"links": [],
|
||||||
"modified": "2023-08-24 17:48:53.045539",
|
"modified": "2023-09-12 16:46:41.042810",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "LMS",
|
"module": "LMS",
|
||||||
"name": "Batch Student",
|
"name": "Batch Student",
|
||||||
|
|||||||
@@ -20,7 +20,6 @@ class LMSCourse(Document):
|
|||||||
self.image = validate_image(self.image)
|
self.image = validate_image(self.image)
|
||||||
|
|
||||||
def validate_instructors(self):
|
def validate_instructors(self):
|
||||||
print(self.is_new(), not self.instructors)
|
|
||||||
if self.is_new() and not self.instructors:
|
if self.is_new() and not self.instructors:
|
||||||
frappe.get_doc(
|
frappe.get_doc(
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -116,15 +116,6 @@
|
|||||||
|
|
||||||
{%- block script %}
|
{%- block script %}
|
||||||
{{ super() }}
|
{{ super() }}
|
||||||
{% if is_moderator %}
|
|
||||||
<script>
|
|
||||||
frappe.boot.user = {
|
|
||||||
"can_create": [],
|
|
||||||
"can_select": ["LMS Quiz"],
|
|
||||||
"can_read": ["LMS Quiz"]
|
|
||||||
};
|
|
||||||
</script>
|
|
||||||
{% endif %}
|
|
||||||
<script src="https://cdn.jsdelivr.net/npm/@editorjs/editorjs@latest"></script>
|
<script src="https://cdn.jsdelivr.net/npm/@editorjs/editorjs@latest"></script>
|
||||||
<script src="https://cdn.jsdelivr.net/npm/@editorjs/paragraph@latest"></script>
|
<script src="https://cdn.jsdelivr.net/npm/@editorjs/paragraph@latest"></script>
|
||||||
<script src="https://cdn.jsdelivr.net/npm/@editorjs/header@latest"></script>
|
<script src="https://cdn.jsdelivr.net/npm/@editorjs/header@latest"></script>
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
frappe.ready(() => {
|
frappe.ready(() => {
|
||||||
let self = this;
|
let self = this;
|
||||||
this.quiz_in_lesson = [];
|
|
||||||
|
|
||||||
frappe.telemetry.capture("on_lesson_creation_page", "lms");
|
frappe.telemetry.capture("on_lesson_creation_page", "lms");
|
||||||
|
|
||||||
@@ -15,7 +14,6 @@ frappe.ready(() => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
setup_editor();
|
setup_editor();
|
||||||
fetch_quiz_list();
|
|
||||||
|
|
||||||
$("#save-lesson").click((e) => {
|
$("#save-lesson").click((e) => {
|
||||||
save_lesson(e);
|
save_lesson(e);
|
||||||
@@ -90,11 +88,10 @@ const parse_string_to_lesson = () => {
|
|||||||
});
|
});
|
||||||
} else if (block.includes("{{ Quiz")) {
|
} else if (block.includes("{{ Quiz")) {
|
||||||
let quiz = block.match(/'([^']+)'/)[1];
|
let quiz = block.match(/'([^']+)'/)[1];
|
||||||
this.quiz_in_lesson.push(quiz);
|
|
||||||
lesson_blocks.push({
|
lesson_blocks.push({
|
||||||
type: "quiz",
|
type: "quiz",
|
||||||
data: {
|
data: {
|
||||||
quiz: [quiz],
|
quiz: quiz,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
} else if (block.includes("{{ Video")) {
|
} else if (block.includes("{{ Video")) {
|
||||||
@@ -156,9 +153,7 @@ const parse_lesson_to_string = (data) => {
|
|||||||
if (block.type == "youtube") {
|
if (block.type == "youtube") {
|
||||||
lesson_content += `{{ YouTubeVideo("${block.data.youtube}") }}\n`;
|
lesson_content += `{{ YouTubeVideo("${block.data.youtube}") }}\n`;
|
||||||
} else if (block.type == "quiz") {
|
} else if (block.type == "quiz") {
|
||||||
block.data.quiz.forEach((quiz) => {
|
lesson_content += `{{ Quiz("${block.data.quiz}") }}\n`;
|
||||||
lesson_content += `{{ Quiz("${quiz}") }}\n`;
|
|
||||||
});
|
|
||||||
} else if (block.type == "upload") {
|
} else if (block.type == "upload") {
|
||||||
let url = block.data.file_url;
|
let url = block.data.file_url;
|
||||||
lesson_content += block.data.is_video
|
lesson_content += block.data.is_video
|
||||||
@@ -233,15 +228,6 @@ const validate_mandatory = (lesson_content) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const fetch_quiz_list = () => {
|
|
||||||
frappe.call({
|
|
||||||
method: "lms.lms.doctype.lms_quiz.lms_quiz.get_user_quizzes",
|
|
||||||
callback: (r) => {
|
|
||||||
self.quiz_list = r.message;
|
|
||||||
},
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
const is_video = (url) => {
|
const is_video = (url) => {
|
||||||
let video_types = ["mov", "mp4", "mkv"];
|
let video_types = ["mov", "mp4", "mkv"];
|
||||||
let video_extension = url.split(".").pop();
|
let video_extension = url.split(".").pop();
|
||||||
@@ -339,57 +325,10 @@ class Quiz {
|
|||||||
this.data = data;
|
this.data = data;
|
||||||
}
|
}
|
||||||
|
|
||||||
get_fields() {
|
|
||||||
let fields = [
|
|
||||||
{
|
|
||||||
fieldname: "start_section",
|
|
||||||
fieldtype: "Section Break",
|
|
||||||
label: __(
|
|
||||||
"To create a new quiz, click on the button below. Once you have created the new quiz you can come back to this lesson and add it from here."
|
|
||||||
),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
fieldname: "create_quiz",
|
|
||||||
fieldtype: "Button",
|
|
||||||
label: __("Create Quiz"),
|
|
||||||
click: () => {
|
|
||||||
window.location.href = "/quizzes";
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
fieldname: "quiz_information",
|
|
||||||
fieldtype: "HTML",
|
|
||||||
options: __("OR"),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
fieldname: "quiz_list_section",
|
|
||||||
fieldtype: "Section Break",
|
|
||||||
label: __("Select a exisitng quiz to add to this lesson."),
|
|
||||||
},
|
|
||||||
];
|
|
||||||
let break_index = Math.ceil(self.quiz_list.length / 2) + 4;
|
|
||||||
|
|
||||||
self.quiz_list.forEach((quiz) => {
|
|
||||||
fields.push({
|
|
||||||
fieldname: quiz.name,
|
|
||||||
fieldtype: "Check",
|
|
||||||
label: quiz.title,
|
|
||||||
default: self.quiz_in_lesson.includes(quiz.name) ? 1 : 0,
|
|
||||||
read_only: self.quiz_in_lesson.includes(quiz.name) ? 1 : 0,
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
fields.splice(break_index, 0, {
|
|
||||||
fieldname: "column_break",
|
|
||||||
fieldtype: "Column Break",
|
|
||||||
});
|
|
||||||
return fields;
|
|
||||||
}
|
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
this.wrapper = document.createElement("div");
|
this.wrapper = document.createElement("div");
|
||||||
if (this.data && this.data.quiz) {
|
if (this.data && this.data.quiz) {
|
||||||
$(this.wrapper).html(this.render_quiz());
|
$(this.wrapper).html(this.render_quiz(this.data.quiz));
|
||||||
} else {
|
} else {
|
||||||
this.render_quiz_dialog();
|
this.render_quiz_dialog();
|
||||||
}
|
}
|
||||||
@@ -398,16 +337,24 @@ class Quiz {
|
|||||||
|
|
||||||
render_quiz_dialog() {
|
render_quiz_dialog() {
|
||||||
let me = this;
|
let me = this;
|
||||||
let fields = this.get_fields();
|
|
||||||
let quizdialog = new frappe.ui.Dialog({
|
let quizdialog = new frappe.ui.Dialog({
|
||||||
title: __("Manage Quiz"),
|
title: __("Manage Quiz"),
|
||||||
fields: fields,
|
fields: [
|
||||||
|
{
|
||||||
|
fieldname: "quiz",
|
||||||
|
fieldtype: "Link",
|
||||||
|
label: __("Quiz"),
|
||||||
|
options: "LMS Quiz",
|
||||||
|
only_select: 1,
|
||||||
|
},
|
||||||
|
],
|
||||||
primary_action_label: __("Insert"),
|
primary_action_label: __("Insert"),
|
||||||
primary_action(values) {
|
primary_action(values) {
|
||||||
me.analyze_quiz_list(values);
|
me.quiz = values.quiz;
|
||||||
quizdialog.hide();
|
quizdialog.hide();
|
||||||
|
$(me.wrapper).html(me.render_quiz(me.quiz));
|
||||||
},
|
},
|
||||||
secondary_action_label: __("Create New Quiz"),
|
secondary_action_label: __("Create New"),
|
||||||
secondary_action: () => {
|
secondary_action: () => {
|
||||||
window.location.href = `/quizzes`;
|
window.location.href = `/quizzes`;
|
||||||
},
|
},
|
||||||
@@ -419,38 +366,19 @@ class Quiz {
|
|||||||
}, 1000);
|
}, 1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
analyze_quiz_list(values) {
|
render_quiz(quiz) {
|
||||||
/* If quiz is selected and is not already in the lesson then render it.*/
|
return `<div class="common-card-style p-2 my-2 bold-heading">
|
||||||
|
|
||||||
this.quiz_to_render = [];
|
|
||||||
Object.keys(values).forEach((key) => {
|
|
||||||
if (values[key] === 1 && !self.quiz_in_lesson.includes(key)) {
|
|
||||||
self.quiz_in_lesson.push(key);
|
|
||||||
this.quiz_to_render.push(key);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
$(this.wrapper).html(this.render_quiz());
|
|
||||||
}
|
|
||||||
|
|
||||||
render_quiz() {
|
|
||||||
let html = ``;
|
|
||||||
let quiz_list = this.data.quiz || this.quiz_to_render;
|
|
||||||
quiz_list.forEach((quiz) => {
|
|
||||||
html += `<div class="common-card-style p-2 my-2 bold-heading">
|
|
||||||
Quiz: ${quiz}
|
Quiz: ${quiz}
|
||||||
</div>`;
|
</div>`;
|
||||||
});
|
|
||||||
return html;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
validate(savedData) {
|
validate(savedData) {
|
||||||
return !savedData.quiz || !savedData.quiz.length ? false : true;
|
return !savedData.quiz || !savedData.quiz.trim() ? false : true;
|
||||||
}
|
}
|
||||||
|
|
||||||
save(block_content) {
|
save(block_content) {
|
||||||
return {
|
return {
|
||||||
quiz: this.data.quiz || this.quiz_to_render,
|
quiz: this.data.quiz || this.quiz,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user