From 6a63697a4447cdc1d14609f3bfa48fd0bb5bbde7 Mon Sep 17 00:00:00 2001 From: SimonLab Date: Mon, 14 Nov 2022 15:39:24 +0000 Subject: [PATCH 01/15] start replacing tags input --- assets/js/app.js | 16 +++++++++- lib/app_web.ex | 2 +- lib/app_web/live/app_live.ex | 7 +++-- lib/app_web/live/app_live.html.heex | 45 ++++++++++++++++++++++------- 4 files changed, 54 insertions(+), 16 deletions(-) diff --git a/assets/js/app.js b/assets/js/app.js index 4db090ea..5a396ef5 100644 --- a/assets/js/app.js +++ b/assets/js/app.js @@ -5,8 +5,22 @@ import {Socket} from "phoenix" import {LiveSocket} from "phoenix_live_view" import topbar from "../vendor/topbar" + +let Hooks = {} let csrfToken = document.querySelector("meta[name='csrf-token']").getAttribute("content") -let liveSocket = new LiveSocket("/live", Socket, {params: {_csrf_token: csrfToken}}) + +let liveSocket = new LiveSocket("/live", Socket, { + hooks: Hooks, + dom:{ + onBeforeElUpdated(from, to) { + if (from._x_dataStack) { + window.Alpine.clone(from, to) + } + } + }, + params: {_csrf_token: csrfToken} +}) + // Show progress bar on live navigation and form submits topbar.config({barColors: {0: "#29d"}, shadowColor: "rgba(0, 0, 0, .3)"}) diff --git a/lib/app_web.ex b/lib/app_web.ex index ca3311b4..7b58fcc3 100644 --- a/lib/app_web.ex +++ b/lib/app_web.ex @@ -44,7 +44,7 @@ defmodule AppWeb do def live_view do quote do use Phoenix.LiveView, - layout: {AppWeb.LayoutView, "live.html"} + layout: {AppWeb.LayoutView, :live} unquote(view_helpers()) end diff --git a/lib/app_web/live/app_live.ex b/lib/app_web/live/app_live.ex index 060120c1..1219c6ea 100644 --- a/lib/app_web/live/app_live.ex +++ b/lib/app_web/live/app_live.ex @@ -1,9 +1,8 @@ defmodule AppWeb.AppLive do require Logger - use AppWeb, :live_view use Timex - alias App.{Item, Timer} + alias App.{Item, Tag, Timer} # run authentication on mount on_mount AppWeb.AuthController alias Phoenix.Socket.Broadcast @@ -19,6 +18,7 @@ defmodule AppWeb.AppLive do person_id = get_person_id(socket.assigns) items = Item.items_with_timers(person_id) + tags = Tag.list_person_tags(person_id) {:ok, assign(socket, @@ -26,7 +26,8 @@ defmodule AppWeb.AppLive do editing_timers: [], editing: nil, filter: "active", - filter_tag: nil + filter_tag: nil, + tags: tags )} end diff --git a/lib/app_web/live/app_live.html.heex b/lib/app_web/live/app_live.html.heex index db127c54..f09df938 100644 --- a/lib/app_web/live/app_live.html.heex +++ b/lib/app_web/live/app_live.html.heex @@ -1,10 +1,5 @@ -
-
- +
+ + +
- + +
+
    + <%= for tag <- @tags do %> +
  • + <%= tag.text %> +
  • + <% end %> +
+
+
+ -
From dcf77340c45f22b91e0029579935b63629c52124 Mon Sep 17 00:00:00 2001 From: SimonLab Date: Mon, 21 Nov 2022 13:48:59 +0000 Subject: [PATCH 02/15] Remove unused file Remove nav.html as it is not used --- lib/app_web/templates/layout/nav.html.heex | 36 ---------------------- 1 file changed, 36 deletions(-) delete mode 100644 lib/app_web/templates/layout/nav.html.heex diff --git a/lib/app_web/templates/layout/nav.html.heex b/lib/app_web/templates/layout/nav.html.heex deleted file mode 100644 index 2fb8bce6..00000000 --- a/lib/app_web/templates/layout/nav.html.heex +++ /dev/null @@ -1,36 +0,0 @@ - -<%= render("nav.html", conn: @conn) %> -
- -
From 822d82bee82f1657192f8358bdfa2774c72eb7d0 Mon Sep 17 00:00:00 2001 From: SimonLab Date: Mon, 21 Nov 2022 14:35:01 +0000 Subject: [PATCH 03/15] Update UI for text, tags form Update width for large screen --- assets/css/app.css | 1 + lib/app_web/live/app_live.html.heex | 14 ++++++++------ 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/assets/css/app.css b/assets/css/app.css index 3f3dbc60..eca5b057 100644 --- a/assets/css/app.css +++ b/assets/css/app.css @@ -84,3 +84,4 @@ input[type=radio].has-error:not(.phx-no-feedback) { 100% { opacity: 1; } } +[x-cloak] { display: none !important; } diff --git a/lib/app_web/live/app_live.html.heex b/lib/app_web/live/app_live.html.heex index f09df938..21261340 100644 --- a/lib/app_web/live/app_live.html.heex +++ b/lib/app_web/live/app_live.html.heex @@ -1,5 +1,5 @@ -
- +
+ - +
= 0.0.0"}, {:phoenix_html, "~> 3.0"}, {:phoenix_live_reload, "~> 1.2", only: :dev}, - {:phoenix_live_view, "~> 0.18.0"}, + {:phoenix_live_view, "~> 0.18.3"}, {:floki, ">= 0.30.0", only: :test}, {:esbuild, "~> 0.4", runtime: Mix.env() == :dev}, {:telemetry_metrics, "~> 0.6"}, diff --git a/mix.lock b/mix.lock index 12548ae1..345bd61e 100644 --- a/mix.lock +++ b/mix.lock @@ -3,7 +3,7 @@ "atomic_map": {:hex, :atomic_map, "0.9.3", "3c7f1302e0590164732d08ca999708efbb2cd768abf2911cf140280ce2dc499d", [:mix], [], "hexpm", "c237babf301bd2435bd85b96cffc973022b4cbb7721537059ee0dd3bb74938d2"}, "auth_plug": {:hex, :auth_plug, "1.4.20", "537fe997e647a59f7777795e75e669bcb36e7203bad6933fccbe2f36bc408b6b", [:mix], [{:envar, "~> 1.0.8", [hex: :envar, repo: "hexpm", optional: false]}, {:httpoison, "~> 1.8.0", [hex: :httpoison, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}, {:joken, "~> 2.5", [hex: :joken, repo: "hexpm", optional: false]}, {:plug, "~> 1.10", [hex: :plug, repo: "hexpm", optional: false]}, {:useful, "~> 1.0.8", [hex: :useful, repo: "hexpm", optional: false]}], "hexpm", "fcf38a52eb4e83e31da7478e831567d1bff3138375e027576b282ae819b25482"}, "bunt": {:hex, :bunt, "0.2.1", "e2d4792f7bc0ced7583ab54922808919518d0e57ee162901a16a1b6664ef3b14", [:mix], [], "hexpm", "a330bfb4245239787b15005e66ae6845c9cd524a288f0d141c148b02603777a5"}, - "castore": {:hex, :castore, "0.1.18", "deb5b9ab02400561b6f5708f3e7660fc35ca2d51bfc6a940d2f513f89c2975fc", [:mix], [], "hexpm", "61bbaf6452b782ef80b33cdb45701afbcf0a918a45ebe7e73f1130d661e66a06"}, + "castore": {:hex, :castore, "0.1.19", "a2c3e46d62b7f3aa2e6f88541c21d7400381e53704394462b9fd4f06f6d42bb6", [:mix], [], "hexpm", "e96e0161a5dc82ef441da24d5fa74aefc40d920f3a6645d15e1f9f3e66bb2109"}, "certifi": {:hex, :certifi, "2.9.0", "6f2a475689dd47f19fb74334859d460a2dc4e3252a3324bd2111b8f0429e7e21", [:rebar3], [], "hexpm", "266da46bdb06d6c6d35fde799bcb28d36d985d424ad7c08b5bb48f5b5cdd4641"}, "combine": {:hex, :combine, "0.10.0", "eff8224eeb56498a2af13011d142c5e7997a80c8f5b97c499f84c841032e429f", [:mix], [], "hexpm", "1b1dbc1790073076580d0d1d64e42eae2366583e7aecd455d1215b0d16f2451b"}, "comeonin": {:hex, :comeonin, "5.3.3", "2c564dac95a35650e9b6acfe6d2952083d8a08e4a89b93a481acb552b325892e", [:mix], [], "hexpm", "3e38c9c2cb080828116597ca8807bb482618a315bfafd98c90bc22a821cc84df"}, @@ -45,15 +45,16 @@ "nimble_parsec": {:hex, :nimble_parsec, "1.2.3", "244836e6e3f1200c7f30cb56733fd808744eca61fd182f731eac4af635cc6d0b", [:mix], [], "hexpm", "c8d789e39b9131acf7b99291e93dae60ab48ef14a7ee9d58c6964f59efb570b0"}, "parse_trans": {:hex, :parse_trans, "3.3.1", "16328ab840cc09919bd10dab29e431da3af9e9e7e7e6f0089dd5a2d2820011d8", [:rebar3], [], "hexpm", "07cd9577885f56362d414e8c4c4e6bdf10d43a8767abb92d24cbe8b24c54888b"}, "petal_components": {:hex, :petal_components, "0.18.5", "f7abd370d179e8ab1eff491a7a85526984ead78b41190b03f6ec5df04932cdbf", [:mix], [{:heroicons, "~> 0.5.0", [hex: :heroicons, repo: "hexpm", optional: false]}, {:phoenix, "~> 1.6", [hex: :phoenix, repo: "hexpm", optional: false]}, {:phoenix_ecto, "~> 4.4", [hex: :phoenix_ecto, repo: "hexpm", optional: false]}, {:phoenix_live_view, "~> 0.18.0", [hex: :phoenix_live_view, repo: "hexpm", optional: false]}], "hexpm", "d38982b0e9fa39884cfaf5e49bdc77a6be16b17b73fc19001b2a27fe4b672dca"}, - "phoenix": {:hex, :phoenix, "1.6.14", "57678366dc1d5bad49832a0fc7f12c2830c10d3eacfad681bfe9602cd4445f04", [:mix], [{:castore, ">= 0.0.0", [hex: :castore, repo: "hexpm", optional: false]}, {: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", "d48c0da00b3d4cd1aad6055387917491af9f6e1f1e96cedf6c6b7998df9dba26"}, + "phoenix": {:hex, :phoenix, "1.6.15", "0a1d96bbc10747fd83525370d691953cdb6f3ccbac61aa01b4acb012474b047d", [:mix], [{:castore, ">= 0.0.0", [hex: :castore, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:phoenix_pubsub, "~> 2.0", [hex: :phoenix_pubsub, repo: "hexpm", optional: false]}, {:phoenix_view, "~> 1.0 or ~> 2.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", "d70ab9fbf6b394755ea88b644d34d79d8b146e490973151f248cacd122d20672"}, "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"}, "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.18.2", "635cf07de947235deb030cd6b776c71a3b790ab04cebf526aa8c879fe17c7784", [:mix], [{:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:phoenix, "~> 1.6 or ~> 1.7", [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", "da287a77327e996cc166e4c440c3ad5ab33ccdb151b91c793209b39ebbce5b75"}, + "phoenix_live_view": {:hex, :phoenix_live_view, "0.18.3", "2e3d009422addf8b15c3dccc65ce53baccbe26f7cfd21d264680b5867789a9c1", [:mix], [{:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:phoenix, "~> 1.6.15 or ~> 1.7.0", [hex: :phoenix, repo: "hexpm", optional: false]}, {:phoenix_html, "~> 3.1", [hex: :phoenix_html, repo: "hexpm", optional: false]}, {:phoenix_template, "~> 1.0", [hex: :phoenix_template, repo: "hexpm", optional: false]}, {:phoenix_view, "~> 2.0", [hex: :phoenix_view, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4.2 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "c8845177a866e017dcb7083365393c8f00ab061b8b6b2bda575891079dce81b2"}, "phoenix_pubsub": {:hex, :phoenix_pubsub, "2.1.1", "ba04e489ef03763bf28a17eb2eaddc2c20c6d217e2150a61e3298b0f4c2012b5", [:mix], [], "hexpm", "81367c6d1eea5878ad726be80808eb5a787a23dee699f96e72b1109c57cdd8d9"}, - "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.6", "187beb6b67c6cec50503e940f0434ea4692b19384d47e5fdfd701e93cadb4cc2", [: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", "02b9c6b9955bce92c829f31d6284bf53c591ca63c4fb9ff81dfd0418667a34ff"}, - "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"}, + "phoenix_template": {:hex, :phoenix_template, "1.0.0", "c57bc5044f25f007dc86ab21895688c098a9f846a8dda6bc40e2d0ddc146e38f", [:mix], [{:phoenix_html, "~> 2.14.2 or ~> 3.0", [hex: :phoenix_html, repo: "hexpm", optional: true]}], "hexpm", "1b066f99a26fd22064c12b2600a9a6e56700f591bf7b20b418054ea38b4d4357"}, + "phoenix_view": {:hex, :phoenix_view, "2.0.2", "6bd4d2fd595ef80d33b439ede6a19326b78f0f1d8d62b9a318e3d9c1af351098", [:mix], [{:phoenix_html, "~> 2.14.2 or ~> 3.0", [hex: :phoenix_html, repo: "hexpm", optional: true]}, {:phoenix_template, "~> 1.0", [hex: :phoenix_template, repo: "hexpm", optional: false]}], "hexpm", "a929e7230ea5c7ee0e149ffcf44ce7cf7f4b6d2bfe1752dd7c084cdff152d36f"}, + "plug": {:hex, :plug, "1.14.0", "ba4f558468f69cbd9f6b356d25443d0b796fbdc887e03fa89001384a9cac638f", [: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", "bf020432c7d4feb7b3af16a0c2701455cbbbb95e5b6866132cb09eb0c29adc14"}, + "plug_cowboy": {:hex, :plug_cowboy, "2.6.0", "d1cf12ff96a1ca4f52207c5271a6c351a4733f413803488d75b70ccf44aebec2", [:mix], [{:cowboy, "~> 2.7", [hex: :cowboy, repo: "hexpm", optional: false]}, {:cowboy_telemetry, "~> 0.3", [hex: :cowboy_telemetry, repo: "hexpm", optional: false]}, {:plug, "~> 1.14", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm", "073cf20b753ce6682ed72905cd62a2d4bd9bad1bf9f7feb02a1b8e525bd94fa6"}, "plug_crypto": {:hex, :plug_crypto, "1.2.3", "8f77d13aeb32bfd9e654cb68f0af517b371fb34c56c9f2b58fe3df1235c1251a", [:mix], [], "hexpm", "b5672099c6ad5c202c45f5a403f21a3411247f164e4a8fab056e5cd8a290f4a2"}, "postgrex": {:hex, :postgrex, "0.16.5", "fcc4035cc90e23933c5d69a9cd686e329469446ef7abba2cf70f08e2c4b69810", [: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]}, {:table, "~> 0.1.0", [hex: :table, repo: "hexpm", optional: true]}], "hexpm", "edead639dc6e882618c01d8fc891214c481ab9a3788dfe38dd5e37fd1d5fb2e8"}, "pre_commit": {:hex, :pre_commit, "0.3.4", "e2850f80be8090d50ad8019ef2426039307ff5dfbe70c736ad0d4d401facf304", [:mix], [], "hexpm", "16f684ba4f1fed1cba6b19e082b0f8d696e6f1c679285fedf442296617ba5f4e"}, From 2a979a0406a3fd383c34a998c3988ea0b4748a6d Mon Sep 17 00:00:00 2001 From: SimonLab Date: Mon, 21 Nov 2022 15:15:24 +0000 Subject: [PATCH 05/15] Remove format check in CI Remove mix format --check-formatted The mix format add new line for the textarea html tag which add spaces in the item content --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 96a5a36d..e1851337 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -43,8 +43,8 @@ jobs: deps-${{ runner.os }}-${{ matrix.otp }}-${{ matrix.elixir }} - name: Install dependencies run: mix deps.get - - name: Check code is formatted - run: mix format --check-formatted + # - name: Check code is formatted + # run: mix format --check-formatted - name: Run Tests run: mix coveralls.json env: From c2644198cd40e9aa088d5daf11ecb26dfcc9f704 Mon Sep 17 00:00:00 2001 From: SimonLab Date: Mon, 21 Nov 2022 15:48:04 +0000 Subject: [PATCH 06/15] Display pill for tag's colour Display tag colour in dropdown --- lib/app_web/live/app_live.html.heex | 34 ++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/lib/app_web/live/app_live.html.heex b/lib/app_web/live/app_live.html.heex index 0b9115f2..7829f429 100644 --- a/lib/app_web/live/app_live.html.heex +++ b/lib/app_web/live/app_live.html.heex @@ -43,10 +43,38 @@ x-transition x-cloak > -
    +
      <%= for tag <- @tags do %> -
    • - <%= tag.text %> +
    • +
      +
      + + + + <%= tag.text %> + +
      + <%= if true do %> + + + + <% end %> +
    • <% end %>
    From 1deaf367995a64f8245abc69e919dc629af63593 Mon Sep 17 00:00:00 2001 From: SimonLab Date: Tue, 22 Nov 2022 14:38:05 +0000 Subject: [PATCH 07/15] Make button/link in nav clickable Make the svg in the link clickable see https://github.com/dwyl/mvp/issues/213 --- lib/app_web/live/app_live.html.heex | 7 ++- lib/app_web/templates/layout/root.html.heex | 52 +++++++++++---------- 2 files changed, 31 insertions(+), 28 deletions(-) diff --git a/lib/app_web/live/app_live.html.heex b/lib/app_web/live/app_live.html.heex index 7829f429..f783e8cc 100644 --- a/lib/app_web/live/app_live.html.heex +++ b/lib/app_web/live/app_live.html.heex @@ -4,7 +4,7 @@ class="w-full py-1 px-1 text-slate-800 text-3xl bg-white bg-clip-padding resize-none - max-h-80 + max-h-100 transition ease-in-out border border-b border-slate-200 focus:border-none focus:outline-none @@ -14,7 +14,7 @@ autofocus="true" required="required" x-data="{resize() { - $el.style.height = '80px'; + $el.style.height = '100px'; $el.style.height = $el.scrollHeight + 'px'; } }" @@ -22,7 +22,7 @@ x-on:input="resize" phx-no-format > - +
    -
    +
    + <%= link to: "/logout", class: "inline-flex items-center font-bold" do %> + + + + + Logout + <% end %> +
    +
    + <% else %> +
    + <%= link to: "/login" , class: "inline-flex items-cennter font-bold" do %> - - + - <%= link("logout", to: "/logout", class: "flex-1") %> -
    -
- <% else %> -
- - - - <%= link("login", to: "/login", class: "flex-1") %> + Login + <% end %>
<% end %>
From a03fca6b5943c4a6c9610316e29c5bcddec56753 Mon Sep 17 00:00:00 2001 From: SimonLab Date: Wed, 23 Nov 2022 11:16:04 +0000 Subject: [PATCH 08/15] Add edit tag link in select dropdown Add link to /tags to allow user to access the edit tags page easily for example when no tags are displayed yet in the dropdwn --- lib/app_web/live/app_live.html.heex | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/app_web/live/app_live.html.heex b/lib/app_web/live/app_live.html.heex index f783e8cc..6cdb58c3 100644 --- a/lib/app_web/live/app_live.html.heex +++ b/lib/app_web/live/app_live.html.heex @@ -21,8 +21,9 @@ x-init="resize" x-on:input="resize" phx-no-format - > - + > + +
<% end %> +
  • + <%= link("edit tags", to: "/tags", class: "block w-full text-center") %> +
  • From d46b79bbc65f7ec25448708c1114bf6b98ada104 Mon Sep 17 00:00:00 2001 From: SimonLab Date: Wed, 23 Nov 2022 15:31:42 +0000 Subject: [PATCH 09/15] Associate the selected tags to the new item - Display check for selected tags - Link selected tags to the created item --- lib/app/item.ex | 2 +- lib/app/tag.ex | 14 +++++++------- lib/app/timer.ex | 1 - lib/app_web/live/app_live.ex | 27 +++++++++++++++++++++++---- lib/app_web/live/app_live.html.heex | 21 +++++++++++++-------- 5 files changed, 44 insertions(+), 21 deletions(-) diff --git a/lib/app/item.ex b/lib/app/item.ex index 2d985496..4cffdaea 100644 --- a/lib/app/item.ex +++ b/lib/app/item.ex @@ -26,7 +26,7 @@ defmodule App.Item do def changeset_with_tags(item, attrs) do changeset(item, attrs) - |> put_assoc(:tags, Tag.parse_and_create_tags(attrs)) + |> put_assoc(:tags, attrs.tags) end @doc """ diff --git a/lib/app/tag.ex b/lib/app/tag.ex index a331a31a..fed71083 100644 --- a/lib/app/tag.ex +++ b/lib/app/tag.ex @@ -28,13 +28,13 @@ defmodule App.Tag do |> Repo.insert() end - def parse_and_create_tags(attrs) do - (attrs[:tags] || "") - |> String.split(",") - |> Enum.map(&String.trim/1) - |> Enum.reject(&(&1 == "")) - |> create_tags(attrs[:person_id]) - end +# def parse_and_create_tags(attrs) do +# (attrs[:tags] || "") +# |> String.split(",") +# |> Enum.map(&String.trim/1) +# |> Enum.reject(&(&1 == "")) +# |> create_tags(attrs[:person_id]) +# end @doc """ Insert the list of tag names given as argument. diff --git a/lib/app/timer.ex b/lib/app/timer.ex index 0063579c..87777c19 100644 --- a/lib/app/timer.ex +++ b/lib/app/timer.ex @@ -379,7 +379,6 @@ defmodule App.Timer do res = Ecto.Adapters.SQL.query!(Repo, sql, [item_id]) if res.num_rows > 0 do - # IO.inspect(res.rows) timer_id = res.rows |> List.first() |> List.first() Logger.debug( diff --git a/lib/app_web/live/app_live.ex b/lib/app_web/live/app_live.ex index 1219c6ea..144e6772 100644 --- a/lib/app_web/live/app_live.ex +++ b/lib/app_web/live/app_live.ex @@ -4,7 +4,7 @@ defmodule AppWeb.AppLive do use Timex alias App.{Item, Tag, Timer} # run authentication on mount - on_mount AppWeb.AuthController + on_mount(AppWeb.AuthController) alias Phoenix.Socket.Broadcast @topic "live" @@ -19,6 +19,8 @@ defmodule AppWeb.AppLive do person_id = get_person_id(socket.assigns) items = Item.items_with_timers(person_id) tags = Tag.list_person_tags(person_id) + changeset = Item.changeset(%Item{}, %{}) + selected_tags = [] {:ok, assign(socket, @@ -27,19 +29,21 @@ defmodule AppWeb.AppLive do editing: nil, filter: "active", filter_tag: nil, - tags: tags + tags: tags, + changeset: changeset, + selected_tags: selected_tags )} end @impl true - def handle_event("create", %{"text" => text, "tags" => tags}, socket) do + def handle_event("create", %{"text" => text}, socket) do person_id = get_person_id(socket.assigns) Item.create_item_with_tags(%{ text: text, person_id: person_id, status: 2, - tags: tags + tags: socket.assigns.selected_tags }) AppWeb.Endpoint.broadcast(@topic, "update", :create) @@ -60,6 +64,21 @@ defmodule AppWeb.AppLive do {:noreply, socket} end + @impl true + def handle_event("toggle_tag", value, socket) do + selected_tags = socket.assigns.selected_tags + tag = Tag.get_tag!(value["tag_id"]) + + selected_tags = + if Enum.member?(selected_tags, tag) do + List.delete(selected_tags, tag) + else + [tag | selected_tags] + end + + {:noreply, assign(socket, selected_tags: selected_tags)} + end + @impl true def handle_event("delete", %{"id" => item_id}, socket) do Item.delete_item(item_id) diff --git a/lib/app_web/live/app_live.html.heex b/lib/app_web/live/app_live.html.heex index 6cdb58c3..489a4752 100644 --- a/lib/app_web/live/app_live.html.heex +++ b/lib/app_web/live/app_live.html.heex @@ -1,5 +1,10 @@
    - + <.form + :let={_f} + for={@changeset} + phx-submit="create" + class="w-full lg:w-1/2 m-auto" + > + >
  • @@ -61,7 +66,7 @@ <%= tag.text %>
    - <%= if true do %> + <%= if Enum.member?(@selected_tags, tag) do %>
  • - + @@ -108,7 +113,7 @@ Save - +
      <%= for item <- filter_items(@items, @filter, @filter_tag) do %> From db56c231a6b672448b3d5e4b581fe34dd3104f02 Mon Sep 17 00:00:00 2001 From: SimonLab Date: Wed, 23 Nov 2022 15:51:56 +0000 Subject: [PATCH 10/15] Display selected tags Display the current selected tags under the search input --- lib/app_web/live/app_live.html.heex | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/app_web/live/app_live.html.heex b/lib/app_web/live/app_live.html.heex index 489a4752..d6f4d2e9 100644 --- a/lib/app_web/live/app_live.html.heex +++ b/lib/app_web/live/app_live.html.heex @@ -26,7 +26,8 @@ x-init="resize" x-on:input="resize" phx-no-format - > + > +
      + +
      + <%= for selected_tag <- @selected_tags do %> + + <%= selected_tag.text %> + + <% end %> +
      From 8c6cd75094d89950185d0b12a061ce6ef031e43c Mon Sep 17 00:00:00 2001 From: SimonLab Date: Wed, 23 Nov 2022 21:51:14 +0000 Subject: [PATCH 11/15] Use phx-change to track item text value Keep track of the item value. Avoid reset the text item when selecting a tag --- lib/app/tag.ex | 14 +++++++------- lib/app_web/live/app_live.ex | 26 ++++++++++++++++++++++++-- lib/app_web/live/app_live.html.heex | 9 +++++---- 3 files changed, 36 insertions(+), 13 deletions(-) diff --git a/lib/app/tag.ex b/lib/app/tag.ex index fed71083..5133c880 100644 --- a/lib/app/tag.ex +++ b/lib/app/tag.ex @@ -28,13 +28,13 @@ defmodule App.Tag do |> Repo.insert() end -# def parse_and_create_tags(attrs) do -# (attrs[:tags] || "") -# |> String.split(",") -# |> Enum.map(&String.trim/1) -# |> Enum.reject(&(&1 == "")) -# |> create_tags(attrs[:person_id]) -# end + # def parse_and_create_tags(attrs) do + # (attrs[:tags] || "") + # |> String.split(",") + # |> Enum.map(&String.trim/1) + # |> Enum.reject(&(&1 == "")) + # |> create_tags(attrs[:person_id]) + # end @doc """ Insert the list of tag names given as argument. diff --git a/lib/app_web/live/app_live.ex b/lib/app_web/live/app_live.ex index 144e6772..8acb52b8 100644 --- a/lib/app_web/live/app_live.ex +++ b/lib/app_web/live/app_live.ex @@ -31,10 +31,16 @@ defmodule AppWeb.AppLive do filter_tag: nil, tags: tags, changeset: changeset, - selected_tags: selected_tags + selected_tags: selected_tags, + text_value: "" )} end + @impl true + def handle_event("validate", %{"text" => text}, socket) do + {:noreply, assign(socket, text_value: text)} + end + @impl true def handle_event("create", %{"text" => text}, socket) do person_id = get_person_id(socket.assigns) @@ -66,8 +72,10 @@ defmodule AppWeb.AppLive do @impl true def handle_event("toggle_tag", value, socket) do + person_id = get_person_id(socket.assigns) selected_tags = socket.assigns.selected_tags tag = Tag.get_tag!(value["tag_id"]) + tags = Tag.list_person_tags(person_id) selected_tags = if Enum.member?(selected_tags, tag) do @@ -75,8 +83,22 @@ defmodule AppWeb.AppLive do else [tag | selected_tags] end + |> Enum.sort_by(& &1.text) + + {:noreply, assign(socket, tags: tags, selected_tags: selected_tags)} + end + + @impl true + def handle_event("filter-tags", %{"key" => _key, "value" => value}, socket) do + person_id = get_person_id(socket.assigns) + + tags = + Tag.list_person_tags(person_id) + |> Enum.filter(fn t -> + String.contains?(String.downcase(t.text), String.downcase(value)) + end) - {:noreply, assign(socket, selected_tags: selected_tags)} + {:noreply, assign(socket, tags: tags)} end @impl true diff --git a/lib/app_web/live/app_live.html.heex b/lib/app_web/live/app_live.html.heex index d6f4d2e9..356f58fb 100644 --- a/lib/app_web/live/app_live.html.heex +++ b/lib/app_web/live/app_live.html.heex @@ -2,6 +2,7 @@ <.form :let={_f} for={@changeset} + phx-change="validate" phx-submit="create" class="w-full lg:w-1/2 m-auto" > @@ -25,9 +26,7 @@ }" x-init="resize" x-on:input="resize" - phx-no-format - > - + ><%= @text_value %>
      @@ -93,7 +94,7 @@ -
      +
      <%= for selected_tag <- @selected_tags do %> Date: Thu, 24 Nov 2022 07:03:34 +0000 Subject: [PATCH 12/15] Remove changeset for item Remove changeset as not used in form --- lib/app_web/live/app_live.ex | 4 +--- lib/app_web/live/app_live.html.heex | 4 ++-- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/lib/app_web/live/app_live.ex b/lib/app_web/live/app_live.ex index 8acb52b8..4217847a 100644 --- a/lib/app_web/live/app_live.ex +++ b/lib/app_web/live/app_live.ex @@ -19,7 +19,6 @@ defmodule AppWeb.AppLive do person_id = get_person_id(socket.assigns) items = Item.items_with_timers(person_id) tags = Tag.list_person_tags(person_id) - changeset = Item.changeset(%Item{}, %{}) selected_tags = [] {:ok, @@ -30,7 +29,6 @@ defmodule AppWeb.AppLive do filter: "active", filter_tag: nil, tags: tags, - changeset: changeset, selected_tags: selected_tags, text_value: "" )} @@ -53,7 +51,7 @@ defmodule AppWeb.AppLive do }) AppWeb.Endpoint.broadcast(@topic, "update", :create) - {:noreply, socket} + {:noreply, assign(socket, text_value: "", selected_tags: [])} end @impl true diff --git a/lib/app_web/live/app_live.html.heex b/lib/app_web/live/app_live.html.heex index 356f58fb..5a99f00f 100644 --- a/lib/app_web/live/app_live.html.heex +++ b/lib/app_web/live/app_live.html.heex @@ -1,8 +1,7 @@
      <.form :let={_f} - for={@changeset} - phx-change="validate" + for={:item} phx-submit="create" class="w-full lg:w-1/2 m-auto" > @@ -16,6 +15,7 @@ focus:border-none focus:outline-none my-2" name="text" + phx-change="validate" placeholder="What needs to be done?" autofocus="true" required="required" From 94e9daa3c00469e60c14d6a0401a62ba02180840 Mon Sep 17 00:00:00 2001 From: SimonLab Date: Mon, 28 Nov 2022 15:53:38 +0000 Subject: [PATCH 13/15] Update tests Update test after changes made for selecting tags --- lib/app/item.ex | 10 +++++----- lib/app_web/live/app_live.ex | 5 ++--- lib/app_web/live/app_live.html.heex | 4 ++-- mix.lock | 20 ++++++++++---------- test/app/item_test.exs | 4 ++-- test/app_web/live/app_live_test.exs | 17 ++++++++++++----- 6 files changed, 33 insertions(+), 27 deletions(-) diff --git a/lib/app/item.ex b/lib/app/item.ex index 4cffdaea..e93a68ea 100644 --- a/lib/app/item.ex +++ b/lib/app/item.ex @@ -117,11 +117,11 @@ defmodule App.Item do @doc """ Update an item and its associated tags """ - def update_item_with_tags(%Item{} = item, attrs) do - item - |> Item.changeset_with_tags(attrs) - |> Repo.update() - end + #def update_item_with_tags(%Item{} = item, attrs) do + # item + # |> Item.changeset_with_tags(attrs) + # |> Repo.update() + #end def delete_item(id) do get_item!(id) diff --git a/lib/app_web/live/app_live.ex b/lib/app_web/live/app_live.ex index 4217847a..21f8c6b8 100644 --- a/lib/app_web/live/app_live.ex +++ b/lib/app_web/live/app_live.ex @@ -144,15 +144,14 @@ defmodule AppWeb.AppLive do @impl true def handle_event( "update-item", - %{"id" => item_id, "text" => text, "tags" => tags}, + %{"id" => item_id, "text" => text}, socket ) do person_id = get_person_id(socket.assigns) current_item = Item.get_item!(item_id) - Item.update_item_with_tags(current_item, %{ + Item.update_item(current_item, %{ text: text, - tags: tags, person_id: person_id }) diff --git a/lib/app_web/live/app_live.html.heex b/lib/app_web/live/app_live.html.heex index 5a99f00f..a5e16016 100644 --- a/lib/app_web/live/app_live.html.heex +++ b/lib/app_web/live/app_live.html.heex @@ -263,13 +263,13 @@ required="required" value={item.text} ><%= item.text %> - + />--> diff --git a/mix.lock b/mix.lock index 345bd61e..75000bd8 100644 --- a/mix.lock +++ b/mix.lock @@ -1,7 +1,7 @@ %{ "argon2_elixir": {:hex, :argon2_elixir, "3.0.0", "fd4405f593e77b525a5c667282172dd32772d7c4fa58cdecdaae79d2713b6c5f", [:make, :mix], [{:comeonin, "~> 5.3", [hex: :comeonin, repo: "hexpm", optional: false]}, {:elixir_make, "~> 0.6", [hex: :elixir_make, repo: "hexpm", optional: false]}], "hexpm", "8b753b270af557d51ba13fcdebc0f0ab27a2a6792df72fd5a6cf9cfaffcedc57"}, "atomic_map": {:hex, :atomic_map, "0.9.3", "3c7f1302e0590164732d08ca999708efbb2cd768abf2911cf140280ce2dc499d", [:mix], [], "hexpm", "c237babf301bd2435bd85b96cffc973022b4cbb7721537059ee0dd3bb74938d2"}, - "auth_plug": {:hex, :auth_plug, "1.4.20", "537fe997e647a59f7777795e75e669bcb36e7203bad6933fccbe2f36bc408b6b", [:mix], [{:envar, "~> 1.0.8", [hex: :envar, repo: "hexpm", optional: false]}, {:httpoison, "~> 1.8.0", [hex: :httpoison, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}, {:joken, "~> 2.5", [hex: :joken, repo: "hexpm", optional: false]}, {:plug, "~> 1.10", [hex: :plug, repo: "hexpm", optional: false]}, {:useful, "~> 1.0.8", [hex: :useful, repo: "hexpm", optional: false]}], "hexpm", "fcf38a52eb4e83e31da7478e831567d1bff3138375e027576b282ae819b25482"}, + "auth_plug": {:hex, :auth_plug, "1.4.21", "9092d4bf949d82390a49d4178321f4ee765a5cd711dea00b14abcfafe4075278", [:mix], [{:envar, "~> 1.0.8", [hex: :envar, repo: "hexpm", optional: false]}, {:httpoison, "~> 1.8.0", [hex: :httpoison, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}, {:joken, "~> 2.5", [hex: :joken, repo: "hexpm", optional: false]}, {:plug, "~> 1.10", [hex: :plug, repo: "hexpm", optional: false]}, {:useful, "~> 1.0.8", [hex: :useful, repo: "hexpm", optional: false]}], "hexpm", "4f8c13457f6447e54d7e6195ba6ef43f0c454b170cb188e2c49b76d85fff4bbd"}, "bunt": {:hex, :bunt, "0.2.1", "e2d4792f7bc0ced7583ab54922808919518d0e57ee162901a16a1b6664ef3b14", [:mix], [], "hexpm", "a330bfb4245239787b15005e66ae6845c9cd524a288f0d141c148b02603777a5"}, "castore": {:hex, :castore, "0.1.19", "a2c3e46d62b7f3aa2e6f88541c21d7400381e53704394462b9fd4f06f6d42bb6", [:mix], [], "hexpm", "e96e0161a5dc82ef441da24d5fa74aefc40d920f3a6645d15e1f9f3e66bb2109"}, "certifi": {:hex, :certifi, "2.9.0", "6f2a475689dd47f19fb74334859d460a2dc4e3252a3324bd2111b8f0429e7e21", [:rebar3], [], "hexpm", "266da46bdb06d6c6d35fde799bcb28d36d985d424ad7c08b5bb48f5b5cdd4641"}, @@ -12,26 +12,26 @@ "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"}, "credo": {:hex, :credo, "1.6.7", "323f5734350fd23a456f2688b9430e7d517afb313fbd38671b8a4449798a7854", [:mix], [{:bunt, "~> 0.2.1", [hex: :bunt, repo: "hexpm", optional: false]}, {:file_system, "~> 0.2.8", [hex: :file_system, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "41e110bfb007f7eda7f897c10bf019ceab9a0b269ce79f015d54b0dcf4fc7dd3"}, - "db_connection": {:hex, :db_connection, "2.4.2", "f92e79aff2375299a16bcb069a14ee8615c3414863a6fef93156aee8e86c2ff3", [:mix], [{:connection, "~> 1.0", [hex: :connection, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "4fe53ca91b99f55ea249693a0229356a08f4d1a7931d8ffa79289b145fe83668"}, + "db_connection": {:hex, :db_connection, "2.4.3", "3b9aac9f27347ec65b271847e6baeb4443d8474289bd18c1d6f4de655b70c94d", [:mix], [{:connection, "~> 1.0", [hex: :connection, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "c127c15b0fa6cfb32eed07465e05da6c815b032508d4ed7c116122871df73c12"}, "decimal": {:hex, :decimal, "2.0.0", "a78296e617b0f5dd4c6caf57c714431347912ffb1d0842e998e9792b5642d697", [:mix], [], "hexpm", "34666e9c55dea81013e77d9d87370fe6cb6291d1ef32f46a1600230b1d44f577"}, "earmark_parser": {:hex, :earmark_parser, "1.4.29", "149d50dcb3a93d9f3d6f3ecf18c918fb5a2d3c001b5d3305c926cddfbd33355b", [:mix], [], "hexpm", "4902af1b3eb139016aed210888748db8070b8125c2342ce3dcae4f38dcc63503"}, - "ecto": {:hex, :ecto, "3.9.1", "67173b1687afeb68ce805ee7420b4261649d5e2deed8fe5550df23bab0bc4396", [: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", "c80bb3d736648df790f7f92f81b36c922d9dd3203ca65be4ff01d067f54eb304"}, - "ecto_sql": {:hex, :ecto_sql, "3.9.0", "2bb21210a2a13317e098a420a8c1cc58b0c3421ab8e3acfa96417dab7817918c", [:mix], [{:db_connection, "~> 2.5 or ~> 2.4.1", [hex: :db_connection, repo: "hexpm", optional: false]}, {:ecto, "~> 3.9.0", [hex: :ecto, repo: "hexpm", optional: false]}, {:myxql, "~> 0.6.0", [hex: :myxql, repo: "hexpm", optional: true]}, {:postgrex, "~> 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", "a8f3f720073b8b1ac4c978be25fa7960ed7fd44997420c304a4a2e200b596453"}, + "ecto": {:hex, :ecto, "3.9.2", "017db3bc786ff64271108522c01a5d3f6ba0aea5c84912cfb0dd73bf13684108", [: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", "21466d5177e09e55289ac7eade579a642578242c7a3a9f91ad5c6583337a9d15"}, + "ecto_sql": {:hex, :ecto_sql, "3.9.1", "9bd5894eecc53d5b39d0c95180d4466aff00e10679e13a5cfa725f6f85c03c22", [:mix], [{:db_connection, "~> 2.4.1 or ~> 2.5", [hex: :db_connection, repo: "hexpm", optional: false]}, {:ecto, "~> 3.9.0", [hex: :ecto, repo: "hexpm", optional: false]}, {:myxql, "~> 0.6.0", [hex: :myxql, repo: "hexpm", optional: true]}, {:postgrex, "~> 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", "5fd470a4fff2e829bbf9dcceb7f3f9f6d1e49b4241e802f614de6b8b67c51118"}, "elixir_make": {:hex, :elixir_make, "0.6.3", "bc07d53221216838d79e03a8019d0839786703129599e9619f4ab74c8c096eac", [:mix], [], "hexpm", "f5cbd651c5678bcaabdbb7857658ee106b12509cd976c2c2fca99688e1daf716"}, "envar": {:hex, :envar, "1.0.9", "b51976b00035efd254c3f51ee7f3cf2e22f91350ef104da393d1d71286eb4fdc", [:mix], [], "hexpm", "bfc3a73f97910c744e0d9e53722ad2d1f73bbb392d2dd1cac63e0af27776fde3"}, "esbuild": {:hex, :esbuild, "0.5.0", "d5bb08ff049d7880ee3609ed5c4b864bd2f46445ea40b16b4acead724fb4c4a3", [:mix], [{:castore, ">= 0.0.0", [hex: :castore, repo: "hexpm", optional: false]}], "hexpm", "f183a0b332d963c4cfaf585477695ea59eef9a6f2204fdd0efa00e099694ffe5"}, - "ex_doc": {:hex, :ex_doc, "0.29.0", "4a1cb903ce746aceef9c1f9ae8a6c12b742a5461e6959b9d3b24d813ffbea146", [: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", "f096adb8bbca677d35d278223361c7792d496b3fc0d0224c9d4bc2f651af5db1"}, - "excoveralls": {:hex, :excoveralls, "0.15.0", "ac941bf85f9f201a9626cc42b2232b251ad8738da993cf406a4290cacf562ea4", [:mix], [{:hackney, "~> 1.16", [hex: :hackney, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "9631912006b27eca30a2f3c93562bc7ae15980afb014ceb8147dc5cdd8f376f1"}, + "ex_doc": {:hex, :ex_doc, "0.29.1", "b1c652fa5f92ee9cf15c75271168027f92039b3877094290a75abcaac82a9f77", [: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", "b7745fa6374a36daf484e2a2012274950e084815b936b1319aeebcf7809574f6"}, + "excoveralls": {:hex, :excoveralls, "0.15.1", "83c8cf7973dd9d1d853dce37a2fb98aaf29b564bf7d01866e409abf59dac2c0e", [:mix], [{:hackney, "~> 1.16", [hex: :hackney, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "f8416bd90c0082d56a2178cf46c837595a06575f70a5624f164a1ffe37de07e7"}, "fields": {:hex, :fields, "2.9.1", "af8ce8e90e0e33df3ca173adec0839f34778c229211e35f5258971fe57ee40ff", [:mix], [{:argon2_elixir, "~> 3.0.0", [hex: :argon2_elixir, repo: "hexpm", optional: false]}, {:ecto, "~> 3.8", [hex: :ecto, repo: "hexpm", optional: false]}, {:envar, "~> 1.0.8", [hex: :envar, repo: "hexpm", optional: false]}, {:html_sanitize_ex, "~> 1.4.2", [hex: :html_sanitize_ex, repo: "hexpm", optional: false]}], "hexpm", "caa388160938fc5180c32bec66514c87ebae3a4029c9371f42e9ccb0093ad7f5"}, "file_system": {:hex, :file_system, "0.2.10", "fb082005a9cd1711c05b5248710f8826b02d7d1784e7c3451f9c1231d4fc162d", [:mix], [], "hexpm", "41195edbfb562a593726eda3b3e8b103a309b733ad25f3d642ba49696bf715dc"}, - "floki": {:hex, :floki, "0.33.1", "f20f1eb471e726342b45ccb68edb9486729e7df94da403936ea94a794f072781", [:mix], [{:html_entities, "~> 0.5.0", [hex: :html_entities, repo: "hexpm", optional: false]}], "hexpm", "461035fd125f13fdf30f243c85a0b1e50afbec876cbf1ceefe6fddd2e6d712c6"}, + "floki": {:hex, :floki, "0.34.0", "002d0cc194b48794d74711731db004fafeb328fe676976f160685262d43706a8", [:mix], [], "hexpm", "9c3a9f43f40dde00332a589bd9d389b90c1f518aef500364d00636acc5ebc99c"}, "gettext": {:hex, :gettext, "0.20.0", "75ad71de05f2ef56991dbae224d35c68b098dd0e26918def5bb45591d5c8d429", [:mix], [], "hexpm", "1c03b177435e93a47441d7f681a7040bd2a816ece9e2666d1c9001035121eb3d"}, - "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"}, + "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"}, "heroicons": {:hex, :heroicons, "0.5.1", "cca0dcca07af5f74d8a7d111e40418d3615d65e6773c0ea10e20cef070fd30aa", [:mix], [{:castore, ">= 0.0.0", [hex: :castore, repo: "hexpm", optional: false]}, {:phoenix_live_view, "~> 0.18.2", [hex: :phoenix_live_view, repo: "hexpm", optional: false]}], "hexpm", "4b096d0a1d50e9054df9b12cc637c9f65c3972ff086791d3f2d1846f0653117e"}, "html_entities": {:hex, :html_entities, "0.5.2", "9e47e70598da7de2a9ff6af8758399251db6dbb7eebe2b013f2bbd2515895c3c", [:mix], [], "hexpm", "c53ba390403485615623b9531e97696f076ed415e8d8058b1dbaa28181f4fdcc"}, "html_sanitize_ex": {:hex, :html_sanitize_ex, "1.4.2", "c479398b6de798c03eb5d04a0a9a9159d73508f83f6590a00b8eacba3619cf4c", [:mix], [{:mochiweb, "~> 2.15", [hex: :mochiweb, repo: "hexpm", optional: false]}], "hexpm", "aef6c28585d06a9109ad591507e508854c5559561f950bbaea773900dd369b0e"}, "httpoison": {:hex, :httpoison, "1.8.2", "9eb9c63ae289296a544842ef816a85d881d4a31f518a0fec089aaa744beae290", [:mix], [{:hackney, "~> 1.17", [hex: :hackney, repo: "hexpm", optional: false]}], "hexpm", "2bb350d26972e30c96e2ca74a1aaf8293d61d0742ff17f01e0279fef11599921"}, - "idna": {:hex, :idna, "6.1.1", "8a63070e9f7d0c62eb9d9fcb360a7de382448200fbbd1b106cc96d3d8099df8d", [:rebar3], [{:unicode_util_compat, "~>0.7.0", [hex: :unicode_util_compat, repo: "hexpm", optional: false]}], "hexpm", "92376eb7894412ed19ac475e4a86f7b413c1b9fbb5bd16dccd57934157944cea"}, + "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.4.0", "e855647bc964a44e2f67df589ccf49105ae039d4179db7f6271dfd3843dc27e6", [:mix], [{:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "79a3791085b2a0f743ca04cec0f7be26443738779d09302e01318f97bdb82121"}, "joken": {:hex, :joken, "2.5.0", "09be497d804b8115eb6f07615cef2e60c2a1008fb89dc0aef0d4c4b4609b99aa", [:mix], [{:jose, "~> 1.11.2", [hex: :jose, repo: "hexpm", optional: false]}], "hexpm", "22b25c89617c5ed8ca7b31026340a25ea0f9ca7160f9706b79be9ed81fdf74e7"}, "jose": {:hex, :jose, "1.11.2", "f4c018ccf4fdce22c71e44d471f15f723cb3efab5d909ab2ba202b5bf35557b3", [:mix, :rebar3], [], "hexpm", "98143fbc48d55f3a18daba82d34fe48959d44538e9697c08f34200fa5f0947d2"}, @@ -48,7 +48,7 @@ "phoenix": {:hex, :phoenix, "1.6.15", "0a1d96bbc10747fd83525370d691953cdb6f3ccbac61aa01b4acb012474b047d", [:mix], [{:castore, ">= 0.0.0", [hex: :castore, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:phoenix_pubsub, "~> 2.0", [hex: :phoenix_pubsub, repo: "hexpm", optional: false]}, {:phoenix_view, "~> 1.0 or ~> 2.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", "d70ab9fbf6b394755ea88b644d34d79d8b146e490973151f248cacd122d20672"}, "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"}, - "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_reload": {:hex, :phoenix_live_reload, "1.4.0", "4fe222c0be55fdc3f9c711e24955fc42a7cd9b7a2f5f406f2580a567c335a573", [: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", "bebf0fc2d2113b61cb5968f585367234b7b4c21d963d691de7b4b2dc6cdaae6f"}, "phoenix_live_view": {:hex, :phoenix_live_view, "0.18.3", "2e3d009422addf8b15c3dccc65ce53baccbe26f7cfd21d264680b5867789a9c1", [:mix], [{:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:phoenix, "~> 1.6.15 or ~> 1.7.0", [hex: :phoenix, repo: "hexpm", optional: false]}, {:phoenix_html, "~> 3.1", [hex: :phoenix_html, repo: "hexpm", optional: false]}, {:phoenix_template, "~> 1.0", [hex: :phoenix_template, repo: "hexpm", optional: false]}, {:phoenix_view, "~> 2.0", [hex: :phoenix_view, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4.2 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "c8845177a866e017dcb7083365393c8f00ab061b8b6b2bda575891079dce81b2"}, "phoenix_pubsub": {:hex, :phoenix_pubsub, "2.1.1", "ba04e489ef03763bf28a17eb2eaddc2c20c6d217e2150a61e3298b0f4c2012b5", [:mix], [], "hexpm", "81367c6d1eea5878ad726be80808eb5a787a23dee699f96e72b1109c57cdd8d9"}, "phoenix_template": {:hex, :phoenix_template, "1.0.0", "c57bc5044f25f007dc86ab21895688c098a9f846a8dda6bc40e2d0ddc146e38f", [:mix], [{:phoenix_html, "~> 2.14.2 or ~> 3.0", [hex: :phoenix_html, repo: "hexpm", optional: true]}], "hexpm", "1b066f99a26fd22064c12b2600a9a6e56700f591bf7b20b418054ea38b4d4357"}, diff --git a/test/app/item_test.exs b/test/app/item_test.exs index 51e61589..13db547d 100644 --- a/test/app/item_test.exs +++ b/test/app/item_test.exs @@ -65,12 +65,12 @@ defmodule App.ItemTest do text: "new item", person_id: 1, status: 2, - tags: "tag1, tag2, tag3" + tags: [] } test "get_item!/1 returns the item with given id" do {:ok, item} = Item.create_item_with_tags(@valid_attrs) - assert length(item.tags) == 3 + assert length(item.tags) == 0 end end diff --git a/test/app_web/live/app_live_test.exs b/test/app_web/live/app_live_test.exs index 7b98e75d..1abb9186 100644 --- a/test/app_web/live/app_live_test.exs +++ b/test/app_web/live/app_live_test.exs @@ -188,13 +188,11 @@ defmodule AppWeb.AppLiveTest do assert render_submit(view, "update-item", %{ "id" => item.id, - "text" => "Learn more Elixir", - "tags" => "Learn, Elixir" + "text" => "Learn more Elixir" }) updated_item = Item.get_item!(item.id) assert updated_item.text == "Learn more Elixir" - assert length(updated_item.tags) == 2 end test "update an item's timer", %{conn: conn} do @@ -571,12 +569,21 @@ defmodule AppWeb.AppLiveTest do end test "filter items by tag name", %{conn: conn} do + {:ok, tag1} = + Tag.create_tag(%{person_id: 0, text: "tag1", color: "#FCA5A5"}) + + {:ok, tag2} = + Tag.create_tag(%{person_id: 0, text: "tag2", color: "#FCA5A5"}) + + {:ok, tag3} = + Tag.create_tag(%{person_id: 0, text: "tag3", color: "#FCA5A5"}) + {:ok, _item} = Item.create_item_with_tags(%{ text: "Item1 to do", person_id: 0, status: 2, - tags: "tag1, tag2" + tags: [tag1, tag2] }) {:ok, _item} = @@ -584,7 +591,7 @@ defmodule AppWeb.AppLiveTest do text: "Item2 to do", person_id: 0, status: 2, - tags: "tag1, tag3" + tags: [tag1, tag3] }) {:ok, view, _html} = live(conn, "/?filter_by=all") From c1b61968593be00a5174bdbe804b5d6b7530f0e8 Mon Sep 17 00:00:00 2001 From: SimonLab Date: Mon, 28 Nov 2022 17:02:11 +0000 Subject: [PATCH 14/15] Add tests for dropdown tag list Add test for `handle_event` functions linked to the tags select input --- lib/app/item.ex | 5 +++-- lib/app_web/live/app_live.html.heex | 1 - test/app_web/live/app_live_test.exs | 24 ++++++++++++++++++++++++ 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/lib/app/item.ex b/lib/app/item.ex index e93a68ea..7ee13755 100644 --- a/lib/app/item.ex +++ b/lib/app/item.ex @@ -117,11 +117,12 @@ defmodule App.Item do @doc """ Update an item and its associated tags """ - #def update_item_with_tags(%Item{} = item, attrs) do + + # def update_item_with_tags(%Item{} = item, attrs) do # item # |> Item.changeset_with_tags(attrs) # |> Repo.update() - #end + # end def delete_item(id) do get_item!(id) diff --git a/lib/app_web/live/app_live.html.heex b/lib/app_web/live/app_live.html.heex index a5e16016..aa4a46ac 100644 --- a/lib/app_web/live/app_live.html.heex +++ b/lib/app_web/live/app_live.html.heex @@ -270,7 +270,6 @@ value={tags_to_string(item.tags)} placeholder="tag1, tag2..." />--> -
      "new item"}) =~ "new item" + end + + test "select tag", %{conn: conn} do + {:ok, view, _html} = live(conn, "/") + + {:ok, tag1} = + Tag.create_tag(%{person_id: 0, text: "tag1", color: "#FCA5A5"}) + + assert render_hook(view, "toggle_tag", %{"tag_id" => tag1.id}) + # can toggle again the same tag + assert render_hook(view, "toggle_tag", %{"tag_id" => tag1.id}) + end + + test "filter list tags", %{conn: conn} do + {:ok, _tag1} = + Tag.create_tag(%{person_id: 0, text: "tag1", color: "#FCA5A5"}) + + {:ok, view, _html} = live(conn, "/") + assert render_hook(view, "filter-tags", %{"key" => "t", "value" => "t"}) + end + defp create_person(_) do person = Person.create_person(%{"person_id" => 0, "name" => "guest"}) %{person: person} From e9104d75732bcd8e2ece20a3e7f77e8d72939e6b Mon Sep 17 00:00:00 2001 From: SimonLab Date: Tue, 29 Nov 2022 09:41:42 +0000 Subject: [PATCH 15/15] Add back `mix format --checked` Add format check on Github CI back see: https://github.com/dwyl/mvp/pull/209#discussion_r1034109685 --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e1851337..96a5a36d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -43,8 +43,8 @@ jobs: deps-${{ runner.os }}-${{ matrix.otp }}-${{ matrix.elixir }} - name: Install dependencies run: mix deps.get - # - name: Check code is formatted - # run: mix format --check-formatted + - name: Check code is formatted + run: mix format --check-formatted - name: Run Tests run: mix coveralls.json env: