Merge pull request #643 from pateljannat/timetable-customisations
feat: timetable customisations
This commit is contained in:
2
.github/helper/install.sh
vendored
2
.github/helper/install.sh
vendored
@@ -43,4 +43,4 @@ build_pid=$!
|
||||
bench --site lms.test reinstall --yes
|
||||
bench --site lms.test install-app lms
|
||||
|
||||
wait $build_pid
|
||||
wait $build_pid
|
||||
3
.github/workflows/ci.yml
vendored
3
.github/workflows/ci.yml
vendored
@@ -77,5 +77,4 @@ jobs:
|
||||
run: bench --site frappe.local build
|
||||
- name: run tests
|
||||
working-directory: /home/runner/frappe-bench
|
||||
run: bench --site frappe.local run-tests --app lms
|
||||
|
||||
run: bench --site frappe.local run-tests --app lms
|
||||
@@ -12,12 +12,16 @@ frappe.ui.form.on("LMS Batch", {
|
||||
});
|
||||
|
||||
frm.set_query("reference_doctype", "timetable", function () {
|
||||
let doctypes = [
|
||||
"Course Lesson",
|
||||
"LMS Quiz",
|
||||
"LMS Assignment",
|
||||
"LMS Live Class",
|
||||
];
|
||||
let doctypes = ["Course Lesson", "LMS Quiz", "LMS Assignment"];
|
||||
return {
|
||||
filters: {
|
||||
name: ["in", doctypes],
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
frm.set_query("reference_doctype", "timetable_legends", function () {
|
||||
let doctypes = ["Course Lesson", "LMS Quiz", "LMS Assignment"];
|
||||
return {
|
||||
filters: {
|
||||
name: ["in", doctypes],
|
||||
@@ -27,36 +31,41 @@ frappe.ui.form.on("LMS Batch", {
|
||||
},
|
||||
|
||||
timetable_template: function (frm) {
|
||||
if (frm.doc.timetable_template) {
|
||||
frm.clear_table("timetable");
|
||||
frm.refresh_fields();
|
||||
|
||||
frappe.call({
|
||||
method: "frappe.client.get_list",
|
||||
args: {
|
||||
doctype: "LMS Batch Timetable",
|
||||
parent: "LMS Timetable Template",
|
||||
fields: [
|
||||
"reference_doctype",
|
||||
"reference_docname",
|
||||
"day",
|
||||
"start_time",
|
||||
"end_time",
|
||||
"duration",
|
||||
],
|
||||
filters: {
|
||||
parent: frm.doc.timetable_template,
|
||||
},
|
||||
order_by: "idx",
|
||||
},
|
||||
callback: (data) => {
|
||||
add_timetable_rows(frm, data.message);
|
||||
},
|
||||
});
|
||||
}
|
||||
set_timetable(frm);
|
||||
},
|
||||
});
|
||||
|
||||
const set_timetable = (frm) => {
|
||||
if (frm.doc.timetable_template) {
|
||||
frm.clear_table("timetable");
|
||||
frm.refresh_fields();
|
||||
|
||||
frappe.call({
|
||||
method: "frappe.client.get_list",
|
||||
args: {
|
||||
doctype: "LMS Batch Timetable",
|
||||
parent: "LMS Timetable Template",
|
||||
fields: [
|
||||
"reference_doctype",
|
||||
"reference_docname",
|
||||
"day",
|
||||
"start_time",
|
||||
"end_time",
|
||||
"duration",
|
||||
],
|
||||
filters: {
|
||||
parent: frm.doc.timetable_template,
|
||||
parenttype: "LMS Timetable Template",
|
||||
},
|
||||
order_by: "idx",
|
||||
},
|
||||
callback: (data) => {
|
||||
add_timetable_rows(frm, data.message);
|
||||
},
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
const add_timetable_rows = (frm, timetable) => {
|
||||
timetable.forEach((row) => {
|
||||
let child = frm.add_child("timetable");
|
||||
@@ -75,5 +84,40 @@ const add_timetable_rows = (frm, timetable) => {
|
||||
child.duration = row.duration;
|
||||
});
|
||||
frm.refresh_field("timetable");
|
||||
|
||||
set_legends(frm);
|
||||
};
|
||||
|
||||
const set_legends = (frm) => {
|
||||
if (frm.doc.timetable_template) {
|
||||
frm.clear_table("timetable_legends");
|
||||
frm.refresh_fields();
|
||||
frappe.call({
|
||||
method: "frappe.client.get_list",
|
||||
args: {
|
||||
doctype: "LMS Timetable Legend",
|
||||
parent: "LMS Timetable Template",
|
||||
fields: ["reference_doctype", "label", "color"],
|
||||
filters: {
|
||||
parent: frm.doc.timetable_template,
|
||||
parenttype: "LMS Timetable Template",
|
||||
},
|
||||
order_by: "idx",
|
||||
},
|
||||
callback: (data) => {
|
||||
add_legend_rows(frm, data.message);
|
||||
},
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
const add_legend_rows = (frm, legends) => {
|
||||
legends.forEach((row) => {
|
||||
let child = frm.add_child("timetable_legends");
|
||||
child.reference_doctype = row.reference_doctype;
|
||||
child.label = row.label;
|
||||
child.color = row.color;
|
||||
});
|
||||
frm.refresh_field("timetable_legends");
|
||||
frm.save();
|
||||
};
|
||||
|
||||
@@ -35,8 +35,10 @@
|
||||
"timetable_template",
|
||||
"column_break_anya",
|
||||
"show_live_class",
|
||||
"allow_future",
|
||||
"section_break_ontp",
|
||||
"timetable",
|
||||
"timetable_legends",
|
||||
"pricing_tab",
|
||||
"section_break_gsac",
|
||||
"paid_batch",
|
||||
@@ -220,7 +222,7 @@
|
||||
"default": "0",
|
||||
"fieldname": "show_live_class",
|
||||
"fieldtype": "Check",
|
||||
"label": "Show Live Class"
|
||||
"label": "Show live class"
|
||||
},
|
||||
{
|
||||
"fieldname": "section_break_ontp",
|
||||
@@ -263,11 +265,23 @@
|
||||
"fieldtype": "Code",
|
||||
"label": "Custom Script (JavaScript)",
|
||||
"options": "Javascript"
|
||||
},
|
||||
{
|
||||
"fieldname": "timetable_legends",
|
||||
"fieldtype": "Table",
|
||||
"label": "Timetable Legends",
|
||||
"options": "LMS Timetable Legend"
|
||||
},
|
||||
{
|
||||
"default": "1",
|
||||
"fieldname": "allow_future",
|
||||
"fieldtype": "Check",
|
||||
"label": "Allow accessing future dates"
|
||||
}
|
||||
],
|
||||
"index_web_pages_for_search": 1,
|
||||
"links": [],
|
||||
"modified": "2023-09-28 12:18:34.418812",
|
||||
"modified": "2023-10-12 12:53:37.351989",
|
||||
"modified_by": "Administrator",
|
||||
"module": "LMS",
|
||||
"name": "LMS Batch",
|
||||
|
||||
0
lms/lms/doctype/lms_timetable_legend/__init__.py
Normal file
0
lms/lms/doctype/lms_timetable_legend/__init__.py
Normal file
@@ -0,0 +1,8 @@
|
||||
// Copyright (c) 2023, Frappe and contributors
|
||||
// For license information, please see license.txt
|
||||
|
||||
// frappe.ui.form.on("LMS Timetable Legend", {
|
||||
// refresh(frm) {
|
||||
|
||||
// },
|
||||
// });
|
||||
@@ -0,0 +1,52 @@
|
||||
{
|
||||
"actions": [],
|
||||
"allow_rename": 1,
|
||||
"autoname": "hash",
|
||||
"creation": "2023-10-11 16:36:45.079267",
|
||||
"default_view": "List",
|
||||
"doctype": "DocType",
|
||||
"editable_grid": 1,
|
||||
"engine": "InnoDB",
|
||||
"field_order": [
|
||||
"reference_doctype",
|
||||
"label",
|
||||
"color"
|
||||
],
|
||||
"fields": [
|
||||
{
|
||||
"fieldname": "reference_doctype",
|
||||
"fieldtype": "Link",
|
||||
"in_list_view": 1,
|
||||
"label": "Reference DocType",
|
||||
"options": "DocType",
|
||||
"reqd": 1
|
||||
},
|
||||
{
|
||||
"fieldname": "color",
|
||||
"fieldtype": "Color",
|
||||
"in_list_view": 1,
|
||||
"label": "Color",
|
||||
"reqd": 1
|
||||
},
|
||||
{
|
||||
"fieldname": "label",
|
||||
"fieldtype": "Data",
|
||||
"in_list_view": 1,
|
||||
"label": "Label",
|
||||
"reqd": 1
|
||||
}
|
||||
],
|
||||
"index_web_pages_for_search": 1,
|
||||
"istable": 1,
|
||||
"links": [],
|
||||
"modified": "2023-10-11 17:15:37.039139",
|
||||
"modified_by": "Administrator",
|
||||
"module": "LMS",
|
||||
"name": "LMS Timetable Legend",
|
||||
"naming_rule": "Random",
|
||||
"owner": "Administrator",
|
||||
"permissions": [],
|
||||
"sort_field": "modified",
|
||||
"sort_order": "DESC",
|
||||
"states": []
|
||||
}
|
||||
@@ -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 LMSTimetableLegend(Document):
|
||||
pass
|
||||
@@ -0,0 +1,9 @@
|
||||
# Copyright (c) 2023, Frappe and Contributors
|
||||
# See license.txt
|
||||
|
||||
# import frappe
|
||||
from frappe.tests.utils import FrappeTestCase
|
||||
|
||||
|
||||
class TestLMSTimetableLegend(FrappeTestCase):
|
||||
pass
|
||||
@@ -11,5 +11,19 @@ frappe.ui.form.on("LMS Timetable Template", {
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
frm.set_query("reference_doctype", "timetable_legends", function () {
|
||||
let doctypes = [
|
||||
"Course Lesson",
|
||||
"LMS Quiz",
|
||||
"LMS Assignment",
|
||||
"LMS Live Class",
|
||||
];
|
||||
return {
|
||||
filters: {
|
||||
name: ["in", doctypes],
|
||||
},
|
||||
};
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
@@ -8,7 +8,8 @@
|
||||
"engine": "InnoDB",
|
||||
"field_order": [
|
||||
"title",
|
||||
"timetable"
|
||||
"timetable",
|
||||
"timetable_legends"
|
||||
],
|
||||
"fields": [
|
||||
{
|
||||
@@ -21,11 +22,17 @@
|
||||
"fieldtype": "Table",
|
||||
"label": "Timetable",
|
||||
"options": "LMS Batch Timetable"
|
||||
},
|
||||
{
|
||||
"fieldname": "timetable_legends",
|
||||
"fieldtype": "Table",
|
||||
"label": "Timetable Legends",
|
||||
"options": "LMS Timetable Legend"
|
||||
}
|
||||
],
|
||||
"index_web_pages_for_search": 1,
|
||||
"links": [],
|
||||
"modified": "2023-09-18 17:57:15.819072",
|
||||
"modified": "2023-10-11 17:09:05.096243",
|
||||
"modified_by": "Administrator",
|
||||
"module": "LMS",
|
||||
"name": "LMS Timetable Template",
|
||||
|
||||
@@ -552,7 +552,7 @@
|
||||
{% for legend in legends %}
|
||||
<div class="legend-item">
|
||||
<div class="legend-color" style="background-color: {{ legend.color }}"></div>
|
||||
<div class="legend-text">{{ legend.title }}</div>
|
||||
<div class="legend-text">{{ legend.label }}</div>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
@@ -574,6 +574,8 @@
|
||||
<script>
|
||||
frappe.boot.single_types = []
|
||||
let courses = {{ course_list | json }};
|
||||
const legends = {{ legends | json }};
|
||||
const allow_future = {{ batch_info.allow_future }}
|
||||
</script>
|
||||
|
||||
<link rel="stylesheet" href="https://uicdn.toast.com/calendar/latest/toastui-calendar.min.css" />
|
||||
|
||||
@@ -653,7 +653,6 @@ const setup_calendar = (events) => {
|
||||
const options = get_calendar_options(element, calendar_id);
|
||||
const calendar = new Calendar(container, options);
|
||||
this.calendar_ = calendar;
|
||||
console.log(options);
|
||||
create_events(calendar, events);
|
||||
add_links_to_events(calendar, events);
|
||||
scroll_to_date(calendar, events);
|
||||
@@ -698,8 +697,8 @@ const get_calendar_options = (element, calendar_id) => {
|
||||
|
||||
const create_events = (calendar, events, calendar_id) => {
|
||||
let calendar_events = [];
|
||||
|
||||
events.forEach((event, idx) => {
|
||||
let clr = get_background_color(event.reference_doctype);
|
||||
calendar_events.push({
|
||||
id: `event${idx}`,
|
||||
calendarId: calendar_id,
|
||||
@@ -707,7 +706,7 @@ const create_events = (calendar, events, calendar_id) => {
|
||||
start: `${event.date}T${event.start_time}`,
|
||||
end: `${event.date}T${event.end_time}`,
|
||||
isAllday: event.start_time ? false : true,
|
||||
borderColor: get_background_color(event.reference_doctype),
|
||||
borderColor: clr,
|
||||
backgroundColor: "var(--fg-color)",
|
||||
customStyle: {
|
||||
borderRadius: "var(--border-radius-md)",
|
||||
@@ -724,10 +723,15 @@ const create_events = (calendar, events, calendar_id) => {
|
||||
calendar.createEvents(calendar_events);
|
||||
};
|
||||
|
||||
const add_links_to_events = (calendar, events) => {
|
||||
const add_links_to_events = (calendar) => {
|
||||
calendar.on("clickEvent", ({ event }) => {
|
||||
const el = document.getElementById("clicked-event");
|
||||
window.open(event.raw.url, "_blank");
|
||||
let event_date = event.start.d.d;
|
||||
event_date = moment(event_date).format("YYYY-MM-DD");
|
||||
|
||||
let current_date = moment().format("YYYY-MM-DD");
|
||||
if (allow_future || moment(event_date).isSameOrBefore(current_date)) {
|
||||
window.open(event.raw.url, "_blank");
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
@@ -764,10 +768,10 @@ const set_calendar_range = (calendar, events) => {
|
||||
};
|
||||
|
||||
const get_background_color = (doctype) => {
|
||||
if (doctype == "Course Lesson") return "var(--blue-400)";
|
||||
if (doctype == "LMS Quiz") return "var(--green-400)";
|
||||
if (doctype == "LMS Assignment") return "var(--orange-400)";
|
||||
if (doctype == "LMS Live Class") return "var(--purple-400)";
|
||||
const match = legends.filter((legend) => {
|
||||
return legend.reference_doctype == doctype;
|
||||
});
|
||||
if (match.length) return match[0].color;
|
||||
};
|
||||
|
||||
const email_to_students = () => {
|
||||
|
||||
@@ -42,6 +42,7 @@ def get_context(context):
|
||||
"currency",
|
||||
"batch_details",
|
||||
"published",
|
||||
"allow_future",
|
||||
],
|
||||
as_dict=True,
|
||||
)
|
||||
@@ -96,7 +97,7 @@ def get_context(context):
|
||||
"parent": batch_name,
|
||||
},
|
||||
)
|
||||
context.legends = get_legends()
|
||||
context.legends = get_legends(batch_name)
|
||||
|
||||
custom_tabs = frappe.get_hooks("lms_batch_tabs")
|
||||
|
||||
@@ -261,22 +262,9 @@ def get_course_progress(batch_courses, student_details):
|
||||
student_details.courses[course.course] = 0
|
||||
|
||||
|
||||
def get_legends():
|
||||
return [
|
||||
{
|
||||
"title": "Lesson",
|
||||
"color": "var(--blue-400)",
|
||||
},
|
||||
{
|
||||
"title": "Quiz",
|
||||
"color": "var(--green-400)",
|
||||
},
|
||||
{
|
||||
"title": "Assignment",
|
||||
"color": "var(--orange-400)",
|
||||
},
|
||||
{
|
||||
"title": "Live Class",
|
||||
"color": "var(--purple-400)",
|
||||
},
|
||||
]
|
||||
def get_legends(batch):
|
||||
return frappe.get_all(
|
||||
"LMS Timetable Legend",
|
||||
filters={"parenttype": "LMS Batch", "parent": batch},
|
||||
fields=["reference_doctype", "color", "label"],
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user