Skip to content

Commit

Permalink
Adding Teacher Comment Mailer
Browse files Browse the repository at this point in the history
  • Loading branch information
Shounaks committed Nov 29, 2024
1 parent 3ff0c5d commit fcabcf4
Show file tree
Hide file tree
Showing 4 changed files with 119 additions and 0 deletions.
22 changes: 22 additions & 0 deletions app/mailers/teacher_response_mailer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
class TeacherResponseMailer < ApplicationMailer
def add_general
@doubtfire_host = Doubtfire::Application.config.institution[:host]
@doubtfire_product_name = Doubtfire::Application.config.institution[:product_name]
@unsubscribe_url = "#{@doubtfire_host}/#/home?notifications"
end

def recieved_notification(project, task)
return nil if project.nil?

add_general

@student = project.student
@project = project
@convenor = project.main_convenor_user

email_with_name = %("#{@student.name}" <#{@student.email}>)
convenor_email = %("#{@convenor.name}" <#{@convenor.email}>)
subject = "#{project.unit.name} #{task}: You have recieved comments."
mail(to: email_with_name, from: convenor_email, subject: subject)
end
end
8 changes: 8 additions & 0 deletions app/models/task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -735,6 +735,14 @@ def add_status_comment(current_user, status)
comment.recipient = current_user == project.student ? project.tutor_for(task_definition) : project.student
comment.save!

# send emails...
begin
logger.info "Sending comment notification email for project #{project.id}"
TeacherResponseMailer.recieved_notification(project,self).deliver
rescue => e
logger.error "Failed to send emails from comment submission. Rescued with error: #{e.message}"
end

comment
end

Expand Down
73 changes: 73 additions & 0 deletions app/views/teacher_response_mailer/recieved_notification.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
body {
font-family: "Lucida Grande", "Helvetica Neue", Helvetica, Arial, sans-serif;
color: #333;
font-size: 14px;
width: 500px;
margin: 100px auto 0px auto;
font-size: 0.9em;
}
main {
background-image: url('https://<%= @doubtfire_host %>/assets/images/logo.svg');
background-size: 3.5em;
background-repeat: no-repeat;
background-position: 30px 45px;
padding: 30px 40px;
padding-left: 100px;
border: solid 1px #aaa;
border-radius: 7px;
line-height: 200%;
text-align: justify;
}
footer {
text-align: right;
margin-top: 10px;
color: #aaa;
font-size: 0.7em;
}
a, a:visited {
color: #6a97d2;
text-decoration: none;
}
a:hover {
text-decoration: underline;
}
ul {
list-style: none;
}
h1 {
font-size: 1.1em;
}
</style>
</head>
<body>
<main>
<h1> <%= @doubtfire_product_name %> Notification </h1>
<p>Hi <%= @student.first_name %>,</p>
<p>
I have checked your tasks and provided some feedback. Login and check the status <%= @hasComments ? 'and comments' : ''%> of the following tasks:
<ul>
<% @tasks.each do |task| %>
<li>
<strong><%= task.task_definition.abbreviation %> - </strong>
<a href="https://<%= @doubtfire_host %>/#/projects/<%=@project.id%>/dashboard/<%=task.task_definition.abbreviation%>">
<%=task.task_definition.name%>
</a>
<%= task.is_last_comment_by?(@tutor) ? ' with comments' : ''%>
</li>
<% end %>
</ul>
</p>
<p>
Cheers, <br />
The <%= @doubtfire_product_name %> Team on behalf of <%= @tutor.name %>
</p>
</main>
<footer>
<a href="<%= @unsubscribe_url %>">Unsubscribe</a> | Generated with <%= @doubtfire_product_name %>
</footer>
</body>
</html>
16 changes: 16 additions & 0 deletions app/views/teacher_response_mailer/recieved_notification.text.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
Hi <%= @student.first_name %>,

I have checked your tasks and provided some feedback. Login and check the status<%= @has_comments ? ' and comments' : ''%> of the following tasks:

<% @tasks.each do |task| %>
* <%= task.task_definition.abbreviation %> - <%=task.task_definition.name%> <%= task.is_last_comment_by?(@tutor) ? ' - with comments' : ''%>
<% end %>

Cheers,
The <%= @doubtfire_product_name %> Team on behalf of <%= @tutor.name %>

---

Visit <%= @unsubscribe_url%> to unsubscribe from these notifications.

Generated with <%= @doubtfire_product_name %>

0 comments on commit fcabcf4

Please sign in to comment.