feat: redirection from class flow

This commit is contained in:
Jannat Patel
2023-08-01 18:02:02 +05:30
parent 5d2b19cc43
commit 845b906851
10 changed files with 79 additions and 41 deletions

View File

@@ -21,11 +21,10 @@ frappe.ui.form.on("LMS Class", {
}, },
callback: (r) => { callback: (r) => {
if (r.message) { if (r.message) {
console.log(r.message);
r.message.forEach((lesson) => { r.message.forEach((lesson) => {
console.log(typeof lesson);
let row = frm.add_child("scheduled_flow"); let row = frm.add_child("scheduled_flow");
row.lesson = lesson.name; row.lesson = lesson.name;
row.lesson_title = lesson.title;
}); });
frm.refresh_field("scheduled_flow"); frm.refresh_field("scheduled_flow");
} }

View File

@@ -8,8 +8,9 @@
"engine": "InnoDB", "engine": "InnoDB",
"field_order": [ "field_order": [
"lesson", "lesson",
"date", "lesson_title",
"column_break_yikh", "column_break_yikh",
"date",
"start_time", "start_time",
"end_time" "end_time"
], ],
@@ -43,12 +44,19 @@
"fieldtype": "Date", "fieldtype": "Date",
"in_list_view": 1, "in_list_view": 1,
"label": "Date" "label": "Date"
},
{
"fetch_from": "lesson.title",
"fieldname": "lesson_title",
"fieldtype": "Data",
"in_list_view": 1,
"label": "Lesson Title"
} }
], ],
"index_web_pages_for_search": 1, "index_web_pages_for_search": 1,
"istable": 1, "istable": 1,
"links": [], "links": [],
"modified": "2023-07-31 16:53:36.829164", "modified": "2023-08-01 12:31:27.512437",
"modified_by": "Administrator", "modified_by": "Administrator",
"module": "LMS", "module": "LMS",
"name": "Scheduled Flow", "name": "Scheduled Flow",

View File

@@ -120,7 +120,7 @@
{% else %} {% else %}
{% if progress != 100 and membership and not course.upcoming %} {% 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 "" %} {% set query_parameter = "?batch=" + membership.batch if membership.batch else "" %}

View File

@@ -57,7 +57,10 @@
<div data-lesson="{{ lesson.name }}" class="lesson-info {% if active %} active-lesson {% endif %}"> <div data-lesson="{{ lesson.name }}" class="lesson-info {% if active %} active-lesson {% endif %}">
{% if membership or lesson.include_in_preview or is_instructor or has_course_moderator_role() %} {% if membership or lesson.include_in_preview or is_instructor or has_course_moderator_role() %}
<a class="lesson-links" href="{{ get_lesson_url(course.name, lesson.number) }}{{course.query_parameter}}" <a class="lesson-links"
{% if not from_class %}
href="{{ get_lesson_url(course.name, lesson.number) }}{{course.query_parameter}}"
{% endif %}
{% if is_instructor and not lesson.include_in_preview %} {% if is_instructor and not lesson.include_in_preview %}
title="{{ _('This lesson is not available for preview. As you are the Instructor of the course only you can see it.') }}" title="{{ _('This lesson is not available for preview. As you are the Instructor of the course only you can see it.') }}"
{% endif %}> {% endif %}>

View File

@@ -200,16 +200,8 @@ const expand_the_first_chapter = () => {
}; };
const expand_the_active_chapter = () => { const expand_the_active_chapter = () => {
/* Find anchor matching the URL for course details page */ let selector = $(".course-home-headings.title");
let selector = $( console.log(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) { if (selector.length && $(".course-details-page").length) {
expand_for_course_details(selector); expand_for_course_details(selector);
} else if ($(".active-lesson").length) { } else if ($(".active-lesson").length) {
@@ -225,15 +217,11 @@ const expand_the_active_chapter = () => {
const expand_for_course_details = (selector) => { const expand_for_course_details = (selector) => {
$(".lesson-info").removeClass("active-lesson"); $(".lesson-info").removeClass("active-lesson");
$(".lesson-info").each((i, elem) => { $(".lesson-info").each((i, elem) => {
let href = $(elem).find("use").attr("href"); if ($(elem).data("lesson") == selector.data("lesson")) {
href.endsWith("blue") && $(elem).addClass("active-lesson");
$(elem) show_section($(elem).parent().parent());
.find("use") }
.attr("href", href.substring(0, href.length - 5));
}); });
selector.addClass("active-lesson");
show_section(selector.parent().parent());
}; };
const show_section = (element) => { const show_section = (element) => {

View File

@@ -1,6 +1,7 @@
frappe.ready(() => { frappe.ready(() => {
frappe.telemetry.capture("on_lesson_creation_page", "lms"); frappe.telemetry.capture("on_lesson_creation_page", "lms");
let self = this; let self = this;
this.quiz_in_lesson = [];
if ($("#current-lesson-content").length) { if ($("#current-lesson-content").length) {
parse_string_to_lesson(); parse_string_to_lesson();
} }
@@ -48,7 +49,6 @@ const setup_editor = () => {
const parse_string_to_lesson = () => { const parse_string_to_lesson = () => {
let lesson_content = $("#current-lesson-content").html(); let lesson_content = $("#current-lesson-content").html();
let lesson_blocks = []; let lesson_blocks = [];
this.quiz_in_lesson = [];
lesson_content.split("\n").forEach((block) => { lesson_content.split("\n").forEach((block) => {
if (block.includes("{{ YouTubeVideo")) { if (block.includes("{{ YouTubeVideo")) {

View File

@@ -39,13 +39,14 @@
{% endif %} {% endif %}
<div class="course-details-outline"> <div class="course-details-outline">
{{ 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) }}
</div> </div>
</div> </div>
<div class="lesson-parent"> <div class="lesson-parent">
{{ BreadCrumb(course, lesson) }} {{ BreadCrumb(course, lesson, class_info) }}
{{ LessonContent(lesson) }} {{ LessonContent(lesson, class_info) }}
{% if course.status == "Approved" and not course.upcoming %} {% if course.status == "Approved" and not course.upcoming and not class_info %}
{{ Discussions() }} {{ Discussions() }}
{% endif %} {% endif %}
</div> </div>
@@ -56,19 +57,39 @@
<!-- BreadCrumb --> <!-- BreadCrumb -->
{% macro BreadCrumb(course, lesson) %} {% macro BreadCrumb(course, lesson, class_info) %}
<div class="breadcrumb"> <div class="breadcrumb">
<a class="dark-links" href="/courses">{{ _("All Courses") }}</a> {% if class_info %}
<a class="dark-links" href="/courses">
{{ _("All Classes") }}
</a>
<img class="ml-1 mr-1" src="/assets/lms/icons/chevron-right.svg"> <img class="ml-1 mr-1" src="/assets/lms/icons/chevron-right.svg">
<a class="dark-links" href="/courses/{{ course.name }}">{{ course.title }}</a> <a class="dark-links" href="/classes/{{ class_info.name }}">
{{ class_info.title }}
</a>
<img class="ml-1 mr-1" src="/assets/lms/icons/chevron-right.svg"> <img class="ml-1 mr-1" src="/assets/lms/icons/chevron-right.svg">
<span class="breadcrumb-destination">{{ lesson.title if lesson.title else _("New Lesson") }}</span> <span class="breadcrumb-destination">
{{ lesson.title }}
</span>
{% else %}
<a class="dark-links" href="/courses">
{{ _("All Courses") }}
</a>
<img class="ml-1 mr-1" src="/assets/lms/icons/chevron-right.svg">
<a class="dark-links" href="/courses/{{ course.name }}">
{{ course.title }}
</a>
<img class="ml-1 mr-1" src="/assets/lms/icons/chevron-right.svg">
<span class="breadcrumb-destination">
{{ lesson.title }}
</span>
{% endif %}
</div> </div>
{% endmacro %} {% endmacro %}
<!-- Lesson Details --> <!-- Lesson Details -->
{% macro LessonContent(lesson) %} {% macro LessonContent(lesson, class_info) %}
{% set instructors = get_instructors(course.name) %} {% set instructors = get_instructors(course.name) %}
{% set is_instructor = is_instructor(course.name) %} {% set is_instructor = is_instructor(course.name) %}
@@ -144,8 +165,9 @@
{% endif %} {% endif %}
</div> </div>
{% if not class_info %}
{{ pagination(prev_url, next_url) }} {{ pagination(prev_url, next_url) }}
{% endif %}
</div> </div>
{% endmacro %} {% endmacro %}

View File

@@ -15,6 +15,16 @@ def get_context(context):
chapter_index = frappe.form_dict.get("chapter") chapter_index = frappe.form_dict.get("chapter")
lesson_index = frappe.form_dict.get("lesson") 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}" lesson_number = f"{chapter_index}.{lesson_index}"
context.lesson_number = lesson_number context.lesson_number = lesson_number
context.lesson_index = lesson_index context.lesson_index = lesson_index

View File

@@ -482,8 +482,8 @@
{% for lesson in flow %} {% for lesson in flow %}
<div class="grid-row"> <div class="grid-row">
<div class="row data-row"> <div class="row data-row">
<a class="col grid-static-col clickable"> <a class="col grid-static-col clickable" href="{{ lesson.url }}">
{{ lesson.lesson }} {{ lesson.title }}
</a> </a>
</div> </div>
</div> </div>

View File

@@ -8,6 +8,8 @@ from lms.lms.utils import (
get_course_progress, get_course_progress,
has_submitted_assessment, has_submitted_assessment,
has_graded_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): 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: for lesson in lessons:
lesson.update( 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 return lessons