diff --git a/school/lms/utils.py b/school/lms/utils.py index cf0fd163..4df6f045 100644 --- a/school/lms/utils.py +++ b/school/lms/utils.py @@ -1,7 +1,7 @@ import re import frappe from frappe.utils import flt, cint, cstr -from school.lms.md import markdown_to_html +from school.lms.md import markdown_to_html, find_macros import string from frappe import _ @@ -85,6 +85,13 @@ def get_lesson_details(chapter): lesson_details = frappe.db.get_value("Course Lesson", row.lesson, ["name", "title", "include_in_preview", "body", "creation"], as_dict=True) lesson_details.number = flt("{}.{}".format(chapter.idx, row.idx)) + lesson_details.icon = "icon-list" + macros = find_macros(lesson_details.body) + for macro in macros: + if macro[0] == "YouTubeVideo": + lesson_details.icon = "icon-video" + elif macro[0] == "Quiz": + lesson_details.icon = "icon-quiz" lessons.append(lesson_details) return lessons diff --git a/school/lms/web_form/chapter/chapter.js b/school/lms/web_form/chapter/chapter.js index 5315afbf..6d710013 100644 --- a/school/lms/web_form/chapter/chapter.js +++ b/school/lms/web_form/chapter/chapter.js @@ -1,5 +1,8 @@ frappe.ready(function() { - frappe.web_form.after_save = () => { - window.location.href = `/courses/${frappe.web_form.doc.course}`; + frappe.web_form.after_save = () => { + frappe.msgprint(__("Chapter has been saved successfully. Go back to the course and add this chapter to the chapters table.")) + setTimeout(() => { + window.location.href = `/courses/${frappe.web_form.doc.course}`; + }, 3000); } }); diff --git a/school/lms/web_form/lesson/lesson.js b/school/lms/web_form/lesson/lesson.js index bf3a24c8..0044ba2d 100644 --- a/school/lms/web_form/lesson/lesson.js +++ b/school/lms/web_form/lesson/lesson.js @@ -1,15 +1,16 @@ frappe.ready(function() { frappe.web_form.after_save = () => { - setTimeout(() => { frappe.call({ method: "school.lms.doctype.course_lesson.course_lesson.get_lesson_info", args: { "chapter": frappe.web_form.doc.chapter }, callback: (data) => { - window.location.href = `/courses/${data.message}`; + frappe.msgprint(__(`Lesson has been saved successfully. Go back to the chapter and add this lesson to the lessons table.`)); + setTimeout(() => { + window.location.href = `/courses/${data.message}`; + }, 3000); } - }); }); }; }); diff --git a/school/lms/widgets/CourseCard.html b/school/lms/widgets/CourseCard.html index 437d54ab..fb7fae59 100644 --- a/school/lms/widgets/CourseCard.html +++ b/school/lms/widgets/CourseCard.html @@ -17,11 +17,41 @@
{% if get_lessons(course.name) | length %} - {{ get_lessons(course.name) | length }} {{ _("Lessons") }} +
+ + + + {{ get_lessons(course.name) | length }} {{ _("Lessons") }} +
{% endif %} + {% if course.status and course.status != "Approved"%} {% set pill_color = "gray" if course.status == "In Progress" else "orange" %} - {{ course.status }} +
{{ course.status }}
+ {% endif %} + + {% set student_count = get_students(course.name) | length %} + {% set avg_rating = get_average_rating(course.name) %} + {% if student_count and avg_rating %} +
+ {% if student_count %} +
+ + + + {{ student_count }} +
+ {% endif %} + + {% if avg_rating %} +
+ + + + {{ frappe.utils.flt(avg_rating, frappe.get_system_settings("float_precision") or 3) }} +
+ {% endif %} +
{% endif %}
{{ course.title }}
@@ -61,22 +91,6 @@ - {% set student_count = get_students(course.name) | length %} - - {% if student_count %} - - - {{ student_count }} - - {% endif %} - {% set avg_rating = get_average_rating(course.name) %} - {% if avg_rating %} - - - {{ frappe.utils.flt(avg_rating, frappe.get_system_settings("float_precision") or 3) }} - - {% endif %} -
{% if read_only %} diff --git a/school/lms/widgets/CourseOutline.html b/school/lms/widgets/CourseOutline.html index d80b7f9a..1cb38938 100644 --- a/school/lms/widgets/CourseOutline.html +++ b/school/lms/widgets/CourseOutline.html @@ -23,12 +23,15 @@
{% for lesson in get_lessons(course.name, chapter) %} - -
+ {% set active = membership.current_lesson == lesson.name %} +
{% if membership or lesson.include_in_preview %} + + + {{ lesson.title }} {% if membership %} @@ -43,14 +46,18 @@ title="This lesson is not available for preview. As you are the Instructor of the course only you can see it." href="{{ get_lesson_url(course.name, lesson.number) }}{{course.query_parameter}}" data-course="{{ course.name }}"> - + + +
{{ lesson.title }}
{% else %}
@@ -83,7 +90,7 @@ frappe.ready(() => { }); const expand_the_first_chapter = () => { - var elements = $(".course-outline .collapse"); + let elements = $(".course-outline .collapse"); elements.each((i, element) => { if (i < 1) { show_section(element); @@ -95,13 +102,21 @@ const expand_the_first_chapter = () => { const expand_the_active_chapter = () => { /* Find anchor matching the URL for course details page */ - var selector = $(`a[href="${decodeURIComponent(window.location.pathname)}"]`).parent(); + let selector = $(`a[href="${decodeURIComponent(window.location.pathname)}"]`).parent(); if (!selector.length) { selector = $(`a[href^="${decodeURIComponent(window.location.pathname)}"]`).parent(); } if (selector.length && $(".course-details-page").length) { - $(".lesson-info").removeClass("active-lesson") + $(".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)); + }) + selector.addClass("active-lesson"); + let href = selector.find("use").attr("href"); + !href.endsWith("blue") && selector.find("use").attr("href", `${href}-blue`); + show_section(selector.parent().parent()); } @@ -124,7 +139,7 @@ const show_section = (element) => { }; const rotate_chapter_icon = (e) => { - var icon = $(e.currentTarget).children(".chapter-icon"); + let icon = $(e.currentTarget).children(".chapter-icon"); if (icon.css("transform") == "none") { icon.css("transform", "rotate(90deg)"); } else { diff --git a/school/lms/widgets/Reviews.html b/school/lms/widgets/Reviews.html index f4331e0b..bf6069b4 100644 --- a/school/lms/widgets/Reviews.html +++ b/school/lms/widgets/Reviews.html @@ -19,7 +19,7 @@
{% for i in [1, 2, 3, 4, 5] %} - + {% endfor %} @@ -49,14 +49,16 @@ {% if reviews | length %}
{% for review in reviews %} -
-