This repository was archived by the owner on May 13, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Issues 18 and 25: Daily/weekly summary for users and admins #34
Open
henriquelampert
wants to merge
2
commits into
infosimples:master
Choose a base branch
from
henriquelampert:summary_mail
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,4 +17,6 @@ | |
|
|
||
| # Ignore user profile files | ||
| /.rvmrc | ||
| .DS_Store | ||
| .DS_Store | ||
|
|
||
| /config/smtp_config.yml | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| jQuery -> | ||
| if $("#user_is_admin").is ":checked" | ||
| $("#subscription_to_admin").show() | ||
| else | ||
| $("#subscription_to_admin").hide() | ||
|
|
||
| $("#user_is_admin").change -> $("#subscription_to_admin").toggle() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| class UserMailer < ActionMailer::Base | ||
| include TimesheetHelper | ||
| helper_method :hours_and_minutes | ||
|
|
||
| before_action :set_date | ||
|
|
||
| default from: "Cuckoo <#{SMTP_CONFIG[:from_email]}>" | ||
|
|
||
| def send_day_summary_to_all_subscribers | ||
|
|
||
| users = User.where(subscriber_to_user_summary_email: true) | ||
|
|
||
| users.each do |user| | ||
| user_day_summary_email(user).deliver | ||
| end | ||
|
|
||
| admins = User.where(subscriber_to_admin_summary_email: true) | ||
|
|
||
| admin_day_summary_email(admins).deliver | ||
|
|
||
| end | ||
|
|
||
| def send_week_summary_to_all_subscribers | ||
|
|
||
| users = User.where(subscriber_to_user_summary_email: true) | ||
|
|
||
| users.each do |user| | ||
| user_week_summary_email(user).deliver | ||
| end | ||
|
|
||
| admins = User.where(subscriber_to_admin_summary_email: true) | ||
|
|
||
| admin_week_summary_email(admins).deliver | ||
|
|
||
| end | ||
|
|
||
| def user_day_summary_email(user) | ||
| @user = user | ||
| subject = (@date.strftime('%b/%d')) + ' summary' | ||
| mail to: user.email, subject: subject, | ||
| content: 'html', template_name: 'user_day_summary_email' | ||
| end | ||
|
|
||
| def admin_day_summary_email(recipients) | ||
| @users = User.all | ||
| subject = 'All users ' + @date.strftime('%b/%d') + ' summary' | ||
| emails = get_emails_from(recipients) | ||
| mail to: emails, subject: subject, | ||
| content: 'html', template_name: 'admin_day_summary_email' | ||
| end | ||
|
|
||
| def user_week_summary_email(user) | ||
| @user = user | ||
| subject = @date.at_beginning_of_week.strftime('%b/%d') \ | ||
| + ' to ' + @date.at_end_of_week.strftime('%b/%d') + ' summary' | ||
| mail to: user.email, subject: subject, | ||
| content: 'html', template_name: 'user_week_summary_email' | ||
| end | ||
|
|
||
| def admin_week_summary_email(recipients) | ||
| @users = User.all | ||
| subject = 'All users ' + @date.at_beginning_of_week.strftime('%b/%d') \ | ||
| + ' to ' + @date.at_end_of_week.strftime('%b/%d') + ' summary' | ||
| emails = get_emails_from(recipients) | ||
| mail to: emails, subject: subject, | ||
| content: 'html', template_name: 'admin_week_summary_email' | ||
| end | ||
|
|
||
| private | ||
|
|
||
| def set_date | ||
| @date = Time.current.to_date | ||
| end | ||
|
|
||
| def get_emails_from(recipients) | ||
| if (recipients.class == User) | ||
| recipients.email | ||
| else | ||
| recipients.collect(&:email) | ||
| end | ||
| end | ||
|
|
||
| end | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| class Report | ||
|
|
||
| def initialize(user) | ||
| @user = user | ||
| end | ||
|
|
||
| def week_summary(date = Time.current.to_date) | ||
|
|
||
| week_begin = date.at_beginning_of_week.at_midnight.gmtime | ||
| week_end = date.at_end_of_week.at_midnight.gmtime | ||
| entries = TimeEntry.where(user_id: @user.id) | ||
| .where('started_at >= ? AND started_at < ?', week_begin, week_end) | ||
| .includes(:project, :task) | ||
|
|
||
| time_summary = {} | ||
| entries.each do |time_entry| | ||
| project = time_entry.project.name | ||
| task = time_entry.task.name | ||
|
|
||
| if (time_summary[project].nil?) | ||
| time_summary[project] = {} | ||
| time_summary[project][:total] = 0 | ||
| time_summary[project][:tasks] = {} | ||
| end | ||
|
|
||
| if (time_summary[project][:tasks][task].nil?) | ||
| time_summary[project][:tasks][task] = 0 | ||
| end | ||
|
|
||
| if (!time_entry.total_time.nil?) | ||
| time_summary[project][:total] += time_entry.total_time | ||
| time_summary[project][:tasks][task] += time_entry.total_time | ||
| end | ||
|
|
||
| end | ||
|
|
||
| { | ||
| date: date, | ||
| weekdays: week_days(date), | ||
| week_hours: week_hours(date), | ||
| time_summary: time_summary | ||
| } | ||
|
|
||
| end | ||
|
|
||
| def day_summary(date = Time.current.to_date) | ||
| { | ||
| date: date, | ||
| weekdays: week_days(date), | ||
| week_hours: week_hours(date), | ||
| day_entries: day_entries(date) | ||
| } | ||
| end | ||
|
|
||
| def week_hours(date = Time.current.to_date) | ||
| Timesheet.new(@user).week_hours(date) | ||
| end | ||
|
|
||
| def week_days(date = Time.current.to_date) | ||
| (date.at_beginning_of_week..date.at_end_of_week) | ||
| end | ||
|
|
||
| def day_entries(date = Time.current.to_date) | ||
| Timesheet.new(@user).day_entries(date) | ||
| end | ||
|
|
||
|
|
||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,92 @@ | ||
| <% if !summary[:day_entries].find_by(ended_at: nil).nil? %> | ||
|
||
| <h3> You have clock(s) still <span style="color:white; background-color:red">Running</span>!!! </h3> | ||
| <% end %> | ||
|
|
||
| <table> | ||
| <tr> | ||
| <% summary[:weekdays].each do |weekday| %> | ||
| <td style="text-align:center;<%= (weekday.day == summary[:date].day) ? "font-weight:bold" : "color:#777" %>" > | ||
| <%= weekday.strftime('%A') %><br> | ||
| <span>(<%= hours_and_minutes(summary[:week_hours][weekday.day]) %>)</span> | ||
| </td> | ||
| <% end %> | ||
| <td style="text-align:center; color:#777"> | ||
| Total<br> | ||
| <span>(<%= hours_and_minutes(summary[:week_hours].values.sum) %>)</span> | ||
| </td> | ||
| </tr> | ||
| </table> | ||
|
|
||
| <br> | ||
|
|
||
| <% if summary[:day_entries].empty? %> | ||
| <div><%= t :no_time_entry %></div> | ||
| <% else %> | ||
| <!-- Table with the time entries --> | ||
| <table style="text-align:center"> | ||
| <!-- Header of table with the time entries variables --> | ||
| <thead> | ||
| <tr> | ||
| <th style="text-align:left">Activity</th> | ||
| <th>Time</th> | ||
| <th>Duration</th> | ||
| </tr> | ||
| </thead> | ||
| <tbody> | ||
| <% summary[:day_entries].each do |time_entry| %> | ||
| <tr> | ||
| <td style="text-align:left; min-width:10em"> | ||
| <ul style="list-style-type:none; padding-left:0px"> | ||
|
|
||
| <!-- Project | Task > Description --> | ||
| <li style="text-align:left"> | ||
|
|
||
| <div style="text-size:1.2em"> | ||
| <% if time_entry.is_billable? %> | ||
| <span style="background-color:blue; color:white">Billable</span> | ||
| <% end %> | ||
| <%= time_entry.project.name %><span> | </span><%= time_entry.task.name %> | ||
| <% if time_entry.description.present? %><span>></span><% end %> | ||
| </div> | ||
|
|
||
| <% if time_entry.description.present? %> | ||
| <div style="margin-left:8px"> | ||
| <%= simple_format time_entry.description %> | ||
| </div> | ||
| <% end %> | ||
|
|
||
| </li> | ||
|
|
||
| </ul> | ||
| </td> | ||
|
|
||
| <td style="min-width:5em"> | ||
|
|
||
| <!-- Started_at and Ended_at Time column --> | ||
| <div style="text-size:1.2em"> | ||
| <%= time_entry.started_at.strftime("%H:%M") %><br> | ||
| <%= time_entry.ended_at.strftime("%H:%M") unless time_entry.ended_at.nil? %> | ||
| </div> | ||
|
|
||
| </td> | ||
|
|
||
| <td> | ||
|
|
||
| <!-- Duration column --> | ||
| <div style="text-size:1.2em"> | ||
| <% if !time_entry.ended_at.nil? %> | ||
| <%= hours_and_minutes(time_entry.ended_at - time_entry.started_at) %> | ||
| <% else %> | ||
| <span style="background-color:red; color:white">Running</span> | ||
| <% end %> | ||
| </div> | ||
| </td> | ||
|
|
||
| </tr> | ||
|
|
||
| <% end %><!-- end for day_entries loop --> | ||
|
|
||
| </tbody> | ||
|
|
||
| </table> | ||
| <% end %> | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| <!-- Table with week hours --> | ||
|
||
| <table> | ||
| <tr> | ||
| <% summary[:weekdays].each do |weekday| %> | ||
| <td style="text-align:center; color:#555"> | ||
| <%= weekday.strftime('%A') %><br> | ||
| <span>(<%= hours_and_minutes(summary[:week_hours][weekday.day]) %>)</span> | ||
| </td> | ||
| <% end %> | ||
| <td style="text-align:center"> | ||
| Total<br> | ||
| <span>(<%= hours_and_minutes(summary[:week_hours].values.sum) %>)</span> | ||
| </td> | ||
| </tr> | ||
| </table> | ||
|
|
||
| <% if summary[:time_summary].empty? %> | ||
| <br> | ||
| <div><%= t :no_time_entry %></div> | ||
| <% else %> | ||
| <!-- Table with time spent on each project and tasks --> | ||
| <table style="text-align:center"> | ||
| <tbody> | ||
| <% summary[:time_summary].each do |project, info| %> | ||
| <tr> | ||
| <td style="text-align:left; min-width:250px"> | ||
| <ul style="list-style-type:none; padding-left:0px"> | ||
| <!-- Project | Task > Description --> | ||
| <li style="text-align:left; margin:0px"> | ||
|
|
||
| <div style="font-size:1.25em; font-weight:bold"> | ||
| <%= project %> | ||
| </div> | ||
|
|
||
| </li> | ||
|
|
||
| </ul> | ||
| </td> | ||
|
|
||
| <td> | ||
|
|
||
| <div style="font-size:1.25em; font-weight:bold"> | ||
| <%= hours_and_minutes(info[:total]) %> | ||
| </div> | ||
|
|
||
| </td> | ||
|
|
||
| </tr> | ||
|
|
||
| <tr style="text-align:left"> | ||
| <td style="padding-left:8px; max-width:450px"> | ||
| <% info[:tasks].each do |task, duration| %> | ||
| <span div style="font-size:1em"> | ||
| <%= task %> (<%= hours_and_minutes(duration) %>) | ||
| </span><br> | ||
| <% end %> | ||
| </td> | ||
| </tr> | ||
|
|
||
| <% end %><!-- end for day_entries loop --> | ||
|
|
||
| </tbody> | ||
|
|
||
| </table> | ||
| <% end %> | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| <!DOCTYPE html> | ||
|
||
| <html> | ||
| <head> | ||
| <meta content='text/html; charset=UTF-8' http-equiv='Content-Type' /> | ||
| </head> | ||
| <body> | ||
| <% @users.each do |user| %> | ||
| <h2><%= user.name %></h2> | ||
| <%= render 'day_summary', summary: Report.new(user).day_summary %> | ||
|
||
| <% end %> | ||
| </body> | ||
| </html> | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rename the following methods: