Current section

11 Versions

Jump to

Compare versions

12 files changed
+217 additions
-244 deletions
  @@ -3,7 +3,7 @@
3 3 {<<"description">>,<<"MavuBeUserUi: Backend-User-UI for mavu_* projects">>}.
4 4 {<<"elixir">>,<<"~> 1.0">>}.
5 5 {<<"files">>,
6 - [<<"lib">>,<<"lib/error_helpers.ex">>,<<"lib/live">>,
6 + [<<"lib">>,<<"lib/error_helpers.html.ex">>,<<"lib/live">>,
7 7 <<"lib/live/edit_component.ex">>,<<"lib/live/edit_component.html.heex">>,
8 8 <<"lib/live/list_component.ex">>,<<"lib/live/list_component.html.heex">>,
9 9 <<"lib/live/mavu_list">>,<<"lib/live/mavu_list/pagination_component.ex">>,
  @@ -28,30 +28,30 @@
28 28 {<<"name">>,<<"phoenix">>},
29 29 {<<"optional">>,false},
30 30 {<<"repository">>,<<"hexpm">>},
31 - {<<"requirement">>,<<">= 1.5.0">>}],
31 + {<<"requirement">>,<<">= 1.7.0">>}],
32 32 [{<<"app">>,<<"phoenix_live_view">>},
33 33 {<<"name">>,<<"phoenix_live_view">>},
34 34 {<<"optional">>,false},
35 35 {<<"repository">>,<<"hexpm">>},
36 - {<<"requirement">>,<<">= 0.17.2">>}],
36 + {<<"requirement">>,<<">= 0.18.0">>}],
37 37 [{<<"app">>,<<"mavu_form">>},
38 38 {<<"name">>,<<"mavu_form">>},
39 39 {<<"optional">>,false},
40 40 {<<"repository">>,<<"hexpm">>},
41 - {<<"requirement">>,<<"~> 0.1.0">>}],
42 - [{<<"app">>,<<"mavu_buckets">>},
43 - {<<"name">>,<<"mavu_buckets">>},
41 + {<<"requirement">>,<<">= 0.1.0">>}],
42 + [{<<"app">>,<<"mavu_list">>},
43 + {<<"name">>,<<"mavu_list">>},
44 44 {<<"optional">>,false},
45 45 {<<"repository">>,<<"hexpm">>},
46 - {<<"requirement">>,<<"~> 0.1.0">>}],
47 - [{<<"app">>,<<"mavu_content">>},
48 - {<<"name">>,<<"mavu_content">>},
49 - {<<"optional">>,false},
50 - {<<"repository">>,<<"hexpm">>},
51 - {<<"requirement">>,<<"~> 0.1.0">>}],
46 + {<<"requirement">>,<<">= 0.1.0">>}],
52 47 [{<<"app">>,<<"ecto">>},
53 48 {<<"name">>,<<"ecto">>},
54 49 {<<"optional">>,false},
55 50 {<<"repository">>,<<"hexpm">>},
56 - {<<"requirement">>,<<">= 3.0.0">>}]]}.
57 - {<<"version">>,<<"0.1.12">>}.
51 + {<<"requirement">>,<<">= 3.0.0">>}],
52 + [{<<"app">>,<<"heroicons">>},
53 + {<<"name">>,<<"heroicons">>},
54 + {<<"optional">>,false},
55 + {<<"repository">>,<<"hexpm">>},
56 + {<<"requirement">>,<<">= 0.5.0">>}]]}.
57 + {<<"version">>,<<"0.2.1">>}.
  @@ -6,64 +6,17 @@ defmodule MavuBeUserUi.BackendHelpers do
6 6 def tw_class(:narrow_container, _), do: "max-w-md mx-auto"
7 7 def tw_class(_, _), do: ""
8 8
9 - def remove_tag_params(html, tags_to_remove) when is_list(tags_to_remove) do
10 - {:safe,
11 - Phoenix.HTML.html_escape(html)
12 - |> Phoenix.HTML.safe_to_string()
13 - |> Floki.parse_fragment!()
14 - |> Floki.find_and_update(
15 - "input",
16 - fn
17 - {name, attributes, children} ->
18 - {name, remove_attributes(attributes, tags_to_remove), children}
19 -
20 - {name, attributes} ->
21 - {name, remove_attributes(attributes, tags_to_remove)}
22 -
23 - other ->
24 - other
25 - end
26 - )
27 - |> Floki.raw_html()}
28 - end
29 -
30 9 def remove_attributes(attributes, tags_to_remove) when is_list(tags_to_remove) do
31 - # {attributes, tags_to_remove} |> MyApp.Error.die(label: "mwuits-debug 2021-01-16_20:06 ")
32 10 attributes
33 11 |> Enum.filter(fn {key, _val} ->
34 12 key not in tags_to_remove
35 13 end)
36 14 end
37 15
38 - def tw_icon(icon_fun, size) when is_integer(size) and is_function(icon_fun, 1) do
39 - icon_fun.(class: "w-#{size} h-#{size}") |> Phoenix.HTML.raw()
40 - end
41 -
42 - def tw_icon(icon_fun, class) when is_binary(class) and is_function(icon_fun, 1) do
43 - icon_fun.(class: class) |> Phoenix.HTML.raw()
44 - end
45 -
46 - def tw_icon(icon_fun, opts) when is_list(opts) and is_function(icon_fun, 1) do
47 - icon_fun.(opts) |> Phoenix.HTML.raw()
48 - end
49 -
50 - defdelegate local_date(utc_date), to: MyAppWeb.MyHelpers
51 -
52 - defdelegate format_date(utc_date), to: MyAppWeb.MyHelpers
53 -
54 - defdelegate trans(lang_or_params, txt_en, txt_de \\ nil), to: MyAppWeb.MyHelpers
55 -
56 - defdelegate lang_from_params(lang_or_params), to: MyAppWeb.MyHelpers
57 -
58 16 defdelegate if_empty(val, default_val), to: MavuUtils
59 17 defdelegate if_nil(val, default_val), to: MavuUtils
60 18 defdelegate present?(term), to: MavuUtils
61 19 defdelegate empty?(term), to: MavuUtils
62 20 defdelegate true?(term), to: MavuUtils
63 21 defdelegate false?(term), to: MavuUtils
64 -
65 - # def s(_lang_or_params, _key, default \\ nil, _variables \\ []), do: default
66 -
67 - # defdelegate s(lang_or_params, key, default \\ nil, variables \\ []),
68 - # to: MyAppWeb.MyHelpers
69 22 end
  @@ -1,76 +0,0 @@
1 - defmodule MavuBeUserUi.ErrorHelpers do
2 - @moduledoc """
3 - Conveniences for translating and building error messages.
4 - """
5 -
6 - use Phoenix.HTML
7 -
8 - @doc """
9 - Generates tag for inlined form input errors.
10 - """
11 -
12 - # def error_tag(form, field) do
13 - # Enum.map(Keyword.get_values(form.errors, field), fn error ->
14 - # content_tag(:span, translate_error(error), class: "invalid-feedback")
15 - # end)
16 - # end
17 -
18 - def error_tag(form, field) do
19 - form.errors
20 - |> Keyword.get_values(field)
21 - |> Enum.map(fn error ->
22 - content_tag(:p, "↑ " <> translate_error(error),
23 - class: "mt-2 text-sm text-red-600",
24 - data: [phx_error_for: input_id(form, field)]
25 - )
26 - end)
27 - end
28 -
29 - def has_error(form, field) do
30 - form.errors
31 - |> Keyword.get_values(field)
32 - |> case do
33 - [] -> false
34 - _ -> true
35 - end
36 - end
37 -
38 - def standalone_error_tag(form, field) do
39 - form.errors
40 - |> Keyword.get_values(field)
41 - |> Enum.map(fn error ->
42 - content_tag(:div, translate_error(error),
43 - class: "alert alert-danger",
44 - data: [phx_error_for: input_id(form, field)]
45 - )
46 - end)
47 - end
48 -
49 - @doc """
50 - Translates an error message using gettext.
51 - """
52 - def translate_error({msg, opts}) do
53 - # When using gettext, we typically pass the strings we want
54 - # to translate as a static argument:
55 - #
56 - # # Translate "is invalid" in the "errors" domain
57 - # dgettext("errors", "is invalid")
58 - #
59 - # # Translate the number of files with plural rules
60 - # dngettext("errors", "1 file", "%{count} files", count)
61 - #
62 - # Because the error messages we show in our forms and APIs
63 - # are defined inside Ecto, we need to translate them dynamically.
64 - # This requires us to call the Gettext module passing our gettext
65 - # backend as first argument.
66 - #
67 - # Note we use the "errors" domain, which means translations
68 - # should be written to the errors.po file. The :count option is
69 - # set by Ecto and indicates we should also apply plural rules.
70 - if count = opts[:count] do
71 - Gettext.dngettext(MyAppWeb.Gettext, "errors", msg, msg, count, opts)
72 - else
73 - Gettext.dgettext(MyAppWeb.Gettext, "errors", msg, opts)
74 - end
75 - end
76 - end
  @@ -0,0 +1,77 @@
1 + defmodule MavuBeUserUi.ErrorHelpers do
2 + @moduledoc """
3 + Conveniences for translating and building error messages.
4 + """
5 +
6 + use Phoenix.HTML
7 +
8 + @doc """
9 + Generates tag for inlined form input errors.
10 + """
11 +
12 + # def error_tag(form, field) do
13 + # Enum.map(Keyword.get_values(form.errors, field), fn error ->
14 + # content_tag(:span, translate_error(error), class: "invalid-feedback")
15 + # end)
16 + # end
17 +
18 + def error_tag(form, field) do
19 + form.errors
20 + |> Keyword.get_values(field)
21 + |> Enum.map(fn error ->
22 + content_tag(:p, "↑ " <> translate_error(error),
23 + class: "mt-2 text-sm text-red-600",
24 + data: [phx_error_for: input_id(form, field)]
25 + )
26 + end)
27 + end
28 +
29 + def has_error(form, field) do
30 + form.errors
31 + |> Keyword.get_values(field)
32 + |> case do
33 + [] -> false
34 + _ -> true
35 + end
36 + end
37 +
38 + def standalone_error_tag(form, field) do
39 + form.errors
40 + |> Keyword.get_values(field)
41 + |> Enum.map(fn error ->
42 + content_tag(:div, translate_error(error),
43 + class: "alert alert-danger",
44 + data: [phx_error_for: input_id(form, field)]
45 + )
46 + end)
47 + end
48 +
49 + @doc """
50 + Translates an error message using gettext.
51 + """
52 + def translate_error({msg, _opts}) do
53 + # When using gettext, we typically pass the strings we want
54 + # to translate as a static argument:
55 + #
56 + # # Translate "is invalid" in the "errors" domain
57 + # dgettext("errors", "is invalid")
58 + #
59 + # # Translate the number of files with plural rules
60 + # dngettext("errors", "1 file", "%{count} files", count)
61 + #
62 + # Because the error messages we show in our forms and APIs
63 + # are defined inside Ecto, we need to translate them dynamically.
64 + # This requires us to call the Gettext module passing our gettext
65 + # backend as first argument.
66 + #
67 + # Note we use the "errors" domain, which means translations
68 + # should be written to the errors.po file. The :count option is
69 + # set by Ecto and indicates we should also apply plural rules.
70 + # if count = opts[:count] do
71 + # Gettext.dngettext(MyAppWeb.Gettext, "errors", msg, msg, count, opts)
72 + # else
73 + # Gettext.dgettext(MyAppWeb.Gettext, "errors", msg, opts)
74 + # end
75 + msg
76 + end
77 + end
  @@ -6,6 +6,8 @@ defmodule MavuBeUserUi.Live.EditComponent do
6 6 # alias MyApp.BeAccounts.BeUser
7 7 alias MyApp.Repo
8 8
9 + alias Phoenix.LiveView.JS
10 +
9 11 import MavuBeUserUi, only: [get_conf_val: 2]
10 12
11 13 def accounts_module(assigns),
  @@ -103,7 +105,7 @@ defmodule MavuBeUserUi.Live.EditComponent do
103 105 end
104 106
105 107 def return_path(socket) do
106 - socket.assigns.base_path.(%{})
108 + socket.assigns.base_path
107 109 end
108 110
109 111 def generate_default_rec(assigns) when is_map(assigns) do
Loading more files…