From fe1ca06a84b692af89b4a24c8cb8892d6112c7f4 Mon Sep 17 00:00:00 2001 From: nelsonic Date: Wed, 8 Dec 2021 23:39:30 +0000 Subject: [PATCH 01/24] mix phx.new app #53 --- .formatter.exs | 5 + .gitignore | 34 ++++ README.md | 73 +++++++- assets/css/app.css | 120 +++++++++++++ assets/css/phoenix.css | 101 +++++++++++ assets/js/app.js | 45 +++++ assets/vendor/topbar.js | 157 ++++++++++++++++++ config/config.exs | 40 +++++ config/dev.exs | 74 +++++++++ config/prod.exs | 49 ++++++ config/runtime.exs | 67 ++++++++ config/test.exs | 27 +++ lib/app.ex | 9 + lib/app/application.ex | 36 ++++ lib/app/repo.ex | 5 + lib/app_web.ex | 110 ++++++++++++ lib/app_web/controllers/page_controller.ex | 7 + lib/app_web/endpoint.ex | 46 +++++ lib/app_web/gettext.ex | 24 +++ lib/app_web/router.ex | 27 +++ lib/app_web/telemetry.ex | 71 ++++++++ lib/app_web/templates/layout/app.html.heex | 5 + lib/app_web/templates/layout/live.html.heex | 11 ++ lib/app_web/templates/layout/root.html.heex | 28 ++++ lib/app_web/templates/page/index.html.heex | 41 +++++ lib/app_web/views/error_helpers.ex | 47 ++++++ lib/app_web/views/error_view.ex | 16 ++ lib/app_web/views/layout_view.ex | 7 + lib/app_web/views/page_view.ex | 3 + mix.exs | 68 ++++++++ mix.lock | 33 ++++ priv/gettext/en/LC_MESSAGES/errors.po | 112 +++++++++++++ priv/gettext/errors.pot | 95 +++++++++++ priv/repo/migrations/.formatter.exs | 4 + priv/repo/seeds.exs | 11 ++ priv/static/favicon.ico | Bin 0 -> 1258 bytes priv/static/images/phoenix.png | Bin 0 -> 13900 bytes priv/static/robots.txt | 5 + .../controllers/page_controller_test.exs | 8 + test/app_web/views/error_view_test.exs | 14 ++ test/app_web/views/layout_view_test.exs | 8 + test/app_web/views/page_view_test.exs | 3 + test/support/channel_case.ex | 36 ++++ test/support/conn_case.ex | 39 +++++ test/support/data_case.ex | 51 ++++++ test/test_helper.exs | 2 + 46 files changed, 1773 insertions(+), 1 deletion(-) create mode 100644 .formatter.exs create mode 100644 .gitignore create mode 100644 assets/css/app.css create mode 100644 assets/css/phoenix.css create mode 100644 assets/js/app.js create mode 100644 assets/vendor/topbar.js create mode 100644 config/config.exs create mode 100644 config/dev.exs create mode 100644 config/prod.exs create mode 100644 config/runtime.exs create mode 100644 config/test.exs create mode 100644 lib/app.ex create mode 100644 lib/app/application.ex create mode 100644 lib/app/repo.ex create mode 100644 lib/app_web.ex create mode 100644 lib/app_web/controllers/page_controller.ex create mode 100644 lib/app_web/endpoint.ex create mode 100644 lib/app_web/gettext.ex create mode 100644 lib/app_web/router.ex create mode 100644 lib/app_web/telemetry.ex create mode 100644 lib/app_web/templates/layout/app.html.heex create mode 100644 lib/app_web/templates/layout/live.html.heex create mode 100644 lib/app_web/templates/layout/root.html.heex create mode 100644 lib/app_web/templates/page/index.html.heex create mode 100644 lib/app_web/views/error_helpers.ex create mode 100644 lib/app_web/views/error_view.ex create mode 100644 lib/app_web/views/layout_view.ex create mode 100644 lib/app_web/views/page_view.ex create mode 100644 mix.exs create mode 100644 mix.lock create mode 100644 priv/gettext/en/LC_MESSAGES/errors.po create mode 100644 priv/gettext/errors.pot create mode 100644 priv/repo/migrations/.formatter.exs create mode 100644 priv/repo/seeds.exs create mode 100644 priv/static/favicon.ico create mode 100644 priv/static/images/phoenix.png create mode 100644 priv/static/robots.txt create mode 100644 test/app_web/controllers/page_controller_test.exs create mode 100644 test/app_web/views/error_view_test.exs create mode 100644 test/app_web/views/layout_view_test.exs create mode 100644 test/app_web/views/page_view_test.exs create mode 100644 test/support/channel_case.ex create mode 100644 test/support/conn_case.ex create mode 100644 test/support/data_case.ex create mode 100644 test/test_helper.exs diff --git a/.formatter.exs b/.formatter.exs new file mode 100644 index 0000000..8a6391c --- /dev/null +++ b/.formatter.exs @@ -0,0 +1,5 @@ +[ + import_deps: [:ecto, :phoenix], + inputs: ["*.{ex,exs}", "priv/*/seeds.exs", "{config,lib,test}/**/*.{ex,exs}"], + subdirectories: ["priv/*/migrations"] +] diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..98bca20 --- /dev/null +++ b/.gitignore @@ -0,0 +1,34 @@ +# The directory Mix will write compiled artifacts to. +/_build/ + +# If you run "mix test --cover", coverage assets end up here. +/cover/ + +# The directory Mix downloads your dependencies sources to. +/deps/ + +# Where 3rd-party dependencies like ExDoc output generated docs. +/doc/ + +# Ignore .fetch files in case you like to edit your project deps locally. +/.fetch + +# If the VM crashes, it generates a dump, let's ignore it too. +erl_crash.dump + +# Also ignore archive artifacts (built via "mix archive.build"). +*.ez + +# Ignore package tarball (built via "mix hex.build"). +app-*.tar + +# Ignore assets that are produced by build tools. +/priv/static/assets/ + +# Ignore digested assets cache. +/priv/static/cache_manifest.json + +# In case you use Node.js/npm, you want to ignore these. +npm-debug.log +/assets/node_modules/ + diff --git a/README.md b/README.md index 743f1f8..eed71c1 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,73 @@ # sleep -Insomnia :-( + +Sleep is the single most important activity we perform in life.
+A keystone activity + + +# Why? + +# What? + +# Who? + +# When? + + + + +# How? + + + + +# _Tutorial_ + + +## Implementation Note + +We built this MVP App using using +[**`Elixir`**](https://github.com/dwyl/learn-elixir) +and +[**`Phoenix`**](https://github.com/dwyl/learn-phoenix-framework) +because it's one of the simplest ways +to build web applications +from first principals. +Our objective is to get to a _useable_ app +as **_fast_ as possible** +so we can start inputting/saving data. +You will see below, +that we can get up-and-running +with a **basic interface**, +**saving data** to the database, +**authentication** +and ***deployment*** +in **_less_ than 20 minutes**.1 +Anyone who knows basic programming +(e.g. `Python`, `JavaScript`, etc.) +should be able to follow along. + + + + +```sh +mix phx.new app --no-mailer --no-dashboard +``` + +This creates a new Phoenix Web App named **`app`** +without the mailer (email) or live dashboard +but with a database and `LiveView` support. + + +To start your Phoenix server: + +* Install dependencies with `mix deps.get` +* Create and migrate your database with `mix ecto.setup` +* Start Phoenix endpoint with `mix phx.server` + + + + +1 +Other approaches to web app development +might get you different results ... +https://twitter.com/iamdevloper/status/787969734918668289 \ No newline at end of file diff --git a/assets/css/app.css b/assets/css/app.css new file mode 100644 index 0000000..19c2e51 --- /dev/null +++ b/assets/css/app.css @@ -0,0 +1,120 @@ +/* This file is for your main application CSS */ +@import "./phoenix.css"; + +/* Alerts and form errors used by phx.new */ +.alert { + padding: 15px; + margin-bottom: 20px; + border: 1px solid transparent; + border-radius: 4px; +} +.alert-info { + color: #31708f; + background-color: #d9edf7; + border-color: #bce8f1; +} +.alert-warning { + color: #8a6d3b; + background-color: #fcf8e3; + border-color: #faebcc; +} +.alert-danger { + color: #a94442; + background-color: #f2dede; + border-color: #ebccd1; +} +.alert p { + margin-bottom: 0; +} +.alert:empty { + display: none; +} +.invalid-feedback { + color: #a94442; + display: block; + margin: -1rem 0 2rem; +} + +/* LiveView specific classes for your customization */ +.phx-no-feedback.invalid-feedback, +.phx-no-feedback .invalid-feedback { + display: none; +} + +.phx-click-loading { + opacity: 0.5; + transition: opacity 1s ease-out; +} + +.phx-loading{ + cursor: wait; +} + +.phx-modal { + opacity: 1!important; + position: fixed; + z-index: 1; + left: 0; + top: 0; + width: 100%; + height: 100%; + overflow: auto; + background-color: rgba(0,0,0,0.4); +} + +.phx-modal-content { + background-color: #fefefe; + margin: 15vh auto; + padding: 20px; + border: 1px solid #888; + width: 80%; +} + +.phx-modal-close { + color: #aaa; + float: right; + font-size: 28px; + font-weight: bold; +} + +.phx-modal-close:hover, +.phx-modal-close:focus { + color: black; + text-decoration: none; + cursor: pointer; +} + +.fade-in-scale { + animation: 0.2s ease-in 0s normal forwards 1 fade-in-scale-keys; +} + +.fade-out-scale { + animation: 0.2s ease-out 0s normal forwards 1 fade-out-scale-keys; +} + +.fade-in { + animation: 0.2s ease-out 0s normal forwards 1 fade-in-keys; +} +.fade-out { + animation: 0.2s ease-out 0s normal forwards 1 fade-out-keys; +} + +@keyframes fade-in-scale-keys{ + 0% { scale: 0.95; opacity: 0; } + 100% { scale: 1.0; opacity: 1; } +} + +@keyframes fade-out-scale-keys{ + 0% { scale: 1.0; opacity: 1; } + 100% { scale: 0.95; opacity: 0; } +} + +@keyframes fade-in-keys{ + 0% { opacity: 0; } + 100% { opacity: 1; } +} + +@keyframes fade-out-keys{ + 0% { opacity: 1; } + 100% { opacity: 0; } +} diff --git a/assets/css/phoenix.css b/assets/css/phoenix.css new file mode 100644 index 0000000..0d59050 --- /dev/null +++ b/assets/css/phoenix.css @@ -0,0 +1,101 @@ +/* Includes some default style for the starter application. + * This can be safely deleted to start fresh. + */ + +/* Milligram v1.4.1 https://milligram.github.io + * Copyright (c) 2020 CJ Patoilo Licensed under the MIT license + */ + +*,*:after,*:before{box-sizing:inherit}html{box-sizing:border-box;font-size:62.5%}body{color:#000000;font-family:'Helvetica Neue', 'Helvetica', 'Arial', sans-serif;font-size:1.6em;font-weight:300;letter-spacing:.01em;line-height:1.6}blockquote{border-left:0.3rem solid #d1d1d1;margin-left:0;margin-right:0;padding:1rem 1.5rem}blockquote *:last-child{margin-bottom:0}.button,button,input[type='button'],input[type='reset'],input[type='submit']{background-color:#0069d9;border:0.1rem solid #0069d9;border-radius:.4rem;color:#fff;cursor:pointer;display:inline-block;font-size:1.1rem;font-weight:700;height:3.8rem;letter-spacing:.1rem;line-height:3.8rem;padding:0 3.0rem;text-align:center;text-decoration:none;text-transform:uppercase;white-space:nowrap}.button:focus,.button:hover,button:focus,button:hover,input[type='button']:focus,input[type='button']:hover,input[type='reset']:focus,input[type='reset']:hover,input[type='submit']:focus,input[type='submit']:hover{background-color:#606c76;border-color:#606c76;color:#fff;outline:0}.button[disabled],button[disabled],input[type='button'][disabled],input[type='reset'][disabled],input[type='submit'][disabled]{cursor:default;opacity:.5}.button[disabled]:focus,.button[disabled]:hover,button[disabled]:focus,button[disabled]:hover,input[type='button'][disabled]:focus,input[type='button'][disabled]:hover,input[type='reset'][disabled]:focus,input[type='reset'][disabled]:hover,input[type='submit'][disabled]:focus,input[type='submit'][disabled]:hover{background-color:#0069d9;border-color:#0069d9}.button.button-outline,button.button-outline,input[type='button'].button-outline,input[type='reset'].button-outline,input[type='submit'].button-outline{background-color:transparent;color:#0069d9}.button.button-outline:focus,.button.button-outline:hover,button.button-outline:focus,button.button-outline:hover,input[type='button'].button-outline:focus,input[type='button'].button-outline:hover,input[type='reset'].button-outline:focus,input[type='reset'].button-outline:hover,input[type='submit'].button-outline:focus,input[type='submit'].button-outline:hover{background-color:transparent;border-color:#606c76;color:#606c76}.button.button-outline[disabled]:focus,.button.button-outline[disabled]:hover,button.button-outline[disabled]:focus,button.button-outline[disabled]:hover,input[type='button'].button-outline[disabled]:focus,input[type='button'].button-outline[disabled]:hover,input[type='reset'].button-outline[disabled]:focus,input[type='reset'].button-outline[disabled]:hover,input[type='submit'].button-outline[disabled]:focus,input[type='submit'].button-outline[disabled]:hover{border-color:inherit;color:#0069d9}.button.button-clear,button.button-clear,input[type='button'].button-clear,input[type='reset'].button-clear,input[type='submit'].button-clear{background-color:transparent;border-color:transparent;color:#0069d9}.button.button-clear:focus,.button.button-clear:hover,button.button-clear:focus,button.button-clear:hover,input[type='button'].button-clear:focus,input[type='button'].button-clear:hover,input[type='reset'].button-clear:focus,input[type='reset'].button-clear:hover,input[type='submit'].button-clear:focus,input[type='submit'].button-clear:hover{background-color:transparent;border-color:transparent;color:#606c76}.button.button-clear[disabled]:focus,.button.button-clear[disabled]:hover,button.button-clear[disabled]:focus,button.button-clear[disabled]:hover,input[type='button'].button-clear[disabled]:focus,input[type='button'].button-clear[disabled]:hover,input[type='reset'].button-clear[disabled]:focus,input[type='reset'].button-clear[disabled]:hover,input[type='submit'].button-clear[disabled]:focus,input[type='submit'].button-clear[disabled]:hover{color:#0069d9}code{background:#f4f5f6;border-radius:.4rem;font-size:86%;margin:0 .2rem;padding:.2rem .5rem;white-space:nowrap}pre{background:#f4f5f6;border-left:0.3rem solid #0069d9;overflow-y:hidden}pre>code{border-radius:0;display:block;padding:1rem 1.5rem;white-space:pre}hr{border:0;border-top:0.1rem solid #f4f5f6;margin:3.0rem 0}input[type='color'],input[type='date'],input[type='datetime'],input[type='datetime-local'],input[type='email'],input[type='month'],input[type='number'],input[type='password'],input[type='search'],input[type='tel'],input[type='text'],input[type='url'],input[type='week'],input:not([type]),textarea,select{-webkit-appearance:none;background-color:transparent;border:0.1rem solid #d1d1d1;border-radius:.4rem;box-shadow:none;box-sizing:inherit;height:3.8rem;padding:.6rem 1.0rem .7rem;width:100%}input[type='color']:focus,input[type='date']:focus,input[type='datetime']:focus,input[type='datetime-local']:focus,input[type='email']:focus,input[type='month']:focus,input[type='number']:focus,input[type='password']:focus,input[type='search']:focus,input[type='tel']:focus,input[type='text']:focus,input[type='url']:focus,input[type='week']:focus,input:not([type]):focus,textarea:focus,select:focus{border-color:#0069d9;outline:0}select{background:url('data:image/svg+xml;utf8,') center right no-repeat;padding-right:3.0rem}select:focus{background-image:url('data:image/svg+xml;utf8,')}select[multiple]{background:none;height:auto}textarea{min-height:6.5rem}label,legend{display:block;font-size:1.6rem;font-weight:700;margin-bottom:.5rem}fieldset{border-width:0;padding:0}input[type='checkbox'],input[type='radio']{display:inline}.label-inline{display:inline-block;font-weight:normal;margin-left:.5rem}.container{margin:0 auto;max-width:112.0rem;padding:0 2.0rem;position:relative;width:100%}.row{display:flex;flex-direction:column;padding:0;width:100%}.row.row-no-padding{padding:0}.row.row-no-padding>.column{padding:0}.row.row-wrap{flex-wrap:wrap}.row.row-top{align-items:flex-start}.row.row-bottom{align-items:flex-end}.row.row-center{align-items:center}.row.row-stretch{align-items:stretch}.row.row-baseline{align-items:baseline}.row .column{display:block;flex:1 1 auto;margin-left:0;max-width:100%;width:100%}.row .column.column-offset-10{margin-left:10%}.row .column.column-offset-20{margin-left:20%}.row .column.column-offset-25{margin-left:25%}.row .column.column-offset-33,.row .column.column-offset-34{margin-left:33.3333%}.row .column.column-offset-40{margin-left:40%}.row .column.column-offset-50{margin-left:50%}.row .column.column-offset-60{margin-left:60%}.row .column.column-offset-66,.row .column.column-offset-67{margin-left:66.6666%}.row .column.column-offset-75{margin-left:75%}.row .column.column-offset-80{margin-left:80%}.row .column.column-offset-90{margin-left:90%}.row .column.column-10{flex:0 0 10%;max-width:10%}.row .column.column-20{flex:0 0 20%;max-width:20%}.row .column.column-25{flex:0 0 25%;max-width:25%}.row .column.column-33,.row .column.column-34{flex:0 0 33.3333%;max-width:33.3333%}.row .column.column-40{flex:0 0 40%;max-width:40%}.row .column.column-50{flex:0 0 50%;max-width:50%}.row .column.column-60{flex:0 0 60%;max-width:60%}.row .column.column-66,.row .column.column-67{flex:0 0 66.6666%;max-width:66.6666%}.row .column.column-75{flex:0 0 75%;max-width:75%}.row .column.column-80{flex:0 0 80%;max-width:80%}.row .column.column-90{flex:0 0 90%;max-width:90%}.row .column .column-top{align-self:flex-start}.row .column .column-bottom{align-self:flex-end}.row .column .column-center{align-self:center}@media (min-width: 40rem){.row{flex-direction:row;margin-left:-1.0rem;width:calc(100% + 2.0rem)}.row .column{margin-bottom:inherit;padding:0 1.0rem}}a{color:#0069d9;text-decoration:none}a:focus,a:hover{color:#606c76}dl,ol,ul{list-style:none;margin-top:0;padding-left:0}dl dl,dl ol,dl ul,ol dl,ol ol,ol ul,ul dl,ul ol,ul ul{font-size:90%;margin:1.5rem 0 1.5rem 3.0rem}ol{list-style:decimal inside}ul{list-style:circle inside}.button,button,dd,dt,li{margin-bottom:1.0rem}fieldset,input,select,textarea{margin-bottom:1.5rem}blockquote,dl,figure,form,ol,p,pre,table,ul{margin-bottom:2.5rem}table{border-spacing:0;display:block;overflow-x:auto;text-align:left;width:100%}td,th{border-bottom:0.1rem solid #e1e1e1;padding:1.2rem 1.5rem}td:first-child,th:first-child{padding-left:0}td:last-child,th:last-child{padding-right:0}@media (min-width: 40rem){table{display:table;overflow-x:initial}}b,strong{font-weight:bold}p{margin-top:0}h1,h2,h3,h4,h5,h6{font-weight:300;letter-spacing:-.1rem;margin-bottom:2.0rem;margin-top:0}h1{font-size:4.6rem;line-height:1.2}h2{font-size:3.6rem;line-height:1.25}h3{font-size:2.8rem;line-height:1.3}h4{font-size:2.2rem;letter-spacing:-.08rem;line-height:1.35}h5{font-size:1.8rem;letter-spacing:-.05rem;line-height:1.5}h6{font-size:1.6rem;letter-spacing:0;line-height:1.4}img{max-width:100%}.clearfix:after{clear:both;content:' ';display:table}.float-left{float:left}.float-right{float:right} + +/* General style */ +h1{font-size: 3.6rem; line-height: 1.25} +h2{font-size: 2.8rem; line-height: 1.3} +h3{font-size: 2.2rem; letter-spacing: -.08rem; line-height: 1.35} +h4{font-size: 1.8rem; letter-spacing: -.05rem; line-height: 1.5} +h5{font-size: 1.6rem; letter-spacing: 0; line-height: 1.4} +h6{font-size: 1.4rem; letter-spacing: 0; line-height: 1.2} +pre{padding: 1em;} + +.container{ + margin: 0 auto; + max-width: 80.0rem; + padding: 0 2.0rem; + position: relative; + width: 100% +} +select { + width: auto; +} + +/* Phoenix promo and logo */ +.phx-hero { + text-align: center; + border-bottom: 1px solid #e3e3e3; + background: #eee; + border-radius: 6px; + padding: 3em 3em 1em; + margin-bottom: 3rem; + font-weight: 200; + font-size: 120%; +} +.phx-hero input { + background: #ffffff; +} +.phx-logo { + min-width: 300px; + margin: 1rem; + display: block; +} +.phx-logo img { + width: auto; + display: block; +} + +/* Headers */ +header { + width: 100%; + background: #fdfdfd; + border-bottom: 1px solid #eaeaea; + margin-bottom: 2rem; +} +header section { + align-items: center; + display: flex; + flex-direction: column; + justify-content: space-between; +} +header section :first-child { + order: 2; +} +header section :last-child { + order: 1; +} +header nav ul, +header nav li { + margin: 0; + padding: 0; + display: block; + text-align: right; + white-space: nowrap; +} +header nav ul { + margin: 1rem; + margin-top: 0; +} +header nav a { + display: block; +} + +@media (min-width: 40.0rem) { /* Small devices (landscape phones, 576px and up) */ + header section { + flex-direction: row; + } + header nav ul { + margin: 1rem; + } + .phx-logo { + flex-basis: 527px; + margin: 2rem 1rem; + } +} diff --git a/assets/js/app.js b/assets/js/app.js new file mode 100644 index 0000000..2ca06a5 --- /dev/null +++ b/assets/js/app.js @@ -0,0 +1,45 @@ +// We import the CSS which is extracted to its own file by esbuild. +// Remove this line if you add a your own CSS build pipeline (e.g postcss). +import "../css/app.css" + +// If you want to use Phoenix channels, run `mix help phx.gen.channel` +// to get started and then uncomment the line below. +// import "./user_socket.js" + +// You can include dependencies in two ways. +// +// The simplest option is to put them in assets/vendor and +// import them using relative paths: +// +// import "../vendor/some-package.js" +// +// Alternatively, you can `npm install some-package --prefix assets` and import +// them using a path starting with the package name: +// +// import "some-package" +// + +// Include phoenix_html to handle method=PUT/DELETE in forms and buttons. +import "phoenix_html" +// Establish Phoenix Socket and LiveView configuration. +import {Socket} from "phoenix" +import {LiveSocket} from "phoenix_live_view" +import topbar from "../vendor/topbar" + +let csrfToken = document.querySelector("meta[name='csrf-token']").getAttribute("content") +let liveSocket = new LiveSocket("/live", Socket, {params: {_csrf_token: csrfToken}}) + +// Show progress bar on live navigation and form submits +topbar.config({barColors: {0: "#29d"}, shadowColor: "rgba(0, 0, 0, .3)"}) +window.addEventListener("phx:page-loading-start", info => topbar.show()) +window.addEventListener("phx:page-loading-stop", info => topbar.hide()) + +// connect if there are any LiveViews on the page +liveSocket.connect() + +// expose liveSocket on window for web console debug logs and latency simulation: +// >> liveSocket.enableDebug() +// >> liveSocket.enableLatencySim(1000) // enabled for duration of browser session +// >> liveSocket.disableLatencySim() +window.liveSocket = liveSocket + diff --git a/assets/vendor/topbar.js b/assets/vendor/topbar.js new file mode 100644 index 0000000..1f62209 --- /dev/null +++ b/assets/vendor/topbar.js @@ -0,0 +1,157 @@ +/** + * @license MIT + * topbar 1.0.0, 2021-01-06 + * https://buunguyen.github.io/topbar + * Copyright (c) 2021 Buu Nguyen + */ +(function (window, document) { + "use strict"; + + // https://gist.github.com/paulirish/1579671 + (function () { + var lastTime = 0; + var vendors = ["ms", "moz", "webkit", "o"]; + for (var x = 0; x < vendors.length && !window.requestAnimationFrame; ++x) { + window.requestAnimationFrame = + window[vendors[x] + "RequestAnimationFrame"]; + window.cancelAnimationFrame = + window[vendors[x] + "CancelAnimationFrame"] || + window[vendors[x] + "CancelRequestAnimationFrame"]; + } + if (!window.requestAnimationFrame) + window.requestAnimationFrame = function (callback, element) { + var currTime = new Date().getTime(); + var timeToCall = Math.max(0, 16 - (currTime - lastTime)); + var id = window.setTimeout(function () { + callback(currTime + timeToCall); + }, timeToCall); + lastTime = currTime + timeToCall; + return id; + }; + if (!window.cancelAnimationFrame) + window.cancelAnimationFrame = function (id) { + clearTimeout(id); + }; + })(); + + var canvas, + progressTimerId, + fadeTimerId, + currentProgress, + showing, + addEvent = function (elem, type, handler) { + if (elem.addEventListener) elem.addEventListener(type, handler, false); + else if (elem.attachEvent) elem.attachEvent("on" + type, handler); + else elem["on" + type] = handler; + }, + options = { + autoRun: true, + barThickness: 3, + barColors: { + 0: "rgba(26, 188, 156, .9)", + ".25": "rgba(52, 152, 219, .9)", + ".50": "rgba(241, 196, 15, .9)", + ".75": "rgba(230, 126, 34, .9)", + "1.0": "rgba(211, 84, 0, .9)", + }, + shadowBlur: 10, + shadowColor: "rgba(0, 0, 0, .6)", + className: null, + }, + repaint = function () { + canvas.width = window.innerWidth; + canvas.height = options.barThickness * 5; // need space for shadow + + var ctx = canvas.getContext("2d"); + ctx.shadowBlur = options.shadowBlur; + ctx.shadowColor = options.shadowColor; + + var lineGradient = ctx.createLinearGradient(0, 0, canvas.width, 0); + for (var stop in options.barColors) + lineGradient.addColorStop(stop, options.barColors[stop]); + ctx.lineWidth = options.barThickness; + ctx.beginPath(); + ctx.moveTo(0, options.barThickness / 2); + ctx.lineTo( + Math.ceil(currentProgress * canvas.width), + options.barThickness / 2 + ); + ctx.strokeStyle = lineGradient; + ctx.stroke(); + }, + createCanvas = function () { + canvas = document.createElement("canvas"); + var style = canvas.style; + style.position = "fixed"; + style.top = style.left = style.right = style.margin = style.padding = 0; + style.zIndex = 100001; + style.display = "none"; + if (options.className) canvas.classList.add(options.className); + document.body.appendChild(canvas); + addEvent(window, "resize", repaint); + }, + topbar = { + config: function (opts) { + for (var key in opts) + if (options.hasOwnProperty(key)) options[key] = opts[key]; + }, + show: function () { + if (showing) return; + showing = true; + if (fadeTimerId !== null) window.cancelAnimationFrame(fadeTimerId); + if (!canvas) createCanvas(); + canvas.style.opacity = 1; + canvas.style.display = "block"; + topbar.progress(0); + if (options.autoRun) { + (function loop() { + progressTimerId = window.requestAnimationFrame(loop); + topbar.progress( + "+" + 0.05 * Math.pow(1 - Math.sqrt(currentProgress), 2) + ); + })(); + } + }, + progress: function (to) { + if (typeof to === "undefined") return currentProgress; + if (typeof to === "string") { + to = + (to.indexOf("+") >= 0 || to.indexOf("-") >= 0 + ? currentProgress + : 0) + parseFloat(to); + } + currentProgress = to > 1 ? 1 : to; + repaint(); + return currentProgress; + }, + hide: function () { + if (!showing) return; + showing = false; + if (progressTimerId != null) { + window.cancelAnimationFrame(progressTimerId); + progressTimerId = null; + } + (function loop() { + if (topbar.progress("+.1") >= 1) { + canvas.style.opacity -= 0.05; + if (canvas.style.opacity <= 0.05) { + canvas.style.display = "none"; + fadeTimerId = null; + return; + } + } + fadeTimerId = window.requestAnimationFrame(loop); + })(); + }, + }; + + if (typeof module === "object" && typeof module.exports === "object") { + module.exports = topbar; + } else if (typeof define === "function" && define.amd) { + define(function () { + return topbar; + }); + } else { + this.topbar = topbar; + } +}.call(this, window, document)); diff --git a/config/config.exs b/config/config.exs new file mode 100644 index 0000000..6db4064 --- /dev/null +++ b/config/config.exs @@ -0,0 +1,40 @@ +# This file is responsible for configuring your application +# and its dependencies with the aid of the Config module. +# +# This configuration file is loaded before any dependency and +# is restricted to this project. + +# General application configuration +import Config + +config :app, + ecto_repos: [App.Repo] + +# Configures the endpoint +config :app, AppWeb.Endpoint, + url: [host: "localhost"], + render_errors: [view: AppWeb.ErrorView, accepts: ~w(html json), layout: false], + pubsub_server: App.PubSub, + live_view: [signing_salt: "EljQ3mdd"] + +# Configure esbuild (the version is required) +config :esbuild, + version: "0.13.5", + default: [ + args: + ~w(js/app.js --bundle --target=es2017 --outdir=../priv/static/assets --external:/fonts/* --external:/images/*), + cd: Path.expand("../assets", __DIR__), + env: %{"NODE_PATH" => Path.expand("../deps", __DIR__)} + ] + +# Configures Elixir's Logger +config :logger, :console, + format: "$time $metadata[$level] $message\n", + metadata: [:request_id] + +# Use Jason for JSON parsing in Phoenix +config :phoenix, :json_library, Jason + +# Import environment specific config. This must remain at the bottom +# of this file so it overrides the configuration defined above. +import_config "#{config_env()}.exs" diff --git a/config/dev.exs b/config/dev.exs new file mode 100644 index 0000000..34e510c --- /dev/null +++ b/config/dev.exs @@ -0,0 +1,74 @@ +import Config + +# Configure your database +config :app, App.Repo, + username: "postgres", + password: "postgres", + database: "app_dev", + hostname: "localhost", + show_sensitive_data_on_connection_error: true, + pool_size: 10 + +# For development, we disable any cache and enable +# debugging and code reloading. +# +# The watchers configuration can be used to run external +# watchers to your application. For example, we use it +# with esbuild to bundle .js and .css sources. +config :app, AppWeb.Endpoint, + # Binding to loopback ipv4 address prevents access from other machines. + # Change to `ip: {0, 0, 0, 0}` to allow access from other machines. + http: [ip: {127, 0, 0, 1}, port: 4000], + check_origin: false, + code_reloader: true, + debug_errors: true, + secret_key_base: "P98QsPutADCPf5f2YVIk4hYV3x5671vu8LY+nIoGfwYxH7h6rDm6sYf6cXnDDwzU", + watchers: [ + # Start the esbuild watcher by calling Esbuild.install_and_run(:default, args) + esbuild: {Esbuild, :install_and_run, [:default, ~w(--sourcemap=inline --watch)]} + ] + +# ## SSL Support +# +# In order to use HTTPS in development, a self-signed +# certificate can be generated by running the following +# Mix task: +# +# mix phx.gen.cert +# +# Note that this task requires Erlang/OTP 20 or later. +# Run `mix help phx.gen.cert` for more information. +# +# The `http:` config above can be replaced with: +# +# https: [ +# port: 4001, +# cipher_suite: :strong, +# keyfile: "priv/cert/selfsigned_key.pem", +# certfile: "priv/cert/selfsigned.pem" +# ], +# +# If desired, both `http:` and `https:` keys can be +# configured to run both http and https servers on +# different ports. + +# Watch static and templates for browser reloading. +config :app, AppWeb.Endpoint, + live_reload: [ + patterns: [ + ~r"priv/static/.*(js|css|png|jpeg|jpg|gif|svg)$", + ~r"priv/gettext/.*(po)$", + ~r"lib/app_web/(live|views)/.*(ex)$", + ~r"lib/app_web/templates/.*(eex)$" + ] + ] + +# Do not include metadata nor timestamps in development logs +config :logger, :console, format: "[$level] $message\n" + +# Set a higher stacktrace during development. Avoid configuring such +# in production as building large stacktraces may be expensive. +config :phoenix, :stacktrace_depth, 20 + +# Initialize plugs at runtime for faster development compilation +config :phoenix, :plug_init_mode, :runtime diff --git a/config/prod.exs b/config/prod.exs new file mode 100644 index 0000000..d5f74e9 --- /dev/null +++ b/config/prod.exs @@ -0,0 +1,49 @@ +import Config + +# For production, don't forget to configure the url host +# to something meaningful, Phoenix uses this information +# when generating URLs. +# +# Note we also include the path to a cache manifest +# containing the digested version of static files. This +# manifest is generated by the `mix phx.digest` task, +# which you should run after static files are built and +# before starting your production server. +config :app, AppWeb.Endpoint, cache_static_manifest: "priv/static/cache_manifest.json" + +# Do not print debug messages in production +config :logger, level: :info + +# ## SSL Support +# +# To get SSL working, you will need to add the `https` key +# to the previous section and set your `:url` port to 443: +# +# config :app, AppWeb.Endpoint, +# ..., +# url: [host: "example.com", port: 443], +# https: [ +# ..., +# port: 443, +# cipher_suite: :strong, +# keyfile: System.get_env("SOME_APP_SSL_KEY_PATH"), +# certfile: System.get_env("SOME_APP_SSL_CERT_PATH") +# ] +# +# The `cipher_suite` is set to `:strong` to support only the +# latest and more secure SSL ciphers. This means old browsers +# and clients may not be supported. You can set it to +# `:compatible` for wider support. +# +# `:keyfile` and `:certfile` expect an absolute path to the key +# and cert in disk or a relative path inside priv, for example +# "priv/ssl/server.key". For all supported SSL configuration +# options, see https://hexdocs.pm/plug/Plug.SSL.html#configure/1 +# +# We also recommend setting `force_ssl` in your endpoint, ensuring +# no data is ever sent via http, always redirecting to https: +# +# config :app, AppWeb.Endpoint, +# force_ssl: [hsts: true] +# +# Check `Plug.SSL` for all available options in `force_ssl`. diff --git a/config/runtime.exs b/config/runtime.exs new file mode 100644 index 0000000..4a2c1d6 --- /dev/null +++ b/config/runtime.exs @@ -0,0 +1,67 @@ +import Config + +# config/runtime.exs is executed for all environments, including +# during releases. It is executed after compilation and before the +# system starts, so it is typically used to load production configuration +# and secrets from environment variables or elsewhere. Do not define +# any compile-time configuration in here, as it won't be applied. +# The block below contains prod specific runtime configuration. + +# Start the phoenix server if environment is set and running in a release +if System.get_env("PHX_SERVER") && System.get_env("RELEASE_NAME") do + config :app, AppWeb.Endpoint, server: true +end + +if config_env() == :prod do + database_url = + System.get_env("DATABASE_URL") || + raise """ + environment variable DATABASE_URL is missing. + For example: ecto://USER:PASS@HOST/DATABASE + """ + + maybe_ipv6 = if System.get_env("ECTO_IPV6"), do: [:inet6], else: [] + + config :app, App.Repo, + # ssl: true, + url: database_url, + pool_size: String.to_integer(System.get_env("POOL_SIZE") || "10"), + socket_options: maybe_ipv6 + + # The secret key base is used to sign/encrypt cookies and other secrets. + # A default value is used in config/dev.exs and config/test.exs but you + # want to use a different value for prod and you most likely don't want + # to check this value into version control, so we use an environment + # variable instead. + secret_key_base = + System.get_env("SECRET_KEY_BASE") || + raise """ + environment variable SECRET_KEY_BASE is missing. + You can generate one by calling: mix phx.gen.secret + """ + + host = System.get_env("PHX_HOST") || "example.com" + port = String.to_integer(System.get_env("PORT") || "4000") + + config :app, AppWeb.Endpoint, + url: [host: host, port: 443], + http: [ + # Enable IPv6 and bind on all interfaces. + # Set it to {0, 0, 0, 0, 0, 0, 0, 1} for local network only access. + # See the documentation on https://hexdocs.pm/plug_cowboy/Plug.Cowboy.html + # for details about using IPv6 vs IPv4 and loopback vs public addresses. + ip: {0, 0, 0, 0, 0, 0, 0, 0}, + port: port + ], + secret_key_base: secret_key_base + + # ## Using releases + # + # If you are doing OTP releases, you need to instruct Phoenix + # to start each relevant endpoint: + # + # config :app, AppWeb.Endpoint, server: true + # + # Then you can assemble a release by calling `mix release`. + # See `mix help release` for more information. +end diff --git a/config/test.exs b/config/test.exs new file mode 100644 index 0000000..844de13 --- /dev/null +++ b/config/test.exs @@ -0,0 +1,27 @@ +import Config + +# Configure your database +# +# The MIX_TEST_PARTITION environment variable can be used +# to provide built-in test partitioning in CI environment. +# Run `mix help test` for more information. +config :app, App.Repo, + username: "postgres", + password: "postgres", + database: "app_test#{System.get_env("MIX_TEST_PARTITION")}", + hostname: "localhost", + pool: Ecto.Adapters.SQL.Sandbox, + pool_size: 10 + +# We don't run a server during test. If one is required, +# you can enable the server option below. +config :app, AppWeb.Endpoint, + http: [ip: {127, 0, 0, 1}, port: 4002], + secret_key_base: "3/NTUnmg2ROG9Tcv7V/9XtNoUvcpQ+bi/mmOhptESLHM6ZzWS3WaGMrLbKx6c1LR", + server: false + +# Print only warnings and errors during test +config :logger, level: :warn + +# Initialize plugs at runtime for faster test compilation +config :phoenix, :plug_init_mode, :runtime diff --git a/lib/app.ex b/lib/app.ex new file mode 100644 index 0000000..a10dc06 --- /dev/null +++ b/lib/app.ex @@ -0,0 +1,9 @@ +defmodule App do + @moduledoc """ + App keeps the contexts that define your domain + and business logic. + + Contexts are also responsible for managing your data, regardless + if it comes from the database, an external API or others. + """ +end diff --git a/lib/app/application.ex b/lib/app/application.ex new file mode 100644 index 0000000..7b9240f --- /dev/null +++ b/lib/app/application.ex @@ -0,0 +1,36 @@ +defmodule App.Application do + # See https://hexdocs.pm/elixir/Application.html + # for more information on OTP Applications + @moduledoc false + + use Application + + @impl true + def start(_type, _args) do + children = [ + # Start the Ecto repository + App.Repo, + # Start the Telemetry supervisor + AppWeb.Telemetry, + # Start the PubSub system + {Phoenix.PubSub, name: App.PubSub}, + # Start the Endpoint (http/https) + AppWeb.Endpoint + # Start a worker by calling: App.Worker.start_link(arg) + # {App.Worker, arg} + ] + + # See https://hexdocs.pm/elixir/Supervisor.html + # for other strategies and supported options + opts = [strategy: :one_for_one, name: App.Supervisor] + Supervisor.start_link(children, opts) + end + + # Tell Phoenix to update the endpoint configuration + # whenever the application is updated. + @impl true + def config_change(changed, _new, removed) do + AppWeb.Endpoint.config_change(changed, removed) + :ok + end +end diff --git a/lib/app/repo.ex b/lib/app/repo.ex new file mode 100644 index 0000000..857bd3f --- /dev/null +++ b/lib/app/repo.ex @@ -0,0 +1,5 @@ +defmodule App.Repo do + use Ecto.Repo, + otp_app: :app, + adapter: Ecto.Adapters.Postgres +end diff --git a/lib/app_web.ex b/lib/app_web.ex new file mode 100644 index 0000000..646e7c3 --- /dev/null +++ b/lib/app_web.ex @@ -0,0 +1,110 @@ +defmodule AppWeb do + @moduledoc """ + The entrypoint for defining your web interface, such + as controllers, views, channels and so on. + + This can be used in your application as: + + use AppWeb, :controller + use AppWeb, :view + + The definitions below will be executed for every view, + controller, etc, so keep them short and clean, focused + on imports, uses and aliases. + + Do NOT define functions inside the quoted expressions + below. Instead, define any helper function in modules + and import those modules here. + """ + + def controller do + quote do + use Phoenix.Controller, namespace: AppWeb + + import Plug.Conn + import AppWeb.Gettext + alias AppWeb.Router.Helpers, as: Routes + end + end + + def view do + quote do + use Phoenix.View, + root: "lib/app_web/templates", + namespace: AppWeb + + # Import convenience functions from controllers + import Phoenix.Controller, + only: [get_flash: 1, get_flash: 2, view_module: 1, view_template: 1] + + # Include shared imports and aliases for views + unquote(view_helpers()) + end + end + + def live_view do + quote do + use Phoenix.LiveView, + layout: {AppWeb.LayoutView, "live.html"} + + unquote(view_helpers()) + end + end + + def live_component do + quote do + use Phoenix.LiveComponent + + unquote(view_helpers()) + end + end + + def component do + quote do + use Phoenix.Component + + unquote(view_helpers()) + end + end + + def router do + quote do + use Phoenix.Router + + import Plug.Conn + import Phoenix.Controller + import Phoenix.LiveView.Router + end + end + + def channel do + quote do + use Phoenix.Channel + import AppWeb.Gettext + end + end + + defp view_helpers do + quote do + # Use all HTML functionality (forms, tags, etc) + use Phoenix.HTML + + # Import LiveView and .heex helpers (live_render, live_patch, <.form>, etc) + import Phoenix.LiveView.Helpers + + # Import basic rendering functionality (render, render_layout, etc) + import Phoenix.View + + import AppWeb.ErrorHelpers + import AppWeb.Gettext + alias AppWeb.Router.Helpers, as: Routes + end + end + + @doc """ + When used, dispatch to the appropriate controller/view/etc. + """ + defmacro __using__(which) when is_atom(which) do + apply(__MODULE__, which, []) + end +end diff --git a/lib/app_web/controllers/page_controller.ex b/lib/app_web/controllers/page_controller.ex new file mode 100644 index 0000000..2941548 --- /dev/null +++ b/lib/app_web/controllers/page_controller.ex @@ -0,0 +1,7 @@ +defmodule AppWeb.PageController do + use AppWeb, :controller + + def index(conn, _params) do + render(conn, "index.html") + end +end diff --git a/lib/app_web/endpoint.ex b/lib/app_web/endpoint.ex new file mode 100644 index 0000000..1a403ab --- /dev/null +++ b/lib/app_web/endpoint.ex @@ -0,0 +1,46 @@ +defmodule AppWeb.Endpoint do + use Phoenix.Endpoint, otp_app: :app + + # The session will be stored in the cookie and signed, + # this means its contents can be read but not tampered with. + # Set :encryption_salt if you would also like to encrypt it. + @session_options [ + store: :cookie, + key: "_app_key", + signing_salt: "th1l2L6/" + ] + + socket "/live", Phoenix.LiveView.Socket, websocket: [connect_info: [session: @session_options]] + + # Serve at "/" the static files from "priv/static" directory. + # + # You should set gzip to true if you are running phx.digest + # when deploying your static files in production. + plug Plug.Static, + at: "/", + from: :app, + gzip: false, + only: ~w(assets fonts images favicon.ico robots.txt) + + # Code reloading can be explicitly enabled under the + # :code_reloader configuration of your endpoint. + if code_reloading? do + socket "/phoenix/live_reload/socket", Phoenix.LiveReloader.Socket + plug Phoenix.LiveReloader + plug Phoenix.CodeReloader + plug Phoenix.Ecto.CheckRepoStatus, otp_app: :app + end + + plug Plug.RequestId + plug Plug.Telemetry, event_prefix: [:phoenix, :endpoint] + + plug Plug.Parsers, + parsers: [:urlencoded, :multipart, :json], + pass: ["*/*"], + json_decoder: Phoenix.json_library() + + plug Plug.MethodOverride + plug Plug.Head + plug Plug.Session, @session_options + plug AppWeb.Router +end diff --git a/lib/app_web/gettext.ex b/lib/app_web/gettext.ex new file mode 100644 index 0000000..19bc04e --- /dev/null +++ b/lib/app_web/gettext.ex @@ -0,0 +1,24 @@ +defmodule AppWeb.Gettext do + @moduledoc """ + A module providing Internationalization with a gettext-based API. + + By using [Gettext](https://hexdocs.pm/gettext), + your module gains a set of macros for translations, for example: + + import AppWeb.Gettext + + # Simple translation + gettext("Here is the string to translate") + + # Plural translation + ngettext("Here is the string to translate", + "Here are the strings to translate", + 3) + + # Domain-based translation + dgettext("errors", "Here is the error message to translate") + + See the [Gettext Docs](https://hexdocs.pm/gettext) for detailed usage. + """ + use Gettext, otp_app: :app +end diff --git a/lib/app_web/router.ex b/lib/app_web/router.ex new file mode 100644 index 0000000..fd6c64c --- /dev/null +++ b/lib/app_web/router.ex @@ -0,0 +1,27 @@ +defmodule AppWeb.Router do + use AppWeb, :router + + pipeline :browser do + plug :accepts, ["html"] + plug :fetch_session + plug :fetch_live_flash + plug :put_root_layout, {AppWeb.LayoutView, :root} + plug :protect_from_forgery + plug :put_secure_browser_headers + end + + pipeline :api do + plug :accepts, ["json"] + end + + scope "/", AppWeb do + pipe_through :browser + + get "/", PageController, :index + end + + # Other scopes may use custom stacks. + # scope "/api", AppWeb do + # pipe_through :api + # end +end diff --git a/lib/app_web/telemetry.ex b/lib/app_web/telemetry.ex new file mode 100644 index 0000000..516863e --- /dev/null +++ b/lib/app_web/telemetry.ex @@ -0,0 +1,71 @@ +defmodule AppWeb.Telemetry do + use Supervisor + import Telemetry.Metrics + + def start_link(arg) do + Supervisor.start_link(__MODULE__, arg, name: __MODULE__) + end + + @impl true + def init(_arg) do + children = [ + # Telemetry poller will execute the given period measurements + # every 10_000ms. Learn more here: https://hexdocs.pm/telemetry_metrics + {:telemetry_poller, measurements: periodic_measurements(), period: 10_000} + # Add reporters as children of your supervision tree. + # {Telemetry.Metrics.ConsoleReporter, metrics: metrics()} + ] + + Supervisor.init(children, strategy: :one_for_one) + end + + def metrics do + [ + # Phoenix Metrics + summary("phoenix.endpoint.stop.duration", + unit: {:native, :millisecond} + ), + summary("phoenix.router_dispatch.stop.duration", + tags: [:route], + unit: {:native, :millisecond} + ), + + # Database Metrics + summary("app.repo.query.total_time", + unit: {:native, :millisecond}, + description: "The sum of the other measurements" + ), + summary("app.repo.query.decode_time", + unit: {:native, :millisecond}, + description: "The time spent decoding the data received from the database" + ), + summary("app.repo.query.query_time", + unit: {:native, :millisecond}, + description: "The time spent executing the query" + ), + summary("app.repo.query.queue_time", + unit: {:native, :millisecond}, + description: "The time spent waiting for a database connection" + ), + summary("app.repo.query.idle_time", + unit: {:native, :millisecond}, + description: + "The time the connection spent waiting before being checked out for the query" + ), + + # VM Metrics + summary("vm.memory.total", unit: {:byte, :kilobyte}), + summary("vm.total_run_queue_lengths.total"), + summary("vm.total_run_queue_lengths.cpu"), + summary("vm.total_run_queue_lengths.io") + ] + end + + defp periodic_measurements do + [ + # A module, function and arguments to be invoked periodically. + # This function must call :telemetry.execute/3 and a metric must be added above. + # {AppWeb, :count_users, []} + ] + end +end diff --git a/lib/app_web/templates/layout/app.html.heex b/lib/app_web/templates/layout/app.html.heex new file mode 100644 index 0000000..169aed9 --- /dev/null +++ b/lib/app_web/templates/layout/app.html.heex @@ -0,0 +1,5 @@ +
+ + + <%= @inner_content %> +
diff --git a/lib/app_web/templates/layout/live.html.heex b/lib/app_web/templates/layout/live.html.heex new file mode 100644 index 0000000..a29d604 --- /dev/null +++ b/lib/app_web/templates/layout/live.html.heex @@ -0,0 +1,11 @@ +
+ + + + + <%= @inner_content %> +
diff --git a/lib/app_web/templates/layout/root.html.heex b/lib/app_web/templates/layout/root.html.heex new file mode 100644 index 0000000..0eeff7f --- /dev/null +++ b/lib/app_web/templates/layout/root.html.heex @@ -0,0 +1,28 @@ + + + + + + + <%= csrf_meta_tag() %> + <%= live_title_tag assigns[:page_title] || "App", suffix: " · Phoenix Framework" %> + + + + +
+
+ + +
+
+ <%= @inner_content %> + + diff --git a/lib/app_web/templates/page/index.html.heex b/lib/app_web/templates/page/index.html.heex new file mode 100644 index 0000000..f844bd8 --- /dev/null +++ b/lib/app_web/templates/page/index.html.heex @@ -0,0 +1,41 @@ +
+

<%= gettext "Welcome to %{name}!", name: "Phoenix" %>

+

Peace of mind from prototype to production

+
+ +
+ + +
diff --git a/lib/app_web/views/error_helpers.ex b/lib/app_web/views/error_helpers.ex new file mode 100644 index 0000000..a1b7f20 --- /dev/null +++ b/lib/app_web/views/error_helpers.ex @@ -0,0 +1,47 @@ +defmodule AppWeb.ErrorHelpers do + @moduledoc """ + Conveniences for translating and building error messages. + """ + + use Phoenix.HTML + + @doc """ + Generates tag for inlined form input errors. + """ + def error_tag(form, field) do + Enum.map(Keyword.get_values(form.errors, field), fn error -> + content_tag(:span, translate_error(error), + class: "invalid-feedback", + phx_feedback_for: input_name(form, field) + ) + end) + end + + @doc """ + Translates an error message using gettext. + """ + def translate_error({msg, opts}) do + # When using gettext, we typically pass the strings we want + # to translate as a static argument: + # + # # Translate "is invalid" in the "errors" domain + # dgettext("errors", "is invalid") + # + # # Translate the number of files with plural rules + # dngettext("errors", "1 file", "%{count} files", count) + # + # Because the error messages we show in our forms and APIs + # are defined inside Ecto, we need to translate them dynamically. + # This requires us to call the Gettext module passing our gettext + # backend as first argument. + # + # Note we use the "errors" domain, which means translations + # should be written to the errors.po file. The :count option is + # set by Ecto and indicates we should also apply plural rules. + if count = opts[:count] do + Gettext.dngettext(AppWeb.Gettext, "errors", msg, msg, count, opts) + else + Gettext.dgettext(AppWeb.Gettext, "errors", msg, opts) + end + end +end diff --git a/lib/app_web/views/error_view.ex b/lib/app_web/views/error_view.ex new file mode 100644 index 0000000..a6651a5 --- /dev/null +++ b/lib/app_web/views/error_view.ex @@ -0,0 +1,16 @@ +defmodule AppWeb.ErrorView do + use AppWeb, :view + + # If you want to customize a particular status code + # for a certain format, you may uncomment below. + # def render("500.html", _assigns) do + # "Internal Server Error" + # end + + # By default, Phoenix returns the status message from + # the template name. For example, "404.html" becomes + # "Not Found". + def template_not_found(template, _assigns) do + Phoenix.Controller.status_message_from_template(template) + end +end diff --git a/lib/app_web/views/layout_view.ex b/lib/app_web/views/layout_view.ex new file mode 100644 index 0000000..69e85d2 --- /dev/null +++ b/lib/app_web/views/layout_view.ex @@ -0,0 +1,7 @@ +defmodule AppWeb.LayoutView do + use AppWeb, :view + + # Phoenix LiveDashboard is available only in development by default, + # so we instruct Elixir to not warn if the dashboard route is missing. + @compile {:no_warn_undefined, {Routes, :live_dashboard_path, 2}} +end diff --git a/lib/app_web/views/page_view.ex b/lib/app_web/views/page_view.ex new file mode 100644 index 0000000..8ba34d2 --- /dev/null +++ b/lib/app_web/views/page_view.ex @@ -0,0 +1,3 @@ +defmodule AppWeb.PageView do + use AppWeb, :view +end diff --git a/mix.exs b/mix.exs new file mode 100644 index 0000000..4ca5afb --- /dev/null +++ b/mix.exs @@ -0,0 +1,68 @@ +defmodule App.MixProject do + use Mix.Project + + def project do + [ + app: :app, + version: "0.1.0", + elixir: "~> 1.12", + elixirc_paths: elixirc_paths(Mix.env()), + compilers: [:gettext] ++ Mix.compilers(), + start_permanent: Mix.env() == :prod, + aliases: aliases(), + deps: deps() + ] + end + + # Configuration for the OTP application. + # + # Type `mix help compile.app` for more information. + def application do + [ + mod: {App.Application, []}, + extra_applications: [:logger, :runtime_tools] + ] + end + + # Specifies which paths to compile per environment. + defp elixirc_paths(:test), do: ["lib", "test/support"] + defp elixirc_paths(_), do: ["lib"] + + # Specifies your project dependencies. + # + # Type `mix help deps` for examples and options. + defp deps do + [ + {:phoenix, "~> 1.6.4"}, + {:phoenix_ecto, "~> 4.4"}, + {:ecto_sql, "~> 3.6"}, + {:postgrex, ">= 0.0.0"}, + {:phoenix_html, "~> 3.0"}, + {:phoenix_live_reload, "~> 1.2", only: :dev}, + {:phoenix_live_view, "~> 0.17.5"}, + {:floki, ">= 0.30.0", only: :test}, + {:esbuild, "~> 0.3", runtime: Mix.env() == :dev}, + {:telemetry_metrics, "~> 0.6"}, + {:telemetry_poller, "~> 1.0"}, + {:gettext, "~> 0.18"}, + {:jason, "~> 1.2"}, + {:plug_cowboy, "~> 2.5"} + ] + end + + # Aliases are shortcuts or tasks specific to the current project. + # For example, to install project dependencies and perform other setup tasks, run: + # + # $ mix setup + # + # See the documentation for `Mix` for more info on aliases. + defp aliases do + [ + setup: ["deps.get", "ecto.setup"], + "ecto.setup": ["ecto.create", "ecto.migrate", "run priv/repo/seeds.exs"], + "ecto.reset": ["ecto.drop", "ecto.setup"], + test: ["ecto.create --quiet", "ecto.migrate --quiet", "test"], + "assets.deploy": ["esbuild default --minify", "phx.digest"] + ] + end +end diff --git a/mix.lock b/mix.lock new file mode 100644 index 0000000..a0cc3b0 --- /dev/null +++ b/mix.lock @@ -0,0 +1,33 @@ +%{ + "castore": {:hex, :castore, "0.1.13", "ccf3ab251ffaebc4319f41d788ce59a6ab3f42b6c27e598ad838ffecee0b04f9", [:mix], [], "hexpm", "a14a7eecfec7e20385493dbb92b0d12c5d77ecfd6307de10102d58c94e8c49c0"}, + "connection": {:hex, :connection, "1.1.0", "ff2a49c4b75b6fb3e674bfc5536451607270aac754ffd1bdfe175abe4a6d7a68", [:mix], [], "hexpm", "722c1eb0a418fbe91ba7bd59a47e28008a189d47e37e0e7bb85585a016b2869c"}, + "cowboy": {:hex, :cowboy, "2.9.0", "865dd8b6607e14cf03282e10e934023a1bd8be6f6bacf921a7e2a96d800cd452", [:make, :rebar3], [{:cowlib, "2.11.0", [hex: :cowlib, repo: "hexpm", optional: false]}, {:ranch, "1.8.0", [hex: :ranch, repo: "hexpm", optional: false]}], "hexpm", "2c729f934b4e1aa149aff882f57c6372c15399a20d54f65c8d67bef583021bde"}, + "cowboy_telemetry": {:hex, :cowboy_telemetry, "0.4.0", "f239f68b588efa7707abce16a84d0d2acf3a0f50571f8bb7f56a15865aae820c", [:rebar3], [{:cowboy, "~> 2.7", [hex: :cowboy, repo: "hexpm", optional: false]}, {:telemetry, "~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "7d98bac1ee4565d31b62d59f8823dfd8356a169e7fcbb83831b8a5397404c9de"}, + "cowlib": {:hex, :cowlib, "2.11.0", "0b9ff9c346629256c42ebe1eeb769a83c6cb771a6ee5960bd110ab0b9b872063", [:make, :rebar3], [], "hexpm", "2b3e9da0b21c4565751a6d4901c20d1b4cc25cbb7fd50d91d2ab6dd287bc86a9"}, + "db_connection": {:hex, :db_connection, "2.4.1", "6411f6e23f1a8b68a82fa3a36366d4881f21f47fc79a9efb8c615e62050219da", [:mix], [{:connection, "~> 1.0", [hex: :connection, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "ea36d226ec5999781a9a8ad64e5d8c4454ecedc7a4d643e4832bf08efca01f00"}, + "decimal": {:hex, :decimal, "2.0.0", "a78296e617b0f5dd4c6caf57c714431347912ffb1d0842e998e9792b5642d697", [:mix], [], "hexpm", "34666e9c55dea81013e77d9d87370fe6cb6291d1ef32f46a1600230b1d44f577"}, + "ecto": {:hex, :ecto, "3.7.1", "a20598862351b29f80f285b21ec5297da1181c0442687f9b8329f0445d228892", [:mix], [{:decimal, "~> 1.6 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "d36e5b39fc479e654cffd4dbe1865d9716e4a9b6311faff799b6f90ab81b8638"}, + "ecto_sql": {:hex, :ecto_sql, "3.7.1", "8de624ef50b2a8540252d8c60506379fbbc2707be1606853df371cf53df5d053", [:mix], [{:db_connection, "~> 2.2", [hex: :db_connection, repo: "hexpm", optional: false]}, {:ecto, "~> 3.7.0", [hex: :ecto, repo: "hexpm", optional: false]}, {:myxql, "~> 0.4.0 or ~> 0.5.0", [hex: :myxql, repo: "hexpm", optional: true]}, {:postgrex, "~> 0.15.0 or ~> 1.0", [hex: :postgrex, repo: "hexpm", optional: true]}, {:tds, "~> 2.1.1 or ~> 2.2", [hex: :tds, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4.0 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "2b42a32e2ce92f64aba5c88617891ab3b0ba34f3f3a503fa20009eae1a401c81"}, + "esbuild": {:hex, :esbuild, "0.4.0", "9f17db148aead4cf1e6e6a584214357287a93407b5fb51a031f122b61385d4c2", [:mix], [{:castore, ">= 0.0.0", [hex: :castore, repo: "hexpm", optional: false]}], "hexpm", "b61e4e6b92ffe45e4ee4755a22de6211a67c67987dc02afb35a425a0add1d447"}, + "file_system": {:hex, :file_system, "0.2.10", "fb082005a9cd1711c05b5248710f8826b02d7d1784e7c3451f9c1231d4fc162d", [:mix], [], "hexpm", "41195edbfb562a593726eda3b3e8b103a309b733ad25f3d642ba49696bf715dc"}, + "floki": {:hex, :floki, "0.32.0", "f915dc15258bc997d49be1f5ef7d3992f8834d6f5695270acad17b41f5bcc8e2", [:mix], [{:html_entities, "~> 0.5.0", [hex: :html_entities, repo: "hexpm", optional: false]}], "hexpm", "1c5a91cae1fd8931c26a4826b5e2372c284813904c8bacb468b5de39c7ececbd"}, + "gettext": {:hex, :gettext, "0.18.2", "7df3ea191bb56c0309c00a783334b288d08a879f53a7014341284635850a6e55", [:mix], [], "hexpm", "f9f537b13d4fdd30f3039d33cb80144c3aa1f8d9698e47d7bcbcc8df93b1f5c5"}, + "html_entities": {:hex, :html_entities, "0.5.2", "9e47e70598da7de2a9ff6af8758399251db6dbb7eebe2b013f2bbd2515895c3c", [:mix], [], "hexpm", "c53ba390403485615623b9531e97696f076ed415e8d8058b1dbaa28181f4fdcc"}, + "jason": {:hex, :jason, "1.2.2", "ba43e3f2709fd1aa1dce90aaabfd039d000469c05c56f0b8e31978e03fa39052", [:mix], [{:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "18a228f5f0058ee183f29f9eae0805c6e59d61c3b006760668d8d18ff0d12179"}, + "mime": {:hex, :mime, "2.0.2", "0b9e1a4c840eafb68d820b0e2158ef5c49385d17fb36855ac6e7e087d4b1dcc5", [:mix], [], "hexpm", "e6a3f76b4c277739e36c2e21a2c640778ba4c3846189d5ab19f97f126df5f9b7"}, + "phoenix": {:hex, :phoenix, "1.6.4", "bc9a757f0a4eac88e1e3501245a6259e74d30970df8c072836d755608dbc4c7d", [:mix], [{:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:phoenix_pubsub, "~> 2.0", [hex: :phoenix_pubsub, repo: "hexpm", optional: false]}, {:phoenix_view, "~> 1.0", [hex: :phoenix_view, repo: "hexpm", optional: false]}, {:plug, "~> 1.10", [hex: :plug, repo: "hexpm", optional: false]}, {:plug_cowboy, "~> 2.2", [hex: :plug_cowboy, repo: "hexpm", optional: true]}, {:plug_crypto, "~> 1.2", [hex: :plug_crypto, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "9b6cb3f31e3ea1049049852703eca794f7afdb0c1dc111d8f166ba032c103a80"}, + "phoenix_ecto": {:hex, :phoenix_ecto, "4.4.0", "0672ed4e4808b3fbed494dded89958e22fb882de47a97634c0b13e7b0b5f7720", [:mix], [{:ecto, "~> 3.3", [hex: :ecto, repo: "hexpm", optional: false]}, {:phoenix_html, "~> 2.14.2 or ~> 3.0", [hex: :phoenix_html, repo: "hexpm", optional: true]}, {:plug, "~> 1.9", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm", "09864e558ed31ee00bd48fcc1d4fc58ae9678c9e81649075431e69dbabb43cc1"}, + "phoenix_html": {:hex, :phoenix_html, "3.1.0", "0b499df05aad27160d697a9362f0e89fa0e24d3c7a9065c2bd9d38b4d1416c09", [:mix], [{:plug, "~> 1.5", [hex: :plug, repo: "hexpm", optional: true]}], "hexpm", "0c0a98a2cefa63433657983a2a594c7dee5927e4391e0f1bfd3a151d1def33fc"}, + "phoenix_live_reload": {:hex, :phoenix_live_reload, "1.3.3", "3a53772a6118d5679bf50fc1670505a290e32a1d195df9e069d8c53ab040c054", [:mix], [{:file_system, "~> 0.2.1 or ~> 0.3", [hex: :file_system, repo: "hexpm", optional: false]}, {:phoenix, "~> 1.4", [hex: :phoenix, repo: "hexpm", optional: false]}], "hexpm", "766796676e5f558dbae5d1bdb066849673e956005e3730dfd5affd7a6da4abac"}, + "phoenix_live_view": {:hex, :phoenix_live_view, "0.17.5", "63f52a6f9f6983f04e424586ff897c016ecc5e4f8d1e2c22c2887af1c57215d8", [:mix], [{:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:phoenix, "~> 1.5.9 or ~> 1.6.0", [hex: :phoenix, repo: "hexpm", optional: false]}, {:phoenix_html, "~> 3.1", [hex: :phoenix_html, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4.2 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "c5586e6a3d4df71b8214c769d4f5eb8ece2b4001711a7ca0f97323c36958b0e3"}, + "phoenix_pubsub": {:hex, :phoenix_pubsub, "2.0.0", "a1ae76717bb168cdeb10ec9d92d1480fec99e3080f011402c0a2d68d47395ffb", [:mix], [], "hexpm", "c52d948c4f261577b9c6fa804be91884b381a7f8f18450c5045975435350f771"}, + "phoenix_view": {:hex, :phoenix_view, "1.0.0", "fea71ecaaed71178b26dd65c401607de5ec22e2e9ef141389c721b3f3d4d8011", [:mix], [{:phoenix_html, "~> 2.14.2 or ~> 3.0", [hex: :phoenix_html, repo: "hexpm", optional: true]}], "hexpm", "82be3e2516f5633220246e2e58181282c71640dab7afc04f70ad94253025db0c"}, + "plug": {:hex, :plug, "1.12.1", "645678c800601d8d9f27ad1aebba1fdb9ce5b2623ddb961a074da0b96c35187d", [:mix], [{:mime, "~> 1.0 or ~> 2.0", [hex: :mime, repo: "hexpm", optional: false]}, {:plug_crypto, "~> 1.1.1 or ~> 1.2", [hex: :plug_crypto, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4.3 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "d57e799a777bc20494b784966dc5fbda91eb4a09f571f76545b72a634ce0d30b"}, + "plug_cowboy": {:hex, :plug_cowboy, "2.5.2", "62894ccd601cf9597e2c23911ff12798a8a18d237e9739f58a6b04e4988899fe", [:mix], [{:cowboy, "~> 2.7", [hex: :cowboy, repo: "hexpm", optional: false]}, {:cowboy_telemetry, "~> 0.3", [hex: :cowboy_telemetry, repo: "hexpm", optional: false]}, {:plug, "~> 1.7", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm", "ea6e87f774c8608d60c8d34022a7d073bd7680a0a013f049fc62bf35efea1044"}, + "plug_crypto": {:hex, :plug_crypto, "1.2.2", "05654514ac717ff3a1843204b424477d9e60c143406aa94daf2274fdd280794d", [:mix], [], "hexpm", "87631c7ad914a5a445f0a3809f99b079113ae4ed4b867348dd9eec288cecb6db"}, + "postgrex": {:hex, :postgrex, "0.15.13", "7794e697481799aee8982688c261901de493eb64451feee6ea58207d7266d54a", [:mix], [{:connection, "~> 1.0", [hex: :connection, repo: "hexpm", optional: false]}, {:db_connection, "~> 2.1", [hex: :db_connection, repo: "hexpm", optional: false]}, {:decimal, "~> 1.5 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}], "hexpm", "3ffb76e1a97cfefe5c6a95632a27ffb67f28871c9741fb585f9d1c3cd2af70f1"}, + "ranch": {:hex, :ranch, "1.8.0", "8c7a100a139fd57f17327b6413e4167ac559fbc04ca7448e9be9057311597a1d", [:make, :rebar3], [], "hexpm", "49fbcfd3682fab1f5d109351b61257676da1a2fdbe295904176d5e521a2ddfe5"}, + "telemetry": {:hex, :telemetry, "1.0.0", "0f453a102cdf13d506b7c0ab158324c337c41f1cc7548f0bc0e130bbf0ae9452", [:rebar3], [], "hexpm", "73bc09fa59b4a0284efb4624335583c528e07ec9ae76aca96ea0673850aec57a"}, + "telemetry_metrics": {:hex, :telemetry_metrics, "0.6.1", "315d9163a1d4660aedc3fee73f33f1d355dcc76c5c3ab3d59e76e3edf80eef1f", [:mix], [{:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "7be9e0871c41732c233be71e4be11b96e56177bf15dde64a8ac9ce72ac9834c6"}, + "telemetry_poller": {:hex, :telemetry_poller, "1.0.0", "db91bb424e07f2bb6e73926fcafbfcbcb295f0193e0a00e825e589a0a47e8453", [:rebar3], [{:telemetry, "~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "b3a24eafd66c3f42da30fc3ca7dda1e9d546c12250a2d60d7b81d264fbec4f6e"}, +} diff --git a/priv/gettext/en/LC_MESSAGES/errors.po b/priv/gettext/en/LC_MESSAGES/errors.po new file mode 100644 index 0000000..844c4f5 --- /dev/null +++ b/priv/gettext/en/LC_MESSAGES/errors.po @@ -0,0 +1,112 @@ +## `msgid`s in this file come from POT (.pot) files. +## +## Do not add, change, or remove `msgid`s manually here as +## they're tied to the ones in the corresponding POT file +## (with the same domain). +## +## Use `mix gettext.extract --merge` or `mix gettext.merge` +## to merge POT files into PO files. +msgid "" +msgstr "" +"Language: en\n" + +## From Ecto.Changeset.cast/4 +msgid "can't be blank" +msgstr "" + +## From Ecto.Changeset.unique_constraint/3 +msgid "has already been taken" +msgstr "" + +## From Ecto.Changeset.put_change/3 +msgid "is invalid" +msgstr "" + +## From Ecto.Changeset.validate_acceptance/3 +msgid "must be accepted" +msgstr "" + +## From Ecto.Changeset.validate_format/3 +msgid "has invalid format" +msgstr "" + +## From Ecto.Changeset.validate_subset/3 +msgid "has an invalid entry" +msgstr "" + +## From Ecto.Changeset.validate_exclusion/3 +msgid "is reserved" +msgstr "" + +## From Ecto.Changeset.validate_confirmation/3 +msgid "does not match confirmation" +msgstr "" + +## From Ecto.Changeset.no_assoc_constraint/3 +msgid "is still associated with this entry" +msgstr "" + +msgid "are still associated with this entry" +msgstr "" + +## From Ecto.Changeset.validate_length/3 +msgid "should have %{count} item(s)" +msgid_plural "should have %{count} item(s)" +msgstr[0] "" +msgstr[1] "" + +msgid "should be %{count} character(s)" +msgid_plural "should be %{count} character(s)" +msgstr[0] "" +msgstr[1] "" + +msgid "should be %{count} byte(s)" +msgid_plural "should be %{count} byte(s)" +msgstr[0] "" +msgstr[1] "" + +msgid "should have at least %{count} item(s)" +msgid_plural "should have at least %{count} item(s)" +msgstr[0] "" +msgstr[1] "" + +msgid "should be at least %{count} character(s)" +msgid_plural "should be at least %{count} character(s)" +msgstr[0] "" +msgstr[1] "" + +msgid "should be at least %{count} byte(s)" +msgid_plural "should be at least %{count} byte(s)" +msgstr[0] "" +msgstr[1] "" + +msgid "should have at most %{count} item(s)" +msgid_plural "should have at most %{count} item(s)" +msgstr[0] "" +msgstr[1] "" + +msgid "should be at most %{count} character(s)" +msgid_plural "should be at most %{count} character(s)" +msgstr[0] "" +msgstr[1] "" + +msgid "should be at most %{count} byte(s)" +msgid_plural "should be at most %{count} byte(s)" +msgstr[0] "" +msgstr[1] "" + +## From Ecto.Changeset.validate_number/3 +msgid "must be less than %{number}" +msgstr "" + +msgid "must be greater than %{number}" +msgstr "" + +msgid "must be less than or equal to %{number}" +msgstr "" + +msgid "must be greater than or equal to %{number}" +msgstr "" + +msgid "must be equal to %{number}" +msgstr "" diff --git a/priv/gettext/errors.pot b/priv/gettext/errors.pot new file mode 100644 index 0000000..39a220b --- /dev/null +++ b/priv/gettext/errors.pot @@ -0,0 +1,95 @@ +## This is a PO Template file. +## +## `msgid`s here are often extracted from source code. +## Add new translations manually only if they're dynamic +## translations that can't be statically extracted. +## +## Run `mix gettext.extract` to bring this file up to +## date. Leave `msgstr`s empty as changing them here has no +## effect: edit them in PO (`.po`) files instead. + +## From Ecto.Changeset.cast/4 +msgid "can't be blank" +msgstr "" + +## From Ecto.Changeset.unique_constraint/3 +msgid "has already been taken" +msgstr "" + +## From Ecto.Changeset.put_change/3 +msgid "is invalid" +msgstr "" + +## From Ecto.Changeset.validate_acceptance/3 +msgid "must be accepted" +msgstr "" + +## From Ecto.Changeset.validate_format/3 +msgid "has invalid format" +msgstr "" + +## From Ecto.Changeset.validate_subset/3 +msgid "has an invalid entry" +msgstr "" + +## From Ecto.Changeset.validate_exclusion/3 +msgid "is reserved" +msgstr "" + +## From Ecto.Changeset.validate_confirmation/3 +msgid "does not match confirmation" +msgstr "" + +## From Ecto.Changeset.no_assoc_constraint/3 +msgid "is still associated with this entry" +msgstr "" + +msgid "are still associated with this entry" +msgstr "" + +## From Ecto.Changeset.validate_length/3 +msgid "should be %{count} character(s)" +msgid_plural "should be %{count} character(s)" +msgstr[0] "" +msgstr[1] "" + +msgid "should have %{count} item(s)" +msgid_plural "should have %{count} item(s)" +msgstr[0] "" +msgstr[1] "" + +msgid "should be at least %{count} character(s)" +msgid_plural "should be at least %{count} character(s)" +msgstr[0] "" +msgstr[1] "" + +msgid "should have at least %{count} item(s)" +msgid_plural "should have at least %{count} item(s)" +msgstr[0] "" +msgstr[1] "" + +msgid "should be at most %{count} character(s)" +msgid_plural "should be at most %{count} character(s)" +msgstr[0] "" +msgstr[1] "" + +msgid "should have at most %{count} item(s)" +msgid_plural "should have at most %{count} item(s)" +msgstr[0] "" +msgstr[1] "" + +## From Ecto.Changeset.validate_number/3 +msgid "must be less than %{number}" +msgstr "" + +msgid "must be greater than %{number}" +msgstr "" + +msgid "must be less than or equal to %{number}" +msgstr "" + +msgid "must be greater than or equal to %{number}" +msgstr "" + +msgid "must be equal to %{number}" +msgstr "" diff --git a/priv/repo/migrations/.formatter.exs b/priv/repo/migrations/.formatter.exs new file mode 100644 index 0000000..49f9151 --- /dev/null +++ b/priv/repo/migrations/.formatter.exs @@ -0,0 +1,4 @@ +[ + import_deps: [:ecto_sql], + inputs: ["*.exs"] +] diff --git a/priv/repo/seeds.exs b/priv/repo/seeds.exs new file mode 100644 index 0000000..fe3037b --- /dev/null +++ b/priv/repo/seeds.exs @@ -0,0 +1,11 @@ +# Script for populating the database. You can run it as: +# +# mix run priv/repo/seeds.exs +# +# Inside the script, you can read and write to any of your +# repositories directly: +# +# App.Repo.insert!(%App.SomeSchema{}) +# +# We recommend using the bang functions (`insert!`, `update!` +# and so on) as they will fail if something goes wrong. diff --git a/priv/static/favicon.ico b/priv/static/favicon.ico new file mode 100644 index 0000000000000000000000000000000000000000..73de524aaadcf60fbe9d32881db0aa86b58b5cb9 GIT binary patch literal 1258 zcmbtUO>fgM7{=qN=;Mz_82;lvPEdVaxv-<-&=sZLwab?3I zBP>U*&(Hv<5n@9ZQ$vhg#|u$Zmtq8BV;+W*7(?jOx-{r?#TE&$Sdq77MbdJjD5`-q zMm_z(jLv3t>5NhzK{%aG(Yudfpjd3AFdKe2U7&zdepTe>^s(@!&0X8TJ`h+-I?84Ml# literal 0 HcmV?d00001 diff --git a/priv/static/images/phoenix.png b/priv/static/images/phoenix.png new file mode 100644 index 0000000000000000000000000000000000000000..9c81075f63d2151e6f40e9aa66f665749a87cc6a GIT binary patch literal 13900 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 UWxWXg`G1#+f~I_}taaG`2PLnS&Hw-a literal 0 HcmV?d00001 diff --git a/priv/static/robots.txt b/priv/static/robots.txt new file mode 100644 index 0000000..26e06b5 --- /dev/null +++ b/priv/static/robots.txt @@ -0,0 +1,5 @@ +# See https://www.robotstxt.org/robotstxt.html for documentation on how to use the robots.txt file +# +# To ban all spiders from the entire site uncomment the next two lines: +# User-agent: * +# Disallow: / diff --git a/test/app_web/controllers/page_controller_test.exs b/test/app_web/controllers/page_controller_test.exs new file mode 100644 index 0000000..4bb48b7 --- /dev/null +++ b/test/app_web/controllers/page_controller_test.exs @@ -0,0 +1,8 @@ +defmodule AppWeb.PageControllerTest do + use AppWeb.ConnCase + + test "GET /", %{conn: conn} do + conn = get(conn, "/") + assert html_response(conn, 200) =~ "Welcome to Phoenix!" + end +end diff --git a/test/app_web/views/error_view_test.exs b/test/app_web/views/error_view_test.exs new file mode 100644 index 0000000..85a326c --- /dev/null +++ b/test/app_web/views/error_view_test.exs @@ -0,0 +1,14 @@ +defmodule AppWeb.ErrorViewTest do + use AppWeb.ConnCase, async: true + + # Bring render/3 and render_to_string/3 for testing custom views + import Phoenix.View + + test "renders 404.html" do + assert render_to_string(AppWeb.ErrorView, "404.html", []) == "Not Found" + end + + test "renders 500.html" do + assert render_to_string(AppWeb.ErrorView, "500.html", []) == "Internal Server Error" + end +end diff --git a/test/app_web/views/layout_view_test.exs b/test/app_web/views/layout_view_test.exs new file mode 100644 index 0000000..1ba98bc --- /dev/null +++ b/test/app_web/views/layout_view_test.exs @@ -0,0 +1,8 @@ +defmodule AppWeb.LayoutViewTest do + use AppWeb.ConnCase, async: true + + # When testing helpers, you may want to import Phoenix.HTML and + # use functions such as safe_to_string() to convert the helper + # result into an HTML string. + # import Phoenix.HTML +end diff --git a/test/app_web/views/page_view_test.exs b/test/app_web/views/page_view_test.exs new file mode 100644 index 0000000..75067ce --- /dev/null +++ b/test/app_web/views/page_view_test.exs @@ -0,0 +1,3 @@ +defmodule AppWeb.PageViewTest do + use AppWeb.ConnCase, async: true +end diff --git a/test/support/channel_case.ex b/test/support/channel_case.ex new file mode 100644 index 0000000..0a16e32 --- /dev/null +++ b/test/support/channel_case.ex @@ -0,0 +1,36 @@ +defmodule AppWeb.ChannelCase do + @moduledoc """ + This module defines the test case to be used by + channel tests. + + Such tests rely on `Phoenix.ChannelTest` and also + import other functionality to make it easier + to build common data structures and query the data layer. + + Finally, if the test case interacts with the database, + we enable the SQL sandbox, so changes done to the database + are reverted at the end of every test. If you are using + PostgreSQL, you can even run database tests asynchronously + by setting `use AppWeb.ChannelCase, async: true`, although + this option is not recommended for other databases. + """ + + use ExUnit.CaseTemplate + + using do + quote do + # Import conveniences for testing with channels + import Phoenix.ChannelTest + import AppWeb.ChannelCase + + # The default endpoint for testing + @endpoint AppWeb.Endpoint + end + end + + setup tags do + pid = Ecto.Adapters.SQL.Sandbox.start_owner!(App.Repo, shared: not tags[:async]) + on_exit(fn -> Ecto.Adapters.SQL.Sandbox.stop_owner(pid) end) + :ok + end +end diff --git a/test/support/conn_case.ex b/test/support/conn_case.ex new file mode 100644 index 0000000..1fb9113 --- /dev/null +++ b/test/support/conn_case.ex @@ -0,0 +1,39 @@ +defmodule AppWeb.ConnCase do + @moduledoc """ + This module defines the test case to be used by + tests that require setting up a connection. + + Such tests rely on `Phoenix.ConnTest` and also + import other functionality to make it easier + to build common data structures and query the data layer. + + Finally, if the test case interacts with the database, + we enable the SQL sandbox, so changes done to the database + are reverted at the end of every test. If you are using + PostgreSQL, you can even run database tests asynchronously + by setting `use AppWeb.ConnCase, async: true`, although + this option is not recommended for other databases. + """ + + use ExUnit.CaseTemplate + + using do + quote do + # Import conveniences for testing with connections + import Plug.Conn + import Phoenix.ConnTest + import AppWeb.ConnCase + + alias AppWeb.Router.Helpers, as: Routes + + # The default endpoint for testing + @endpoint AppWeb.Endpoint + end + end + + setup tags do + pid = Ecto.Adapters.SQL.Sandbox.start_owner!(App.Repo, shared: not tags[:async]) + on_exit(fn -> Ecto.Adapters.SQL.Sandbox.stop_owner(pid) end) + {:ok, conn: Phoenix.ConnTest.build_conn()} + end +end diff --git a/test/support/data_case.ex b/test/support/data_case.ex new file mode 100644 index 0000000..3022d33 --- /dev/null +++ b/test/support/data_case.ex @@ -0,0 +1,51 @@ +defmodule App.DataCase do + @moduledoc """ + This module defines the setup for tests requiring + access to the application's data layer. + + You may define functions here to be used as helpers in + your tests. + + Finally, if the test case interacts with the database, + we enable the SQL sandbox, so changes done to the database + are reverted at the end of every test. If you are using + PostgreSQL, you can even run database tests asynchronously + by setting `use App.DataCase, async: true`, although + this option is not recommended for other databases. + """ + + use ExUnit.CaseTemplate + + using do + quote do + alias App.Repo + + import Ecto + import Ecto.Changeset + import Ecto.Query + import App.DataCase + end + end + + setup tags do + pid = Ecto.Adapters.SQL.Sandbox.start_owner!(App.Repo, shared: not tags[:async]) + on_exit(fn -> Ecto.Adapters.SQL.Sandbox.stop_owner(pid) end) + :ok + end + + @doc """ + A helper that transforms changeset errors into a map of messages. + + assert {:error, changeset} = Accounts.create_user(%{password: "short"}) + assert "password is too short" in errors_on(changeset).password + assert %{password: ["password is too short"]} = errors_on(changeset) + + """ + def errors_on(changeset) do + Ecto.Changeset.traverse_errors(changeset, fn {message, opts} -> + Regex.replace(~r"%{(\w+)}", message, fn _, key -> + opts |> Keyword.get(String.to_existing_atom(key), key) |> to_string() + end) + end) + end +end diff --git a/test/test_helper.exs b/test/test_helper.exs new file mode 100644 index 0000000..4fe7a40 --- /dev/null +++ b/test/test_helper.exs @@ -0,0 +1,2 @@ +ExUnit.start() +Ecto.Adapters.SQL.Sandbox.mode(App.Repo, :manual) From 60ce732e408c9770eb8a5b8665042b682720b0cf Mon Sep 17 00:00:00 2001 From: nelsonic Date: Thu, 9 Dec 2021 00:16:14 +0000 Subject: [PATCH 02/24] add outline of desired functionality in "How?" section for #53 --- README.md | 44 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 42 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index eed71c1..ee9464b 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,16 @@ A keystone activity # How? +Firstly, you can try the App via Heroku: +https://sleepdev.herokuapp.com +Try: ++ **Log _in_** ++ **Start** a sleep timer ++ **Stop** the timer ++ **Log _out_**. ++ **Log _back in_** ++ ***Confirm*** your "sleep" session was recorded. # _Tutorial_ @@ -47,7 +56,7 @@ Anyone who knows basic programming should be able to follow along. - +## Create New Phoenix App ```sh mix phx.new app --no-mailer --no-dashboard @@ -58,12 +67,43 @@ without the mailer (email) or live dashboard but with a database and `LiveView` support. -To start your Phoenix server: +When you see the prompt asking you +to fetch and install the dependencies: + +``` +Fetch and install dependencies? [Yn] +``` + +Type `y` followed by the `Enter` key: + +You should then see: + +``` +* running mix deps.get +* running mix deps.compile +``` + +To start the Phoenix server: * Install dependencies with `mix deps.get` * Create and migrate your database with `mix ecto.setup` * Start Phoenix endpoint with `mix phx.server` +You should see the following output in your terminal: + +``` +[info] Running AppWeb.Endpoint with cowboy 2.9.0 at 127.0.0.1:4000 (http) +[debug] Downloading esbuild from https://registry.npmjs.org/esbuild-darwin-64/-/esbuild-darwin-64-0.13.5.tgz +[info] Access AppWeb.Endpoint at http://localhost:4000 +[watch] build finished, watching for changes... +``` + +When you open http://localhost:4000 in your web browser, +you should see see something similar to the following: + +![phoenix-framerwork-welcome-page](https://user-images.githubusercontent.com/194400/145309471-306fdd5e-324f-4c4a-bd9f-6fddbec7f512.png) + + From dac8dcbbffb5e7d8a1ca88e35602d90bd26facc0 Mon Sep 17 00:00:00 2001 From: nelsonic Date: Sun, 20 Feb 2022 22:31:40 +0000 Subject: [PATCH 03/24] [WiP] add detail to README.md for #53 --- README.md | 45 +++++++++++++++++++++++++++++++++++++-------- 1 file changed, 37 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index ee9464b..2a1fe48 100644 --- a/README.md +++ b/README.md @@ -1,22 +1,36 @@ # sleep -Sleep is the single most important activity we perform in life.
-A keystone activity +Sleep is the single most important activity in life.
+A good night's sleep +can dramatically in personal effectiveness +in all areas of your life. # Why? +If you don't get a good night's sleep ... + # What? +This App + # Who? # When? +You can start using this MVP _now_ (_tonight_). + +> If you're reading this past **22:00**, +go straight to the "***Try it!***" section +and treat yourself to an _early_ night! + # How? +## Try it! + Firstly, you can try the App via Heroku: https://sleepdev.herokuapp.com @@ -29,9 +43,21 @@ Try: + ***Confirm*** your "sleep" session was recorded. + +## Run it! + +Now that you've tried it on Heroku, +try running the _finished_ (MVP) on your `localhost`: + + + + + # _Tutorial_ + + ## Implementation Note We built this MVP App using using @@ -50,11 +76,19 @@ with a **basic interface**, **saving data** to the database, **authentication** and ***deployment*** -in **_less_ than 20 minutes**.1 +in **_less_ than 20 minutes**. Anyone who knows basic programming (e.g. `Python`, `JavaScript`, etc.) should be able to follow along. +If you get stuck, +[please ask questions!]() + ## Create New Phoenix App @@ -106,8 +140,3 @@ you should see see something similar to the following: - -1 -Other approaches to web app development -might get you different results ... -https://twitter.com/iamdevloper/status/787969734918668289 \ No newline at end of file From ec906838de3a85051a26eb1626df58a3773d210a Mon Sep 17 00:00:00 2001 From: nelsonic Date: Sun, 20 Feb 2022 22:38:15 +0000 Subject: [PATCH 04/24] move tutorial to its own file #53 --- tutorial.md | 90 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 tutorial.md diff --git a/tutorial.md b/tutorial.md new file mode 100644 index 0000000..f7150fa --- /dev/null +++ b/tutorial.md @@ -0,0 +1,90 @@ +# _Tutorial_ + +This tutorial takes you through _building_ a sleep tracking App from scratch +so that you can understand how it works. +If you get stuck, _please_ +[**ask questions**!](https://github.com/dwyl/sleep/issues) + + +## Implementation Note + +We built this MVP App using using +[**`Elixir`**](https://github.com/dwyl/learn-elixir) +and +[**`Phoenix`**](https://github.com/dwyl/learn-phoenix-framework) +because it's one of the simplest ways +to build web applications +from first principals. +Our objective is to get to a _useable_ app +as **_fast_ as possible** +so we can start inputting/saving data. +You will see below, +that we can get up-and-running +with a **basic interface**, +**saving data** to the database, +**authentication** +and ***deployment*** +in **_less_ than 20 minutes**. +Anyone who knows basic programming +(e.g. `Python`, `JavaScript`, etc.) +should be able to follow along. + + + + +## Create New Phoenix App + +```sh +mix phx.new app --no-mailer --no-dashboard +``` + +This creates a new Phoenix Web App named **`app`** +without the mailer (email) or live dashboard +but with a database and `LiveView` support. + + +When you see the prompt asking you +to fetch and install the dependencies: + +``` +Fetch and install dependencies? [Yn] +``` + +Type `y` followed by the `Enter` key: + +You should then see: + +``` +* running mix deps.get +* running mix deps.compile +``` + +To start the Phoenix server: + +* Install dependencies with `mix deps.get` +* Create and migrate your database with `mix ecto.setup` +* Start Phoenix endpoint with `mix phx.server` + +You should see the following output in your terminal: + +``` +[info] Running AppWeb.Endpoint with cowboy 2.9.0 at 127.0.0.1:4000 (http) +[debug] Downloading esbuild from https://registry.npmjs.org/esbuild-darwin-64/-/esbuild-darwin-64-0.13.5.tgz +[info] Access AppWeb.Endpoint at http://localhost:4000 +[watch] build finished, watching for changes... +``` + +When you open http://localhost:4000 in your web browser, +you should see see something similar to the following: + +![phoenix-framerwork-welcome-page](https://user-images.githubusercontent.com/194400/145309471-306fdd5e-324f-4c4a-bd9f-6fddbec7f512.png) + + + \ No newline at end of file From 6fb3a05a1bea1b5bf5304344036dde8d77e205d2 Mon Sep 17 00:00:00 2001 From: nelsonic Date: Sun, 20 Feb 2022 22:38:49 +0000 Subject: [PATCH 05/24] update version of Phoenix to 1.6.6 --- README.md | 141 +++++++++++++++++----------------------- config/config.exs | 4 +- config/dev.exs | 4 +- config/runtime.exs | 2 +- config/test.exs | 4 +- lib/app_web/endpoint.ex | 2 +- mix.exs | 2 +- mix.lock | 20 +++--- 8 files changed, 80 insertions(+), 99 deletions(-) diff --git a/README.md b/README.md index 2a1fe48..8b06ccf 100644 --- a/README.md +++ b/README.md @@ -1,21 +1,48 @@ # sleep -Sleep is the single most important activity in life.
+Sleep is the single most important activity in life; +it restores our tired bodies +and consolidates neural connections to help form/retain memories. A good night's sleep -can dramatically in personal effectiveness -in all areas of your life. +can dramatically increase effectiveness +in all areas of your life. +Tracking your sleep times +and reflecting on your sleep quality +can help you focus on this vital +aspect of health and longevity. # Why? -If you don't get a good night's sleep ... +If you don't get a good night's sleep +virtually everything about your next day +will be worse. + +See below for all the areas sleep affects. + # What? -This App +This App is the simplest possible sleep tracker +(_other than using a paper notepad and pen +or a note taking App on your phone ..._) + +A deliberatly basic version of an App is +commonly referred to as Minimum Viable Product ("MVP") +which means it has the minimum features to be useful, +but leaves a lot enhancements out. + +If you think of a feature/improvement, _please_ +[**open an issue**!](https://github.com/dwyl/sleep/issues) +Contributions/ideas are always welcome +and we're delighted to extend this +in response to feedback! # Who? +Everyone sleeps. + + # When? You can start using this MVP _now_ (_tonight_). @@ -29,114 +56,68 @@ and treat yourself to an _early_ night! # How? + + ## Try it! Firstly, you can try the App via Heroku: https://sleepdev.herokuapp.com -Try: +Try the following actions: + + **Log _in_** -+ **Start** a sleep timer -+ **Stop** the timer -+ **Log _out_**. -+ **Log _back in_** ++ **_Start_** a sleep timer ++ **Stop** the timer - to confirm that it works. ++ **Log _out_** - to confirm that no data is stored in the browser. ++ **Log _back in_** - with the same Google or GitHub account you used to login before. + ***Confirm*** your "sleep" session was recorded. - ## Run it! Now that you've tried it on Heroku, -try running the _finished_ (MVP) on your `localhost`: - - - - +if you want to dig deeper, +try running the _finished_ (MVP) on your computer. -# _Tutorial_ +Open a terminal window and run the following commands: +Clone the project to your computer: +``` +git clone git@github.com:dwyl/sleep.git +``` +Navigate to the **`sleep`** directory: -## Implementation Note - -We built this MVP App using using -[**`Elixir`**](https://github.com/dwyl/learn-elixir) -and -[**`Phoenix`**](https://github.com/dwyl/learn-phoenix-framework) -because it's one of the simplest ways -to build web applications -from first principals. -Our objective is to get to a _useable_ app -as **_fast_ as possible** -so we can start inputting/saving data. -You will see below, -that we can get up-and-running -with a **basic interface**, -**saving data** to the database, -**authentication** -and ***deployment*** -in **_less_ than 20 minutes**. -Anyone who knows basic programming -(e.g. `Python`, `JavaScript`, etc.) -should be able to follow along. -If you get stuck, -[please ask questions!]() - - - -## Create New Phoenix App - -```sh -mix phx.new app --no-mailer --no-dashboard ``` - -This creates a new Phoenix Web App named **`app`** -without the mailer (email) or live dashboard -but with a database and `LiveView` support. +cd sleep +``` -When you see the prompt asking you -to fetch and install the dependencies: +Install the dependencies: ``` -Fetch and install dependencies? [Yn] +mix deps.get ``` -Type `y` followed by the `Enter` key: -You should then see: -``` -* running mix deps.get -* running mix deps.compile -``` -To start the Phoenix server: -* Install dependencies with `mix deps.get` -* Create and migrate your database with `mix ecto.setup` -* Start Phoenix endpoint with `mix phx.server` -You should see the following output in your terminal: + [![HitCount](http://hits.dwyl.com/dwyl/sleep.svg?style=flat-square)](http://hits.dwyl.com/dwyl/sleep) -``` -[info] Running AppWeb.Endpoint with cowboy 2.9.0 at 127.0.0.1:4000 (http) -[debug] Downloading esbuild from https://registry.npmjs.org/esbuild-darwin-64/-/esbuild-darwin-64-0.13.5.tgz -[info] Access AppWeb.Endpoint at http://localhost:4000 -[watch] build finished, watching for changes... -``` -When you open http://localhost:4000 in your web browser, -you should see see something similar to the following: +# Research + +We have read several books on sleep (_so you don't have to_). -![phoenix-framerwork-welcome-page](https://user-images.githubusercontent.com/194400/145309471-306fdd5e-324f-4c4a-bd9f-6fddbec7f512.png) +## Why Focus on Sleep? +If you aren't sleeping enough +you will not be able to function. +## How Sleep Affects You +> Insert table of good vs. bad sleep. \ No newline at end of file diff --git a/config/config.exs b/config/config.exs index 6db4064..b713397 100644 --- a/config/config.exs +++ b/config/config.exs @@ -15,11 +15,11 @@ config :app, AppWeb.Endpoint, url: [host: "localhost"], render_errors: [view: AppWeb.ErrorView, accepts: ~w(html json), layout: false], pubsub_server: App.PubSub, - live_view: [signing_salt: "EljQ3mdd"] + live_view: [signing_salt: "xBrfDbtX"] # Configure esbuild (the version is required) config :esbuild, - version: "0.13.5", + version: "0.14.0", default: [ args: ~w(js/app.js --bundle --target=es2017 --outdir=../priv/static/assets --external:/fonts/* --external:/images/*), diff --git a/config/dev.exs b/config/dev.exs index 34e510c..1287ff4 100644 --- a/config/dev.exs +++ b/config/dev.exs @@ -4,8 +4,8 @@ import Config config :app, App.Repo, username: "postgres", password: "postgres", - database: "app_dev", hostname: "localhost", + database: "app_dev", show_sensitive_data_on_connection_error: true, pool_size: 10 @@ -22,7 +22,7 @@ config :app, AppWeb.Endpoint, check_origin: false, code_reloader: true, debug_errors: true, - secret_key_base: "P98QsPutADCPf5f2YVIk4hYV3x5671vu8LY+nIoGfwYxH7h6rDm6sYf6cXnDDwzU", + secret_key_base: "FMt0CN3SA1QGb+x5TystE+yQE5YS75Ly0uKNfHRJGjTGHMUR9q1C70CNbgQsaIiJ", watchers: [ # Start the esbuild watcher by calling Esbuild.install_and_run(:default, args) esbuild: {Esbuild, :install_and_run, [:default, ~w(--sourcemap=inline --watch)]} diff --git a/config/runtime.exs b/config/runtime.exs index 4a2c1d6..1c2c816 100644 --- a/config/runtime.exs +++ b/config/runtime.exs @@ -7,7 +7,7 @@ import Config # any compile-time configuration in here, as it won't be applied. # The block below contains prod specific runtime configuration. -# Start the phoenix server if environment is set and running in a release +# Start the phoenix server if environment is set and running in a release if System.get_env("PHX_SERVER") && System.get_env("RELEASE_NAME") do config :app, AppWeb.Endpoint, server: true end diff --git a/config/test.exs b/config/test.exs index 844de13..178fbd9 100644 --- a/config/test.exs +++ b/config/test.exs @@ -8,8 +8,8 @@ import Config config :app, App.Repo, username: "postgres", password: "postgres", - database: "app_test#{System.get_env("MIX_TEST_PARTITION")}", hostname: "localhost", + database: "app_test#{System.get_env("MIX_TEST_PARTITION")}", pool: Ecto.Adapters.SQL.Sandbox, pool_size: 10 @@ -17,7 +17,7 @@ config :app, App.Repo, # you can enable the server option below. config :app, AppWeb.Endpoint, http: [ip: {127, 0, 0, 1}, port: 4002], - secret_key_base: "3/NTUnmg2ROG9Tcv7V/9XtNoUvcpQ+bi/mmOhptESLHM6ZzWS3WaGMrLbKx6c1LR", + secret_key_base: "2OeS9YY+RJ3qEQ/8oR1AIGk5mIl5wLXCACa4nZeP0PbI0N962ucj4Gt1duce+2io", server: false # Print only warnings and errors during test diff --git a/lib/app_web/endpoint.ex b/lib/app_web/endpoint.ex index 1a403ab..3e5d706 100644 --- a/lib/app_web/endpoint.ex +++ b/lib/app_web/endpoint.ex @@ -7,7 +7,7 @@ defmodule AppWeb.Endpoint do @session_options [ store: :cookie, key: "_app_key", - signing_salt: "th1l2L6/" + signing_salt: "+eEfnYug" ] socket "/live", Phoenix.LiveView.Socket, websocket: [connect_info: [session: @session_options]] diff --git a/mix.exs b/mix.exs index 4ca5afb..1a172de 100644 --- a/mix.exs +++ b/mix.exs @@ -33,7 +33,7 @@ defmodule App.MixProject do # Type `mix help deps` for examples and options. defp deps do [ - {:phoenix, "~> 1.6.4"}, + {:phoenix, "~> 1.6.6"}, {:phoenix_ecto, "~> 4.4"}, {:ecto_sql, "~> 3.6"}, {:postgrex, ">= 0.0.0"}, diff --git a/mix.lock b/mix.lock index a0cc3b0..f81daeb 100644 --- a/mix.lock +++ b/mix.lock @@ -1,5 +1,5 @@ %{ - "castore": {:hex, :castore, "0.1.13", "ccf3ab251ffaebc4319f41d788ce59a6ab3f42b6c27e598ad838ffecee0b04f9", [:mix], [], "hexpm", "a14a7eecfec7e20385493dbb92b0d12c5d77ecfd6307de10102d58c94e8c49c0"}, + "castore": {:hex, :castore, "0.1.15", "dbb300827d5a3ec48f396ca0b77ad47058578927e9ebe792abd99fcbc3324326", [:mix], [], "hexpm", "c69379b907673c7e6eb229f09a0a09b60bb27cfb9625bcb82ea4c04ba82a8442"}, "connection": {:hex, :connection, "1.1.0", "ff2a49c4b75b6fb3e674bfc5536451607270aac754ffd1bdfe175abe4a6d7a68", [:mix], [], "hexpm", "722c1eb0a418fbe91ba7bd59a47e28008a189d47e37e0e7bb85585a016b2869c"}, "cowboy": {:hex, :cowboy, "2.9.0", "865dd8b6607e14cf03282e10e934023a1bd8be6f6bacf921a7e2a96d800cd452", [:make, :rebar3], [{:cowlib, "2.11.0", [hex: :cowlib, repo: "hexpm", optional: false]}, {:ranch, "1.8.0", [hex: :ranch, repo: "hexpm", optional: false]}], "hexpm", "2c729f934b4e1aa149aff882f57c6372c15399a20d54f65c8d67bef583021bde"}, "cowboy_telemetry": {:hex, :cowboy_telemetry, "0.4.0", "f239f68b588efa7707abce16a84d0d2acf3a0f50571f8bb7f56a15865aae820c", [:rebar3], [{:cowboy, "~> 2.7", [hex: :cowboy, repo: "hexpm", optional: false]}, {:telemetry, "~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "7d98bac1ee4565d31b62d59f8823dfd8356a169e7fcbb83831b8a5397404c9de"}, @@ -7,25 +7,25 @@ "db_connection": {:hex, :db_connection, "2.4.1", "6411f6e23f1a8b68a82fa3a36366d4881f21f47fc79a9efb8c615e62050219da", [:mix], [{:connection, "~> 1.0", [hex: :connection, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "ea36d226ec5999781a9a8ad64e5d8c4454ecedc7a4d643e4832bf08efca01f00"}, "decimal": {:hex, :decimal, "2.0.0", "a78296e617b0f5dd4c6caf57c714431347912ffb1d0842e998e9792b5642d697", [:mix], [], "hexpm", "34666e9c55dea81013e77d9d87370fe6cb6291d1ef32f46a1600230b1d44f577"}, "ecto": {:hex, :ecto, "3.7.1", "a20598862351b29f80f285b21ec5297da1181c0442687f9b8329f0445d228892", [:mix], [{:decimal, "~> 1.6 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "d36e5b39fc479e654cffd4dbe1865d9716e4a9b6311faff799b6f90ab81b8638"}, - "ecto_sql": {:hex, :ecto_sql, "3.7.1", "8de624ef50b2a8540252d8c60506379fbbc2707be1606853df371cf53df5d053", [:mix], [{:db_connection, "~> 2.2", [hex: :db_connection, repo: "hexpm", optional: false]}, {:ecto, "~> 3.7.0", [hex: :ecto, repo: "hexpm", optional: false]}, {:myxql, "~> 0.4.0 or ~> 0.5.0", [hex: :myxql, repo: "hexpm", optional: true]}, {:postgrex, "~> 0.15.0 or ~> 1.0", [hex: :postgrex, repo: "hexpm", optional: true]}, {:tds, "~> 2.1.1 or ~> 2.2", [hex: :tds, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4.0 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "2b42a32e2ce92f64aba5c88617891ab3b0ba34f3f3a503fa20009eae1a401c81"}, + "ecto_sql": {:hex, :ecto_sql, "3.7.2", "55c60aa3a06168912abf145c6df38b0295c34118c3624cf7a6977cd6ce043081", [:mix], [{:db_connection, "~> 2.2", [hex: :db_connection, repo: "hexpm", optional: false]}, {:ecto, "~> 3.7.0", [hex: :ecto, repo: "hexpm", optional: false]}, {:myxql, "~> 0.4.0 or ~> 0.5.0 or ~> 0.6.0", [hex: :myxql, repo: "hexpm", optional: true]}, {:postgrex, "~> 0.15.0 or ~> 0.16.0 or ~> 1.0", [hex: :postgrex, repo: "hexpm", optional: true]}, {:tds, "~> 2.1.1 or ~> 2.2", [hex: :tds, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4.0 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "3c218ea62f305dcaef0b915fb56583195e7b91c91dcfb006ba1f669bfacbff2a"}, "esbuild": {:hex, :esbuild, "0.4.0", "9f17db148aead4cf1e6e6a584214357287a93407b5fb51a031f122b61385d4c2", [:mix], [{:castore, ">= 0.0.0", [hex: :castore, repo: "hexpm", optional: false]}], "hexpm", "b61e4e6b92ffe45e4ee4755a22de6211a67c67987dc02afb35a425a0add1d447"}, "file_system": {:hex, :file_system, "0.2.10", "fb082005a9cd1711c05b5248710f8826b02d7d1784e7c3451f9c1231d4fc162d", [:mix], [], "hexpm", "41195edbfb562a593726eda3b3e8b103a309b733ad25f3d642ba49696bf715dc"}, "floki": {:hex, :floki, "0.32.0", "f915dc15258bc997d49be1f5ef7d3992f8834d6f5695270acad17b41f5bcc8e2", [:mix], [{:html_entities, "~> 0.5.0", [hex: :html_entities, repo: "hexpm", optional: false]}], "hexpm", "1c5a91cae1fd8931c26a4826b5e2372c284813904c8bacb468b5de39c7ececbd"}, - "gettext": {:hex, :gettext, "0.18.2", "7df3ea191bb56c0309c00a783334b288d08a879f53a7014341284635850a6e55", [:mix], [], "hexpm", "f9f537b13d4fdd30f3039d33cb80144c3aa1f8d9698e47d7bcbcc8df93b1f5c5"}, + "gettext": {:hex, :gettext, "0.19.1", "564953fd21f29358e68b91634799d9d26989f8d039d7512622efb3c3b1c97892", [:mix], [], "hexpm", "10c656c0912b8299adba9b061c06947511e3f109ab0d18b44a866a4498e77222"}, "html_entities": {:hex, :html_entities, "0.5.2", "9e47e70598da7de2a9ff6af8758399251db6dbb7eebe2b013f2bbd2515895c3c", [:mix], [], "hexpm", "c53ba390403485615623b9531e97696f076ed415e8d8058b1dbaa28181f4fdcc"}, - "jason": {:hex, :jason, "1.2.2", "ba43e3f2709fd1aa1dce90aaabfd039d000469c05c56f0b8e31978e03fa39052", [:mix], [{:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "18a228f5f0058ee183f29f9eae0805c6e59d61c3b006760668d8d18ff0d12179"}, + "jason": {:hex, :jason, "1.3.0", "fa6b82a934feb176263ad2df0dbd91bf633d4a46ebfdffea0c8ae82953714946", [:mix], [{:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "53fc1f51255390e0ec7e50f9cb41e751c260d065dcba2bf0d08dc51a4002c2ac"}, "mime": {:hex, :mime, "2.0.2", "0b9e1a4c840eafb68d820b0e2158ef5c49385d17fb36855ac6e7e087d4b1dcc5", [:mix], [], "hexpm", "e6a3f76b4c277739e36c2e21a2c640778ba4c3846189d5ab19f97f126df5f9b7"}, - "phoenix": {:hex, :phoenix, "1.6.4", "bc9a757f0a4eac88e1e3501245a6259e74d30970df8c072836d755608dbc4c7d", [:mix], [{:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:phoenix_pubsub, "~> 2.0", [hex: :phoenix_pubsub, repo: "hexpm", optional: false]}, {:phoenix_view, "~> 1.0", [hex: :phoenix_view, repo: "hexpm", optional: false]}, {:plug, "~> 1.10", [hex: :plug, repo: "hexpm", optional: false]}, {:plug_cowboy, "~> 2.2", [hex: :plug_cowboy, repo: "hexpm", optional: true]}, {:plug_crypto, "~> 1.2", [hex: :plug_crypto, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "9b6cb3f31e3ea1049049852703eca794f7afdb0c1dc111d8f166ba032c103a80"}, + "phoenix": {:hex, :phoenix, "1.6.6", "281c8ce8dccc9f60607346b72cdfc597c3dde134dd9df28dff08282f0b751754", [:mix], [{:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:phoenix_pubsub, "~> 2.0", [hex: :phoenix_pubsub, repo: "hexpm", optional: false]}, {:phoenix_view, "~> 1.0", [hex: :phoenix_view, repo: "hexpm", optional: false]}, {:plug, "~> 1.10", [hex: :plug, repo: "hexpm", optional: false]}, {:plug_cowboy, "~> 2.2", [hex: :plug_cowboy, repo: "hexpm", optional: true]}, {:plug_crypto, "~> 1.2", [hex: :plug_crypto, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "807bd646e64cd9dc83db016199715faba72758e6db1de0707eef0a2da4924364"}, "phoenix_ecto": {:hex, :phoenix_ecto, "4.4.0", "0672ed4e4808b3fbed494dded89958e22fb882de47a97634c0b13e7b0b5f7720", [:mix], [{:ecto, "~> 3.3", [hex: :ecto, repo: "hexpm", optional: false]}, {:phoenix_html, "~> 2.14.2 or ~> 3.0", [hex: :phoenix_html, repo: "hexpm", optional: true]}, {:plug, "~> 1.9", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm", "09864e558ed31ee00bd48fcc1d4fc58ae9678c9e81649075431e69dbabb43cc1"}, - "phoenix_html": {:hex, :phoenix_html, "3.1.0", "0b499df05aad27160d697a9362f0e89fa0e24d3c7a9065c2bd9d38b4d1416c09", [:mix], [{:plug, "~> 1.5", [hex: :plug, repo: "hexpm", optional: true]}], "hexpm", "0c0a98a2cefa63433657983a2a594c7dee5927e4391e0f1bfd3a151d1def33fc"}, + "phoenix_html": {:hex, :phoenix_html, "3.2.0", "1c1219d4b6cb22ac72f12f73dc5fad6c7563104d083f711c3fcd8551a1f4ae11", [:mix], [{:plug, "~> 1.5", [hex: :plug, repo: "hexpm", optional: true]}], "hexpm", "36ec97ba56d25c0136ef1992c37957e4246b649d620958a1f9fa86165f8bc54f"}, "phoenix_live_reload": {:hex, :phoenix_live_reload, "1.3.3", "3a53772a6118d5679bf50fc1670505a290e32a1d195df9e069d8c53ab040c054", [:mix], [{:file_system, "~> 0.2.1 or ~> 0.3", [hex: :file_system, repo: "hexpm", optional: false]}, {:phoenix, "~> 1.4", [hex: :phoenix, repo: "hexpm", optional: false]}], "hexpm", "766796676e5f558dbae5d1bdb066849673e956005e3730dfd5affd7a6da4abac"}, - "phoenix_live_view": {:hex, :phoenix_live_view, "0.17.5", "63f52a6f9f6983f04e424586ff897c016ecc5e4f8d1e2c22c2887af1c57215d8", [:mix], [{:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:phoenix, "~> 1.5.9 or ~> 1.6.0", [hex: :phoenix, repo: "hexpm", optional: false]}, {:phoenix_html, "~> 3.1", [hex: :phoenix_html, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4.2 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "c5586e6a3d4df71b8214c769d4f5eb8ece2b4001711a7ca0f97323c36958b0e3"}, + "phoenix_live_view": {:hex, :phoenix_live_view, "0.17.7", "05a42377075868a678d446361effba80cefef19ab98941c01a7a4c7560b29121", [:mix], [{:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:phoenix, "~> 1.5.9 or ~> 1.6.0", [hex: :phoenix, repo: "hexpm", optional: false]}, {:phoenix_html, "~> 3.1", [hex: :phoenix_html, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4.2 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "25eaf41028eb351b90d4f69671874643a09944098fefd0d01d442f40a6091b6f"}, "phoenix_pubsub": {:hex, :phoenix_pubsub, "2.0.0", "a1ae76717bb168cdeb10ec9d92d1480fec99e3080f011402c0a2d68d47395ffb", [:mix], [], "hexpm", "c52d948c4f261577b9c6fa804be91884b381a7f8f18450c5045975435350f771"}, - "phoenix_view": {:hex, :phoenix_view, "1.0.0", "fea71ecaaed71178b26dd65c401607de5ec22e2e9ef141389c721b3f3d4d8011", [:mix], [{:phoenix_html, "~> 2.14.2 or ~> 3.0", [hex: :phoenix_html, repo: "hexpm", optional: true]}], "hexpm", "82be3e2516f5633220246e2e58181282c71640dab7afc04f70ad94253025db0c"}, - "plug": {:hex, :plug, "1.12.1", "645678c800601d8d9f27ad1aebba1fdb9ce5b2623ddb961a074da0b96c35187d", [:mix], [{:mime, "~> 1.0 or ~> 2.0", [hex: :mime, repo: "hexpm", optional: false]}, {:plug_crypto, "~> 1.1.1 or ~> 1.2", [hex: :plug_crypto, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4.3 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "d57e799a777bc20494b784966dc5fbda91eb4a09f571f76545b72a634ce0d30b"}, + "phoenix_view": {:hex, :phoenix_view, "1.1.2", "1b82764a065fb41051637872c7bd07ed2fdb6f5c3bd89684d4dca6e10115c95a", [:mix], [{:phoenix_html, "~> 2.14.2 or ~> 3.0", [hex: :phoenix_html, repo: "hexpm", optional: true]}], "hexpm", "7ae90ad27b09091266f6adbb61e1d2516a7c3d7062c6789d46a7554ec40f3a56"}, + "plug": {:hex, :plug, "1.13.3", "93b299039c21a8b82cc904d13812bce4ced45cf69153e8d35ca16ffb3e8c5d98", [:mix], [{:mime, "~> 1.0 or ~> 2.0", [hex: :mime, repo: "hexpm", optional: false]}, {:plug_crypto, "~> 1.1.1 or ~> 1.2", [hex: :plug_crypto, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4.3 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "98c8003e4faf7b74a9ac41bee99e328b08f069bf932747d4a7532e97ae837a17"}, "plug_cowboy": {:hex, :plug_cowboy, "2.5.2", "62894ccd601cf9597e2c23911ff12798a8a18d237e9739f58a6b04e4988899fe", [:mix], [{:cowboy, "~> 2.7", [hex: :cowboy, repo: "hexpm", optional: false]}, {:cowboy_telemetry, "~> 0.3", [hex: :cowboy_telemetry, repo: "hexpm", optional: false]}, {:plug, "~> 1.7", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm", "ea6e87f774c8608d60c8d34022a7d073bd7680a0a013f049fc62bf35efea1044"}, "plug_crypto": {:hex, :plug_crypto, "1.2.2", "05654514ac717ff3a1843204b424477d9e60c143406aa94daf2274fdd280794d", [:mix], [], "hexpm", "87631c7ad914a5a445f0a3809f99b079113ae4ed4b867348dd9eec288cecb6db"}, - "postgrex": {:hex, :postgrex, "0.15.13", "7794e697481799aee8982688c261901de493eb64451feee6ea58207d7266d54a", [:mix], [{:connection, "~> 1.0", [hex: :connection, repo: "hexpm", optional: false]}, {:db_connection, "~> 2.1", [hex: :db_connection, repo: "hexpm", optional: false]}, {:decimal, "~> 1.5 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}], "hexpm", "3ffb76e1a97cfefe5c6a95632a27ffb67f28871c9741fb585f9d1c3cd2af70f1"}, + "postgrex": {:hex, :postgrex, "0.16.1", "f94628a32c571266f53cd1e5fca705e626e2417bf1eee6f868985d14e874160a", [:mix], [{:connection, "~> 1.1", [hex: :connection, repo: "hexpm", optional: false]}, {:db_connection, "~> 2.1", [hex: :db_connection, repo: "hexpm", optional: false]}, {:decimal, "~> 1.5 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}], "hexpm", "6b225df32c857b9430619dbe30200a7ae664e23415a771ae9209396ee8eeee64"}, "ranch": {:hex, :ranch, "1.8.0", "8c7a100a139fd57f17327b6413e4167ac559fbc04ca7448e9be9057311597a1d", [:make, :rebar3], [], "hexpm", "49fbcfd3682fab1f5d109351b61257676da1a2fdbe295904176d5e521a2ddfe5"}, "telemetry": {:hex, :telemetry, "1.0.0", "0f453a102cdf13d506b7c0ab158324c337c41f1cc7548f0bc0e130bbf0ae9452", [:rebar3], [], "hexpm", "73bc09fa59b4a0284efb4624335583c528e07ec9ae76aca96ea0673850aec57a"}, "telemetry_metrics": {:hex, :telemetry_metrics, "0.6.1", "315d9163a1d4660aedc3fee73f33f1d355dcc76c5c3ab3d59e76e3edf80eef1f", [:mix], [{:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "7be9e0871c41732c233be71e4be11b96e56177bf15dde64a8ac9ce72ac9834c6"}, From 4ef32da966a88254cd50bbc287509eb856cb0f78 Mon Sep 17 00:00:00 2001 From: nelsonic Date: Sun, 6 Mar 2022 21:29:28 +0000 Subject: [PATCH 06/24] add context for "App" Namespace to tutorial.md #53 --- tutorial.md | 97 ++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 96 insertions(+), 1 deletion(-) diff --git a/tutorial.md b/tutorial.md index f7150fa..2554632 100644 --- a/tutorial.md +++ b/tutorial.md @@ -87,4 +87,99 @@ you should see see something similar to the following: \ No newline at end of file +--> + +So far so good. + + +#### Quick Note on App Naming Conventions + +You will often see Phoenix apps with the name of the app in the project files +e.g: in the **`Chat`** example +[github.com/dwyl/phoenix-chat-example](https://github.com/dwyl/phoenix-chat-example) + +[lib/chat/repo.ex#L1](https://github.com/dwyl/phoenix-chat-example/blob/main/lib/chat/repo.ex#L1) + +```elixir +defmodule Chat.Repo do + use Ecto.Repo, + otp_app: :chat, + adapter: Ecto.Adapters.Postgres +end +``` + +[lib/chat_web/router.ex#L1](https://github.com/dwyl/phoenix-chat-example/blob/main/lib/chat_web/router.ex#L1) +```elixir +defmodule ChatWeb.Router do + use ChatWeb, :router + +... etc. +``` + +Having `Chat` or `ChatWeb` namespace can be useful +if you're working on multiple Phoenix apps simultaneously +and need to context switch. +That's why we use the `Auth` namespace +in our Authentication App: +[github.com/dwyl/auth](https://github.com/dwyl/auth) + +e.g: +[lib/auth_web/controllers/auth_controller.ex#L1](https://github.com/dwyl/auth/blob/main/lib/auth_web/controllers/auth_controller.ex#L1) + +```elixir +defmodule AuthWeb.AuthController do +... +``` + +The reasons why _this_ app is namespaced **`App`** are:
+**a)** It's less to type and still provides clarity/context.
+**b)**
+**c)** If we _succeed_ in building a sleep-tracking app, +we will re-use some of the code in our "main" App. +[github.com/dwyl/app](https://github.com/dwyl/app) +This means it's easy to +"lift and shift" the code & tests +without needing to waste time with "find & replace". +
+ +If you prefer to namespace your app differently, go for it!s + +## Show Me the Code! 👩‍💻 + +Open the project in your editor/IDE of choice. + +### Create `/live` Directory + +Since we are using Phoenix LiveView for this App, +we need to create a new `live` directory +with the following path: +`lib/app_web/live` + +### Create `app_live.ex` File + +Inside that newly created `/live` directory, +create a new file called +`app_live.ex` +with the path: +`lib/app_web/live/app_live.ex` + +```elixir +defmodule App.AppLive do + use AppWeb, :live_view + + def mount(_params, _session, socket) do + {:ok, socket} + end + + def render(assigns) do + AppWeb.AppView.render("messages.html", assigns) + end +end +``` + + +### Update `router.ex` + +and navigate to the +`lib/app_web/router.ex` file. + From 59cf72709d6303106cba2471318dc543427b6217 Mon Sep 17 00:00:00 2001 From: nelsonic Date: Sun, 13 Mar 2022 13:51:55 +0000 Subject: [PATCH 07/24] Create .github/workflows/ci.yml to run tests #53 --- .github/workflows/ci.yml | 44 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 .github/workflows/ci.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..55c2cf4 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,44 @@ +name: Elixir CI + +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] + +jobs: + build: + name: Build and test + environment: sleep + runs-on: ubuntu-latest + services: + postgres: + image: postgres:12 + ports: ['5432:5432'] + env: + POSTGRES_PASSWORD: postgres + options: >- + --health-cmd pg_isready + --health-interval 10s + --health-timeout 5s + --health-retries 5 + steps: + - uses: actions/checkout@v2 + - name: Set up Elixir + uses: erlef/setup-elixir@885971a72ed1f9240973bd92ab57af8c1aa68f24 + with: + elixir-version: '1.12.3' # Define the elixir version [required] + otp-version: '24.0.2' # Define the OTP version [required] + - name: Restore dependencies cache + uses: actions/cache@v2 + with: + path: deps + key: ${{ runner.os }}-mix-${{ hashFiles('**/mix.lock') }} + restore-keys: ${{ runner.os }}-mix- + - name: Install dependencies + run: mix deps.get + - name: Run Tests + run: mix coveralls.json + + - name: Upload coverage to Codecov + uses: codecov/codecov-action@v1 \ No newline at end of file From 6231fab5ba6f64ea30d8ee3d02a0282ead027f75 Mon Sep 17 00:00:00 2001 From: nelsonic Date: Sun, 13 Mar 2022 13:59:18 +0000 Subject: [PATCH 08/24] add more detail to README.md and links in tutorial.md #53 --- README.md | 62 ++++++++++++++++++++++++++++-------- lib/app_web/live/app_live.ex | 11 +++++++ tutorial.md | 44 +++++++++++++++++-------- 3 files changed, 90 insertions(+), 27 deletions(-) create mode 100644 lib/app_web/live/app_live.ex diff --git a/README.md b/README.md index 8b06ccf..166dec3 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,23 @@ -# sleep +
+ +# sleep 💤 + +![sleep-hero-image](https://user-images.githubusercontent.com/194400/159523182-0db2588a-658d-45ae-8ce3-98c37a47ca72.jpeg) + + +### “_Sleep is the single most effective thing we can do to reset our brain and body health each day._”
~ Matthew Walker, Why We Sleep: Unlocking the Power of Sleep and Dreams + +
+ +[![GitHub Workflow Status](https://img.shields.io/github/workflow/status/dwyl/sleep/Elixir%20CI?label=build&style=flat-square)](https://github.com/dwyl/phoenix-liveview-chat-example/actions/workflows/cy.yml) +[![codecov test coverage](https://img.shields.io/codecov/c/github/dwyl/sleep/main.svg?style=flat-square)](https://codecov.io/github/dwyl/phoenix-liveview-chat-example?branch=main) +[![HitCount](http://hits.dwyl.com/dwyl/sleep.svg?style=flat-square&show=unique)](http://hits.dwyl.com/dwyl/sleep) + +**Try it**: [**sleepdev.herokuapp.com**](https://sleepdev.herokuapp.com/) +![wake-sleeping-heroku-app](https://liveview-chat-example.herokuapp.com/ping) +
+ +
Sleep is the single most important activity in life; it restores our tired bodies @@ -11,17 +30,19 @@ and reflecting on your sleep quality can help you focus on this vital aspect of health and longevity. +
-# Why? +# Why? 🤷‍♀️ If you don't get a good night's sleep virtually everything about your next day will be worse. -See below for all the areas sleep affects. +> See below for all the areas sleep affects. +
-# What? +# What? 📱 🛌 This App is the simplest possible sleep tracker (_other than using a paper notepad and pen @@ -34,33 +55,42 @@ but leaves a lot enhancements out. If you think of a feature/improvement, _please_ [**open an issue**!](https://github.com/dwyl/sleep/issues) -Contributions/ideas are always welcome +**Contributions/ideas** are **_always_ welcome** and we're delighted to extend this in response to feedback! -# Who? +
+ +# Who? 👤 -Everyone sleeps. +_Everyone_ that sleeps. +
-# When? +# When? 🕗 -You can start using this MVP _now_ (_tonight_). +You can start using the MVP _now_ (_tonight_)! > If you're reading this past **22:00**, go straight to the "***Try it!***" section and treat yourself to an _early_ night! +Bookmark (⭐) the project +and come back to it tomorrow +
+It's never too late +to start focusing on your sleep quality. # How? -## Try it! +## _Try_ it! -Firstly, you can try the App via Heroku: +Firstly, if you haven't already, +you can _try_ the App via Heroku: https://sleepdev.herokuapp.com Try the following actions: @@ -73,7 +103,7 @@ Try the following actions: + ***Confirm*** your "sleep" session was recorded. -## Run it! +## _Run_ it! Now that you've tried it on Heroku, if you want to dig deeper, @@ -100,19 +130,23 @@ Install the dependencies: mix deps.get ``` +_Run_ the app: +``` +mix phx.server +``` - [![HitCount](http://hits.dwyl.com/dwyl/sleep.svg?style=flat-square)](http://hits.dwyl.com/dwyl/sleep) - # Research We have read several books on sleep (_so you don't have to_). +### “_Before you sleep, read something that is exquisite, and worth remembering._” ~
Desiderius Erasmus + ## Why Focus on Sleep? If you aren't sleeping enough diff --git a/lib/app_web/live/app_live.ex b/lib/app_web/live/app_live.ex new file mode 100644 index 0000000..c85df71 --- /dev/null +++ b/lib/app_web/live/app_live.ex @@ -0,0 +1,11 @@ +defmodule App.AppLive do + use AppWeb, :live_view + + def mount(_params, _session, socket) do + {:ok, socket} + end + + def render(assigns) do + AppWeb.AppView.render("messages.html", assigns) + end +end \ No newline at end of file diff --git a/tutorial.md b/tutorial.md index 2554632..57fdd1a 100644 --- a/tutorial.md +++ b/tutorial.md @@ -1,7 +1,8 @@ # _Tutorial_ -This tutorial takes you through _building_ a sleep tracking App from scratch -so that you can understand how it works. +This tutorial takes you through _building_ +a sleep tracking App from scratch +so that you can _understand_ how it works. If you get stuck, _please_ [**ask questions**!](https://github.com/dwyl/sleep/issues) @@ -9,9 +10,10 @@ If you get stuck, _please_ ## Implementation Note We built this MVP App using using -[**`Elixir`**](https://github.com/dwyl/learn-elixir) -and +[**`Elixir`**](https://github.com/dwyl/learn-elixir), [**`Phoenix`**](https://github.com/dwyl/learn-phoenix-framework) +and +[**`LiveView`**](https://github.com/dwyl/phoenix-liveview-counter-tutorial) because it's one of the simplest ways to build web applications from first principals. @@ -37,16 +39,17 @@ might get you different results ... https://twitter.com/iamdevloper/status/787969734918668289 --> -## Create New Phoenix App +## 1. Create a New Phoenix App ```sh -mix phx.new app --no-mailer --no-dashboard +mix phx.new app --live --no-mailer --no-dashboard ``` This creates a new Phoenix Web App named **`app`** -without the mailer (email) or live dashboard -but with a database and `LiveView` support. - +with everything setup for `LiveView` support +but without the mailer (email) or live dashboard +cause we won't be needing either of those features +and we don't want unused/untested code. When you see the prompt asking you to fetch and install the dependencies: @@ -117,7 +120,7 @@ defmodule ChatWeb.Router do ``` Having `Chat` or `ChatWeb` namespace can be useful -if you're working on multiple Phoenix apps simultaneously +if you're working on multiple Phoenix apps _simultaneously_ and need to context switch. That's why we use the `Auth` namespace in our Authentication App: @@ -133,7 +136,10 @@ defmodule AuthWeb.AuthController do The reasons why _this_ app is namespaced **`App`** are:
**a)** It's less to type and still provides clarity/context.
-**b)**
+**b)** The word "sleep" has a special significance in Erlang/Elixir +see: [`sleep/1`](https://www.erlang.org/doc/man/timer.html#sleep-1) +so we don't want our IDE constantly suggesting that we +suspend the process ...
**c)** If we _succeed_ in building a sleep-tracking app, we will re-use some of the code in our "main" App. [github.com/dwyl/app](https://github.com/dwyl/app) @@ -142,7 +148,9 @@ This means it's easy to without needing to waste time with "find & replace".
-If you prefer to namespace your app differently, go for it!s +If you prefer to namespace your app differently, go for it! + +
## Show Me the Code! 👩‍💻 @@ -155,14 +163,18 @@ we need to create a new `live` directory with the following path: `lib/app_web/live` +e.g: `mkdir lib/app_web/live` + ### Create `app_live.ex` File Inside that newly created `/live` directory, create a new file called `app_live.ex` -with the path: +so the file path is: `lib/app_web/live/app_live.ex` +_Type_ the following code in the file: + ```elixir defmodule App.AppLive do use AppWeb, :live_view @@ -178,8 +190,14 @@ end ``` + ### Update `router.ex` + and navigate to the `lib/app_web/router.ex` file. + + + +[![HitCount](http://hits.dwyl.com/dwyl/sleep-tutorial.svg?style=flat-square)](http://hits.dwyl.com/dwyl/sleep) \ No newline at end of file From f48898f4b44fcaf7a1fb98ee8c3d9f9102fd7ff7 Mon Sep 17 00:00:00 2001 From: nelsonic Date: Sun, 13 Mar 2022 14:22:04 +0000 Subject: [PATCH 09/24] add ExCoveralls & coveralls.json to check test coverage #53 --- README.md | 143 +++++++++++++++++++++++++++++++++++++++++++------ coveralls.json | 14 +++++ mix.exs | 35 ++++++++++-- mix.lock | 15 ++++++ tutorial.md | 27 ++++++---- 5 files changed, 205 insertions(+), 29 deletions(-) create mode 100644 coveralls.json diff --git a/README.md b/README.md index 166dec3..c7ebe95 100644 --- a/README.md +++ b/README.md @@ -5,13 +5,15 @@ ![sleep-hero-image](https://user-images.githubusercontent.com/194400/159523182-0db2588a-658d-45ae-8ce3-98c37a47ca72.jpeg) -### “_Sleep is the single most effective thing we can do to reset our brain and body health each day._”
~ Matthew Walker, Why We Sleep: Unlocking the Power of Sleep and Dreams +## “_Sleep is the single most effective thing we can do
to reset our brain and body health each day._”
~ Matthew Walker, Why We Sleep
[![GitHub Workflow Status](https://img.shields.io/github/workflow/status/dwyl/sleep/Elixir%20CI?label=build&style=flat-square)](https://github.com/dwyl/phoenix-liveview-chat-example/actions/workflows/cy.yml) [![codecov test coverage](https://img.shields.io/codecov/c/github/dwyl/sleep/main.svg?style=flat-square)](https://codecov.io/github/dwyl/phoenix-liveview-chat-example?branch=main) -[![HitCount](http://hits.dwyl.com/dwyl/sleep.svg?style=flat-square&show=unique)](http://hits.dwyl.com/dwyl/sleep) +[![Hex pm](https://img.shields.io/hexpm/v/phoenix_live_view.svg?style=flat-square)](https://hex.pm/packages/phoenix_live_view) +[![contributions welcome](https://img.shields.io/badge/contributions-welcome-brightgreen.svg?style=flat-square)](https://github.com/dwyl/phoenix-liveview-counter-tutorial/issues) +[![HitCount](http://hits.dwyl.com/dwyl/sleep.svg?style=flat-square)](http://hits.dwyl.com/dwyl/sleep) **Try it**: [**sleepdev.herokuapp.com**](https://sleepdev.herokuapp.com/) ![wake-sleeping-heroku-app](https://liveview-chat-example.herokuapp.com/ping) @@ -34,27 +36,29 @@ aspect of health and longevity. # Why? 🤷‍♀️ -If you don't get a good night's sleep -virtually everything about your next day +When you sleep well and feel rested, +you have mental clarity and energy +to focus on Deep Work tasks. +By contrast if you don't get a good night's sleep +virtually everything about your day will be worse. -> See below for all the areas sleep affects.
# What? 📱 🛌 -This App is the simplest possible sleep tracker -(_other than using a paper notepad and pen +This App is the simplest possible **sleep tracker** +(_other than using a paper notepad + pen or a note taking App on your phone ..._) -A deliberatly basic version of an App is +A **_deliberately_ basic** version of an App is commonly referred to as Minimum Viable Product ("MVP") which means it has the minimum features to be useful, but leaves a lot enhancements out. If you think of a feature/improvement, _please_ -[**open an issue**!](https://github.com/dwyl/sleep/issues) +[**open an issue**!](https://github.com/dwyl/sleep/issues).
**Contributions/ideas** are **_always_ welcome** and we're delighted to extend this in response to feedback! @@ -73,26 +77,40 @@ You can start using the MVP _now_ (_tonight_)! > If you're reading this past **22:00**, go straight to the "***Try it!***" section -and treat yourself to an _early_ night! +and start recording your sleep _now_. Bookmark (⭐) the project -and come back to it tomorrow +and come back to it tomorrow.
It's never too late to start focusing on your sleep quality. +The benefits of good sleep habits +will last the rest of your life +and may _extend_ it! +
+ +# How? 👩‍💻 + +There are 3 steps to this: -# How? +1. Try it! (2 mins) +2. Run it! (5 mins) +3. Build it! (20 mins) +Let's get started. +
-## _Try_ it! +## 1. _Try_ it! Firstly, if you haven't already, you can _try_ the App via Heroku: https://sleepdev.herokuapp.com +# @TODO: insert GIF of _performing_ the actions! + Try the following actions: + **Log _in_** @@ -102,13 +120,82 @@ Try the following actions: + **Log _back in_** - with the same Google or GitHub account you used to login before. + ***Confirm*** your "sleep" session was recorded. +Once you've given the app a quick test, +it's time try _running_ it. + +
-## _Run_ it! +## 2. _Run_ it! Now that you've tried it on Heroku, if you want to dig deeper, try running the _finished_ (MVP) on your computer. + +## Prerequisites 📝 + +Make sure you have the following installed: + ++ [x] Elixir: +https://elixir-lang.org/install.html ++ [x] Phoenix: +https://hexdocs.pm/phoenix/installation.html ++ [x] Postgres: +https://www.postgresql.org/download + +### _Check_ You Have Everything _Before_ Starting + +Check you have the _latest version_ of **Elixir** +(_run the following command in your terminal_): + +```sh +elixir -v +``` + +You should see something like: + +```sh +Erlang/OTP 24 [erts-12.1.2] [source] [64-bit] [smp:12:12] [ds:12:12:10] [async-threads:1] [jit] + +Elixir 1.13 (compiled with Erlang/OTP 22) +``` + +Check you have the **latest** version of **Phoenix**: + +```sh +mix phx.new -v +``` + +You should see: + +```sh +Phoenix v1.6.6 +``` + +_Confirm_ **PostgreSQL** is running (_so the App can store chat messages_) +run the following command: + +```sh +lsof -i :5432 +``` + +You should see output _similar_ to the following: + +```sh +COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME +postgres 529 Alex 5u IPv6 0xbc5d729e529f062b 0t0 TCP localhost:postgresql (LISTEN) +postgres 529 Alex 6u IPv4 0xbc5d729e55a89a13 0t0 TCP localhost:postgresql (LISTEN) +``` + +This tells us that PostgreSQL is "_listening_" on TCP Port `5432` +(_the default port_) + +With all those "pre-flight checks" performed, let's get _going_! + +
+ +## Clone, Install & Run the App! + Open a terminal window and run the following commands: Clone the project to your computer: @@ -136,14 +223,38 @@ _Run_ the app: mix phx.server ``` +Open the following URL in your web browser: +http://localhost:4000 +You should expect to see the following: +# @TODO: insert screenshot of _finished_ app! + +
+ +## 3. _Build_ it! 🚀 + +Now that you know what the end result +looks & feels like +and you have a reference implementation +that you _know_ works on your computer, +it's time to write some **`code`** + +**GOTO**: +[https://github.com/dwyl/sleep/blob/main/tutorial.md](https://github.com/dwyl/sleep/blob/main/tutorial.md) + +
+ + + \ No newline at end of file diff --git a/coveralls.json b/coveralls.json new file mode 100644 index 0000000..898e94a --- /dev/null +++ b/coveralls.json @@ -0,0 +1,14 @@ +{ + "coverage_options": { + "minimum_coverage": 100 + }, + "skip_files": [ + "test/", + "lib/auth/application.ex", + "lib/auth/release.ex", + "lib/auth_web.ex", + "lib/auth_web/views/error_helpers.ex", + "lib/auth_web/channels/user_socket.ex", + "lib/auth_web/telemetry.ex" + ] +} diff --git a/mix.exs b/mix.exs index 1a172de..ad63093 100644 --- a/mix.exs +++ b/mix.exs @@ -4,13 +4,23 @@ defmodule App.MixProject do def project do [ app: :app, - version: "0.1.0", + version: "1.0.0", elixir: "~> 1.12", elixirc_paths: elixirc_paths(Mix.env()), compilers: [:gettext] ++ Mix.compilers(), start_permanent: Mix.env() == :prod, aliases: aliases(), - deps: deps() + deps: deps(), + test_coverage: [tool: ExCoveralls], + preferred_cli_env: [ + c: :test, + coveralls: :test, + "coveralls.detail": :test, + "coveralls.post": :test, + "coveralls.html": :test + ], + package: package(), + description: "Turnkey Auth Auth Application" ] end @@ -46,7 +56,13 @@ defmodule App.MixProject do {:telemetry_poller, "~> 1.0"}, {:gettext, "~> 0.18"}, {:jason, "~> 1.2"}, - {:plug_cowboy, "~> 2.5"} + {:plug_cowboy, "~> 2.5"}, + + # Check test coverage + {:excoveralls, "~> 0.14.3", only: :test}, + + # Create Documentation for publishing Hex.docs: + {:ex_doc, "~> 0.28", only: :dev}, ] end @@ -58,11 +74,22 @@ defmodule App.MixProject do # See the documentation for `Mix` for more info on aliases. defp aliases do [ + c: ["coveralls.html"], setup: ["deps.get", "ecto.setup"], "ecto.setup": ["ecto.create", "ecto.migrate", "run priv/repo/seeds.exs"], "ecto.reset": ["ecto.drop", "ecto.setup"], test: ["ecto.create --quiet", "ecto.migrate --quiet", "test"], - "assets.deploy": ["esbuild default --minify", "phx.digest"] + "assets.deploy": ["esbuild default --minify", "phx.digest"], + ] + end + + defp package() do + [ + files: ~w(lib LICENSE mix.exs README.md), + name: "sleep", + licenses: ["GPL-2.0-or-later"], + maintainers: ["dwyl"], + links: %{"GitHub" => "https://github.com/dwyl/sleep"} ] end end diff --git a/mix.lock b/mix.lock index f81daeb..01d2f1e 100644 --- a/mix.lock +++ b/mix.lock @@ -1,20 +1,33 @@ %{ "castore": {:hex, :castore, "0.1.15", "dbb300827d5a3ec48f396ca0b77ad47058578927e9ebe792abd99fcbc3324326", [:mix], [], "hexpm", "c69379b907673c7e6eb229f09a0a09b60bb27cfb9625bcb82ea4c04ba82a8442"}, + "certifi": {:hex, :certifi, "2.9.0", "6f2a475689dd47f19fb74334859d460a2dc4e3252a3324bd2111b8f0429e7e21", [:rebar3], [], "hexpm", "266da46bdb06d6c6d35fde799bcb28d36d985d424ad7c08b5bb48f5b5cdd4641"}, "connection": {:hex, :connection, "1.1.0", "ff2a49c4b75b6fb3e674bfc5536451607270aac754ffd1bdfe175abe4a6d7a68", [:mix], [], "hexpm", "722c1eb0a418fbe91ba7bd59a47e28008a189d47e37e0e7bb85585a016b2869c"}, "cowboy": {:hex, :cowboy, "2.9.0", "865dd8b6607e14cf03282e10e934023a1bd8be6f6bacf921a7e2a96d800cd452", [:make, :rebar3], [{:cowlib, "2.11.0", [hex: :cowlib, repo: "hexpm", optional: false]}, {:ranch, "1.8.0", [hex: :ranch, repo: "hexpm", optional: false]}], "hexpm", "2c729f934b4e1aa149aff882f57c6372c15399a20d54f65c8d67bef583021bde"}, "cowboy_telemetry": {:hex, :cowboy_telemetry, "0.4.0", "f239f68b588efa7707abce16a84d0d2acf3a0f50571f8bb7f56a15865aae820c", [:rebar3], [{:cowboy, "~> 2.7", [hex: :cowboy, repo: "hexpm", optional: false]}, {:telemetry, "~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "7d98bac1ee4565d31b62d59f8823dfd8356a169e7fcbb83831b8a5397404c9de"}, "cowlib": {:hex, :cowlib, "2.11.0", "0b9ff9c346629256c42ebe1eeb769a83c6cb771a6ee5960bd110ab0b9b872063", [:make, :rebar3], [], "hexpm", "2b3e9da0b21c4565751a6d4901c20d1b4cc25cbb7fd50d91d2ab6dd287bc86a9"}, "db_connection": {:hex, :db_connection, "2.4.1", "6411f6e23f1a8b68a82fa3a36366d4881f21f47fc79a9efb8c615e62050219da", [:mix], [{:connection, "~> 1.0", [hex: :connection, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "ea36d226ec5999781a9a8ad64e5d8c4454ecedc7a4d643e4832bf08efca01f00"}, "decimal": {:hex, :decimal, "2.0.0", "a78296e617b0f5dd4c6caf57c714431347912ffb1d0842e998e9792b5642d697", [:mix], [], "hexpm", "34666e9c55dea81013e77d9d87370fe6cb6291d1ef32f46a1600230b1d44f577"}, + "earmark_parser": {:hex, :earmark_parser, "1.4.24", "344f8d2a558691d3fcdef3f9400157d7c4b3b8e58ee5063297e9ae593e8326d9", [:mix], [], "hexpm", "1f6451b0116dd270449c8f5b30289940ee9c0a39154c783283a08e55af82ea34"}, "ecto": {:hex, :ecto, "3.7.1", "a20598862351b29f80f285b21ec5297da1181c0442687f9b8329f0445d228892", [:mix], [{:decimal, "~> 1.6 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "d36e5b39fc479e654cffd4dbe1865d9716e4a9b6311faff799b6f90ab81b8638"}, "ecto_sql": {:hex, :ecto_sql, "3.7.2", "55c60aa3a06168912abf145c6df38b0295c34118c3624cf7a6977cd6ce043081", [:mix], [{:db_connection, "~> 2.2", [hex: :db_connection, repo: "hexpm", optional: false]}, {:ecto, "~> 3.7.0", [hex: :ecto, repo: "hexpm", optional: false]}, {:myxql, "~> 0.4.0 or ~> 0.5.0 or ~> 0.6.0", [hex: :myxql, repo: "hexpm", optional: true]}, {:postgrex, "~> 0.15.0 or ~> 0.16.0 or ~> 1.0", [hex: :postgrex, repo: "hexpm", optional: true]}, {:tds, "~> 2.1.1 or ~> 2.2", [hex: :tds, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4.0 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "3c218ea62f305dcaef0b915fb56583195e7b91c91dcfb006ba1f669bfacbff2a"}, "esbuild": {:hex, :esbuild, "0.4.0", "9f17db148aead4cf1e6e6a584214357287a93407b5fb51a031f122b61385d4c2", [:mix], [{:castore, ">= 0.0.0", [hex: :castore, repo: "hexpm", optional: false]}], "hexpm", "b61e4e6b92ffe45e4ee4755a22de6211a67c67987dc02afb35a425a0add1d447"}, + "ex_doc": {:hex, :ex_doc, "0.28.3", "6eea2f69995f5fba94cd6dd398df369fe4e777a47cd887714a0976930615c9e6", [:mix], [{:earmark_parser, "~> 1.4.19", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.14", [hex: :makeup_elixir, repo: "hexpm", optional: false]}, {:makeup_erlang, "~> 0.1", [hex: :makeup_erlang, repo: "hexpm", optional: false]}], "hexpm", "05387a6a2655b5f9820f3f627450ed20b4325c25977b2ee69bed90af6688e718"}, + "excoveralls": {:hex, :excoveralls, "0.14.4", "295498f1ae47bdc6dce59af9a585c381e1aefc63298d48172efaaa90c3d251db", [:mix], [{:hackney, "~> 1.16", [hex: :hackney, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "e3ab02f2df4c1c7a519728a6f0a747e71d7d6e846020aae338173619217931c1"}, "file_system": {:hex, :file_system, "0.2.10", "fb082005a9cd1711c05b5248710f8826b02d7d1784e7c3451f9c1231d4fc162d", [:mix], [], "hexpm", "41195edbfb562a593726eda3b3e8b103a309b733ad25f3d642ba49696bf715dc"}, "floki": {:hex, :floki, "0.32.0", "f915dc15258bc997d49be1f5ef7d3992f8834d6f5695270acad17b41f5bcc8e2", [:mix], [{:html_entities, "~> 0.5.0", [hex: :html_entities, repo: "hexpm", optional: false]}], "hexpm", "1c5a91cae1fd8931c26a4826b5e2372c284813904c8bacb468b5de39c7ececbd"}, "gettext": {:hex, :gettext, "0.19.1", "564953fd21f29358e68b91634799d9d26989f8d039d7512622efb3c3b1c97892", [:mix], [], "hexpm", "10c656c0912b8299adba9b061c06947511e3f109ab0d18b44a866a4498e77222"}, + "hackney": {:hex, :hackney, "1.18.1", "f48bf88f521f2a229fc7bae88cf4f85adc9cd9bcf23b5dc8eb6a1788c662c4f6", [:rebar3], [{:certifi, "~>2.9.0", [hex: :certifi, repo: "hexpm", optional: false]}, {:idna, "~>6.1.0", [hex: :idna, repo: "hexpm", optional: false]}, {:metrics, "~>1.0.0", [hex: :metrics, repo: "hexpm", optional: false]}, {:mimerl, "~>1.1", [hex: :mimerl, repo: "hexpm", optional: false]}, {:parse_trans, "3.3.1", [hex: :parse_trans, repo: "hexpm", optional: false]}, {:ssl_verify_fun, "~>1.1.0", [hex: :ssl_verify_fun, repo: "hexpm", optional: false]}, {:unicode_util_compat, "~>0.7.0", [hex: :unicode_util_compat, repo: "hexpm", optional: false]}], "hexpm", "a4ecdaff44297e9b5894ae499e9a070ea1888c84afdd1fd9b7b2bc384950128e"}, "html_entities": {:hex, :html_entities, "0.5.2", "9e47e70598da7de2a9ff6af8758399251db6dbb7eebe2b013f2bbd2515895c3c", [:mix], [], "hexpm", "c53ba390403485615623b9531e97696f076ed415e8d8058b1dbaa28181f4fdcc"}, + "idna": {:hex, :idna, "6.1.1", "8a63070e9f7d0c62eb9d9fcb360a7de382448200fbbd1b106cc96d3d8099df8d", [:rebar3], [{:unicode_util_compat, "~>0.7.0", [hex: :unicode_util_compat, repo: "hexpm", optional: false]}], "hexpm", "92376eb7894412ed19ac475e4a86f7b413c1b9fbb5bd16dccd57934157944cea"}, "jason": {:hex, :jason, "1.3.0", "fa6b82a934feb176263ad2df0dbd91bf633d4a46ebfdffea0c8ae82953714946", [:mix], [{:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "53fc1f51255390e0ec7e50f9cb41e751c260d065dcba2bf0d08dc51a4002c2ac"}, + "makeup": {:hex, :makeup, "1.1.0", "6b67c8bc2882a6b6a445859952a602afc1a41c2e08379ca057c0f525366fc3ca", [:mix], [{:nimble_parsec, "~> 1.2.2 or ~> 1.3", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "0a45ed501f4a8897f580eabf99a2e5234ea3e75a4373c8a52824f6e873be57a6"}, + "makeup_elixir": {:hex, :makeup_elixir, "0.16.0", "f8c570a0d33f8039513fbccaf7108c5d750f47d8defd44088371191b76492b0b", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}, {:nimble_parsec, "~> 1.2.3", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "28b2cbdc13960a46ae9a8858c4bebdec3c9a6d7b4b9e7f4ed1502f8159f338e7"}, + "makeup_erlang": {:hex, :makeup_erlang, "0.1.1", "3fcb7f09eb9d98dc4d208f49cc955a34218fc41ff6b84df7c75b3e6e533cc65f", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm", "174d0809e98a4ef0b3309256cbf97101c6ec01c4ab0b23e926a9e17df2077cbb"}, + "metrics": {:hex, :metrics, "1.0.1", "25f094dea2cda98213cecc3aeff09e940299d950904393b2a29d191c346a8486", [:rebar3], [], "hexpm", "69b09adddc4f74a40716ae54d140f93beb0fb8978d8636eaded0c31b6f099f16"}, "mime": {:hex, :mime, "2.0.2", "0b9e1a4c840eafb68d820b0e2158ef5c49385d17fb36855ac6e7e087d4b1dcc5", [:mix], [], "hexpm", "e6a3f76b4c277739e36c2e21a2c640778ba4c3846189d5ab19f97f126df5f9b7"}, + "mimerl": {:hex, :mimerl, "1.2.0", "67e2d3f571088d5cfd3e550c383094b47159f3eee8ffa08e64106cdf5e981be3", [:rebar3], [], "hexpm", "f278585650aa581986264638ebf698f8bb19df297f66ad91b18910dfc6e19323"}, + "nimble_parsec": {:hex, :nimble_parsec, "1.2.3", "244836e6e3f1200c7f30cb56733fd808744eca61fd182f731eac4af635cc6d0b", [:mix], [], "hexpm", "c8d789e39b9131acf7b99291e93dae60ab48ef14a7ee9d58c6964f59efb570b0"}, + "parse_trans": {:hex, :parse_trans, "3.3.1", "16328ab840cc09919bd10dab29e431da3af9e9e7e7e6f0089dd5a2d2820011d8", [:rebar3], [], "hexpm", "07cd9577885f56362d414e8c4c4e6bdf10d43a8767abb92d24cbe8b24c54888b"}, "phoenix": {:hex, :phoenix, "1.6.6", "281c8ce8dccc9f60607346b72cdfc597c3dde134dd9df28dff08282f0b751754", [:mix], [{:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:phoenix_pubsub, "~> 2.0", [hex: :phoenix_pubsub, repo: "hexpm", optional: false]}, {:phoenix_view, "~> 1.0", [hex: :phoenix_view, repo: "hexpm", optional: false]}, {:plug, "~> 1.10", [hex: :plug, repo: "hexpm", optional: false]}, {:plug_cowboy, "~> 2.2", [hex: :plug_cowboy, repo: "hexpm", optional: true]}, {:plug_crypto, "~> 1.2", [hex: :plug_crypto, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "807bd646e64cd9dc83db016199715faba72758e6db1de0707eef0a2da4924364"}, "phoenix_ecto": {:hex, :phoenix_ecto, "4.4.0", "0672ed4e4808b3fbed494dded89958e22fb882de47a97634c0b13e7b0b5f7720", [:mix], [{:ecto, "~> 3.3", [hex: :ecto, repo: "hexpm", optional: false]}, {:phoenix_html, "~> 2.14.2 or ~> 3.0", [hex: :phoenix_html, repo: "hexpm", optional: true]}, {:plug, "~> 1.9", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm", "09864e558ed31ee00bd48fcc1d4fc58ae9678c9e81649075431e69dbabb43cc1"}, "phoenix_html": {:hex, :phoenix_html, "3.2.0", "1c1219d4b6cb22ac72f12f73dc5fad6c7563104d083f711c3fcd8551a1f4ae11", [:mix], [{:plug, "~> 1.5", [hex: :plug, repo: "hexpm", optional: true]}], "hexpm", "36ec97ba56d25c0136ef1992c37957e4246b649d620958a1f9fa86165f8bc54f"}, @@ -27,7 +40,9 @@ "plug_crypto": {:hex, :plug_crypto, "1.2.2", "05654514ac717ff3a1843204b424477d9e60c143406aa94daf2274fdd280794d", [:mix], [], "hexpm", "87631c7ad914a5a445f0a3809f99b079113ae4ed4b867348dd9eec288cecb6db"}, "postgrex": {:hex, :postgrex, "0.16.1", "f94628a32c571266f53cd1e5fca705e626e2417bf1eee6f868985d14e874160a", [:mix], [{:connection, "~> 1.1", [hex: :connection, repo: "hexpm", optional: false]}, {:db_connection, "~> 2.1", [hex: :db_connection, repo: "hexpm", optional: false]}, {:decimal, "~> 1.5 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}], "hexpm", "6b225df32c857b9430619dbe30200a7ae664e23415a771ae9209396ee8eeee64"}, "ranch": {:hex, :ranch, "1.8.0", "8c7a100a139fd57f17327b6413e4167ac559fbc04ca7448e9be9057311597a1d", [:make, :rebar3], [], "hexpm", "49fbcfd3682fab1f5d109351b61257676da1a2fdbe295904176d5e521a2ddfe5"}, + "ssl_verify_fun": {:hex, :ssl_verify_fun, "1.1.6", "cf344f5692c82d2cd7554f5ec8fd961548d4fd09e7d22f5b62482e5aeaebd4b0", [:make, :mix, :rebar3], [], "hexpm", "bdb0d2471f453c88ff3908e7686f86f9be327d065cc1ec16fa4540197ea04680"}, "telemetry": {:hex, :telemetry, "1.0.0", "0f453a102cdf13d506b7c0ab158324c337c41f1cc7548f0bc0e130bbf0ae9452", [:rebar3], [], "hexpm", "73bc09fa59b4a0284efb4624335583c528e07ec9ae76aca96ea0673850aec57a"}, "telemetry_metrics": {:hex, :telemetry_metrics, "0.6.1", "315d9163a1d4660aedc3fee73f33f1d355dcc76c5c3ab3d59e76e3edf80eef1f", [:mix], [{:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "7be9e0871c41732c233be71e4be11b96e56177bf15dde64a8ac9ce72ac9834c6"}, "telemetry_poller": {:hex, :telemetry_poller, "1.0.0", "db91bb424e07f2bb6e73926fcafbfcbcb295f0193e0a00e825e589a0a47e8453", [:rebar3], [{:telemetry, "~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "b3a24eafd66c3f42da30fc3ca7dda1e9d546c12250a2d60d7b81d264fbec4f6e"}, + "unicode_util_compat": {:hex, :unicode_util_compat, "0.7.0", "bc84380c9ab48177092f43ac89e4dfa2c6d62b40b8bd132b1059ecc7232f9a78", [:rebar3], [], "hexpm", "25eee6d67df61960cf6a794239566599b09e17e668d3700247bc498638152521"}, } diff --git a/tutorial.md b/tutorial.md index 57fdd1a..d00c75d 100644 --- a/tutorial.md +++ b/tutorial.md @@ -1,15 +1,19 @@ -# _Tutorial_ +# _Tutorial_ 👩‍💻 -This tutorial takes you through _building_ +This step-by-step tutorial +takes you through _building_ a sleep tracking App from scratch -so that you can _understand_ how it works. +so you can _understand_ how it works.
If you get stuck, _please_ [**ask questions**!](https://github.com/dwyl/sleep/issues) +Expect it take you around **`20 minutes`** to complete. +Set your pomodoro timer and turn off other distractions! +
-## Implementation Note +## Implementation Note 💡 -We built this MVP App using using +This MVP App is built using using [**`Elixir`**](https://github.com/dwyl/learn-elixir), [**`Phoenix`**](https://github.com/dwyl/learn-phoenix-framework) and @@ -26,10 +30,13 @@ with a **basic interface**, **saving data** to the database, **authentication** and ***deployment*** -in **_less_ than 20 minutes**. +in **`20 minutes`**.
Anyone who knows basic programming (e.g. `Python`, `JavaScript`, etc.) should be able to follow along. +If you get stuck, please don't suffer in silence, +[**open an issue**!](https://github.com/dwyl/sleep/issues).
+ +
-## 1. Create a New Phoenix App +## 1. Create a New Phoenix App 🆕 ```sh mix phx.new app --live --no-mailer --no-dashboard @@ -58,7 +66,7 @@ to fetch and install the dependencies: Fetch and install dependencies? [Yn] ``` -Type `y` followed by the `Enter` key: +Type `y` followed by the `Enter` key. You should then see: @@ -95,7 +103,7 @@ you should see see something similar to the following: So far so good. -#### Quick Note on App Naming Conventions +#### Quick Note on App Naming Conventions 📛 You will often see Phoenix apps with the name of the app in the project files e.g: in the **`Chat`** example @@ -190,7 +198,6 @@ end ``` - ### Update `router.ex` From f8c7cd332a869fe5ba466d0a51c1d842cfc5f742 Mon Sep 17 00:00:00 2001 From: nelsonic Date: Sun, 13 Mar 2022 14:56:00 +0000 Subject: [PATCH 10/24] temporarily lower coverage threshold to 40% to avoid noise while building the tutorial ... --- coveralls.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/coveralls.json b/coveralls.json index 898e94a..f35c17d 100644 --- a/coveralls.json +++ b/coveralls.json @@ -1,6 +1,6 @@ { "coverage_options": { - "minimum_coverage": 100 + "minimum_coverage": 40 }, "skip_files": [ "test/", From 56318a26fc90243a6fedd5a51b8aef5628b10858 Mon Sep 17 00:00:00 2001 From: nelsonic Date: Sun, 13 Mar 2022 15:36:13 +0000 Subject: [PATCH 11/24] 3. Create app_live.ex and insert code #53 --- lib/app_web/live/app_live.ex | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/app_web/live/app_live.ex b/lib/app_web/live/app_live.ex index c85df71..f9df1b5 100644 --- a/lib/app_web/live/app_live.ex +++ b/lib/app_web/live/app_live.ex @@ -1,4 +1,4 @@ -defmodule App.AppLive do +defmodule AppWeb.AppLive do use AppWeb, :live_view def mount(_params, _session, socket) do @@ -6,6 +6,6 @@ defmodule App.AppLive do end def render(assigns) do - AppWeb.AppView.render("messages.html", assigns) + AppWeb.AppView.render("index.html", assigns) end end \ No newline at end of file From 9001fbbdd2611d4ef04826f733bd41f153b1850a Mon Sep 17 00:00:00 2001 From: nelsonic Date: Sun, 13 Mar 2022 15:37:06 +0000 Subject: [PATCH 12/24] 4. Create app_view.ex and add essential code #53 --- lib/app_web/views/app_view.ex | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 lib/app_web/views/app_view.ex diff --git a/lib/app_web/views/app_view.ex b/lib/app_web/views/app_view.ex new file mode 100644 index 0000000..8584438 --- /dev/null +++ b/lib/app_web/views/app_view.ex @@ -0,0 +1,3 @@ +defmodule AppWeb.AppView do + use AppWeb, :view +end \ No newline at end of file From da04c7452c9dfe0f3b34ecbd0473726d1541d885 Mon Sep 17 00:00:00 2001 From: nelsonic Date: Sun, 13 Mar 2022 15:37:57 +0000 Subject: [PATCH 13/24] 5. rename page/index.html.heex to app/index.html.heex and simplify code #53 --- lib/app_web/templates/app/index.html.heex | 1 + 1 file changed, 1 insertion(+) create mode 100644 lib/app_web/templates/app/index.html.heex diff --git a/lib/app_web/templates/app/index.html.heex b/lib/app_web/templates/app/index.html.heex new file mode 100644 index 0000000..24e3930 --- /dev/null +++ b/lib/app_web/templates/app/index.html.heex @@ -0,0 +1 @@ +

App Goes Here!

\ No newline at end of file From 2952ed4e253f2d4365d9ea070b0d947c55898a14 Mon Sep 17 00:00:00 2001 From: nelsonic Date: Sun, 13 Mar 2022 15:38:28 +0000 Subject: [PATCH 14/24] 5. simplify templates/layout/root.html.heex to bare minimum #53 --- lib/app_web/templates/layout/root.html.heex | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/lib/app_web/templates/layout/root.html.heex b/lib/app_web/templates/layout/root.html.heex index 0eeff7f..8ae9372 100644 --- a/lib/app_web/templates/layout/root.html.heex +++ b/lib/app_web/templates/layout/root.html.heex @@ -12,15 +12,7 @@
- - +

Sleep Tracker!

<%= @inner_content %> From 02806583ec21b86c23749d0257d4c7ded235678b Mon Sep 17 00:00:00 2001 From: nelsonic Date: Sun, 13 Mar 2022 15:39:08 +0000 Subject: [PATCH 15/24] 6. Modify router.ex to point to the AppLive instead of Page #53 --- lib/app_web/router.ex | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/lib/app_web/router.ex b/lib/app_web/router.ex index fd6c64c..af43e53 100644 --- a/lib/app_web/router.ex +++ b/lib/app_web/router.ex @@ -17,11 +17,6 @@ defmodule AppWeb.Router do scope "/", AppWeb do pipe_through :browser - get "/", PageController, :index + live "/", AppLive end - - # Other scopes may use custom stacks. - # scope "/api", AppWeb do - # pipe_through :api - # end end From 3468016f91fb1f6022145044864285a5ce0483b3 Mon Sep 17 00:00:00 2001 From: nelsonic Date: Sun, 13 Mar 2022 15:39:30 +0000 Subject: [PATCH 16/24] add steps to tutorial.md #53 --- README.md | 62 ++++++--- lib/app_web/templates/page/index.html.heex | 41 ------ tutorial.md | 150 ++++++++++++++++----- 3 files changed, 159 insertions(+), 94 deletions(-) delete mode 100644 lib/app_web/templates/page/index.html.heex diff --git a/README.md b/README.md index c7ebe95..5322ce4 100644 --- a/README.md +++ b/README.md @@ -16,14 +16,15 @@ [![HitCount](http://hits.dwyl.com/dwyl/sleep.svg?style=flat-square)](http://hits.dwyl.com/dwyl/sleep) **Try it**: [**sleepdev.herokuapp.com**](https://sleepdev.herokuapp.com/) -![wake-sleeping-heroku-app](https://liveview-chat-example.herokuapp.com/ping) +
-Sleep is the single most important activity in life; -it restores our tired bodies -and consolidates neural connections to help form/retain memories. +Sleep is the cornerstone of a healthy life; +it restores your tired body +and consolidates neural connections +to help form/retain memories. A good night's sleep can dramatically increase effectiveness in all areas of your life. @@ -38,19 +39,36 @@ aspect of health and longevity. When you sleep well and feel rested, you have mental clarity and energy -to focus on Deep Work tasks. +to focus on making progress in life.
By contrast if you don't get a good night's sleep virtually everything about your day will be worse. +We wanted a simple way to:
+**a)** ***Track*** our own sleep/wake time & quality.
+**b)** ***Visualize*** our sleep patterns over time.
+**c)** ***Share*** that data with our significant other or any other relevant person.
+ +## Why Write a _Tutorial_? 💭 + +We decided to write this as a **step-by-step tutorial** +because it's a great opportunity +to document the whole process of building the App. +And it means anyone following along +can +[grok](https://en.wikipedia.org/wiki/Grok) +it +and even **_extend_ it** +to add their own features. +
# What? 📱 🛌 This App is the simplest possible **sleep tracker** -(_other than using a paper notepad + pen -or a note taking App on your phone ..._) +(_other than using a notepad + pen +or a notes App on your phone ..._) A **_deliberately_ basic** version of an App is commonly referred to as Minimum Viable Product ("MVP") @@ -78,8 +96,8 @@ You can start using the MVP _now_ (_tonight_)! > If you're reading this past **22:00**, go straight to the "***Try it!***" section and start recording your sleep _now_. -Bookmark (⭐) the project -and come back to it tomorrow. +Please bookmark (⭐) the project +and come back to it tomorrow when you're fresh.
@@ -95,9 +113,9 @@ and may _extend_ it! There are 3 steps to this: -1. Try it! (2 mins) -2. Run it! (5 mins) -3. Build it! (20 mins) +1. _Try_ it! (2 mins) +2. _Run_ it! (5 mins) +3. _Build_ it! (20 mins) Let's get started. @@ -105,9 +123,10 @@ Let's get started. ## 1. _Try_ it! -Firstly, if you haven't already, -you can _try_ the App via Heroku: -https://sleepdev.herokuapp.com +First, if you haven't already, +_try_ the App via Heroku: +[sleepdev.herokuapp.com](https://sleepdev.herokuapp.com) +to get a sense for the interface. # @TODO: insert GIF of _performing_ the actions! @@ -143,7 +162,7 @@ https://hexdocs.pm/phoenix/installation.html + [x] Postgres: https://www.postgresql.org/download -### _Check_ You Have Everything _Before_ Starting +### _Check_ You Have Everything Ready _Before_ Starting Check you have the _latest version_ of **Elixir** (_run the following command in your terminal_): @@ -190,7 +209,9 @@ postgres 529 Alex 6u IPv4 0xbc5d729e55a89a13 0t0 TCP localhost:postgre This tells us that PostgreSQL is "_listening_" on TCP Port `5432` (_the default port_) -With all those "pre-flight checks" performed, let's get _going_! +With all those +[pre-flight checks](https://en.wikipedia.org/wiki/Preflight_checklist) +done, let's get _flying_!
@@ -241,8 +262,8 @@ and you have a reference implementation that you _know_ works on your computer, it's time to write some **`code`** -**GOTO**: -[https://github.com/dwyl/sleep/blob/main/tutorial.md](https://github.com/dwyl/sleep/blob/main/tutorial.md) +## `GOTO:` +[`tutorial.md`](https://github.com/dwyl/sleep/blob/main/tutorial.md)
@@ -267,4 +288,5 @@ you will not be able to function. > Insert table of good vs. bad sleep. ---> \ No newline at end of file +--> +![wake-sleeping-heroku-app](https://liveview-chat-example.herokuapp.com/ping) \ No newline at end of file diff --git a/lib/app_web/templates/page/index.html.heex b/lib/app_web/templates/page/index.html.heex deleted file mode 100644 index f844bd8..0000000 --- a/lib/app_web/templates/page/index.html.heex +++ /dev/null @@ -1,41 +0,0 @@ -
-

<%= gettext "Welcome to %{name}!", name: "Phoenix" %>

-

Peace of mind from prototype to production

-
- -
- - -
diff --git a/tutorial.md b/tutorial.md index d00c75d..cbb2479 100644 --- a/tutorial.md +++ b/tutorial.md @@ -1,27 +1,29 @@ +
+ # _Tutorial_ 👩‍💻 -This step-by-step tutorial -takes you through _building_ +
+ +This **step-by-step tutorial** +guides you through _building_ a sleep tracking App from scratch -so you can _understand_ how it works.
-If you get stuck, _please_ -[**ask questions**!](https://github.com/dwyl/sleep/issues) -Expect it take you around **`20 minutes`** to complete. +so you can _understand_ how it works. +Expect it take around **`20 minutes`** to complete. Set your pomodoro timer and turn off other distractions!
## Implementation Note 💡 -This MVP App is built using using +This App is built using using [**`Elixir`**](https://github.com/dwyl/learn-elixir), [**`Phoenix`**](https://github.com/dwyl/learn-phoenix-framework) and -[**`LiveView`**](https://github.com/dwyl/phoenix-liveview-counter-tutorial) +[**`LiveView`**](https://github.com/dwyl/phoenix-liveview-counter-tutorial#liveview) because it's one of the simplest ways -to build web applications +to build mobile-first responsive web applications from first principals. -Our objective is to get to a _useable_ app +Our objective is to create a _useful_ app as **_fast_ as possible** so we can start inputting/saving data. You will see below, @@ -34,6 +36,9 @@ in **`20 minutes`**.
Anyone who knows basic programming (e.g. `Python`, `JavaScript`, etc.) should be able to follow along. +If you are completely **new** to Phoenix or LiveView, +we recommend starting with the more basic +[LiveView Counter Tutorial](https://github.com/dwyl/phoenix-liveview-counter-tutorial). If you get stuck, please don't suffer in silence, [**open an issue**!](https://github.com/dwyl/sleep/issues).
@@ -49,6 +54,8 @@ https://twitter.com/iamdevloper/status/787969734918668289 ## 1. Create a New Phoenix App 🆕 +In a new terminal window, run the following command: + ```sh mix phx.new app --live --no-mailer --no-dashboard ``` @@ -62,7 +69,7 @@ and we don't want unused/untested code. When you see the prompt asking you to fetch and install the dependencies: -``` +```sh Fetch and install dependencies? [Yn] ``` @@ -70,20 +77,21 @@ Type `y` followed by the `Enter` key. You should then see: -``` +```sh * running mix deps.get * running mix deps.compile ``` To start the Phoenix server: -* Install dependencies with `mix deps.get` -* Create and migrate your database with `mix ecto.setup` -* Start Phoenix endpoint with `mix phx.server` ++ Change working directory into the App, e.g: `cd app` ++ **Install** dependencies with `mix deps.get` ++ **Setup** the database with `mix ecto.setup` ++ **Start** the Phoenix App with `mix phx.server` -You should see the following output in your terminal: +You should see output similar to the following in your terminal: -``` +```sh [info] Running AppWeb.Endpoint with cowboy 2.9.0 at 127.0.0.1:4000 (http) [debug] Downloading esbuild from https://registry.npmjs.org/esbuild-darwin-64/-/esbuild-darwin-64-0.13.5.tgz [info] Access AppWeb.Endpoint at http://localhost:4000 @@ -93,19 +101,16 @@ You should see the following output in your terminal: When you open http://localhost:4000 in your web browser, you should see see something similar to the following: -![phoenix-framerwork-welcome-page](https://user-images.githubusercontent.com/194400/145309471-306fdd5e-324f-4c4a-bd9f-6fddbec7f512.png) - - - +![phoenix-framerwork-welcome-page](https://user-images.githubusercontent.com/194400/159679120-8ffd98a2-d0c9-421e-9c15-d9b6e4004cb8.png) So far so good. +
-#### Quick Note on App Naming Conventions 📛 +### Quick Note on App Naming Conventions 📛 -You will often see Phoenix apps with the name of the app in the project files +You will often see Phoenix applications +with the name of the app in the project files e.g: in the **`Chat`** example [github.com/dwyl/phoenix-chat-example](https://github.com/dwyl/phoenix-chat-example) @@ -128,7 +133,7 @@ defmodule ChatWeb.Router do ``` Having `Chat` or `ChatWeb` namespace can be useful -if you're working on multiple Phoenix apps _simultaneously_ +if you're working on _multiple_ Phoenix apps _simultaneously_ and need to context switch. That's why we use the `Auth` namespace in our Authentication App: @@ -153,7 +158,7 @@ we will re-use some of the code in our "main" App. [github.com/dwyl/app](https://github.com/dwyl/app) This means it's easy to "lift and shift" the code & tests -without needing to waste time with "find & replace". +without needing to waste time with messy "find & replace".
If you prefer to namespace your app differently, go for it! @@ -164,7 +169,9 @@ If you prefer to namespace your app differently, go for it! Open the project in your editor/IDE of choice. -### Create `/live` Directory +
+ +## 2. Create `/live` Directory Since we are using Phoenix LiveView for this App, we need to create a new `live` directory @@ -173,7 +180,7 @@ with the following path: e.g: `mkdir lib/app_web/live` -### Create `app_live.ex` File +## 3. Create `app_live.ex` File Inside that newly created `/live` directory, create a new file called @@ -192,18 +199,95 @@ defmodule App.AppLive do end def render(assigns) do - AppWeb.AppView.render("messages.html", assigns) + AppWeb.AppView.render("index.html", assigns) end end ``` +If you attempt to compile the project now you will see a warning: + + +```elixir +warning: AppWeb.AppView.render/2 is undefined +(module AppWeb.AppView is not available or is yet to be defined) + lib/app_web/live/app_live.ex:9: App.AppLive.render/1 +``` + +## 4. Create `app_view.ex` File + +Create a new file with the path: +`lib/app_web/views/app_view.ex` + +Insert the following code into the file: + +```elixir +defmodule AppWeb.AppView do + use AppWeb, :view +end +``` + +This just tells our new view to `use` all the code +in the `AppWeb` `:view` module (part of Phoenix). + +> If you're _curious_ how `Views` work in `Phoenix`, +see: +[`guides/views.md`](https://github.com/phoenixframework/phoenix/blob/master/guides/views.md`) + + +## 5. Edit the `index.html.heex` and `root.html.heex` Templates + +First **rename** the **`/page`** folder +as we won't be using "pages" in this project. + +From: +`lib/app_web/templates/page/` +To: +`lib/app_web/templates/app/` + +e.g: +```sh +mv lib/app_web/templates/page lib/app_web/templates/app +``` + +Then edit the template at `lib/app_web/templates/app/index.html.heex` replacing the contents with the following line: + +```html +

App Goes Here!

+``` + +Finally to make the layout simpler, +Update the `` section of the +`lib/app_web/templates/layout/root.html.heex` +file to the following: + +```html + +
+
+

Sleep Tracker!

+
+
+ <%= @inner_content %> + +``` + +Don't worry, we will improve on both of these files later. -### Update `router.ex` +### 6. Update `router.ex` -and navigate to the -`lib/app_web/router.ex` file. +Open the `lib/app_web/router.ex` file and +replace the line: +```elixir + get "/", PageController, :index +``` + +With: + +```elixir + live "/", AppLive +``` From 2b2ba87019fab7f324015b95dac69fa279aae590 Mon Sep 17 00:00:00 2001 From: nelsonic Date: Sun, 13 Mar 2022 16:03:14 +0000 Subject: [PATCH 17/24] 7. Add step to tutorial.md to repair broken test #53 --- test/app_web/live/app_live_test.exs | 8 +++ tutorial.md | 99 ++++++++++++++++++++++++++++- 2 files changed, 106 insertions(+), 1 deletion(-) create mode 100644 test/app_web/live/app_live_test.exs diff --git a/test/app_web/live/app_live_test.exs b/test/app_web/live/app_live_test.exs new file mode 100644 index 0000000..8221171 --- /dev/null +++ b/test/app_web/live/app_live_test.exs @@ -0,0 +1,8 @@ +defmodule AppWeb.AppLiveTest do + use AppWeb.ConnCase + + test "GET /", %{conn: conn} do + conn = get(conn, "/") + assert html_response(conn, 200) =~ "Sleep Tracker" + end +end \ No newline at end of file diff --git a/tutorial.md b/tutorial.md index cbb2479..35a602c 100644 --- a/tutorial.md +++ b/tutorial.md @@ -274,7 +274,7 @@ file to the following: Don't worry, we will improve on both of these files later. -### 6. Update `router.ex` +## 6. Update `router.ex` Open the `lib/app_web/router.ex` file and replace the line: @@ -289,6 +289,103 @@ With: live "/", AppLive ``` +## Checkpoint: Working LiveView App 📍 + +At this stage, +if you run the project: + +```sh +mix phx.server +``` + +Open the URL http://localhost:4000 +in your Web Browser; +you should see something similar to this: + + +image + + + +## 7. Update Tests + +If you attempt to run the tests in the project now: + +```sh +mix test +``` + +One of the tests will fail: + + +```elixir +Generated app app +.. + + 1) test GET / (AppWeb.PageControllerTest) + test/app_web/controllers/page_controller_test.exs:4 + Assertion with =~ failed + code: assert html_response(conn, 200) =~ "Welcome to Phoenix!" + left: "\n\n \n \n \n \nApp · Phoenix Framework\n \n \n \n \n
\n
\n

Sleep Tracker!

\n
\n
\n
\n

\n\n

\n

App Goes Here!

\n
\n \n" + right: "Welcome to Phoenix!" + stacktrace: + test/app_web/controllers/page_controller_test.exs:6: (test) +``` + +First given that we won't be using +`controllers` in this App, +rename the test folder from: +`test/app_web/controllers` to `test/app_web/live` + +e.g: +```sh +mv test/app_web/controllers test/app_web/live +``` + +Now rename the file +`test/app_web/live/page_controller_test.exs` +to +`test/app_web/live/app_live_test.exs` + +e.g: +```sh +mv test/app_web/live/page_controller_test.exs test/app_web/live/app_live_test.exs +``` + +Then open the +`test/app_web/live/app_live_test.exs` +file and +replace the entire contents +with the following test code: + +```elixir +defmodule AppWeb.AppLiveTest do + use AppWeb.ConnCase + + test "GET /", %{conn: conn} do + conn = get(conn, "/") + assert html_response(conn, 200) =~ "Sleep Tracker" + end +end +``` + +Now when you re-run the tests: + +```sh +mix test +``` + +You will see the tests pass: + +```sh +... + +Finished in 0.2 seconds (0.1s async, 0.1s sync) +3 tests, 0 failures + +Randomized with seed 575721 +``` + [![HitCount](http://hits.dwyl.com/dwyl/sleep-tutorial.svg?style=flat-square)](http://hits.dwyl.com/dwyl/sleep) \ No newline at end of file From 30d16e2ff5817dcf8d2eb005a18f1d2574ed6d94 Mon Sep 17 00:00:00 2001 From: nelsonic Date: Sun, 13 Mar 2022 16:03:56 +0000 Subject: [PATCH 18/24] Create elixir_buildpack.config and Procfile to deploy demo to Heroku #53 --- Procfile | 1 + elixir_buildpack.config | 10 ++++++++++ test/app_web/controllers/page_controller_test.exs | 8 -------- 3 files changed, 11 insertions(+), 8 deletions(-) create mode 100644 Procfile create mode 100644 elixir_buildpack.config delete mode 100644 test/app_web/controllers/page_controller_test.exs diff --git a/Procfile b/Procfile new file mode 100644 index 0000000..6506faf --- /dev/null +++ b/Procfile @@ -0,0 +1 @@ +web: mix phx.server diff --git a/elixir_buildpack.config b/elixir_buildpack.config new file mode 100644 index 0000000..685b7de --- /dev/null +++ b/elixir_buildpack.config @@ -0,0 +1,10 @@ +# Elixir version +elixir_version=1.12.3 + +# Erlang version +# https://github.com/HashNuke/heroku-buildpack-elixir-otp-builds/blob/master/otp-versions +erlang_version=24.0.3 + +# Invoke assets.deploy defined in your mix.exs to deploy assets with esbuild +# Note we nuke the esbuild executable from the image +hook_post_compile="eval mix assets.deploy && rm -f _build/esbuild" diff --git a/test/app_web/controllers/page_controller_test.exs b/test/app_web/controllers/page_controller_test.exs deleted file mode 100644 index 4bb48b7..0000000 --- a/test/app_web/controllers/page_controller_test.exs +++ /dev/null @@ -1,8 +0,0 @@ -defmodule AppWeb.PageControllerTest do - use AppWeb.ConnCase - - test "GET /", %{conn: conn} do - conn = get(conn, "/") - assert html_response(conn, 200) =~ "Welcome to Phoenix!" - end -end From 8897af8d0e6b95ae46b00ae7bf535bef4e14f2f3 Mon Sep 17 00:00:00 2001 From: nelsonic Date: Sun, 13 Mar 2022 16:22:12 +0000 Subject: [PATCH 19/24] update elixir_buildpack.config and Procfile to always_rebuild=true & mix assets.deploy #53 --- Procfile | 2 +- elixir_buildpack.config | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/Procfile b/Procfile index 6506faf..5a2240a 100644 --- a/Procfile +++ b/Procfile @@ -1 +1 @@ -web: mix phx.server +web: MIX_ENV=prod mix ecto.migrate && mix assets.deploy && mix phx.server diff --git a/elixir_buildpack.config b/elixir_buildpack.config index 685b7de..dd260b0 100644 --- a/elixir_buildpack.config +++ b/elixir_buildpack.config @@ -5,6 +5,8 @@ elixir_version=1.12.3 # https://github.com/HashNuke/heroku-buildpack-elixir-otp-builds/blob/master/otp-versions erlang_version=24.0.3 +always_rebuild=true + # Invoke assets.deploy defined in your mix.exs to deploy assets with esbuild # Note we nuke the esbuild executable from the image hook_post_compile="eval mix assets.deploy && rm -f _build/esbuild" From 6129fa1a45d178386152ab9a1f0e2879ac0498ec Mon Sep 17 00:00:00 2001 From: nelsonic Date: Sun, 13 Mar 2022 16:32:51 +0000 Subject: [PATCH 20/24] use ssl for DB connection on Heroku #53 --- config/prod.exs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/config/prod.exs b/config/prod.exs index d5f74e9..198bdd8 100644 --- a/config/prod.exs +++ b/config/prod.exs @@ -12,7 +12,7 @@ import Config config :app, AppWeb.Endpoint, cache_static_manifest: "priv/static/cache_manifest.json" # Do not print debug messages in production -config :logger, level: :info +config :logger, level: :debug # ## SSL Support # @@ -47,3 +47,12 @@ config :logger, level: :info # force_ssl: [hsts: true] # # Check `Plug.SSL` for all available options in `force_ssl`. + +# had to add this because +dbssl = if System.get_env("HEROKU"), do: true, else: false + +config :auth, Auth.Repo, + ssl: dbssl, + url: System.get_env("DATABASE_URL"), + pool_size: String.to_integer(System.get_env("POOL_SIZE") || "10"), + size: String.to_integer(System.get_env("POOL_SIZE") || "20") \ No newline at end of file From f6e1c3fbeb5bdd2a5da5b9413f2a3cb72fd68879 Mon Sep 17 00:00:00 2001 From: nelsonic Date: Sun, 13 Mar 2022 16:36:18 +0000 Subject: [PATCH 21/24] use ssl for DB connection on Heroku #53 --- config/prod.exs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/prod.exs b/config/prod.exs index 198bdd8..ffb1746 100644 --- a/config/prod.exs +++ b/config/prod.exs @@ -51,7 +51,7 @@ config :logger, level: :debug # had to add this because dbssl = if System.get_env("HEROKU"), do: true, else: false -config :auth, Auth.Repo, +config :app, App.Repo, ssl: dbssl, url: System.get_env("DATABASE_URL"), pool_size: String.to_integer(System.get_env("POOL_SIZE") || "10"), From 3c16d103ae663c41436a098b2ff18e9ada8084c5 Mon Sep 17 00:00:00 2001 From: nelsonic Date: Sun, 13 Mar 2022 16:45:07 +0000 Subject: [PATCH 22/24] Check for DYNO envar instead of HEROKU for db ssl #53 --- config/prod.exs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/config/prod.exs b/config/prod.exs index ffb1746..887b5a6 100644 --- a/config/prod.exs +++ b/config/prod.exs @@ -48,8 +48,8 @@ config :logger, level: :debug # # Check `Plug.SSL` for all available options in `force_ssl`. -# had to add this because -dbssl = if System.get_env("HEROKU"), do: true, else: false +# had to add this for Heroku +dbssl = if System.get_env("DYNO"), do: true, else: false config :app, App.Repo, ssl: dbssl, From 1636477d5023d9bfc5ad4359720c964282132543 Mon Sep 17 00:00:00 2001 From: nelsonic Date: Sun, 13 Mar 2022 17:23:35 +0000 Subject: [PATCH 23/24] set preferred_cli_env for mix coveralls.json task to :test #53 --- README.md | 15 ++++++--------- mix.exs | 3 ++- tutorial.md | 40 +++++++++++++++++++++++++++++++++++++--- 3 files changed, 45 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 5322ce4..6af3475 100644 --- a/README.md +++ b/README.md @@ -66,17 +66,15 @@ to add their own features. # What? 📱 🛌 -This App is the simplest possible **sleep tracker** -(_other than using a notepad + pen -or a notes App on your phone ..._) - +This App is the simplest possible **sleep tracker**. + A **_deliberately_ basic** version of an App is commonly referred to as Minimum Viable Product ("MVP") which means it has the minimum features to be useful, -but leaves a lot enhancements out. - +but leaves the possible enhancements out. If you think of a feature/improvement, _please_ -[**open an issue**!](https://github.com/dwyl/sleep/issues).
+[**open an issue**!](https://github.com/dwyl/sleep/issues). **Contributions/ideas** are **_always_ welcome** and we're delighted to extend this in response to feedback! @@ -262,8 +260,7 @@ and you have a reference implementation that you _know_ works on your computer, it's time to write some **`code`** -## `GOTO:` -[`tutorial.md`](https://github.com/dwyl/sleep/blob/main/tutorial.md) +## `GOTO:` [`tutorial.md`](https://github.com/dwyl/sleep/blob/main/tutorial.md)
diff --git a/mix.exs b/mix.exs index ad63093..133109a 100644 --- a/mix.exs +++ b/mix.exs @@ -17,7 +17,8 @@ defmodule App.MixProject do coveralls: :test, "coveralls.detail": :test, "coveralls.post": :test, - "coveralls.html": :test + "coveralls.html": :test, + "coveralls.json": :test ], package: package(), description: "Turnkey Auth Auth Application" diff --git a/tutorial.md b/tutorial.md index 35a602c..adbe737 100644 --- a/tutorial.md +++ b/tutorial.md @@ -305,18 +305,21 @@ you should see something similar to this: image +The App doesn't _do_ anything yet, +but at least we know it _renders_. +
## 7. Update Tests -If you attempt to run the tests in the project now: +Following the changes we made above, +if you attempt to run the tests in the project now: ```sh mix test ``` -One of the tests will fail: - +You will see that one of the tests fail: ```elixir Generated app app @@ -332,6 +335,13 @@ Generated app app test/app_web/controllers/page_controller_test.exs:6: (test) ``` +It's pretty obvious _why_ the test is failing ... +we removed the "**Welcome to Phoenix!**" text from the template. + +Let's _fix_ the failing test. + +### 7.1 Rename the Test File + First given that we won't be using `controllers` in this App, rename the test folder from: @@ -352,6 +362,8 @@ e.g: mv test/app_web/live/page_controller_test.exs test/app_web/live/app_live_test.exs ``` +### 7.2 Update the Test + Then open the `test/app_web/live/app_live_test.exs` file and @@ -369,6 +381,8 @@ defmodule AppWeb.AppLiveTest do end ``` +### 7.3 Re-run the Tests + Now when you re-run the tests: ```sh @@ -387,5 +401,25 @@ Randomized with seed 575721 ``` +## 8. Create Database Schema + +We could work on the interface first +and then figure out how to store data + + +## X. Start a Sleep Timer + +## X. Stop a Running Sleep Timer + +## X. Display Past Timers + + + + +## X. Authentication + + + + [![HitCount](http://hits.dwyl.com/dwyl/sleep-tutorial.svg?style=flat-square)](http://hits.dwyl.com/dwyl/sleep) \ No newline at end of file From ec5d89a320ab8a7ed45f7e91d37963db6d92a2ce Mon Sep 17 00:00:00 2001 From: nelsonic Date: Sun, 20 Mar 2022 08:30:19 +0000 Subject: [PATCH 24/24] [WiP] add section on test coverage #53 --- README.md | 21 ++--- coveralls.json | 12 +-- lib/app_web/router.ex | 4 - mix.exs | 2 +- tutorial.md | 201 ++++++++++++++++++++++++++++++++++++++++-- 5 files changed, 205 insertions(+), 35 deletions(-) diff --git a/README.md b/README.md index 6af3475..52c6f80 100644 --- a/README.md +++ b/README.md @@ -155,8 +155,6 @@ Make sure you have the following installed: + [x] Elixir: https://elixir-lang.org/install.html -+ [x] Phoenix: -https://hexdocs.pm/phoenix/installation.html + [x] Postgres: https://www.postgresql.org/download @@ -177,18 +175,6 @@ Erlang/OTP 24 [erts-12.1.2] [source] [64-bit] [smp:12:12] [ds:12:12:10] [async-t Elixir 1.13 (compiled with Erlang/OTP 22) ``` -Check you have the **latest** version of **Phoenix**: - -```sh -mix phx.new -v -``` - -You should see: - -```sh -Phoenix v1.6.6 -``` - _Confirm_ **PostgreSQL** is running (_so the App can store chat messages_) run the following command: @@ -204,8 +190,11 @@ postgres 529 Alex 5u IPv6 0xbc5d729e529f062b 0t0 TCP localhost:postgre postgres 529 Alex 6u IPv4 0xbc5d729e55a89a13 0t0 TCP localhost:postgresql (LISTEN) ``` -This tells us that PostgreSQL is "_listening_" on TCP Port `5432` -(_the default port_) +This tells us that `postgresql` +is "_listening_" on TCP Port `5432` +(_the default port_). +If Postgres is not running, +check the docs for you OS. With all those [pre-flight checks](https://en.wikipedia.org/wiki/Preflight_checklist) diff --git a/coveralls.json b/coveralls.json index f35c17d..a1a917c 100644 --- a/coveralls.json +++ b/coveralls.json @@ -4,11 +4,11 @@ }, "skip_files": [ "test/", - "lib/auth/application.ex", - "lib/auth/release.ex", - "lib/auth_web.ex", - "lib/auth_web/views/error_helpers.ex", - "lib/auth_web/channels/user_socket.ex", - "lib/auth_web/telemetry.ex" + "lib/app/application.ex", + "lib/app/release.ex", + "lib/app_web.ex", + "lib/app_web/views/error_helpers.ex", + "lib/app_web/channels/user_socket.ex", + "lib/app_web/telemetry.ex" ] } diff --git a/lib/app_web/router.ex b/lib/app_web/router.ex index af43e53..b048b7d 100644 --- a/lib/app_web/router.ex +++ b/lib/app_web/router.ex @@ -10,10 +10,6 @@ defmodule AppWeb.Router do plug :put_secure_browser_headers end - pipeline :api do - plug :accepts, ["json"] - end - scope "/", AppWeb do pipe_through :browser diff --git a/mix.exs b/mix.exs index 133109a..497b751 100644 --- a/mix.exs +++ b/mix.exs @@ -59,7 +59,7 @@ defmodule App.MixProject do {:jason, "~> 1.2"}, {:plug_cowboy, "~> 2.5"}, - # Check test coverage + # Check test coverage: https://github.com/parroty/excoveralls {:excoveralls, "~> 0.14.3", only: :test}, # Create Documentation for publishing Hex.docs: diff --git a/tutorial.md b/tutorial.md index adbe737..be606c2 100644 --- a/tutorial.md +++ b/tutorial.md @@ -9,7 +9,9 @@ guides you through _building_ a sleep tracking App from scratch so you can _understand_ how it works. Expect it take around **`20 minutes`** to complete. -Set your pomodoro timer and turn off other distractions! +Set your +[pomodoro](https://en.wikipedia.org/wiki/Pomodoro_Technique) +timer and turn off other distractions!
@@ -31,10 +33,10 @@ that we can get up-and-running with a **basic interface**, **saving data** to the database, **authentication** -and ***deployment*** +and ***testing*** in **`20 minutes`**.
Anyone who knows basic programming -(e.g. `Python`, `JavaScript`, etc.) +(e.g. `JavaScript`, `PHP`, `Python`, `Ruby`, etc.) should be able to follow along. If you are completely **new** to Phoenix or LiveView, we recommend starting with the more basic @@ -52,6 +54,27 @@ https://twitter.com/iamdevloper/status/787969734918668289 -->
+## Before You Start + +Check you have the **latest** version of **Phoenix**, +run the following command in your terminal window: + +```sh +mix phx.new -v +``` + +You should see: + +```sh +Phoenix v1.6.6 +``` + +If not, install it now: +https://hexdocs.pm/phoenix/installation.html + + +
+ ## 1. Create a New Phoenix App 🆕 In a new terminal window, run the following command: @@ -400,26 +423,188 @@ Finished in 0.2 seconds (0.1s async, 0.1s sync) Randomized with seed 575721 ``` +
+ +## 8. Test Coverage + Quick Tidy-up + +> This is a **100% optional `3 minute`** +[Sidequest](https://en.wiktionary.org/wiki/sidequest). +If you speed-run it, +you can easily do it in a **`2 mins`**. +But if you prefer to skip head +and continue with the tutorial, +scroll down to Step 9 below. + +
-## 8. Create Database Schema +### _Why_ Test Coverage? -We could work on the interface first -and then figure out how to store data +When building software projects +we try to ensure that all files are tested +and if we cannot test them, +we want to know _why_. + +This has **_multiple_ benefits** including: + +1. **Assurance** that code we write is tested +which reduces undesired behaviour (bugs). +2. **Warning** when new (_untested_) code is introduced +because the coverage level decreases. +3. **Understanding** the parts of the Phoenix Web Framework +and uncover any "magic". + +Let's crack on! + +
+ +### Add `ExCoveralls` to the Dependencies + +Open the `mix.exs` file, +locate the `defp deps do` block and +add the following lines to the list: + +```elixir +# Check test coverage: https://github.com/parroty/excoveralls +{:excoveralls, "~> 0.14.3", only: :test}, +``` + +Next in the `def project do` section of `mix.exs`, +add the lines to the list: + +```elixir +test_coverage: [tool: ExCoveralls], +preferred_cli_env: [ + coveralls: :test, + "coveralls.detail": :test, + "coveralls.post": :test, + "coveralls.html": :test, + "coveralls.json": :test +], +``` + +After saving the the `mix.exs` file, +download the dependencies: + +```sh +mix deps.get +``` + +Once the dependencies are downloaded, +run the tests with coverage +by executing the command: + +### Run the + +```sh +mix coveralls.html +``` + + +```sh +open ./cover/excoveralls.html +``` + +There are several auto-generated +files when you create a Phoenix project. +These are necessary for the project to function +but are + + + +Create a new file +in the root of your project +called `coveralls.json` +and paste the following code in: + +```json +{ + "coverage_options": { + "minimum_coverage": 100 + }, + "skip_files": [ + "test/", + "lib/app/application.ex", + "lib/app/release.ex", + "lib/app_web.ex", + "lib/app_web/views/error_helpers.ex", + "lib/app_web/channels/user_socket.ex", + "lib/app_web/telemetry.ex" + ] +} +``` + + + + +### Ignore Phoenix Files We Cannot Test + +The files we cannot test, we ignore for coverage purposes. + + + + + + +
+ +## 9. Create Database Schema + +Our next step is to think about the data +we want to store for our Sleep Tracking App. + +> **Note**: Some people prefer to work on +the _interface_ of an App first +and then figure out how to store data. +We prefer to think about the _data_ +an App is going to capture/use _first_ +as it's the "easy" part. + +> To understand _why_, watch +"Make Data Structures" by Richard Feldman: +https://youtu.be/x1FU3e0sT1I + + + + + +# Continue + +/Users/n/code/phoenix-liveview-chat-example +https://github.com/dwyl/sleep/blob/basic-sleep-app-issue-%2353/ +https://github.com/dwyl/sleep/blob/basic-sleep-app-issue-%2353/tutorial.md + + +
+ ## X. Start a Sleep Timer + + +
+ ## X. Stop a Running Sleep Timer -## X. Display Past Timers +
+## X. Display Past Timers +
## X. Authentication +
+ +## X. + + +[![HitCount](http://hits.dwyl.com/dwyl/sleep-tutorial.svg?style=flat-square)](http://hits.dwyl.com/dwyl/sleep) -[![HitCount](http://hits.dwyl.com/dwyl/sleep-tutorial.svg?style=flat-square)](http://hits.dwyl.com/dwyl/sleep) \ No newline at end of file +See: +[`Phoenix.LiveViewTest`](https://hexdocs.pm/phoenix_live_view/Phoenix.LiveViewTest.html) +for more info on testing and LiveView. \ No newline at end of file