Skip to content

Commit

Permalink
get both beginning and end of week emails working initial solution
Browse files Browse the repository at this point in the history
  • Loading branch information
cstavitsky committed Sep 13, 2015
1 parent 9d2d614 commit d24e89d
Show file tree
Hide file tree
Showing 11 changed files with 175 additions and 12 deletions.
13 changes: 11 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ source 'https://rubygems.org'

# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.2.4'
# Use sqlite3 as the database for Active Record
gem 'sqlite3'

group :development do
gem 'sqlite3'
end
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0'
# Use Uglifier as compressor for JavaScript assets
Expand All @@ -19,6 +21,8 @@ gem 'jquery-rails'
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder

gem 'jquery-turbolinks'
gem 'jbuilder', '~> 2.0'
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', '~> 0.4.0', group: :doc
Expand Down Expand Up @@ -47,3 +51,8 @@ end

gem 'action_mailer_tls'

group :production do
gem 'pg'
gem 'rails_12factor'
end

12 changes: 12 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ GEM
rails-dom-testing (~> 1.0)
railties (>= 4.2.0)
thor (>= 0.14, < 2.0)
jquery-turbolinks (2.1.0)
railties (>= 3.1.0)
turbolinks
json (1.8.3)
loofah (2.0.3)
nokogiri (>= 1.5.9)
Expand All @@ -74,6 +77,7 @@ GEM
multi_json (1.11.2)
nokogiri (1.6.6.2)
mini_portile (~> 0.6.0)
pg (0.18.3)
rack (1.6.4)
rack-test (0.6.3)
rack (>= 1.0)
Expand All @@ -96,6 +100,11 @@ GEM
rails-deprecated_sanitizer (>= 1.0.1)
rails-html-sanitizer (1.0.2)
loofah (~> 2.0)
rails_12factor (0.0.3)
rails_serve_static_assets
rails_stdout_logging
rails_serve_static_assets (0.0.4)
rails_stdout_logging (0.0.4)
railties (4.2.4)
actionpack (= 4.2.4)
activesupport (= 4.2.4)
Expand Down Expand Up @@ -147,7 +156,10 @@ DEPENDENCIES
coffee-rails (~> 4.1.0)
jbuilder (~> 2.0)
jquery-rails
jquery-turbolinks
pg
rails (= 4.2.4)
rails_12factor
sass-rails (~> 5.0)
sdoc (~> 0.4.0)
spring
Expand Down
1 change: 1 addition & 0 deletions app/assets/javascripts/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@
//
//= require jquery
//= require jquery_ujs
//= require jquery.turbolinks
//= require turbolinks
//= require_tree .
14 changes: 14 additions & 0 deletions app/assets/stylesheets/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,17 @@
text-align: center;
margin: 0 auto;
}

.email-container{
border: 1px dotted black;
width: 400px;
text-align: center;
margin: 0 auto;
}

#send-weekly-email{
color: blue;
width: 400px;
text-align: center;
margin: 0 auto;
}
10 changes: 10 additions & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,16 @@ def current_user

helper_method :current_user

def sat_through_wed
Time.now.saturday? || Time.now.sunday? || Time.now.monday? || Time.now.tuesday? || Time.now.wednesday?
end
helper_method :sat_through_wed

def thurs_through_sat
Time.now.thursday? || Time.now.friday? || Time.now.saturday?
end
helper_method :thurs_through_sat

def authorize
redirect_to '/login' unless current_user
end
Expand Down
1 change: 1 addition & 0 deletions app/views/boss_mailer/beginning_week_email.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,6 @@
<p>Let me know if you have any comments. Thank you!</p>

<%= @user.name %>
<p>Sent via <a href="#">Translucent</a></p>
</body>
</html>
39 changes: 39 additions & 0 deletions app/views/boss_mailer/end_week_email.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<!DOCTYPE html>
<html>
<head>
<meta content='text/html; charset=UTF-8' http-equiv='Content-Type' />
</head>
<body>
Hi <%= @email.addressee_name %>,
<p>
Here's a quick update for the week:
</p>
<p>
Completed this week:
</p>
<ol>
<% @major_projects.each do |project| %>
<li>
<%=project%>
</li>
<% end %>
</ol>

<p>
Open items:
</p>
<ol>
<% @open_projects.each do |project| %>
<li>
<%=project%>
</li>
<% end %>
</ol>


<p>That's all for now. Have a great weekend!</p>

<%= @user.name %>
<p>Sent via <a href="#">Translucent</a></p>
</body>
</html>
23 changes: 22 additions & 1 deletion app/views/emails/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,26 @@
<% if @coworker %>
<div><%=link_to "send your boss the weekly email", new_email_path %></div>
<% if sat_through_wed %>
<div id="send-weekly-email"><h1><%=link_to "beginning of the week? send your boss your plans", new_email_path %></h1></div>

<% elsif thurs_through_sat %>
<div id="send-weekly-email"><h1><%=link_to "end of the week? tell your boss what you got done", new_email_path %></h1></div>

<% end %>


<% @emails.reverse.each do |email| %>
<div class="email-container">
<h3>You sent an email to <%=email.addressee_name%> on <%=email.created_at.strftime("%m/%d")%></h3>
<li>
Major projects for the week were: <%=email.major_projects%>
</li>
<li>
Open projects for the week were: <%=email.open_projects%>
</li>

<% end %>
</div>
<% else %>

<%= link_to "Click to start by adding your boss's email", new_coworker_path %>
Expand Down
55 changes: 54 additions & 1 deletion app/views/emails/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

<!-- if there are no projects, display a link to show jQuery-hidden, ajaxified form to create new projects -->

<% if sat_through_wed %>

<div class="form-container">
<p><b>Fill in the following fields to autogenerate an email about your plans for this week. </b></p>

Expand Down Expand Up @@ -54,6 +56,57 @@
</ol>

<p>Let me know if you have any comments. Thank you!</p>
<%=@user.name%>
-<%=@user.name.capitalize%>
<p>Sent via <a href="#">Translucent</a></p>

<% elsif thurs_through_sat %>

<div class="form-container">
<p><b>Fill in the following fields to autogenerate an email about what you already completed this week. </b></p>

<p><b>Once you hit send, the email will be sent to your boss. </b></p>

<%= form_for @email, url: {action: "create"}, html: {class: "email_form"} do |f| %>
<p>Email Recipient: <%= f.text_field :addressee_email, :value => @user.coworkers.first.email, :id => 'boss-email', :onkeyup => "bossEmailKeyPress()", :onkeypress => "bossEmailKeyPress()" %></p>
<p>Email Subject Line: <%= f.text_field :subject_line_end_week, :value => "Completed tasks and progress this week", :id => 'subject-line', :onkeyup => "subjectLineKeyPress()", :onkeypress => "subjectLineKeyPress()" %></p>
<p>Recipient name: <%= f.text_field :addressee_name, :value => @user.coworkers.first.first_name, :id => 'boss-name', :onkeyup => "bossNameKeyPress()", :onkeypress => "bossNameKeyPress()" %></p>
<p>COMPLETED Projects (separate by comma): <%= f.text_field :major_projects, :id => 'text' %></p>
<p>OPEN Projects (separate by comma): <%= f.text_field :open_projects, :id => 'text2' %></p>

<p>
<%= f.submit "Send email" %>
</p>
<% end %>
</div>

<h3>Email preview:</h3>

<p>
<span id="boss-email-output">(To: <%=@user.coworkers.first.email%>) </span>
</p>

<p>
<span id="subject-line-output">(Subject line: Completed tasks and progress this week) </span>
</p>

<span id="boss-name-output">Hi <%=@user.coworkers.first.first_name%>, </span>

<p>Here's a quick update for the week,</p>

<h4>Completed this week:</h4>
<ol>
<div id="output"></div>
</ol>

<h4>Open items:</h4>
<ol>
<div id="output2"></div>
</ol>

<p>That's all for now. Have a great weekend!</p>
-<%=@user.name.capitalize%>
<p>Sent via <a href="#">Translucent</a></p>

<% end %>

<!--else display -->
1 change: 1 addition & 0 deletions db/migrate/20150912192433_create_emails.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ def change
t.string :addressee_email
t.string :major_projects
t.string :open_projects
t.timestamps
end
end
end
18 changes: 10 additions & 8 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,16 @@
end

create_table "emails", force: :cascade do |t|
t.integer "sender_id"
t.integer "recipient_id"
t.string "subject_line_beginning_week"
t.string "subject_line_end_week"
t.string "addressee_name"
t.string "addressee_email"
t.string "major_projects"
t.string "open_projects"
t.integer "sender_id"
t.integer "recipient_id"
t.string "subject_line_beginning_week"
t.string "subject_line_end_week"
t.string "addressee_name"
t.string "addressee_email"
t.string "major_projects"
t.string "open_projects"
t.datetime "created_at"
t.datetime "updated_at"
end

create_table "projects", force: :cascade do |t|
Expand Down

0 comments on commit d24e89d

Please sign in to comment.