From 0b2b1c8d35e2908a71d1a59ee733bd1811905435 Mon Sep 17 00:00:00 2001 From: Alan Vardy Date: Wed, 18 Dec 2024 17:26:18 -0800 Subject: [PATCH] Update Phoenix Liveview --- cypress/e2e/acceptance.cy.js | 36 +++++++++---------- lib/exzeitable/database.ex | 5 +-- lib/exzeitable/html/format.ex | 2 -- lib/test_web.ex | 6 ++-- lib/test_web/gettext.ex | 2 +- lib/test_web/live_tables/beitrage_table.ex | 2 +- lib/test_web/live_tables/post_table.ex | 2 +- .../live_tables/user_formatted_table.ex | 2 +- lib/test_web/live_tables/user_table.ex | 2 +- .../templates/beitrage/edit.html.heex | 4 +-- .../templates/beitrage/form.html.heex | 14 ++++---- .../templates/beitrage/index.html.heex | 2 +- lib/test_web/templates/beitrage/new.html.heex | 4 +-- .../templates/beitrage/show.html.heex | 8 ++--- lib/test_web/templates/layout/app.html.heex | 6 ++-- lib/test_web/templates/layout/root.html.heex | 4 +-- lib/test_web/templates/page/index.html.heex | 4 +-- .../templates/post/disable_hide.html.heex | 2 +- lib/test_web/templates/post/edit.html.heex | 4 +-- lib/test_web/templates/post/form.html.heex | 14 ++++---- lib/test_web/templates/post/index.html.heex | 2 +- lib/test_web/templates/post/new.html.heex | 4 +-- .../post/no_action_buttons.html.heex | 2 +- .../templates/post/no_pagination.html.heex | 2 +- lib/test_web/templates/post/show.html.heex | 8 ++--- lib/test_web/templates/user/edit.html.heex | 4 +-- lib/test_web/templates/user/form.html.heex | 14 ++++---- .../templates/user/formatted_index.html.heex | 2 +- lib/test_web/templates/user/index.html.heex | 2 +- lib/test_web/templates/user/new.html.heex | 4 +-- lib/test_web/templates/user/show.html.heex | 8 ++--- mix.exs | 2 +- mix.lock | 2 +- 33 files changed, 88 insertions(+), 93 deletions(-) diff --git a/cypress/e2e/acceptance.cy.js b/cypress/e2e/acceptance.cy.js index f6786d59..ba69b5f3 100644 --- a/cypress/e2e/acceptance.cy.js +++ b/cypress/e2e/acceptance.cy.js @@ -1,19 +1,17 @@ -describe('Acceptance Test', function () { +describe('Acceptance Test', function() { // REGULAR ROUTE - it('Can visit the users page', function () { + it('Can visit the users page', function() { cy.visit('http://localhost:5000/users') }) - it('Can hide the names column', function () { + it('Can hide the names column', function() { cy.contains('Bob') - cy.get('[phx-value-column=name]').should('have.length', 2) cy.get('[phx-value-column=name]').first().click() - cy.get('[phx-value-column=name]').should('not.exist') cy.contains('Bob').should('not.exist') }) - it('Can show the names column again', function () { + it('Can show the names column again', function() { cy.contains('Bob').should('not.exist'); cy.contains('Show Name').should('not.exist') cy.contains('Show Field Buttons').first().click() @@ -21,7 +19,7 @@ describe('Acceptance Test', function () { cy.contains('Bob') }) - it('Can visit page 2', function () { + it('Can visit page 2', function() { cy.contains('Bob') cy.contains('Sioban').should('not.exist') cy.get('nav.exz-pagination-nav').contains('2').first().click() @@ -29,7 +27,7 @@ describe('Acceptance Test', function () { cy.contains('Bob').should('not.exist') }) - it('Can search for names', function () { + it('Can search for names', function() { cy.visit('http://localhost:5000/users') cy.contains('Sioban').should('not.exist') cy.get('input#search_search').type('siob') @@ -42,19 +40,17 @@ describe('Acceptance Test', function () { // LIVE SESSION - it('Live Session: Can visit the users page', function () { + it('Live Session: Can visit the users page', function() { cy.visit('http://localhost:5000/live_session_users') }) - it('Live Session: Can hide the names column', function () { + it('Live Session: Can hide the names column', function() { cy.contains('Bob') - cy.get('[phx-value-column=name]').should('have.length', 2) cy.get('[phx-value-column=name]').first().click() - cy.get('[phx-value-column=name]').should('not.exist') cy.contains('Bob').should('not.exist') }) - it('Live Session: Can show the names column again', function () { + it('Live Session: Can show the names column again', function() { cy.contains('Bob').should('not.exist'); cy.contains('Show Name').should('not.exist') cy.contains('Show Field Buttons').first().click() @@ -62,7 +58,7 @@ describe('Acceptance Test', function () { cy.contains('Bob') }) - it('Live Session: Can visit page 2', function () { + it('Live Session: Can visit page 2', function() { cy.contains('Bob') cy.contains('Sioban').should('not.exist') cy.get('nav.exz-pagination-nav').contains('2').first().click() @@ -72,14 +68,14 @@ describe('Acceptance Test', function () { // MISC - it('Doesnt see the action column when there are no action buttons', function () { + it('Doesnt see the action column when there are no action buttons', function() { cy.visit('http://localhost:5000/posts/no_action_buttons') cy.contains('Posts') cy.contains('Show Field Buttons') cy.contains('Actions').should('not.exist') }) - it('Cannot see hide functionality when it is disabled', function () { + it('Cannot see hide functionality when it is disabled', function() { cy.visit('http://localhost:5000/posts/disable_hide') cy.contains('Posts') cy.contains('Actions') @@ -88,7 +84,7 @@ describe('Acceptance Test', function () { cy.contains('Hide').should('not.exist') }) - it('Cannot see pagination when it is disabled', function () { + it('Cannot see pagination when it is disabled', function() { cy.visit('http://localhost:5000/posts/no_pagination') cy.contains('Posts') cy.contains('Actions') @@ -96,13 +92,13 @@ describe('Acceptance Test', function () { cy.contains('Nex').should('not.exist') }) - it('Can use custom formatter', function () { + it('Can use custom formatter', function() { cy.visit('http://localhost:5000/users/formatted') cy.contains('<<< Bob >>>') cy.contains('!!!boB!!!') }) - it('Can use custom text', function () { + it('Can use custom text', function() { cy.visit('http://localhost:5000/beitrage') cy.contains('Beiträge auflisten') cy.contains('Ausblenden') @@ -113,7 +109,7 @@ describe('Acceptance Test', function () { cy.contains('Aktionen') }) - it('Can search across multiple columns', function () { + it('Can search across multiple columns', function() { cy.get('input#search_search').type('1 CONTENT') cy.contains('Post number 1') cy.contains('Post number 2').should('not.exist') diff --git a/lib/exzeitable/database.ex b/lib/exzeitable/database.ex index 0256466b..dac70c10 100644 --- a/lib/exzeitable/database.ex +++ b/lib/exzeitable/database.ex @@ -56,8 +56,9 @@ defmodule Exzeitable.Database do query end - defp modify_query(query, %Params{query_modifier: {mod, fun}} = params) when is_atom(mod) and is_atom(fun) do - apply(mod, fun, [query, params]) + defp modify_query(query, %Params{query_modifier: {mod, fun}} = params) + when is_atom(mod) and is_atom(fun) do + apply(mod, fun, [query, params]) end defp modify_query(_query, %Params{query_modifier: invalid}) do diff --git a/lib/exzeitable/html/format.ex b/lib/exzeitable/html/format.ex index 78c217ee..654f2b20 100644 --- a/lib/exzeitable/html/format.ex +++ b/lib/exzeitable/html/format.ex @@ -27,8 +27,6 @@ defmodule Exzeitable.HTML.Format do |> format_field(fields[key].formatter) end - # coveralls-ignore-stop - @doc "Will output the user supplied label or fall back on the atom" @spec header(Params.t(), {atom, map}) :: String.t() def header(_params, {_key, %{label: label}}) when is_binary(label), do: label diff --git a/lib/test_web.ex b/lib/test_web.ex index dc83e2d1..f4408fd3 100644 --- a/lib/test_web.ex +++ b/lib/test_web.ex @@ -20,9 +20,9 @@ defmodule TestWeb do def controller do quote do use Phoenix.Controller, namespace: TestWeb + use Gettext, backend: TestWeb.Gettext import Plug.Conn - import TestWeb.Gettext alias TestWeb.Router.Helpers, as: Routes import Phoenix.LiveView.Controller end @@ -41,9 +41,9 @@ defmodule TestWeb do import Phoenix.HTML import Phoenix.HTML.Form use PhoenixHTMLHelpers + use Gettext, backend: TestWeb.Gettext import TestWeb.ErrorHelpers - import TestWeb.Gettext alias TestWeb.Router.Helpers, as: Routes import Phoenix.LiveView.Helpers @@ -62,7 +62,7 @@ defmodule TestWeb do def channel do quote do use Phoenix.Channel - import TestWeb.Gettext + use Gettext, backend: TestWeb.Gettext end end diff --git a/lib/test_web/gettext.ex b/lib/test_web/gettext.ex index d4a497aa..871fcdb7 100644 --- a/lib/test_web/gettext.ex +++ b/lib/test_web/gettext.ex @@ -20,5 +20,5 @@ defmodule TestWeb.Gettext do See the [Gettext Docs](https://hexdocs.pm/gettext) for detailed usage. """ - use Gettext, otp_app: :exzeitable + use Gettext.Backend, otp_app: :exzeitable end diff --git a/lib/test_web/live_tables/beitrage_table.ex b/lib/test_web/live_tables/beitrage_table.ex index eefbb7d3..542c83a3 100644 --- a/lib/test_web/live_tables/beitrage_table.ex +++ b/lib/test_web/live_tables/beitrage_table.ex @@ -12,5 +12,5 @@ defmodule TestWeb.BeitrageTable do text: TestWeb.GermanText, refresh: 5000 - def render(assigns), do: ~H"<%= build_table(assigns) %>" + def render(assigns), do: ~H"{build_table(assigns)}" end diff --git a/lib/test_web/live_tables/post_table.ex b/lib/test_web/live_tables/post_table.ex index 6f79dce3..07f01102 100644 --- a/lib/test_web/live_tables/post_table.ex +++ b/lib/test_web/live_tables/post_table.ex @@ -12,7 +12,7 @@ defmodule TestWeb.PostTable do action_buttons: [:show, :edit, :custom_button], refresh: 5000 - def render(assigns), do: ~H"<%= build_table(assigns) %>" + def render(assigns), do: ~H"{build_table(assigns)}" def custom_button(_socket, _entry, _csrf_token), do: "CUSTOM BUTTON" end diff --git a/lib/test_web/live_tables/user_formatted_table.ex b/lib/test_web/live_tables/user_formatted_table.ex index a606949e..90f58cfd 100644 --- a/lib/test_web/live_tables/user_formatted_table.ex +++ b/lib/test_web/live_tables/user_formatted_table.ex @@ -15,7 +15,7 @@ defmodule TestWeb.UserFormattedTable do query: from(u in User), per_page: 5 - def render(assigns), do: ~H"<%= build_table(assigns) %>" + def render(assigns), do: ~H"{build_table(assigns)}" def name_backwards(_socket, entry) do entry diff --git a/lib/test_web/live_tables/user_table.ex b/lib/test_web/live_tables/user_table.ex index 7e8ec983..fc671544 100644 --- a/lib/test_web/live_tables/user_table.ex +++ b/lib/test_web/live_tables/user_table.ex @@ -11,7 +11,7 @@ defmodule TestWeb.UserTable do query: from(u in User), per_page: 5 - def render(assigns), do: ~H"<%= build_table(assigns) %>" + def render(assigns), do: ~H"{build_table(assigns)}" def name_backwards(_socket, entry) do entry diff --git a/lib/test_web/templates/beitrage/edit.html.heex b/lib/test_web/templates/beitrage/edit.html.heex index b7a71c92..683ffd3a 100644 --- a/lib/test_web/templates/beitrage/edit.html.heex +++ b/lib/test_web/templates/beitrage/edit.html.heex @@ -1,5 +1,5 @@

Beitrag bearbeiten

-<%= render("form.html", Map.put(assigns, :action, Routes.post_path(@conn, :update, @post))) %> +{render("form.html", Map.put(assigns, :action, Routes.post_path(@conn, :update, @post)))} -<%= link("Zurück", to: Routes.post_path(@conn, :index)) %> +{link("Zurück", to: Routes.post_path(@conn, :index))} diff --git a/lib/test_web/templates/beitrage/form.html.heex b/lib/test_web/templates/beitrage/form.html.heex index a3430738..0d160b0f 100644 --- a/lib/test_web/templates/beitrage/form.html.heex +++ b/lib/test_web/templates/beitrage/form.html.heex @@ -5,15 +5,15 @@ <% end %> - <%= label(f, :title) %> - <%= text_input(f, :title) %> - <%= error_tag(f, :title) %> + {label(f, :title)} + {text_input(f, :title)} + {error_tag(f, :title)} - <%= label(f, :content) %> - <%= text_input(f, :content) %> - <%= error_tag(f, :content) %> + {label(f, :content)} + {text_input(f, :content)} + {error_tag(f, :content)}
- <%= submit("Sparen") %> + {submit("Sparen")}
<% end %> diff --git a/lib/test_web/templates/beitrage/index.html.heex b/lib/test_web/templates/beitrage/index.html.heex index c0be3e41..429142d5 100644 --- a/lib/test_web/templates/beitrage/index.html.heex +++ b/lib/test_web/templates/beitrage/index.html.heex @@ -1,2 +1,2 @@

Beiträge auflisten

-<%= TestWeb.BeitrageTable.live_table(@conn) %> +{TestWeb.BeitrageTable.live_table(@conn)} diff --git a/lib/test_web/templates/beitrage/new.html.heex b/lib/test_web/templates/beitrage/new.html.heex index 755fb124..ae21cca3 100644 --- a/lib/test_web/templates/beitrage/new.html.heex +++ b/lib/test_web/templates/beitrage/new.html.heex @@ -1,5 +1,5 @@

Neuer Beitrag

-<%= render("form.html", Map.put(assigns, :action, Routes.post_path(@conn, :create))) %> +{render("form.html", Map.put(assigns, :action, Routes.post_path(@conn, :create)))} -<%= link("Zurück", to: Routes.post_path(@conn, :index)) %> +{link("Zurück", to: Routes.post_path(@conn, :index))} diff --git a/lib/test_web/templates/beitrage/show.html.heex b/lib/test_web/templates/beitrage/show.html.heex index e66faad8..65707578 100644 --- a/lib/test_web/templates/beitrage/show.html.heex +++ b/lib/test_web/templates/beitrage/show.html.heex @@ -3,14 +3,14 @@ -<%= link("Bearbeiten", to: Routes.post_path(@conn, :edit, @post)) %> -<%= link("Zurück", to: Routes.post_path(@conn, :index)) %> +{link("Bearbeiten", to: Routes.post_path(@conn, :edit, @post))} +{link("Zurück", to: Routes.post_path(@conn, :index))} diff --git a/lib/test_web/templates/layout/app.html.heex b/lib/test_web/templates/layout/app.html.heex index 78ab6e2f..c9584bc2 100644 --- a/lib/test_web/templates/layout/app.html.heex +++ b/lib/test_web/templates/layout/app.html.heex @@ -1,5 +1,5 @@
- - - <%= @inner_content %> + + + {@inner_content}
diff --git a/lib/test_web/templates/layout/root.html.heex b/lib/test_web/templates/layout/root.html.heex index 5c3b7a43..71012c41 100644 --- a/lib/test_web/templates/layout/root.html.heex +++ b/lib/test_web/templates/layout/root.html.heex @@ -4,7 +4,7 @@ - <%= csrf_meta_tag() %> + {csrf_meta_tag()}