diff --git a/school/lms/utils.py b/school/lms/utils.py index 8f2356fe..7c77288f 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/widgets/CourseCard.html b/school/lms/widgets/CourseCard.html index 52f613ed..c9255b47 100644 --- a/school/lms/widgets/CourseCard.html +++ b/school/lms/widgets/CourseCard.html @@ -17,10 +17,35 @@
{% if get_lessons(course.name) | length %} - +
+ + + {{ get_lessons(course.name) | length }} {{ _("Lessons") }} - +
{% endif %} + +
+ {% 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 %} +
{{ course.title }}
@@ -59,22 +84,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 56c11e67..3b566e7f 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 %} -
-