From 845b9068513639a777b63f0a175c1398d2d3a342 Mon Sep 17 00:00:00 2001 From: Jannat Patel Date: Tue, 1 Aug 2023 18:02:02 +0530 Subject: [PATCH] feat: redirection from class flow --- lms/lms/doctype/lms_class/lms_class.js | 3 +- .../scheduled_flow/scheduled_flow.json | 12 ++++- lms/lms/widgets/CourseCard.html | 2 +- lms/lms/widgets/CourseOutline.html | 5 +- lms/public/js/common_functions.js | 24 +++------- lms/www/batch/edit.js | 2 +- lms/www/batch/learn.html | 46 ++++++++++++++----- lms/www/batch/learn.py | 10 ++++ lms/www/classes/class.html | 4 +- lms/www/classes/class.py | 12 ++++- 10 files changed, 79 insertions(+), 41 deletions(-) diff --git a/lms/lms/doctype/lms_class/lms_class.js b/lms/lms/doctype/lms_class/lms_class.js index a460c88e..7f3c4299 100644 --- a/lms/lms/doctype/lms_class/lms_class.js +++ b/lms/lms/doctype/lms_class/lms_class.js @@ -21,11 +21,10 @@ frappe.ui.form.on("LMS Class", { }, callback: (r) => { if (r.message) { - console.log(r.message); r.message.forEach((lesson) => { - console.log(typeof lesson); let row = frm.add_child("scheduled_flow"); row.lesson = lesson.name; + row.lesson_title = lesson.title; }); frm.refresh_field("scheduled_flow"); } diff --git a/lms/lms/doctype/scheduled_flow/scheduled_flow.json b/lms/lms/doctype/scheduled_flow/scheduled_flow.json index 22714acf..99ef1c33 100644 --- a/lms/lms/doctype/scheduled_flow/scheduled_flow.json +++ b/lms/lms/doctype/scheduled_flow/scheduled_flow.json @@ -8,8 +8,9 @@ "engine": "InnoDB", "field_order": [ "lesson", - "date", + "lesson_title", "column_break_yikh", + "date", "start_time", "end_time" ], @@ -43,12 +44,19 @@ "fieldtype": "Date", "in_list_view": 1, "label": "Date" + }, + { + "fetch_from": "lesson.title", + "fieldname": "lesson_title", + "fieldtype": "Data", + "in_list_view": 1, + "label": "Lesson Title" } ], "index_web_pages_for_search": 1, "istable": 1, "links": [], - "modified": "2023-07-31 16:53:36.829164", + "modified": "2023-08-01 12:31:27.512437", "modified_by": "Administrator", "module": "LMS", "name": "Scheduled Flow", diff --git a/lms/lms/widgets/CourseCard.html b/lms/lms/widgets/CourseCard.html index 486471c9..c17422bb 100644 --- a/lms/lms/widgets/CourseCard.html +++ b/lms/lms/widgets/CourseCard.html @@ -120,7 +120,7 @@ {% else %} {% if progress != 100 and membership and not course.upcoming %} - {% set lesson_index = get_lesson_index(membership.current_lesson or "1.1") %} + {% set lesson_index = get_lesson_index(membership.current_lesson) or "1.1" %} {% set query_parameter = "?batch=" + membership.batch if membership.batch else "" %} diff --git a/lms/lms/widgets/CourseOutline.html b/lms/lms/widgets/CourseOutline.html index 1ef4059b..b513ceee 100644 --- a/lms/lms/widgets/CourseOutline.html +++ b/lms/lms/widgets/CourseOutline.html @@ -57,7 +57,10 @@
{% if membership or lesson.include_in_preview or is_instructor or has_course_moderator_role() %} - diff --git a/lms/public/js/common_functions.js b/lms/public/js/common_functions.js index 2eeb43ae..fc5cead8 100644 --- a/lms/public/js/common_functions.js +++ b/lms/public/js/common_functions.js @@ -200,16 +200,8 @@ const expand_the_first_chapter = () => { }; const expand_the_active_chapter = () => { - /* Find anchor matching the URL for course details page */ - let selector = $( - `a[href="${decodeURIComponent(window.location.pathname)}"]` - ).parent(); - - if (!selector.length) { - selector = $( - `a[href^="${decodeURIComponent(window.location.pathname)}"]` - ).parent(); - } + let selector = $(".course-home-headings.title"); + console.log(selector); if (selector.length && $(".course-details-page").length) { expand_for_course_details(selector); } else if ($(".active-lesson").length) { @@ -225,15 +217,11 @@ const expand_the_active_chapter = () => { const expand_for_course_details = (selector) => { $(".lesson-info").removeClass("active-lesson"); $(".lesson-info").each((i, elem) => { - let href = $(elem).find("use").attr("href"); - href.endsWith("blue") && - $(elem) - .find("use") - .attr("href", href.substring(0, href.length - 5)); + if ($(elem).data("lesson") == selector.data("lesson")) { + $(elem).addClass("active-lesson"); + show_section($(elem).parent().parent()); + } }); - selector.addClass("active-lesson"); - - show_section(selector.parent().parent()); }; const show_section = (element) => { diff --git a/lms/www/batch/edit.js b/lms/www/batch/edit.js index 285fc2d8..dd0ae722 100644 --- a/lms/www/batch/edit.js +++ b/lms/www/batch/edit.js @@ -1,6 +1,7 @@ frappe.ready(() => { frappe.telemetry.capture("on_lesson_creation_page", "lms"); let self = this; + this.quiz_in_lesson = []; if ($("#current-lesson-content").length) { parse_string_to_lesson(); } @@ -48,7 +49,6 @@ const setup_editor = () => { const parse_string_to_lesson = () => { let lesson_content = $("#current-lesson-content").html(); let lesson_blocks = []; - this.quiz_in_lesson = []; lesson_content.split("\n").forEach((block) => { if (block.includes("{{ YouTubeVideo")) { diff --git a/lms/www/batch/learn.html b/lms/www/batch/learn.html index 23003702..f268c076 100644 --- a/lms/www/batch/learn.html +++ b/lms/www/batch/learn.html @@ -39,13 +39,14 @@ {% endif %}
- {{ widgets.CourseOutline(course=course, membership=membership, lesson_page=True) }} + {% set from_class = True if class_info else False %} + {{ widgets.CourseOutline(course=course, membership=membership, lesson_page=True, from_class=from_class) }}
- {{ BreadCrumb(course, lesson) }} - {{ LessonContent(lesson) }} - {% if course.status == "Approved" and not course.upcoming %} + {{ BreadCrumb(course, lesson, class_info) }} + {{ LessonContent(lesson, class_info) }} + {% if course.status == "Approved" and not course.upcoming and not class_info %} {{ Discussions() }} {% endif %}
@@ -56,19 +57,39 @@ -{% macro BreadCrumb(course, lesson) %} +{% macro BreadCrumb(course, lesson, class_info) %}
{% endmacro %} -{% macro LessonContent(lesson) %} +{% macro LessonContent(lesson, class_info) %} {% set instructors = get_instructors(course.name) %} {% set is_instructor = is_instructor(course.name) %} @@ -144,8 +165,9 @@ {% endif %} + {% if not class_info %} {{ pagination(prev_url, next_url) }} - + {% endif %} {% endmacro %} diff --git a/lms/www/batch/learn.py b/lms/www/batch/learn.py index 077b3ba1..fae056f7 100644 --- a/lms/www/batch/learn.py +++ b/lms/www/batch/learn.py @@ -15,6 +15,16 @@ def get_context(context): chapter_index = frappe.form_dict.get("chapter") lesson_index = frappe.form_dict.get("lesson") + class_name = frappe.form_dict.get("class") + + if class_name: + context.class_info = frappe._dict( + { + "name": class_name, + "title": frappe.db.get_value("LMS Class", class_name, "title"), + } + ) + lesson_number = f"{chapter_index}.{lesson_index}" context.lesson_number = lesson_number context.lesson_index = lesson_index diff --git a/lms/www/classes/class.html b/lms/www/classes/class.html index c24a9a3b..fca30578 100644 --- a/lms/www/classes/class.html +++ b/lms/www/classes/class.html @@ -482,8 +482,8 @@ {% for lesson in flow %}
diff --git a/lms/www/classes/class.py b/lms/www/classes/class.py index 25dea202..f8380b25 100644 --- a/lms/www/classes/class.py +++ b/lms/www/classes/class.py @@ -8,6 +8,8 @@ from lms.lms.utils import ( get_course_progress, has_submitted_assessment, has_graded_assessment, + get_lesson_index, + get_lesson_url, ) @@ -189,11 +191,17 @@ def is_student(class_students): def get_scheduled_flow(class_name): - lessons = frappe.get_all("Scheduled Flow", {"parent": class_name}, ["name", "lesson"]) + lessons = frappe.get_all( + "Scheduled Flow", {"parent": class_name}, ["name", "lesson"], order_by="idx" + ) for lesson in lessons: lesson.update( - frappe.db.get_value("Course Lesson", lesson.lesson, ["body"], as_dict=True) + frappe.db.get_value( + "Course Lesson", lesson.lesson, ["title", "body", "course"], as_dict=True + ) ) + lesson["index"] = get_lesson_index(lesson.lesson) + lesson["url"] = get_lesson_url(lesson.course, lesson.index) + "?class=" + class_name return lessons