From fa103ad5d2cf77d3eed836ef926c020fecd52e29 Mon Sep 17 00:00:00 2001 From: pb Date: Wed, 2 Nov 2022 06:07:11 +0100 Subject: [PATCH] seed --- lib/bg1/accounts/user.ex | 2 +- lib/bg1_web/live/assign_user.ex | 5 +++-- lib/bg1_web/live/row_live/index.html.heex | 7 ++++-- lib/bg1_web/live/row_live/show.html.heex | 2 +- .../templates/components/contact_component.ex | 10 ++++----- .../templates/layout/_user_menu.html.heex | 22 +++++++++---------- priv/repo/seeds.exs | 8 +++++++ 7 files changed, 34 insertions(+), 22 deletions(-) diff --git a/lib/bg1/accounts/user.ex b/lib/bg1/accounts/user.ex index 03b5b08..630a06e 100644 --- a/lib/bg1/accounts/user.ex +++ b/lib/bg1/accounts/user.ex @@ -49,7 +49,7 @@ defmodule Bg1.Accounts.User do defp validate_password(changeset, opts) do changeset |> validate_required([:password]) - |> validate_length(:password, min: 12, max: 72) + |> validate_length(:password, min: 2, max: 72) # |> validate_format(:password, ~r/[a-z]/, message: "at least one lower case character") # |> validate_format(:password, ~r/[A-Z]/, message: "at least one upper case character") # |> validate_format(:password, ~r/[!?@#$%^&*_0-9]/, message: "at least one digit or punctuation character") diff --git a/lib/bg1_web/live/assign_user.ex b/lib/bg1_web/live/assign_user.ex index d3e9f38..085cecb 100644 --- a/lib/bg1_web/live/assign_user.ex +++ b/lib/bg1_web/live/assign_user.ex @@ -1,5 +1,6 @@ defmodule Bg1Web.AssignUser do + alias Bg1.Accounts import Phoenix.Component @@ -11,13 +12,13 @@ defmodule Bg1Web.AssignUser do :current_user, fn -> Accounts.get_user_by_session_token_with_parameter(session["user_token"]) - end + end ) |> assign_new( :testvar, fn -> "test var from assign new" - end + end ) } end diff --git a/lib/bg1_web/live/row_live/index.html.heex b/lib/bg1_web/live/row_live/index.html.heex index 6c7cf1d..1be97f2 100644 --- a/lib/bg1_web/live/row_live/index.html.heex +++ b/lib/bg1_web/live/row_live/index.html.heex @@ -4,7 +4,9 @@ <%= inspect @testvar %>
-<%= inspect @current_user %> +current_user preloaded parameter +
+ <%= inspect @current_user.parameter %>
parameters rows @@ -35,7 +37,8 @@ <%= row.title %> - <%= live_redirect "live redirect Show", to: Routes.row_show_path(@socket, :show, row) %> + <.link navigate={"/rows/#{row.id}"}> navigate link | + <.link patch={"/rows/#{row.id}"}> patch link | full reload link | <%= live_patch "Edit", to: Routes.row_index_path(@socket, :edit, row) %> <%= link "Delete", to: "#", phx_click: "delete", phx_value_id: row.id, data: [confirm: "Are you sure?"] %> diff --git a/lib/bg1_web/live/row_live/show.html.heex b/lib/bg1_web/live/row_live/show.html.heex index d40ad3b..76c5a58 100644 --- a/lib/bg1_web/live/row_live/show.html.heex +++ b/lib/bg1_web/live/row_live/show.html.heex @@ -29,7 +29,7 @@ <%= inspect @testvar %>
-<%= inspect @current_user %> +<%= inspect @current_user.parameter %>

diff --git a/lib/bg1_web/templates/components/contact_component.ex b/lib/bg1_web/templates/components/contact_component.ex index 27e2631..4f47514 100644 --- a/lib/bg1_web/templates/components/contact_component.ex +++ b/lib/bg1_web/templates/components/contact_component.ex @@ -8,19 +8,19 @@ defmodule Bg1Web.ContactComponent do @moduledoc """ - component templates + component templates - """ + """ attr :row, Row, required: true attr :parameter, Parameter, default: %Parameter{} def display(assigns) do ~H""" - <%= @row.title%> + <%= @row.title%> - <%= inspect Map.get(@parameter, :phonelink) %> - <%= inspect @parameter.phonelink %> + Phonelink <%= Map.get @parameter, :phonelink %> + <%#= inspect @parameter.phonelink %> """ end diff --git a/lib/bg1_web/templates/layout/_user_menu.html.heex b/lib/bg1_web/templates/layout/_user_menu.html.heex index 74a4fcd..6ae15c3 100644 --- a/lib/bg1_web/templates/layout/_user_menu.html.heex +++ b/lib/bg1_web/templates/layout/_user_menu.html.heex @@ -1,13 +1,13 @@ diff --git a/priv/repo/seeds.exs b/priv/repo/seeds.exs index dfbeb2a..d25e2b2 100644 --- a/priv/repo/seeds.exs +++ b/priv/repo/seeds.exs @@ -9,3 +9,11 @@ # # We recommend using the bang functions (`insert!`, `update!` # and so on) as they will fail if something goes wrong. +alias Bg1.{Accounts, Parameters, Rows} + + + +Accounts.register_user(%{email: "bg1@bg1.com", password: "bg1"}) +Rows.create_row( %{title: "row 1"}) +Rows.create_row( %{title: "row 2"}) +Parameters.create_parameter( %{signature: "signature", phonelink: "phonelink", user_id: 1})