feat: learning flow in class
This commit is contained in:
@@ -11,4 +11,25 @@ frappe.ui.form.on("LMS Class", {
|
||||
};
|
||||
});
|
||||
},
|
||||
|
||||
fetch_lessons: (frm) => {
|
||||
frm.clear_table("scheduled_flow");
|
||||
frappe.call({
|
||||
method: "lms.lms.doctype.lms_class.lms_class.fetch_lessons",
|
||||
args: {
|
||||
courses: frm.doc.courses,
|
||||
},
|
||||
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;
|
||||
});
|
||||
frm.refresh_field("scheduled_flow");
|
||||
}
|
||||
},
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
@@ -24,6 +24,10 @@
|
||||
"description",
|
||||
"students",
|
||||
"courses",
|
||||
"section_break_lbwu",
|
||||
"fetch_lessons",
|
||||
"scheduled_flow",
|
||||
"section_break_ubxi",
|
||||
"custom_component",
|
||||
"assessment_tab",
|
||||
"assessment"
|
||||
@@ -134,11 +138,30 @@
|
||||
"fieldname": "category",
|
||||
"fieldtype": "Autocomplete",
|
||||
"label": "Category"
|
||||
},
|
||||
{
|
||||
"fieldname": "section_break_lbwu",
|
||||
"fieldtype": "Section Break"
|
||||
},
|
||||
{
|
||||
"fieldname": "scheduled_flow",
|
||||
"fieldtype": "Table",
|
||||
"label": "Scheduled Flow",
|
||||
"options": "Scheduled Flow"
|
||||
},
|
||||
{
|
||||
"fieldname": "section_break_ubxi",
|
||||
"fieldtype": "Section Break"
|
||||
},
|
||||
{
|
||||
"fieldname": "fetch_lessons",
|
||||
"fieldtype": "Button",
|
||||
"label": "Fetch Lessons"
|
||||
}
|
||||
],
|
||||
"index_web_pages_for_search": 1,
|
||||
"links": [],
|
||||
"modified": "2023-07-13 11:30:09.097605",
|
||||
"modified": "2023-07-31 15:45:03.839896",
|
||||
"modified_by": "Administrator",
|
||||
"module": "LMS",
|
||||
"name": "LMS Class",
|
||||
|
||||
@@ -8,6 +8,7 @@ import json
|
||||
from frappe import _
|
||||
from frappe.model.document import Document
|
||||
from frappe.utils import cint, format_date, format_datetime
|
||||
from lms.lms.utils import get_lessons
|
||||
|
||||
|
||||
class LMSClass(Document):
|
||||
@@ -188,3 +189,14 @@ def create_class(
|
||||
)
|
||||
class_details.save()
|
||||
return class_details
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def fetch_lessons(courses):
|
||||
lessons = []
|
||||
courses = json.loads(courses)
|
||||
|
||||
for course in courses:
|
||||
lessons.extend(get_lessons(course.get("course")))
|
||||
|
||||
return lessons
|
||||
|
||||
0
lms/lms/doctype/scheduled_flow/__init__.py
Normal file
0
lms/lms/doctype/scheduled_flow/__init__.py
Normal file
60
lms/lms/doctype/scheduled_flow/scheduled_flow.json
Normal file
60
lms/lms/doctype/scheduled_flow/scheduled_flow.json
Normal file
@@ -0,0 +1,60 @@
|
||||
{
|
||||
"actions": [],
|
||||
"allow_rename": 1,
|
||||
"creation": "2023-07-31 15:10:29.287475",
|
||||
"default_view": "List",
|
||||
"doctype": "DocType",
|
||||
"editable_grid": 1,
|
||||
"engine": "InnoDB",
|
||||
"field_order": [
|
||||
"lesson",
|
||||
"date",
|
||||
"column_break_yikh",
|
||||
"start_time",
|
||||
"end_time"
|
||||
],
|
||||
"fields": [
|
||||
{
|
||||
"fieldname": "lesson",
|
||||
"fieldtype": "Link",
|
||||
"in_list_view": 1,
|
||||
"label": "Lesson",
|
||||
"options": "Course Lesson",
|
||||
"reqd": 1
|
||||
},
|
||||
{
|
||||
"fieldname": "start_time",
|
||||
"fieldtype": "Time",
|
||||
"in_list_view": 1,
|
||||
"label": "Start Time"
|
||||
},
|
||||
{
|
||||
"fieldname": "end_time",
|
||||
"fieldtype": "Time",
|
||||
"in_list_view": 1,
|
||||
"label": "End Time"
|
||||
},
|
||||
{
|
||||
"fieldname": "column_break_yikh",
|
||||
"fieldtype": "Column Break"
|
||||
},
|
||||
{
|
||||
"fieldname": "date",
|
||||
"fieldtype": "Date",
|
||||
"in_list_view": 1,
|
||||
"label": "Date"
|
||||
}
|
||||
],
|
||||
"index_web_pages_for_search": 1,
|
||||
"istable": 1,
|
||||
"links": [],
|
||||
"modified": "2023-07-31 16:53:36.829164",
|
||||
"modified_by": "Administrator",
|
||||
"module": "LMS",
|
||||
"name": "Scheduled Flow",
|
||||
"owner": "Administrator",
|
||||
"permissions": [],
|
||||
"sort_field": "modified",
|
||||
"sort_order": "DESC",
|
||||
"states": []
|
||||
}
|
||||
9
lms/lms/doctype/scheduled_flow/scheduled_flow.py
Normal file
9
lms/lms/doctype/scheduled_flow/scheduled_flow.py
Normal file
@@ -0,0 +1,9 @@
|
||||
# Copyright (c) 2023, Frappe and contributors
|
||||
# For license information, please see license.txt
|
||||
|
||||
# import frappe
|
||||
from frappe.model.document import Document
|
||||
|
||||
|
||||
class ScheduledFlow(Document):
|
||||
pass
|
||||
@@ -10,7 +10,7 @@
|
||||
{{ BreadCrumb(class_info) }}
|
||||
<div class="">
|
||||
{{ ClassDetails(class_info) }}
|
||||
{{ ClassSections(class_info, class_courses, class_students, published_courses) }}
|
||||
{{ ClassSections(class_info, class_courses, class_students, published_courses, flow) }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -82,7 +82,7 @@
|
||||
|
||||
|
||||
<!-- Class Sections -->
|
||||
{% macro ClassSections(class_info, class_courses, class_students, published_courses) %}
|
||||
{% macro ClassSections(class_info, class_courses, class_students, published_courses, flow) %}
|
||||
<div class="mt-4">
|
||||
|
||||
{% if is_moderator %}
|
||||
@@ -92,6 +92,7 @@
|
||||
{% endif %}
|
||||
|
||||
<ul class="nav lms-nav" id="classes-tab">
|
||||
|
||||
<li class="nav-item">
|
||||
<a class="nav-link active" data-toggle="tab" href="#courses">
|
||||
{{ _("Courses") }}
|
||||
@@ -101,6 +102,17 @@
|
||||
</a>
|
||||
</li>
|
||||
|
||||
{% if flow | length %}
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" data-toggle="tab" href="#schedule">
|
||||
{{ _("Schedule") }}
|
||||
<span class="course-list-count">
|
||||
{{ flow | length }}
|
||||
</span>
|
||||
</a>
|
||||
</li>
|
||||
{% endif %}
|
||||
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" data-toggle="tab" href="#students">
|
||||
{{ _("Students") }}
|
||||
@@ -141,6 +153,12 @@
|
||||
{{ CoursesSection(class_info, class_courses, published_courses) }}
|
||||
</div>
|
||||
|
||||
{% if flow | length %}
|
||||
<div class="tab-pane" id="schedule" role="tabpanel" aria-labelledby="schedule">
|
||||
{{ ScheduleSection(flow) }}
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
<div class="tab-pane" id="students" role="tabpanel" aria-labelledby="students">
|
||||
{{ StudentsSection(class_info, class_students) }}
|
||||
</div>
|
||||
@@ -450,6 +468,32 @@
|
||||
</div>
|
||||
{% endmacro %}
|
||||
|
||||
|
||||
{% macro ScheduleSection(flow) %}
|
||||
<article>
|
||||
<header class="edit-header mb-5">
|
||||
<div class="bold-heading">
|
||||
{{ _("Schedule") }}
|
||||
</div>
|
||||
</header>
|
||||
<div class="form-grid">
|
||||
<div class="grid-body">
|
||||
<div class="rows">
|
||||
{% for lesson in flow %}
|
||||
<div class="grid-row">
|
||||
<div class="row data-row">
|
||||
<a class="col grid-static-col clickable">
|
||||
{{ lesson.lesson }}
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</article>
|
||||
{% endmacro %}
|
||||
|
||||
{%- block script %}
|
||||
{{ super() }}
|
||||
{% if is_moderator %}
|
||||
|
||||
@@ -73,6 +73,7 @@ def get_context(context):
|
||||
context.is_student = is_student(class_students)
|
||||
context.all_assignments = get_all_assignments(class_name)
|
||||
context.all_quizzes = get_all_quizzes(class_name)
|
||||
context.flow = get_scheduled_flow(class_name)
|
||||
|
||||
|
||||
def get_all_quizzes(class_name):
|
||||
@@ -185,3 +186,14 @@ def sort_students(class_students):
|
||||
def is_student(class_students):
|
||||
students = [student.student for student in class_students]
|
||||
return frappe.session.user in students
|
||||
|
||||
|
||||
def get_scheduled_flow(class_name):
|
||||
lessons = frappe.get_all("Scheduled Flow", {"parent": class_name}, ["name", "lesson"])
|
||||
|
||||
for lesson in lessons:
|
||||
lesson.update(
|
||||
frappe.db.get_value("Course Lesson", lesson.lesson, ["body"], as_dict=True)
|
||||
)
|
||||
|
||||
return lessons
|
||||
|
||||
Reference in New Issue
Block a user