diff --git a/lms/lms/doctype/lms_class/lms_class.py b/lms/lms/doctype/lms_class/lms_class.py
index 43c4f505..fd490dae 100644
--- a/lms/lms/doctype/lms_class/lms_class.py
+++ b/lms/lms/doctype/lms_class/lms_class.py
@@ -92,7 +92,7 @@ def update_course(class_name, course, value):
@frappe.whitelist()
def create_live_class(class_name, title, duration, date, time, description=None):
- date = format_date(date, "yyyy-mm-dd")
+ date = format_date(date, "yyyy-mm-dd", True)
payload = {
"topic": title,
"start_time": format_datetime(f"{date} {time}", "yyyy-MM-ddTHH:mm:ssZ"),
@@ -120,7 +120,7 @@ def create_live_class(class_name, title, duration, date, time, description=None)
"host": frappe.session.user,
"date": date,
"time": time,
- "class": class_name,
+ "class_name": class_name,
"password": data.get("password"),
"description": description,
}
diff --git a/lms/lms/doctype/lms_live_class/lms_live_class.json b/lms/lms/doctype/lms_live_class/lms_live_class.json
index 6c3f8bf8..b3ac10c1 100644
--- a/lms/lms/doctype/lms_live_class/lms_live_class.json
+++ b/lms/lms/doctype/lms_live_class/lms_live_class.json
@@ -9,7 +9,7 @@
"field_order": [
"title",
"host",
- "class",
+ "class_name",
"password",
"column_break_astv",
"description",
@@ -57,12 +57,6 @@
"label": "Timezone",
"reqd": 1
},
- {
- "fieldname": "class",
- "fieldtype": "Link",
- "label": "Class",
- "options": "LMS Class"
- },
{
"fieldname": "host",
"fieldtype": "Link",
@@ -114,11 +108,17 @@
"fieldtype": "Time",
"label": "Time",
"reqd": 1
+ },
+ {
+ "fieldname": "class_name",
+ "fieldtype": "Link",
+ "label": "Class",
+ "options": "LMS Class"
}
],
"index_web_pages_for_search": 1,
"links": [],
- "modified": "2023-03-02 23:00:33.006661",
+ "modified": "2023-03-06 16:59:28.565587",
"modified_by": "Administrator",
"module": "LMS",
"name": "LMS Live Class",
diff --git a/lms/lms/doctype/lms_live_class/lms_live_class.py b/lms/lms/doctype/lms_live_class/lms_live_class.py
index 81de90d2..d6a332eb 100644
--- a/lms/lms/doctype/lms_live_class/lms_live_class.py
+++ b/lms/lms/doctype/lms_live_class/lms_live_class.py
@@ -1,9 +1,60 @@
# Copyright (c) 2023, Frappe and contributors
# For license information, please see license.txt
-# import frappe
+import frappe
from frappe.model.document import Document
class LMSLiveClass(Document):
- pass
+ def after_insert(self):
+ """calendar = frappe.db.get_value(
+ "Google Calendar", {"user": frappe.session.user, "enable": 1}, "name"
+ )
+
+ if calendar:
+ event = self.create_event()
+ self.add_event_participants(event, calendar)"""
+
+ def create_event(self):
+ event = frappe.get_doc(
+ {
+ "doctype": "Event",
+ "subject": f"Live Class {self.title}",
+ "starts_on": f"{self.date} {self.time}",
+ }
+ )
+ event.save()
+
+ return event
+
+ def add_event_participants(self, event, calendar):
+ participants = frappe.get_all(
+ "Class Student", {"parent": self.class_name}, pluck="student"
+ )
+
+ participants.append(frappe.session.user)
+ print(participants)
+ for participant in participants:
+ print(participant)
+ frappe.get_doc(
+ {
+ "doctype": "Event Participants",
+ "reference_doctype": "User",
+ "reference_docname": participant,
+ "email": participant,
+ "parent": event.name,
+ "parenttype": "Event",
+ "parentfield": "event_participants",
+ }
+ ).save()
+
+ event.reload()
+ event.update(
+ {
+ "sync_with_google_calendar": 1,
+ "google_calendar": calendar,
+ "description": f"A Live Class has been scheduled on {frappe.utils.format_date(self.date, 'medium')} at { frappe.utils.format_time(self.time, 'hh:mm a')}. Click on this link to join. {self.join_url}. {self.description}",
+ }
+ )
+
+ event.save()
diff --git a/lms/public/css/style.css b/lms/public/css/style.css
index ede48338..d0658feb 100644
--- a/lms/public/css/style.css
+++ b/lms/public/css/style.css
@@ -1984,3 +1984,19 @@ select {
.resize-none {
resize: none;
}
+
+.lms-page-style {
+ background-color: var(--fg-color);
+ font-size: var(--text-base);
+}
+
+.lms-card {
+ display: flex;
+ flex-direction: column;
+ border-width: 1px;
+ border-radius: 0.75rem;
+ border: 1px solid var(--gray-200);
+ padding: 1rem;
+ height: 100%;
+ position: relative;
+}
diff --git a/lms/www/classes/class.html b/lms/www/classes/class.html
index 46438ceb..9d9199ab 100644
--- a/lms/www/classes/class.html
+++ b/lms/www/classes/class.html
@@ -5,10 +5,10 @@
{% block page_content %}
-
+
{{ BreadCrumb(class_info) }}
-
+
{{ ClassDetails(class_info) }}
{{ ClassSections(class_info, class_courses, class_students, published_courses) }}
@@ -30,7 +30,11 @@
{% macro ClassDetails(class_info) %}
-
+
+
+ {{ class_info.title }}
+
+
{% if class_info.start_date %}
{{ frappe.utils.format_date(class_info.start_date, "medium") }} -
@@ -42,11 +46,8 @@
{% endif %}
-
- {{ class_info.title }}
-
{% if class_info.description %}
-
+
{{ class_info.description }}
{% endif %}
@@ -74,11 +75,13 @@
+ {% if is_moderator or is_student %}
{{ _("Live Class") }}
+ {% endif %}
@@ -93,9 +96,11 @@
{{ StudentsSection(class_info, class_students) }}
+ {% if is_moderator or is_student %}
{{ LiveClassSection(class_info, live_classes) }}
+ {% endif %}
@@ -119,7 +124,7 @@
{% macro StudentsSection(class_info, class_students) %}
-
+
{% if is_moderator %}
{{ AddStudents() }}
{% endif %}
@@ -190,15 +195,15 @@
{% macro LiveClassSection(class_info, live_classes) %}
- {% if is_moderator %}
{{ CreateLiveClass(class_info) }}
- {% endif %}
{{ LiveClassList(class_info, live_classes) }}
{% endmacro %}
{% macro CreateLiveClass(class_info) %}
+
+{% if is_moderator %}
@@ -228,23 +233,38 @@
+{% endif %}
+
{% endmacro %}
{% macro LiveClassList(class_info, live_classes) %}
-
+
{% for class in live_classes %}
-
-
+
+
{{ class.title }}
-
- {{ class.description }}
-
-
+
{{ frappe.utils.format_date(class.date, "medium") }} {{ _("at") }}
{{ frappe.utils.format_time(class.time, "hh:mm a") }}
+
+ {{ class.description }}
+
+
+ {% if class.owner == frappe.session.user and class.date == frappe.utils.getdate() %}
+
+ {{ _("Start Class") }}
+
+ {% endif %}
+
+ {% if is_student and class.date == frappe.utils.getdate() %}
+
+ {{ _("Join Class") }}
+
+ {% endif %}
+
{% endfor %}
diff --git a/lms/www/classes/class.js b/lms/www/classes/class.js
index 09cfcc76..192c3e2d 100644
--- a/lms/www/classes/class.js
+++ b/lms/www/classes/class.js
@@ -83,10 +83,11 @@ const update_course = (e) => {
};
const create_live_class = (e) => {
+ let class_name = $(".class-details").data("class");
frappe.call({
method: "lms.lms.doctype.lms_class.lms_class.create_live_class",
args: {
- class_name: $(".class-details").data("class"),
+ class_name: class_name,
title: $("input[data-fieldname='meeting_title']").val(),
duration: $("input[data-fieldname='meeting_duration']").val(),
date: $("input[data-fieldname='meeting_date']").val(),
@@ -97,6 +98,16 @@ const create_live_class = (e) => {
},
callback: (data) => {
$("#live-class-modal").modal("hide");
+ frappe.show_alert(
+ {
+ message: __("Live Class created successfully"),
+ indicator: "green",
+ },
+ 3
+ );
+ setTimeout(function () {
+ window.location.href = `/classes/${class_name}#live-class`;
+ }, 1000);
},
});
};
diff --git a/lms/www/classes/class.py b/lms/www/classes/class.py
index d5f2fd11..09a98a9c 100644
--- a/lms/www/classes/class.py
+++ b/lms/www/classes/class.py
@@ -1,6 +1,7 @@
import frappe
from lms.lms.utils import has_course_moderator_role
from frappe import _
+from frappe.utils import getdate
def get_context(context):
@@ -28,14 +29,6 @@ def get_context(context):
"Class Student", {"parent": class_name}, ["student", "student_name", "username"]
)
- context.is_moderator = has_course_moderator_role()
-
- context.live_classes = frappe.get_all(
- "LMS Live Class",
- {"class": class_name},
- ["title", "description", "time", "date", "start_url", "join_url"],
- )
-
for student in class_students:
if student.student == frappe.session.user:
session_user.append(student)
@@ -46,3 +39,15 @@ def get_context(context):
context.class_students = session_user + remaining_students
else:
context.class_students = class_students
+
+ context.is_moderator = has_course_moderator_role()
+
+ students = [student.student for student in class_students]
+ context.is_student = frappe.session.user in students
+
+ context.live_classes = frappe.get_all(
+ "LMS Live Class",
+ {"class_name": class_name, "date": [">=", getdate()]},
+ ["title", "description", "time", "date", "start_url", "join_url", "owner"],
+ order_by="date",
+ )
diff --git a/lms/www/classes/index.html b/lms/www/classes/index.html
index 22684ef4..74e26d29 100644
--- a/lms/www/classes/index.html
+++ b/lms/www/classes/index.html
@@ -4,10 +4,10 @@
{% endblock %}
{% block page_content %}
-
+
{% if has_course_moderator_role() %}
-
+
{{ _("Create Class") }}
{% endif %}
@@ -34,7 +34,7 @@
{% set course_count = frappe.db.count("Class Course", {"parent": class.name}) %}
{% set student_count = frappe.db.count("Class Student", {"parent": class.name}) %}
-