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) => {
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");
}

View File

@@ -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",

View File

@@ -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 "" %}

View File

@@ -57,7 +57,10 @@
<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() %}
<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 %}
title="{{ _('This lesson is not available for preview. As you are the Instructor of the course only you can see it.') }}"
{% endif %}>

View File

@@ -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) => {

View File

@@ -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")) {

View File

@@ -39,13 +39,14 @@
{% endif %}
<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 class="lesson-parent">
{{ 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 %}
</div>
@@ -56,19 +57,39 @@
<!-- BreadCrumb -->
{% macro BreadCrumb(course, lesson) %}
{% macro BreadCrumb(course, lesson, class_info) %}
<div class="breadcrumb">
<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 if lesson.title else _("New Lesson") }}</span>
{% 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">
<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">
<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>
{% endmacro %}
<!-- Lesson Details -->
{% 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 %}
</div>
{% if not class_info %}
{{ pagination(prev_url, next_url) }}
{% endif %}
</div>
{% endmacro %}

View File

@@ -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

View File

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

View File

@@ -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