feat: migration to phoenix 1.8 - fix formatting
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
c2cb75a32b
commit
2255dfbf6e
3 changed files with 37 additions and 37 deletions
|
|
@ -51,7 +51,7 @@ defmodule MvWeb do
|
||||||
def live_view do
|
def live_view do
|
||||||
quote do
|
quote do
|
||||||
use Phoenix.LiveView
|
use Phoenix.LiveView
|
||||||
|
|
||||||
on_mount MvWeb.LiveHelpers
|
on_mount MvWeb.LiveHelpers
|
||||||
|
|
||||||
unquote(html_helpers())
|
unquote(html_helpers())
|
||||||
|
|
|
||||||
|
|
@ -12,29 +12,26 @@ defmodule MvWeb.PropertyLive.Form do
|
||||||
|
|
||||||
<.form for={@form} id="property-form" phx-change="validate" phx-submit="save">
|
<.form for={@form} id="property-form" phx-change="validate" phx-submit="save">
|
||||||
<!-- Property Type Selection -->
|
<!-- Property Type Selection -->
|
||||||
<.input
|
<.input
|
||||||
field={@form[:property_type_id]}
|
field={@form[:property_type_id]}
|
||||||
type="select"
|
type="select"
|
||||||
label={gettext("Property type")}
|
label={gettext("Property type")}
|
||||||
options={property_type_options(@property_types)}
|
options={property_type_options(@property_types)}
|
||||||
prompt={gettext("Choose a property type")}
|
prompt={gettext("Choose a property type")}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<!-- Member Selection -->
|
<!-- Member Selection -->
|
||||||
<.input
|
<.input
|
||||||
field={@form[:member_id]}
|
field={@form[:member_id]}
|
||||||
type="select"
|
type="select"
|
||||||
label={gettext("Member")}
|
label={gettext("Member")}
|
||||||
options={member_options(@members)}
|
options={member_options(@members)}
|
||||||
prompt={gettext("Choose a member")}
|
prompt={gettext("Choose a member")}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<!-- Value Input - handles Union type -->
|
<!-- Value Input - handles Union type -->
|
||||||
<%= if @selected_property_type do %>
|
<%= if @selected_property_type do %>
|
||||||
<.union_value_input
|
<.union_value_input form={@form} property_type={@selected_property_type} />
|
||||||
form={@form}
|
|
||||||
property_type={@selected_property_type}
|
|
||||||
/>
|
|
||||||
<% else %>
|
<% else %>
|
||||||
<div class="text-sm text-gray-600">
|
<div class="text-sm text-gray-600">
|
||||||
{gettext("Please select a property type first")}
|
{gettext("Please select a property type first")}
|
||||||
|
|
@ -55,44 +52,44 @@ defmodule MvWeb.PropertyLive.Form do
|
||||||
# Extract the current value from the Property
|
# Extract the current value from the Property
|
||||||
current_value = extract_current_value(assigns.form.data, assigns.property_type.value_type)
|
current_value = extract_current_value(assigns.form.data, assigns.property_type.value_type)
|
||||||
assigns = assign(assigns, :current_value, current_value)
|
assigns = assign(assigns, :current_value, current_value)
|
||||||
|
|
||||||
~H"""
|
~H"""
|
||||||
<div class="space-y-2">
|
<div class="space-y-2">
|
||||||
<label class="block text-sm font-medium text-gray-700">
|
<label class="block text-sm font-medium text-gray-700">
|
||||||
{gettext("Value")}
|
{gettext("Value")}
|
||||||
</label>
|
</label>
|
||||||
|
|
||||||
<%= case @property_type.value_type do %>
|
<%= case @property_type.value_type do %>
|
||||||
<% :string -> %>
|
<% :string -> %>
|
||||||
<.inputs_for :let={value_form} field={@form[:value]}>
|
<.inputs_for :let={value_form} field={@form[:value]}>
|
||||||
<.input field={value_form[:value]} type="text" label="" value={@current_value} />
|
<.input field={value_form[:value]} type="text" label="" value={@current_value} />
|
||||||
<input type="hidden" name={value_form[:_union_type].name} value="string" />
|
<input type="hidden" name={value_form[:_union_type].name} value="string" />
|
||||||
</.inputs_for>
|
</.inputs_for>
|
||||||
|
|
||||||
<% :integer -> %>
|
<% :integer -> %>
|
||||||
<.inputs_for :let={value_form} field={@form[:value]}>
|
<.inputs_for :let={value_form} field={@form[:value]}>
|
||||||
<.input field={value_form[:value]} type="number" label="" value={@current_value} />
|
<.input field={value_form[:value]} type="number" label="" value={@current_value} />
|
||||||
<input type="hidden" name={value_form[:_union_type].name} value="integer" />
|
<input type="hidden" name={value_form[:_union_type].name} value="integer" />
|
||||||
</.inputs_for>
|
</.inputs_for>
|
||||||
|
|
||||||
<% :boolean -> %>
|
<% :boolean -> %>
|
||||||
<.inputs_for :let={value_form} field={@form[:value]}>
|
<.inputs_for :let={value_form} field={@form[:value]}>
|
||||||
<.input field={value_form[:value]} type="checkbox" label="" checked={@current_value} />
|
<.input field={value_form[:value]} type="checkbox" label="" checked={@current_value} />
|
||||||
<input type="hidden" name={value_form[:_union_type].name} value="boolean" />
|
<input type="hidden" name={value_form[:_union_type].name} value="boolean" />
|
||||||
</.inputs_for>
|
</.inputs_for>
|
||||||
|
|
||||||
<% :date -> %>
|
<% :date -> %>
|
||||||
<.inputs_for :let={value_form} field={@form[:value]}>
|
<.inputs_for :let={value_form} field={@form[:value]}>
|
||||||
<.input field={value_form[:value]} type="date" label="" value={format_date_value(@current_value)} />
|
<.input
|
||||||
|
field={value_form[:value]}
|
||||||
|
type="date"
|
||||||
|
label=""
|
||||||
|
value={format_date_value(@current_value)}
|
||||||
|
/>
|
||||||
<input type="hidden" name={value_form[:_union_type].name} value="date" />
|
<input type="hidden" name={value_form[:_union_type].name} value="date" />
|
||||||
</.inputs_for>
|
</.inputs_for>
|
||||||
|
|
||||||
<% :email -> %>
|
<% :email -> %>
|
||||||
<.inputs_for :let={value_form} field={@form[:value]}>
|
<.inputs_for :let={value_form} field={@form[:value]}>
|
||||||
<.input field={value_form[:value]} type="email" label="" value={@current_value} />
|
<.input field={value_form[:value]} type="email" label="" value={@current_value} />
|
||||||
<input type="hidden" name={value_form[:_union_type].name} value="email" />
|
<input type="hidden" name={value_form[:_union_type].name} value="email" />
|
||||||
</.inputs_for>
|
</.inputs_for>
|
||||||
|
|
||||||
<% _ -> %>
|
<% _ -> %>
|
||||||
<div class="text-sm text-red-600">
|
<div class="text-sm text-red-600">
|
||||||
{gettext("Unsupported value type: %{type}", type: @property_type.value_type)}
|
{gettext("Unsupported value type: %{type}", type: @property_type.value_type)}
|
||||||
|
|
@ -103,10 +100,13 @@ defmodule MvWeb.PropertyLive.Form do
|
||||||
end
|
end
|
||||||
|
|
||||||
# Helper function to extract the current value from the Property
|
# Helper function to extract the current value from the Property
|
||||||
defp extract_current_value(%Mv.Membership.Property{value: %Ash.Union{value: value}}, _value_type) do
|
defp extract_current_value(
|
||||||
|
%Mv.Membership.Property{value: %Ash.Union{value: value}},
|
||||||
|
_value_type
|
||||||
|
) do
|
||||||
value
|
value
|
||||||
end
|
end
|
||||||
|
|
||||||
defp extract_current_value(_data, _value_type) do
|
defp extract_current_value(_data, _value_type) do
|
||||||
nil
|
nil
|
||||||
end
|
end
|
||||||
|
|
@ -115,16 +115,16 @@ defmodule MvWeb.PropertyLive.Form do
|
||||||
defp format_date_value(%Date{} = date) do
|
defp format_date_value(%Date{} = date) do
|
||||||
Date.to_iso8601(date)
|
Date.to_iso8601(date)
|
||||||
end
|
end
|
||||||
|
|
||||||
defp format_date_value(nil), do: ""
|
defp format_date_value(nil), do: ""
|
||||||
|
|
||||||
defp format_date_value(date) when is_binary(date) do
|
defp format_date_value(date) when is_binary(date) do
|
||||||
case Date.from_iso8601(date) do
|
case Date.from_iso8601(date) do
|
||||||
{:ok, parsed_date} -> Date.to_iso8601(parsed_date)
|
{:ok, parsed_date} -> Date.to_iso8601(parsed_date)
|
||||||
_ -> ""
|
_ -> ""
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
defp format_date_value(_), do: ""
|
defp format_date_value(_), do: ""
|
||||||
|
|
||||||
@impl true
|
@impl true
|
||||||
|
|
@ -159,7 +159,7 @@ defmodule MvWeb.PropertyLive.Form do
|
||||||
@impl true
|
@impl true
|
||||||
def handle_event("validate", %{"property" => property_params}, socket) do
|
def handle_event("validate", %{"property" => property_params}, socket) do
|
||||||
# Find the selected PropertyType
|
# Find the selected PropertyType
|
||||||
selected_property_type =
|
selected_property_type =
|
||||||
case property_params["property_type_id"] do
|
case property_params["property_type_id"] do
|
||||||
"" -> nil
|
"" -> nil
|
||||||
nil -> nil
|
nil -> nil
|
||||||
|
|
@ -167,7 +167,7 @@ defmodule MvWeb.PropertyLive.Form do
|
||||||
end
|
end
|
||||||
|
|
||||||
# Set the Union type based on the selected PropertyType
|
# Set the Union type based on the selected PropertyType
|
||||||
updated_params =
|
updated_params =
|
||||||
if selected_property_type do
|
if selected_property_type do
|
||||||
union_type = to_string(selected_property_type.value_type)
|
union_type = to_string(selected_property_type.value_type)
|
||||||
put_in(property_params, ["value", "_union_type"], union_type)
|
put_in(property_params, ["value", "_union_type"], union_type)
|
||||||
|
|
@ -183,7 +183,7 @@ defmodule MvWeb.PropertyLive.Form do
|
||||||
|
|
||||||
def handle_event("save", %{"property" => property_params}, socket) do
|
def handle_event("save", %{"property" => property_params}, socket) do
|
||||||
# Set the Union type based on the selected PropertyType
|
# Set the Union type based on the selected PropertyType
|
||||||
updated_params =
|
updated_params =
|
||||||
if socket.assigns.selected_property_type do
|
if socket.assigns.selected_property_type do
|
||||||
union_type = to_string(socket.assigns.selected_property_type.value_type)
|
union_type = to_string(socket.assigns.selected_property_type.value_type)
|
||||||
put_in(property_params, ["value", "_union_type"], union_type)
|
put_in(property_params, ["value", "_union_type"], union_type)
|
||||||
|
|
@ -221,14 +221,14 @@ defmodule MvWeb.PropertyLive.Form do
|
||||||
if property do
|
if property do
|
||||||
# Determine the Union type based on the property_type
|
# Determine the Union type based on the property_type
|
||||||
union_type = property.property_type && property.property_type.value_type
|
union_type = property.property_type && property.property_type.value_type
|
||||||
|
|
||||||
params =
|
params =
|
||||||
if union_type do
|
if union_type do
|
||||||
%{"value" => %{"_union_type" => to_string(union_type)}}
|
%{"value" => %{"_union_type" => to_string(union_type)}}
|
||||||
else
|
else
|
||||||
%{}
|
%{}
|
||||||
end
|
end
|
||||||
|
|
||||||
AshPhoenix.Form.for_update(property, :update, as: "property", params: params)
|
AshPhoenix.Form.for_update(property, :update, as: "property", params: params)
|
||||||
else
|
else
|
||||||
AshPhoenix.Form.for_create(Mv.Membership.Property, :create, as: "property")
|
AshPhoenix.Form.for_create(Mv.Membership.Property, :create, as: "property")
|
||||||
|
|
|
||||||
|
|
@ -44,12 +44,12 @@ defmodule MvWeb.MemberLive.IndexTest do
|
||||||
}
|
}
|
||||||
|
|
||||||
# Submit form and follow the redirect to get the flash message
|
# Submit form and follow the redirect to get the flash message
|
||||||
{:ok, index_view, _html} =
|
{:ok, index_view, _html} =
|
||||||
form_view
|
form_view
|
||||||
|> form("#member-form", form_data)
|
|> form("#member-form", form_data)
|
||||||
|> render_submit()
|
|> render_submit()
|
||||||
|> follow_redirect(conn, "/members")
|
|> follow_redirect(conn, "/members")
|
||||||
|
|
||||||
assert has_element?(index_view, "#flash-group", "Mitglied erstellt erfolgreich")
|
assert has_element?(index_view, "#flash-group", "Mitglied erstellt erfolgreich")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -65,12 +65,12 @@ defmodule MvWeb.MemberLive.IndexTest do
|
||||||
}
|
}
|
||||||
|
|
||||||
# Submit form and follow the redirect to get the flash message
|
# Submit form and follow the redirect to get the flash message
|
||||||
{:ok, index_view, _html} =
|
{:ok, index_view, _html} =
|
||||||
form_view
|
form_view
|
||||||
|> form("#member-form", form_data)
|
|> form("#member-form", form_data)
|
||||||
|> render_submit()
|
|> render_submit()
|
||||||
|> follow_redirect(conn, "/members")
|
|> follow_redirect(conn, "/members")
|
||||||
|
|
||||||
assert has_element?(index_view, "#flash-group", "Member create successfully")
|
assert has_element?(index_view, "#flash-group", "Member create successfully")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue