Skip to content

Commit

Permalink
creates emotion show and create routes #15 #7
Browse files Browse the repository at this point in the history
  • Loading branch information
RobStallion committed Oct 15, 2018
1 parent 4645828 commit 8d142f0
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 13 deletions.
42 changes: 42 additions & 0 deletions lib/afc_web/controllers/emotion_controller.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
defmodule AfcWeb.EmotionController do
use AfcWeb, :controller
alias Afc.{Angry, Happy, Repo}

def show(conn, %{"id" => emotion}) do
{module, changeset} = get_page_module_and_changeset(emotion)

render conn, "form.html", changeset: changeset, module: module
end

def create(conn, params) do
submitted_emotion =
~w(angry happy)
|> Enum.filter(&(Map.has_key?(params, &1)))
|> hd()

form_info = Map.get(params, submitted_emotion)

{module, changeset} =
get_page_module_and_changeset(submitted_emotion, form_info)

case Repo.insert(changeset) do
{:ok, _captured_emotion} ->

# The emotion itself has been captured at this point. Next step
# is to insert into the emotion_log table.
render conn, "captured.html"

{:error, changeset} ->
render conn, "form.html", changeset: changeset, module: module
end
end

defp get_page_module_and_changeset(page, params \\ %{}) do
case page do
"happy" ->
{Happy, Happy.changeset(%Happy{}, params)}
"angry" ->
{Angry, Angry.changeset(%Angry{}, params)}
end
end
end
1 change: 1 addition & 0 deletions lib/afc_web/router.ex
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ defmodule AfcWeb.Router do
pipe_through :browser # Use the default browser stack

get "/", PageController, :index
resources "/emotion", EmotionController, only: [:show, :create]
end

# Other scopes may use custom stacks.
Expand Down
4 changes: 2 additions & 2 deletions lib/afc_web/templates/component/emoji_helper.html.eex
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<div class="tc w4">
<a href="/" class="pointer link black">
<%= link to: emotion_path(@conn, :show, @page), class: "pointer link black" do %>
<%= emoji_p_tag(@emoji) %>
<p class="-mt2"><%= @emotion %></p>
</a>
<%= end %>
</div>
20 changes: 9 additions & 11 deletions lib/afc_web/templates/page/index.html.eex
Original file line number Diff line number Diff line change
@@ -1,29 +1,27 @@
<%= component "day_week_month_bar", [] %>

<div class="w-90 bg-white center br2 pa3 mt-day-week-month mb5">
<div class="">
<p class="pa3 ba br2 dib mb4">10th Oct 2019 (placeholder)</p>
</div>
<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 b f4 mb3">How are you feeling today?</p>
<div class="center w-90">

<div class="flex justify-between pt3 ph1 mb3">
<%= component "emoji_helper", [emoji: "😆", emotion: "Happy"] %>
<%= component "emoji_helper", [emoji: "🤩", emotion: "Excited"] %>
<%= component "emoji_helper", [emoji: "😆", emotion: "Happy", page: "happy", conn: @conn] %>
<%= component "emoji_helper", [emoji: "🤩", emotion: "Excited", page: "happy", conn: @conn] %>
</div>

<div class="flex justify-between pt3 ph1 mb3">
<%= component "emoji_helper", [emoji: "😡", emotion: "Angry"] %>
<%= component "emoji_helper", [emoji: "😭", emotion: "Sad"] %>
<%= component "emoji_helper", [emoji: "😡", emotion: "Angry", page: "angry", conn: @conn] %>
<%= component "emoji_helper", [emoji: "😭", emotion: "Sad", page: "happy", conn: @conn] %>
</div>

<div class="flex justify-between pt3 ph1 mb3">
<%= component "emoji_helper", [emoji: "😬", emotion: "Worried"] %>
<%= component "emoji_helper", [emoji: "😐", emotion: "I don't know"] %>
<%= component "emoji_helper", [emoji: "😬", emotion: "Worried", page: "happy", conn: @conn] %>
<%= component "emoji_helper", [emoji: "😐", emotion: "I don't know", page: "happy", conn: @conn] %>
</div>

<div class="flex justify-between pt3 ph1 mb3">
<%= component "emoji_helper", [emoji: "😶", emotion: "Something else"] %>
<%= component "emoji_helper", [emoji: "😶", emotion: "Something else", page: "happy", conn: @conn] %>
</div>

</div>
Expand Down

0 comments on commit 8d142f0

Please sign in to comment.