Skip to content
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

Emotion log flow #28

Merged
merged 14 commits into from
Oct 16, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
157 changes: 157 additions & 0 deletions .credo.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
# This file contains the configuration for Credo and you are probably reading
# this after creating it with `mix credo.gen.config`.
#
# If you find anything wrong or unclear in this file, please report an
# issue on GitHub: https:/rrrene/credo/issues
#
%{
#
# You can have as many configs as you like in the `configs:` field.
configs: [
%{
#
# Run any exec using `mix credo -C <name>`. If no exec name is given
# "default" is used.
#
name: "default",
#
# These are the files included in the analysis:
files: %{
#
# You can give explicit globs or simply directories.
# In the latter case `**/*.{ex,exs}` will be used.
#
included: ["lib/", "test/"],
excluded: [
~r"/_build/",
~r"/deps/",
~r"web/channels",
"lib/afc/application.ex",
"test/support/*.ex",
"lib/afc_web/views/error_view.ex"
]
},
#
# If you create your own checks, you must specify the source files for
# them here, so they can be loaded by Credo before running the analysis.
#
requires: [],
#
# Credo automatically checks for updates, like e.g. Hex does.
# You can disable this behaviour below:
#
check_for_updates: true,
#
# If you want to enforce a style guide and need a more traditional linting
# experience, you can change `strict` to `true` below:
#
strict: true,
#
# If you want to use uncolored output by default, you can change `color`
# to `false` below:
#
color: true,
#
# You can customize the parameters of any check by adding a second element
# to the tuple.
#
# To disable a check put `false` as second element:
#
# {Credo.Check.Design.DuplicatedCode, false}
#
checks: [
{Credo.Check.Consistency.ExceptionNames},
{Credo.Check.Consistency.LineEndings},
{Credo.Check.Consistency.ParameterPatternMatching},
{Credo.Check.Consistency.SpaceAroundOperators},
{Credo.Check.Consistency.SpaceInParentheses},
{Credo.Check.Consistency.TabsOrSpaces},

# For some checks, like AliasUsage, you can only customize the priority
# Priority values are: `low, normal, high, higher`
#
{Credo.Check.Design.AliasUsage, priority: :low},

# For others you can set parameters

# If you don't want the `setup` and `test` macro calls in ExUnit tests
# or the `schema` macro in Ecto schemas to trigger DuplicatedCode, just
# set the `excluded_macros` parameter to `[:schema, :setup, :test]`.
#
{Credo.Check.Design.DuplicatedCode, excluded_macros: []},

# You can also customize the exit_status of each check.
# If you don't want TODO comments to cause `mix credo` to fail, just
# set this value to 0 (zero).
#
{Credo.Check.Design.TagTODO, exit_status: 2},
{Credo.Check.Design.TagFIXME},

{Credo.Check.Readability.FunctionNames},
{Credo.Check.Readability.LargeNumbers},
{Credo.Check.Readability.MaxLineLength, priority: :low, max_length: 80},
{Credo.Check.Readability.ModuleAttributeNames},
{Credo.Check.Readability.ModuleDoc},
{Credo.Check.Readability.ModuleNames},
{Credo.Check.Readability.ParenthesesOnZeroArityDefs},
{Credo.Check.Readability.ParenthesesInCondition},
{Credo.Check.Readability.PredicateFunctionNames},
{Credo.Check.Readability.PreferImplicitTry},
{Credo.Check.Readability.RedundantBlankLines},
{Credo.Check.Readability.StringSigils},
{Credo.Check.Readability.TrailingBlankLine},
{Credo.Check.Readability.TrailingWhiteSpace},
{Credo.Check.Readability.VariableNames},
{Credo.Check.Readability.Semicolons},
{Credo.Check.Readability.SpaceAfterCommas},

{Credo.Check.Refactor.DoubleBooleanNegation},
{Credo.Check.Refactor.CondStatements},
{Credo.Check.Refactor.CyclomaticComplexity},
{Credo.Check.Refactor.FunctionArity},
{Credo.Check.Refactor.LongQuoteBlocks},
{Credo.Check.Refactor.MatchInCondition},
{Credo.Check.Refactor.NegatedConditionsInUnless},
{Credo.Check.Refactor.NegatedConditionsWithElse},
{Credo.Check.Refactor.Nesting},
{Credo.Check.Refactor.PipeChainStart},
{Credo.Check.Refactor.UnlessWithElse},

{Credo.Check.Warning.BoolOperationOnSameValues},
{Credo.Check.Warning.IExPry},
{Credo.Check.Warning.IoInspect},
{Credo.Check.Warning.LazyLogging},
{Credo.Check.Warning.OperationOnSameValues},
{Credo.Check.Warning.OperationWithConstantResult},
{Credo.Check.Warning.UnusedEnumOperation},
{Credo.Check.Warning.UnusedFileOperation},
{Credo.Check.Warning.UnusedKeywordOperation},
{Credo.Check.Warning.UnusedListOperation},
{Credo.Check.Warning.UnusedPathOperation},
{Credo.Check.Warning.UnusedRegexOperation},
{Credo.Check.Warning.UnusedStringOperation},
{Credo.Check.Warning.UnusedTupleOperation},
{Credo.Check.Warning.RaiseInsideRescue},

# Controversial and experimental checks (opt-in, just remove `, false`)
#
{Credo.Check.Refactor.ABCSize, false},
{Credo.Check.Refactor.AppendSingleItem, false},
{Credo.Check.Refactor.VariableRebinding, false},
{Credo.Check.Warning.MapGetUnsafePass, false},
{Credo.Check.Consistency.MultiAliasImportRequireUse, false},

# Deprecated checks (these will be deleted after a grace period)
#
{Credo.Check.Readability.Specs, false},
{Credo.Check.Warning.NameRedeclarationByAssignment, false},
{Credo.Check.Warning.NameRedeclarationByCase, false},
{Credo.Check.Warning.NameRedeclarationByDef, false},
{Credo.Check.Warning.NameRedeclarationByFn, false},

# Custom checks can be created using `mix credo.gen.check`.
#
]
}
]
}
26 changes: 25 additions & 1 deletion assets/css/app.css
Original file line number Diff line number Diff line change
@@ -1 +1,25 @@
/* This file is for your main application css. */
/* This file is for your main application css. */

.afc-bg-pink {
background-color: #F5BABF;
}

.afc-b--pink {
border-color: #F5BABF;
}

.emoji-font-size {
font-size: 64pt;
}

.-mt2 {
margin-top: -0.5rem;
}

.h-day-week-month {
height: 3rem;
}

.mt-day-week-month {
margin-top: 3rem;
}
14 changes: 14 additions & 0 deletions coveralls.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"coverage_options": {
"minimum_coverage": 10
},
"skip_files": [
"lib/afc.ex",
"lib/afc_web.ex",
"lib/afc_web/channels",
"lib/afc_web/router.ex",
"lib/afc_web/views/error_helpers.ex",
"test/support/channel_case.ex",
"test/support/data_case.ex"
]
}
27 changes: 27 additions & 0 deletions lib/afc/angry.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
defmodule Afc.Angry do
use Ecto.Schema
import Ecto.Changeset


schema "angry" do
field :bullying, :boolean, default: false
field :classwork, :boolean, default: false
field :community, :boolean, default: false
field :else, :boolean, default: false
field :exams, :boolean, default: false
field :"family/home", :boolean, default: false
field :friends, :boolean, default: false
field :homework, :boolean, default: false
field :school, :boolean, default: false
field :teachers, :boolean, default: false
field :reason, :string

timestamps()
end

@doc false
def changeset(angry, attrs) do
angry
|> cast(attrs, [:friends, :school, :"family/home", :community, :bullying, :exams, :teachers, :classwork, :homework, :else, :reason])
end
end
17 changes: 17 additions & 0 deletions lib/afc/happy.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
defmodule Afc.Happy do
use Ecto.Schema
import Ecto.Changeset


schema "happy" do
field :reason_text, :string

timestamps()
end

@doc false
def changeset(happy, attrs) do
happy
|> cast(attrs, [:reason_text])
end
end
18 changes: 18 additions & 0 deletions lib/afc/trusted_adult.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
defmodule Afc.Trusted_adult do
use Ecto.Schema
import Ecto.Changeset


schema "trusted_adults" do
field :email, :string

timestamps()
end

@doc false
def changeset(trusted_adult, attrs) do
trusted_adult
|> cast(attrs, [:email])
|> validate_required([:email])
end
end
20 changes: 20 additions & 0 deletions lib/afc/user.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
defmodule Afc.User do
use Ecto.Schema
import Ecto.Changeset


schema "users" do
field :pin, :integer
field :username, :string
field :trusted_adult_id, :id

timestamps()
end

@doc false
def changeset(user, attrs) do
user
|> cast(attrs, [:username, :pin])
|> validate_required([:username, :pin])
end
end
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
15 changes: 15 additions & 0 deletions lib/afc_web/templates/component/day_week_month_bar.html.eex
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<div class="flex justify-between fixed top-0 h-day-week-month w-100 tc bg-white">
<!-- the border classes on this elem will need to be added depending on -->
<!-- the page the user is on. Leaving in for now so we remember the classes -->
<a class="flex db pointer link black f4 w-33 bb bw2" href="/">
<p class="w-100 self-center">Daily</p>
</a>

<a class="flex db pointer link black f4 w-33" href="/">
<p class="w-100 self-center">Weekly</p>
</a>

<a class="flex db pointer link black f4 w-33" href="/">
<p class="w-100 self-center">Monthly</p>
</a>
</div>
6 changes: 6 additions & 0 deletions lib/afc_web/templates/component/emoji_helper.html.eex
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<div class="tc w4">
<%= link to: emotion_path(@conn, :show, @page), class: "pointer link black" do %>
<%= emoji_p_tag(@emoji) %>
<p class="-mt2"><%= @emotion %></p>
<%= end %>
</div>
12 changes: 8 additions & 4 deletions lib/afc_web/templates/component/navbar.html.eex
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
<div class="flex fixed bottom-0 h3 w-100 tc bg-white bt">
<a class="dib w-33 pointer link pt2 black" href="/">
<div class="flex fixed bottom-0 h3 w-100 tc bg-white bt afc-b--pink">
<a class="dib w-25 pointer link pt2 black" href="/">
<p class="db mv1">Home</p>
</a>

<a class="dib w-33 pointer link pt2 black br bl" href="/">
<a class="dib w-25 pointer link pt2 black" href="/">
<p class="db mv1">Toolbox</p>
</a>

<a class="dib w-33 pointer link pt2 black" href="/">
<a class="dib w-25 pointer link pt2 black" href="/">
<p class="db mv1">Help</p>
</a>

<a class="dib w-25 pointer link pt2 black" href="/">
<p class="db mv1">Logout</p>
</a>
</div>
6 changes: 6 additions & 0 deletions lib/afc_web/templates/emotion/captured.html.eex
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<div class="w-90 bg-white center br2 pa3 mb5">
<p class="tc b f4 mv4">Well done</p>
<p class="tc mb3">Today's log has been completed.</p>
<p class="tc mb5">Do you want to share it with someone?</p>
<p class="tc">no yes</p>
</div>
3 changes: 3 additions & 0 deletions lib/afc_web/templates/emotion/form.html.eex
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<div class="w-90 bg-white center br2 pa3 mb5">
<%= render_autoform(@conn, :create, @module, assigns: [changeset: @changeset]) %>
</div>
Loading