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