From 677dc59399d2b5974a402dc589013013d69078a9 Mon Sep 17 00:00:00 2001 From: Jannat Patel Date: Thu, 31 Aug 2023 11:49:51 +0530 Subject: [PATCH 1/5] feat: instructor notes --- .../doctype/course_lesson/course_lesson.json | 8 ++++- lms/lms/doctype/lms_course/lms_course.py | 2 ++ lms/lms/utils.py | 1 + lms/www/batch/edit.html | 14 ++++++++- lms/www/batch/edit.js | 29 ++++++++++++++++++- lms/www/batch/learn.html | 15 ++++++++-- lms/www/batch/learn.py | 18 ++++++++---- 7 files changed, 77 insertions(+), 10 deletions(-) diff --git a/lms/lms/doctype/course_lesson/course_lesson.json b/lms/lms/doctype/course_lesson/course_lesson.json index eaee75f2..dc224a69 100644 --- a/lms/lms/doctype/course_lesson/course_lesson.json +++ b/lms/lms/doctype/course_lesson/course_lesson.json @@ -23,6 +23,7 @@ "column_break_15", "file_type", "section_break_11", + "instructor_notes", "body", "help_section", "help" @@ -131,11 +132,16 @@ { "fieldname": "column_break_15", "fieldtype": "Column Break" + }, + { + "fieldname": "instructor_notes", + "fieldtype": "Text Editor", + "label": "Instructor Notes" } ], "index_web_pages_for_search": 1, "links": [], - "modified": "2023-05-02 12:42:16.926753", + "modified": "2023-08-31 11:11:22.034553", "modified_by": "Administrator", "module": "LMS", "name": "Course Lesson", diff --git a/lms/lms/doctype/lms_course/lms_course.py b/lms/lms/doctype/lms_course/lms_course.py index 6b51022d..27384f3f 100644 --- a/lms/lms/doctype/lms_course/lms_course.py +++ b/lms/lms/doctype/lms_course/lms_course.py @@ -281,6 +281,7 @@ def save_lesson( preview, idx, lesson, + instructor_notes=None, youtube=None, quiz_id=None, question=None, @@ -296,6 +297,7 @@ def save_lesson( "chapter": chapter, "title": title, "body": body, + "instructor_notes": instructor_notes, "include_in_preview": preview, "youtube": youtube, "quiz_id": quiz_id, diff --git a/lms/lms/utils.py b/lms/lms/utils.py index f41480b5..f101e9f0 100644 --- a/lms/lms/utils.py +++ b/lms/lms/utils.py @@ -141,6 +141,7 @@ def get_lesson_details(chapter): "quiz_id", "question", "file_type", + "instructor_notes", ], as_dict=True, ) diff --git a/lms/www/batch/edit.html b/lms/www/batch/edit.html index 6fa88e22..9c10c042 100644 --- a/lms/www/batch/edit.html +++ b/lms/www/batch/edit.html @@ -86,6 +86,19 @@ +
+
+ {{ _("Instructor Notes") }} +
+
+ {{ _("This notes will only be visible to the Course Creator, Course Evaluaor and Moderator.") }} +
+
+ {% if lesson.instructor_notes %} +
{{ lesson.instructor_notes }}
+ {% endif %} +
+
@@ -117,7 +130,6 @@ }; {% endif %} - {{ include_script('controls.bundle.js') }} diff --git a/lms/www/batch/edit.js b/lms/www/batch/edit.js index dd0ae722..6b050957 100644 --- a/lms/www/batch/edit.js +++ b/lms/www/batch/edit.js @@ -1,7 +1,15 @@ frappe.ready(() => { - frappe.telemetry.capture("on_lesson_creation_page", "lms"); let self = this; this.quiz_in_lesson = []; + + frappe.telemetry.capture("on_lesson_creation_page", "lms"); + + if ($("#instructor-notes").length) { + frappe.require("controls.bundle.js", () => { + make_instructor_notes_component(); + }); + } + if ($("#current-lesson-content").length) { parse_string_to_lesson(); } @@ -149,6 +157,8 @@ const save = (lesson_content) => { preview: $("#preview").prop("checked") ? 1 : 0, idx: $("#lesson-title").data("index"), lesson: lesson ? lesson : "", + instructor_notes: + this.instructor_notes.get_values().instructor_notes, }, callback: (data) => { frappe.show_alert({ @@ -466,3 +476,20 @@ class Upload { }; } } + +const make_instructor_notes_component = () => { + this.instructor_notes = new frappe.ui.FieldGroup({ + fields: [ + { + fieldname: "instructor_notes", + fieldtype: "Text Editor", + default: $("#current-instructor-notes").html(), + }, + ], + body: $("#instructor-notes").get(0), + }); + this.instructor_notes.make(); + $("#instructor-notes .form-section:last").removeClass("empty-section"); + $("#instructor-notes .frappe-control").removeClass("hide-control"); + $("#instructor-notes .form-column").addClass("p-0"); +}; diff --git a/lms/www/batch/learn.html b/lms/www/batch/learn.html index bf4a8d77..8f44c010 100644 --- a/lms/www/batch/learn.html +++ b/lms/www/batch/learn.html @@ -149,17 +149,28 @@ {% if show_lesson %} {% if is_instructor and not lesson.include_in_preview %} -
+
{{ _("This lesson is not available for preview. As you are the Instructor of the course only you can see it.") }} ×
{% endif %} + {% if lesson.instructor_notes and (is_moderator or instructor or is_evaluator) %} +
+
+ {{ _("Instructor Notes") }} +
+
+ {{ lesson.instructor_notes }} +
+
+ {% endif %} + {{ render_html(lesson) }} {% else %} {% set course_link = "" + _('here') + "" %} -
+
{{ _("There is no preview available for this lesson. Please join the course to access it. Click {0} to enroll.").format(course_link) }} diff --git a/lms/www/batch/learn.py b/lms/www/batch/learn.py index 36244a2f..ddc036f1 100644 --- a/lms/www/batch/learn.py +++ b/lms/www/batch/learn.py @@ -2,7 +2,12 @@ import frappe from frappe import _ from frappe.utils import cstr, flt -from lms.lms.utils import get_lesson_url, has_course_moderator_role, is_instructor +from lms.lms.utils import ( + get_lesson_url, + has_course_moderator_role, + is_instructor, + has_course_evaluator_role, +) from lms.www.utils import ( get_common_context, redirect_to_lesson, @@ -37,20 +42,23 @@ def get_context(context): redirect_to_lesson(context.course, index_) context.lesson = get_current_lesson_details(lesson_number, context) - instructor = is_instructor(context.course.name) + context.instructor = is_instructor(context.course.name) + context.is_moderator = has_course_moderator_role() + context.is_evaluator = has_course_evaluator_role() context.show_lesson = ( context.membership or (context.lesson and context.lesson.include_in_preview) - or instructor - or has_course_moderator_role() + or context.instructor + or context.is_moderator + or context.is_evaluator ) if not context.lesson: context.lesson = frappe._dict() if frappe.form_dict.get("edit"): - if not instructor and not has_course_moderator_role(): + if not context.instructor and not context.is_moderator: raise frappe.PermissionError(_("You do not have permission to access this page.")) context.lesson.edit_mode = True else: From 2a0636b32bbf7daa427ff182a41cc567fe63cc26 Mon Sep 17 00:00:00 2001 From: Jannat Patel Date: Thu, 31 Aug 2023 11:58:08 +0530 Subject: [PATCH 2/5] fix: field descriptions --- lms/www/batch/edit.html | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/lms/www/batch/edit.html b/lms/www/batch/edit.html index 9c10c042..0ba36106 100644 --- a/lms/www/batch/edit.html +++ b/lms/www/batch/edit.html @@ -66,13 +66,8 @@ {% macro CreateLesson() %}
-
-
- {{ _("Title") }} -
-
- {{ _("Something Short and Concise") }} -
+
+ {{ _("Title") }}
@@ -91,7 +86,7 @@ {{ _("Instructor Notes") }}
- {{ _("This notes will only be visible to the Course Creator, Course Evaluaor and Moderator.") }} + {{ _("These notes will only be visible to the Course Creator, Course Evaluaor and Moderator.") }}
{% if lesson.instructor_notes %} From 833e714a1fa1948993dccf49ef8c8c04a8b89c2d Mon Sep 17 00:00:00 2001 From: Jannat Patel Date: Thu, 31 Aug 2023 21:33:09 +0530 Subject: [PATCH 3/5] feat: embeds in lesson --- lms/hooks.py | 1 + lms/plugins.py | 14 ++++++++++++++ lms/public/css/style.css | 4 ++++ lms/www/batch/edit.html | 1 + lms/www/batch/edit.js | 29 +++++++++++++++++++++++++++++ 5 files changed, 49 insertions(+) diff --git a/lms/hooks.py b/lms/hooks.py index f8796e7e..e78659ab 100644 --- a/lms/hooks.py +++ b/lms/hooks.py @@ -295,6 +295,7 @@ lms_markdown_macro_renderers = { "YouTubeVideo": "lms.plugins.youtube_video_renderer", "Video": "lms.plugins.video_renderer", "Assignment": "lms.plugins.assignment_renderer", + "Embed": "lms.plugins.embed_renderer", } # page_renderer to manage profile pages diff --git a/lms/plugins.py b/lms/plugins.py index 69571476..a171e05e 100644 --- a/lms/plugins.py +++ b/lms/plugins.py @@ -155,6 +155,20 @@ def youtube_video_renderer(video_id): """ +def embed_renderer(details): + src = details.split("|||")[1] + return f""" + + """ + + def video_renderer(src): return ( f"" diff --git a/lms/public/css/style.css b/lms/public/css/style.css index c3f156a3..e5f5149f 100644 --- a/lms/public/css/style.css +++ b/lms/public/css/style.css @@ -2344,4 +2344,8 @@ select { grid-template-columns: 1fr 1fr; grid-gap: 0.5rem; margin-bottom: 1rem; +} + +.embed-tool__caption { + display: none; } \ No newline at end of file diff --git a/lms/www/batch/edit.html b/lms/www/batch/edit.html index 0ba36106..7ad0b37b 100644 --- a/lms/www/batch/edit.html +++ b/lms/www/batch/edit.html @@ -128,5 +128,6 @@ + {% endblock %} diff --git a/lms/www/batch/edit.js b/lms/www/batch/edit.js index 6b050957..ada34259 100644 --- a/lms/www/batch/edit.js +++ b/lms/www/batch/edit.js @@ -26,6 +26,22 @@ const setup_editor = () => { self.editor = new EditorJS({ holder: "lesson-content", tools: { + embed: { + class: Embed, + config: { + services: { + youtube: true, + vimeo: true, + codepen: true, + slides: { + regex: /https:\/\/docs\.google\.com\/presentation\/d\/e\/([A-Za-z0-9_-]+)\/pub/, + embedUrl: + "https://docs.google.com/presentation/d/e/<%= remote_id %>/embed", + html: "", + }, + }, + }, + }, header: { class: Header, inlineToolbar: ["bold", "italic", "link"], @@ -84,6 +100,15 @@ const parse_string_to_lesson = () => { file_url: video, }, }); + } else if (block.includes("{{ Embed")) { + let embed = block.match(/'([^']+)'/)[1]; + lesson_blocks.push({ + type: "embed", + data: { + service: embed.split("|||")[0], + embed: embed.split("|||")[1], + }, + }); } else if (block.includes("![]")) { let image = block.match(/\((.*?)\)/)[1]; lesson_blocks.push({ @@ -139,6 +164,10 @@ const parse_lesson_to_string = (data) => { "#".repeat(block.data.level) + ` ${block.data.text}\n`; } else if (block.type == "paragraph") { lesson_content += `${block.data.text}\n`; + } else if (block.type == "embed") { + lesson_content += `{{ Embed("${ + block.data.service + }|||${block.data.embed.replace(/&/g, "&")}") }}\n`; } }); save(lesson_content); From ffd9d56896be90348175c45d628e4ccd9603cb94 Mon Sep 17 00:00:00 2001 From: Jannat Patel Date: Thu, 31 Aug 2023 23:29:56 +0530 Subject: [PATCH 4/5] feat: embed pdf --- .../doctype/course_lesson/course_lesson.json | 6 ++-- lms/lms/utils.py | 3 +- lms/plugins.py | 29 ++++++++++++------- lms/www/batch/edit.js | 10 +++++++ lms/www/batch/learn.html | 2 +- 5 files changed, 35 insertions(+), 15 deletions(-) diff --git a/lms/lms/doctype/course_lesson/course_lesson.json b/lms/lms/doctype/course_lesson/course_lesson.json index dc224a69..3fd75f37 100644 --- a/lms/lms/doctype/course_lesson/course_lesson.json +++ b/lms/lms/doctype/course_lesson/course_lesson.json @@ -23,8 +23,8 @@ "column_break_15", "file_type", "section_break_11", - "instructor_notes", "body", + "instructor_notes", "help_section", "help" ], @@ -135,13 +135,13 @@ }, { "fieldname": "instructor_notes", - "fieldtype": "Text Editor", + "fieldtype": "Text", "label": "Instructor Notes" } ], "index_web_pages_for_search": 1, "links": [], - "modified": "2023-08-31 11:11:22.034553", + "modified": "2023-08-31 21:47:06.314995", "modified_by": "Administrator", "module": "LMS", "name": "Course Lesson", diff --git a/lms/lms/utils.py b/lms/lms/utils.py index f101e9f0..5347c2e0 100644 --- a/lms/lms/utils.py +++ b/lms/lms/utils.py @@ -147,6 +147,8 @@ def get_lesson_details(chapter): ) lesson_details.number = flt(f"{chapter.idx}.{row.idx}") lesson_details.icon = get_lesson_icon(lesson_details.body) + if lesson_details.instructor_notes: + lesson_details.instructor_notes = markdown_to_html(lesson_details.instructor_notes) lessons.append(lesson_details) return lessons @@ -311,7 +313,6 @@ def render_html(lesson): if lesson.question: assignment = "{{ Assignment('" + lesson.question + "-" + lesson.file_type + "') }}" text = text + assignment - return markdown_to_html(text) diff --git a/lms/plugins.py b/lms/plugins.py index a171e05e..bc763238 100644 --- a/lms/plugins.py +++ b/lms/plugins.py @@ -156,9 +156,17 @@ def youtube_video_renderer(video_id): def embed_renderer(details): + type = details.split("|||")[0] src = details.split("|||")[1] + width = "100%" + height = "400" + + if type == "pdf": + width = "75%" + height = "600" + return f""" - ", }, + pdf: { + regex: /(https?:\/\/.*\.pdf)/, + embedUrl: "<%= remote_id %>", + html: "", + }, }, }, }, @@ -165,6 +170,11 @@ const parse_lesson_to_string = (data) => { } else if (block.type == "paragraph") { lesson_content += `${block.data.text}\n`; } else if (block.type == "embed") { + if (block.data.service == "pdf") { + if (!block.data.embed.startsWith(window.location.origin)) { + frappe.throw(__("Invalid PDF URL")); + } + } lesson_content += `{{ Embed("${ block.data.service }|||${block.data.embed.replace(/&/g, "&")}") }}\n`; diff --git a/lms/www/batch/learn.html b/lms/www/batch/learn.html index 8f44c010..743a01fc 100644 --- a/lms/www/batch/learn.html +++ b/lms/www/batch/learn.html @@ -157,7 +157,7 @@ {% if lesson.instructor_notes and (is_moderator or instructor or is_evaluator) %}
-
+
{{ _("Instructor Notes") }}
From ce09f273734dccbe3628c1efd7f6c118133bcbe4 Mon Sep 17 00:00:00 2001 From: Jannat Patel Date: Thu, 31 Aug 2023 23:32:46 +0530 Subject: [PATCH 5/5] fix: assignment renderer --- lms/lms/utils.py | 1 + lms/plugins.py | 19 +++++++++---------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/lms/lms/utils.py b/lms/lms/utils.py index 5347c2e0..2829f5d6 100644 --- a/lms/lms/utils.py +++ b/lms/lms/utils.py @@ -313,6 +313,7 @@ def render_html(lesson): if lesson.question: assignment = "{{ Assignment('" + lesson.question + "-" + lesson.file_type + "') }}" text = text + assignment + return markdown_to_html(text) diff --git a/lms/plugins.py b/lms/plugins.py index bc763238..59dcd3ab 100644 --- a/lms/plugins.py +++ b/lms/plugins.py @@ -183,21 +183,20 @@ def video_renderer(src): ) -def assignment_renderer(name): - - """supported_types = { - "Document": ".doc,.docx,.xml,application/msword,application/vnd.openxmlformats-officedocument.wordprocessingml.document", - "PDF": ".pdf", - "Image": ".png, .jpg, .jpeg", - "Video": "video/*", +def assignment_renderer(detail): + supported_types = { + "Document": ".doc,.docx,.xml,application/msword,application/vnd.openxmlformats-officedocument.wordprocessingml.document", + "PDF": ".pdf", + "Image": ".png, .jpg, .jpeg", + "Video": "video/*", } question = detail.split("-")[0] file_type = detail.split("-")[1] accept = supported_types[file_type] if file_type else "" return frappe.render_template( - "templates/assignment.html", - {"question": question, "accept": accept, "file_type": file_type}, - )""" + "templates/assignment.html", + {"question": question, "accept": accept, "file_type": file_type}, + ) def show_custom_signup():