Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/Adding Teacher Comment Mailer #46

Open
wants to merge 2 commits into
base: 8.0.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 received_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.received_notification(project,self).deliver
rescue => e
logger.error "Failed to send emails from comment submission.ProjectID: #{project.id} for task: #{self.id} . 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/<%[email protected]%>/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 %>