-
Notifications
You must be signed in to change notification settings - Fork 0
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
share emotion with trusted adult #63
Merged
Merged
Changes from all commits
Commits
Show all changes
4 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 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains 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 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 |
---|---|---|
|
@@ -8,5 +8,7 @@ services: | |
- .:/app | ||
depends_on: | ||
- db | ||
env_file: | ||
- ./.env | ||
db: | ||
image: postgres:10.5 |
This file contains 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,55 @@ | ||
defmodule Afc.Email do | ||
import Bamboo.Email | ||
|
||
def share_emotion(emotion_log, emotion) do | ||
from = Map.fetch!(System.get_env(), "EMAIL_FROM") | ||
html = emotion_log_to_html(emotion_log, emotion) | ||
txt = emotion_to_text(emotion_log, emotion) | ||
|
||
new_email() | ||
|> to(emotion_log.user.trusted_adult.email) | ||
|> from(from) | ||
|> subject("New shared emotion log") | ||
|> html_body(html) | ||
|> text_body(txt) | ||
end | ||
|
||
def emotion_log_to_html(emotion_log, emotion) do | ||
logged_at = "#{emotion_log.inserted_at.day}-#{emotion_log.inserted_at.month}-#{emotion_log.inserted_at.year}" | ||
|
||
""" | ||
<strong>#{emotion_log.emotion}</strong> | ||
<p>#{logged_at}</p> | ||
<p>reason list:</p> | ||
#{list_reasons(emotion)} | ||
<p>reason text:</p> | ||
<p>#{emotion.reason}</p> | ||
""" | ||
end | ||
|
||
def list_reasons(log) do | ||
log | ||
|> Map.from_struct | ||
|> Enum.filter(fn {_, v} -> v == true end) | ||
|> Keyword.keys | ||
|> Enum.map(fn r -> | ||
if r == :else do | ||
"Something else" | ||
end | ||
|
||
if r == :"family/home" do | ||
"Family / Home" | ||
end | ||
|
||
String.capitalize(to_string r) | ||
end) | ||
|> Enum.join(", ") | ||
end | ||
|
||
def emotion_to_text(emotion_log, emotion) do | ||
""" | ||
#{emotion_log.emotion} | ||
#{emotion.reason} | ||
""" | ||
end | ||
end |
This file contains 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 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,3 @@ | ||
defmodule Afc.Mailer do | ||
use Bamboo.Mailer, otp_app: :afc | ||
end |
This file contains 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 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 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 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 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,25 @@ | ||
defmodule AfcWeb.ShareController do | ||
use AfcWeb, :controller | ||
alias Afc.{Email, Emotion, Mailer, Repo, Emotion.EmotionLog} | ||
|
||
def create(conn, params) do | ||
id = params["emotion_log_id"] | ||
date = params["date"] | ||
case log = Repo.get(EmotionLog, id) |> Repo.preload([user: :trusted_adult]) do | ||
nil -> redirect conn, to: log_path(conn, :index, %{date: date}) | ||
_ -> | ||
emotionSchema = log.emotion |> Emotion.get_emotion_module_name() | ||
case emotion = Repo.get(emotionSchema, log.emotion_id) do | ||
nil -> redirect conn, to: log_path(conn, :index, %{date: date}) | ||
_ -> | ||
Email.share_emotion(log, emotion) |> Mailer.deliver_now | ||
changeset = EmotionLog.changeset log, %{shared: true} | ||
Repo.update(changeset) | ||
redirect conn, to: log_path(conn, :index, %{date: date}) | ||
end | ||
end | ||
end | ||
|
||
|
||
|
||
end |
This file contains 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 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 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 |
---|---|---|
@@ -1,6 +1,7 @@ | ||
<div class="tc mt5 mb3 f4"> | ||
<button type="button" class="b ba afc-b--red ph3 pv2 br2 bg-white">Share with Trusted Adult</button> | ||
<!-- <%= form_for @conn, "/", fn f -> %> | ||
<%= submit("Share with Trusted Adult", class: "b ba afc-b--red ph3 pv2 br2 bg-white") %> | ||
<% end %> --> | ||
<%= form_for @conn, "/share", fn f -> %> | ||
<input type="hidden" name="emotion_log_id" value="<%= @emotion_log.id %>"> | ||
<input type="hidden" name="date" value="<%= @date %>"> | ||
<%= submit("Share with Trusted Adult", class: "b ba afc-b--red ph3 pv2 br2 bg-white pointer") %> | ||
<% end %> | ||
</div> |
This file contains 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 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 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 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 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 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 |
---|---|---|
|
@@ -11,10 +11,11 @@ emotions = [ | |
{Worried, "worried"} | ||
] | ||
|
||
trusted_adult_email = Map.fetch!(System.get_env(), "EMAIL_TRUSTED_ADULT") | ||
adult = | ||
case Repo.get_by(TrustedAdult, email: "[email protected]") do | ||
case Repo.get_by(TrustedAdult, email: trusted_adult_email) do | ||
nil -> | ||
Repo.insert!(%TrustedAdult{email: "[email protected]"}) | ||
Repo.insert!(%TrustedAdult{email: trusted_adult_email}) | ||
adult -> | ||
adult | ||
end | ||
|
This file contains 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 |
---|---|---|
@@ -1,9 +1,10 @@ | ||
alias Afc.{Repo, TrustedAdult, User} | ||
trusted_adult_email = Map.fetch!(System.get_env(), "EMAIL_TRUSTED_ADULT") | ||
|
||
adult = | ||
case Repo.get_by(TrustedAdult, email: "[email protected]") do | ||
case Repo.get_by(TrustedAdult, email: trusted_adult_email) do | ||
nil -> | ||
Repo.insert!(%TrustedAdult{email: "[email protected]"}) | ||
Repo.insert!(%TrustedAdult{email: trusted_adult_email}) | ||
adult -> | ||
adult | ||
end | ||
|
This file contains 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,9 @@ | ||
defmodule Afc.Repo.Migrations.ShareEmotionLog do | ||
use Ecto.Migration | ||
|
||
def change do | ||
alter table(:emotion_logs) do | ||
add :shared, :boolean, default: false, null: false | ||
end | ||
end | ||
end |
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.
Good fix here.