Skip to content

Commit

Permalink
Merge pull request #655 from pateljannat/append-student-email
Browse files Browse the repository at this point in the history
fix: Append student email to batch
  • Loading branch information
pateljannat authored Oct 25, 2023
2 parents 1d77fd3 + 397128f commit 48982e8
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 21 deletions.
9 changes: 0 additions & 9 deletions lms/lms/doctype/lms_batch/lms_batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -396,15 +396,6 @@ def get_timetable_details(timetable):
return timetable


@frappe.whitelist()
def send_email_to_students(batch, subject, reply_to, message):
frappe.only_for("Moderator")
students = frappe.get_all("Batch Student", {"parent": batch}, pluck="student")
frappe.sendmail(
recipients=students, subject=subject, reply_to=reply_to, message=message
)


@frappe.whitelist()
def is_milestone_complete(idx, batch):
previous_rows = frappe.get_all(
Expand Down
4 changes: 4 additions & 0 deletions lms/public/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -2478,4 +2478,8 @@ select {

.questions-table .row-index {
display: none;
}

.text-color {
color: var(--text-color);
}
56 changes: 48 additions & 8 deletions lms/www/batches/batch.html
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,6 @@
</div>
</div>

{% if is_moderator %}
<div class="mt-4">
<button class="btn btn-secondary btn-sm btn-email">
{{ _("Email to Students") }}
</button>
</div>
{% endif %}

{% if batch_info.custom_component %}
<div class="mt-4">
{{ batch_info.custom_component }}
Expand Down Expand Up @@ -140,6 +132,15 @@
</span>
</a>
</li>

<li class="nav-item">
<a class="nav-link" data-toggle="tab" href="#emails">
{{ _("Emails") }}
<span class="course-list-count">
{{ batch_emails | length }}
</span>
</a>
</li>
{% endif %}

{% if batch_students | length and (is_moderator or is_student) %}
Expand Down Expand Up @@ -192,6 +193,10 @@
<div class="tab-pane" id="assessments" role="tabpanel" aria-labelledby="assessments">
{{ AssessmentsSection(batch_info) }}
</div>

<div class="tab-pane" id="emails" role="tabpanel" aria-labelledby="emails">
{{ EmailsSection() }}
</div>
{% endif %}

{% if batch_students | length and (is_moderator or is_student or is_evaluator) %}
Expand Down Expand Up @@ -376,6 +381,41 @@
</article>
{% endmacro %}


{% macro EmailsSection() %}
<div class="my-4">
<button class="btn btn-secondary btn-sm btn-email">
{{ _("Email to Students") }}
</button>
</div>
<div>
{% for email in batch_emails %}
<div class="frappe-card mb-5">
<div class="flex justify-between m-1">
<span class="text-color flex">
<span class="margin-right">
{% 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") }}
</span>
<span>
{{ member.full_name }}
<div class="text-muted">
<span class="frappe-timestamp" data-timestamp="{{ email.communication_date }}" title="{{ communication_date }}">
{{ frappe.utils.pretty_date(email.communication_date) }}
</span>
</div>
</span>
</span>
</div>
<div class="ml-10">
{{ email.content }}
</div>
</div>
{% endfor %}
</div>
{% endmacro %}


{% macro AssessmentList(assessments) %}
{% if assessments | length %}
<div class="form-grid">
Expand Down
32 changes: 28 additions & 4 deletions lms/www/batches/batch.js
Original file line number Diff line number Diff line change
Expand Up @@ -831,19 +831,43 @@ 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,
reply_to: values.reply_to,
message: values.message,
content: values.message,
doctype: "LMS Batch",
name: $(".class-details").data("batch"),
send_email: 1,
},
callback: (r) => {
this.email_dialog.hide();
frappe.show_alert({
message: __("Email sent successfully"),
indicator: "green",
});
setTimeout(() => {
window.location.reload();
}, 2000);
},
});
};
7 changes: 7 additions & 0 deletions lms/www/batches/batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down

0 comments on commit 48982e8

Please sign in to comment.