-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #38 from actnforchildren/previous-emotions
Previous emotions
- Loading branch information
Showing
17 changed files
with
160 additions
and
41 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,3 +23,7 @@ | |
.mt-day-week-month { | ||
margin-top: 3rem; | ||
} | ||
|
||
.afc-b--red { | ||
border-color: #DF001C; | ||
} |
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,4 +1,4 @@ | ||
defmodule Afc.Angry do | ||
defmodule Afc.Emotion.Angry do | ||
use Ecto.Schema | ||
import Ecto.Changeset | ||
|
||
|
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,53 @@ | ||
defmodule Afc.Emotion do | ||
alias Afc.Repo | ||
alias Afc.Emotion.{Angry, EmotionLog, Happy} | ||
import Ecto.Query | ||
use Timex | ||
|
||
def todays_emotion_log(user) do | ||
start_of_today = Timex.today() |> Timex.to_naive_datetime() | ||
|
||
query = | ||
from e in EmotionLog, | ||
where: e.user_id == ^user.id | ||
and e.inserted_at > ^start_of_today | ||
|
||
Repo.one(query) | ||
end | ||
|
||
def get_emotion_module_name(emotion) do | ||
emotion_str = | ||
case is_atom(emotion) do | ||
true -> | ||
Atom.to_string(emotion) | ||
false -> | ||
emotion | ||
end | ||
|> String.capitalize() | ||
|
||
"Elixir.Afc.Emotion." <> emotion_str | ||
|> String.to_atom() | ||
end | ||
|
||
def get_emotion_map(emotion_str) do | ||
emotion_atom = String.to_atom(emotion_str) | ||
emotions_map() |> Map.get(emotion_atom) | ||
end | ||
|
||
def emotion_list do | ||
emotions_map() | ||
|> Map.keys() | ||
end | ||
|
||
defp emotions_map do | ||
%{ | ||
happy: Map.new([module: Happy, emoji: "😆"]), | ||
angry: Map.new([module: Angry, emoji: "😡"]), | ||
excited: Map.new([module: Angry, emoji: "🤩"]), | ||
sad: Map.new([module: Angry, emoji: "😭"]), | ||
worried: Map.new([module: Angry, emoji: "😬"]), | ||
dont_know: Map.new([module: Angry, emoji: "😐"]), | ||
else: Map.new([module: Angry, emoji: "😶"]) | ||
} | ||
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 |
---|---|---|
@@ -1,17 +1,17 @@ | ||
defmodule Afc.Happy do | ||
defmodule Afc.Emotion.Happy do | ||
use Ecto.Schema | ||
import Ecto.Changeset | ||
|
||
|
||
schema "happy" do | ||
field :reason_text, :string | ||
field :reason, :string | ||
|
||
timestamps() | ||
end | ||
|
||
@doc false | ||
def changeset(happy, attrs) do | ||
happy | ||
|> cast(attrs, [:reason_text]) | ||
|> cast(attrs, [: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 |
---|---|---|
@@ -1,7 +1,16 @@ | ||
defmodule AfcWeb.PageController do | ||
use AfcWeb, :controller | ||
alias Afc.{Emotion, Repo} | ||
|
||
def index(conn, _params) do | ||
render conn, "index.html" | ||
case Emotion.todays_emotion_log(conn.assigns.current_user) do | ||
nil -> | ||
render conn, "index.html" | ||
emotion_log -> | ||
module_name = Emotion.get_emotion_module_name(emotion_log.emotion) | ||
emotion = Repo.get(module_name, emotion_log.emotion_id) | ||
|
||
render conn, "single.html", emotion_log: emotion_log, emotion: emotion | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
<div class="tc w4"> | ||
<%= link to: emotion_path(@conn, :show, @page), class: "pointer link black" do %> | ||
<%= emoji_p_tag(@emoji) %> | ||
<%= emoji_p_tag(@emotion) %> | ||
<p class="-mt2"><%= @emotion %></p> | ||
<% 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<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 %> --> | ||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<%= component "day_week_month_bar", [] %> | ||
|
||
<div class="w-90 bg-white center br2 pa3 mb5 mt-day-week-month"> | ||
<p class="pa3 ba br2 dib mb4">10th Oct 2019 (placeholder)</p> | ||
<p class="tc f3 mb3">Today's Log</p> | ||
<div class="center w-100 tc f4"> | ||
<%= emoji_p_tag(@emotion_log.emotion) %> | ||
|
||
<div class="center tl flex mv3"> | ||
<p class="w-40 pl3 pl6-l">I felt:</p> | ||
<p class="w-60"><%= format_emotion(@emotion_log.emotion) %></p> | ||
</div> | ||
|
||
<div class="center tl flex"> | ||
<p class="w-40 pl3 pl6-l">Because:</p> | ||
<p class="w-60"><%= @emotion.reason %></p> | ||
</div> | ||
|
||
</div> | ||
|
||
<%= component "trusted_share_btn", [conn: @conn] %> | ||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,9 @@ | ||
defmodule AfcWeb.PageView do | ||
use AfcWeb, :view | ||
|
||
def format_emotion(emotion) do | ||
emotion | ||
|> Atom.to_string() | ||
|> String.capitalize() | ||
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
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