From a707095faef20e09fc7cad282d3d565431a258fb Mon Sep 17 00:00:00 2001 From: Jannat Patel Date: Mon, 23 Oct 2023 19:11:36 +0530 Subject: [PATCH 1/2] fix: link student emails to batch --- lms/lms/doctype/lms_batch/lms_batch.py | 11 ---------- lms/www/batches/batch.js | 28 +++++++++++++++++++++++--- 2 files changed, 25 insertions(+), 14 deletions(-) diff --git a/lms/lms/doctype/lms_batch/lms_batch.py b/lms/lms/doctype/lms_batch/lms_batch.py index 68ac25a78..828ef2f92 100644 --- a/lms/lms/doctype/lms_batch/lms_batch.py +++ b/lms/lms/doctype/lms_batch/lms_batch.py @@ -381,14 +381,3 @@ def get_timetable_details(timetable): timetable = sorted(timetable, key=lambda k: k["date"]) return timetable - - -@frappe.whitelist() -def send_email_to_students(batch, subject, message): - frappe.only_for("Moderator") - students = frappe.get_all("Batch Student", {"parent": batch}, pluck="student") - frappe.sendmail( - recipients=students, - subject=subject, - message=message, - ) diff --git a/lms/www/batches/batch.js b/lms/www/batches/batch.js index 1f4cd60d8..f2f43f11c 100644 --- a/lms/www/batches/batch.js +++ b/lms/www/batches/batch.js @@ -798,11 +798,33 @@ const email_to_students = () => { const send_email = (values) => { frappe.call({ - method: "lms.lms.doctype.lms_batch.lms_batch.send_email_to_students", + method: "frappe.client.get_list", args: { - batch: $(".class-details").data("batch"), + doctype: "Batch Student", + parent: "LMS Batch", + fields: ["student"], + filters: { + parent: $(".class-details").data("batch"), + }, + }, + callback: (data) => { + send_email_to_students(data.message, values); + }, + }); +}; + +const send_email_to_students = (students, values) => { + students = students.map((row) => row.student); + frappe.call({ + method: "frappe.core.doctype.communication.email.make", + args: { + recipients: students.join(", "), + cc: values.reply_to, subject: values.subject, - message: values.message, + content: values.message, + doctype: "LMS Batch", + name: $(".class-details").data("batch"), + send_email: 1, }, callback: (r) => { this.email_dialog.hide(); From 60e78e8e7483ba8d911e2bc0ef73a662d7681e17 Mon Sep 17 00:00:00 2001 From: Jannat Patel Date: Mon, 23 Oct 2023 20:12:48 +0530 Subject: [PATCH 2/2] feat: emails tab --- lms/public/css/style.css | 4 +++ lms/www/batches/batch.html | 56 ++++++++++++++++++++++++++++++++------ lms/www/batches/batch.js | 3 ++ lms/www/batches/batch.py | 7 +++++ 4 files changed, 62 insertions(+), 8 deletions(-) diff --git a/lms/public/css/style.css b/lms/public/css/style.css index acc05bee9..c6c9e99de 100644 --- a/lms/public/css/style.css +++ b/lms/public/css/style.css @@ -2478,4 +2478,8 @@ select { .questions-table .row-index { display: none; +} + +.text-color { + color: var(--text-color); } \ No newline at end of file diff --git a/lms/www/batches/batch.html b/lms/www/batches/batch.html index 86cb1202f..cda893029 100644 --- a/lms/www/batches/batch.html +++ b/lms/www/batches/batch.html @@ -75,14 +75,6 @@ - {% if is_moderator %} -
- -
- {% endif %} - {% if batch_info.custom_component %}
{{ batch_info.custom_component }} @@ -140,6 +132,15 @@ + + {% endif %} {% if batch_students | length and (is_moderator or is_student) %} @@ -192,6 +193,10 @@
{{ AssessmentsSection(batch_info) }}
+ +
+ {{ EmailsSection() }} +
{% endif %} {% if batch_students | length and (is_moderator or is_student or is_evaluator) %} @@ -376,6 +381,41 @@ {% endmacro %} + +{% macro EmailsSection() %} +
+ +
+
+ {% for email in batch_emails %} +
+
+ + + {% set member = frappe.db.get_value("User", email.sender, ["full_name", "username", "name", "user_image"], as_dict=1) %} + {{ widgets.Avatar(member=member, avatar_class="avatar-small") }} + + + {{ member.full_name }} +
+ + {{ frappe.utils.pretty_date(email.communication_date) }} + +
+
+
+
+
+ {{ email.content }} +
+
+ {% endfor %} +
+{% endmacro %} + + {% macro AssessmentList(assessments) %} {% if assessments | length %}
diff --git a/lms/www/batches/batch.js b/lms/www/batches/batch.js index 5a1407ef3..be3ea75d9 100644 --- a/lms/www/batches/batch.js +++ b/lms/www/batches/batch.js @@ -843,6 +843,9 @@ const send_email_to_students = (students, values) => { message: __("Email sent successfully"), indicator: "green", }); + setTimeout(() => { + window.location.reload(); + }, 2000); }, }); }; diff --git a/lms/www/batches/batch.py b/lms/www/batches/batch.py index bb3ad307e..3f45ef8da 100644 --- a/lms/www/batches/batch.py +++ b/lms/www/batches/batch.py @@ -71,6 +71,13 @@ def get_context(context): ) context.course_name_list = [course.course for course in context.batch_courses] context.assessments = get_assessments(batch_name) + context.batch_emails = frappe.get_all( + "Communication", + filters={"reference_doctype": "LMS Batch", "reference_name": batch_name}, + fields=["subject", "content", "recipients", "cc", "communication_date", "sender"], + order_by="communication_date desc", + ) + context.batch_students = get_class_student_details( batch_students, batch_courses, context.assessments )