Compare commits

..

1 commit

Author SHA1 Message Date
dc438863d3 refactor: Rename Property/PropertyType to CustomFieldValue/CustomField
Some checks failed
continuous-integration/drone/push Build is failing
Complete refactoring of resources, database tables, code references, tests, and documentation for improved naming consistency.
2025-11-13 17:58:12 +01:00
10 changed files with 25 additions and 40 deletions

View file

@ -86,3 +86,4 @@ defmodule Mv.Membership.CustomField do
identity :unique_name, [:name] identity :unique_name, [:name]
end end
end end

View file

@ -81,3 +81,4 @@ defmodule Mv.Membership.CustomFieldValue do
identity :unique_custom_field_per_member, [:member_id, :custom_field_id] identity :unique_custom_field_per_member, [:member_id, :custom_field_id]
end end
end end

View file

@ -137,3 +137,4 @@ defmodule MvWeb.CustomFieldLive.Form do
defp return_path("index", _custom_field), do: ~p"/custom_fields" defp return_path("index", _custom_field), do: ~p"/custom_fields"
defp return_path("show", custom_field), do: ~p"/custom_fields/#{custom_field.id}" defp return_path("show", custom_field), do: ~p"/custom_fields/#{custom_field.id}"
end end

View file

@ -86,3 +86,4 @@ defmodule MvWeb.CustomFieldLive.Index do
{:noreply, stream_delete(socket, :custom_fields, custom_field)} {:noreply, stream_delete(socket, :custom_fields, custom_field)}
end end
end end

View file

@ -64,3 +64,4 @@ defmodule MvWeb.CustomFieldLive.Show do
|> assign(:custom_field, Ash.get!(Mv.Membership.CustomField, id))} |> assign(:custom_field, Ash.get!(Mv.Membership.CustomField, id))}
end end
end end

View file

@ -38,9 +38,7 @@ defmodule MvWeb.CustomFieldValueLive.Form do
<Layouts.app flash={@flash} current_user={@current_user}> <Layouts.app flash={@flash} current_user={@current_user}>
<.header> <.header>
{@page_title} {@page_title}
<:subtitle> <:subtitle>{gettext("Use this form to manage custom_field_value records in your database.")}</:subtitle>
{gettext("Use this form to manage custom_field_value records in your database.")}
</:subtitle>
</.header> </.header>
<.form for={@form} id="custom_field_value-form" phx-change="validate" phx-submit="save"> <.form for={@form} id="custom_field_value-form" phx-change="validate" phx-submit="save">
@ -237,10 +235,7 @@ defmodule MvWeb.CustomFieldValueLive.Form do
socket = socket =
socket socket
|> put_flash( |> put_flash(:info, gettext("Custom field value %{action} successfully", action: action))
:info,
gettext("Custom field value %{action} successfully", action: action)
)
|> push_navigate(to: return_path(socket.assigns.return_to, custom_field_value)) |> push_navigate(to: return_path(socket.assigns.return_to, custom_field_value))
{:noreply, socket} {:noreply, socket}
@ -265,23 +260,16 @@ defmodule MvWeb.CustomFieldValueLive.Form do
%{} %{}
end end
AshPhoenix.Form.for_update(custom_field_value, :update, AshPhoenix.Form.for_update(custom_field_value, :update, as: "custom_field_value", params: params)
as: "custom_field_value",
params: params
)
else else
AshPhoenix.Form.for_create(Mv.Membership.CustomFieldValue, :create, AshPhoenix.Form.for_create(Mv.Membership.CustomFieldValue, :create, as: "custom_field_value")
as: "custom_field_value"
)
end end
assign(socket, form: to_form(form)) assign(socket, form: to_form(form))
end end
defp return_path("index", _custom_field_value), do: ~p"/custom_field_values" defp return_path("index", _custom_field_value), do: ~p"/custom_field_values"
defp return_path("show", custom_field_value), do: ~p"/custom_field_values/#{custom_field_value.id}"
defp return_path("show", custom_field_value),
do: ~p"/custom_field_values/#{custom_field_value.id}"
# Helper functions for selection options # Helper functions for selection options
defp custom_field_options(custom_fields) do defp custom_field_options(custom_fields) do
@ -292,3 +280,4 @@ defmodule MvWeb.CustomFieldValueLive.Form do
Enum.map(members, &{"#{&1.first_name} #{&1.last_name}", &1.id}) Enum.map(members, &{"#{&1.first_name} #{&1.last_name}", &1.id})
end end
end end

View file

@ -39,11 +39,7 @@ defmodule MvWeb.CustomFieldValueLive.Index do
<.table <.table
id="custom_field_values" id="custom_field_values"
rows={@streams.custom_field_values} rows={@streams.custom_field_values}
row_click={ row_click={fn {_id, custom_field_value} -> JS.navigate(~p"/custom_field_values/#{custom_field_value}") end}
fn {_id, custom_field_value} ->
JS.navigate(~p"/custom_field_values/#{custom_field_value}")
end
}
> >
<:col :let={{_id, custom_field_value}} label="Id">{custom_field_value.id}</:col> <:col :let={{_id, custom_field_value}} label="Id">{custom_field_value.id}</:col>
@ -84,3 +80,4 @@ defmodule MvWeb.CustomFieldValueLive.Index do
{:noreply, stream_delete(socket, :custom_field_values, custom_field_value)} {:noreply, stream_delete(socket, :custom_field_values, custom_field_value)}
end end
end end

View file

@ -33,10 +33,7 @@ defmodule MvWeb.CustomFieldValueLive.Show do
<.button navigate={~p"/custom_field_values"}> <.button navigate={~p"/custom_field_values"}>
<.icon name="hero-arrow-left" /> <.icon name="hero-arrow-left" />
</.button> </.button>
<.button <.button variant="primary" navigate={~p"/custom_field_values/#{@custom_field_value}/edit?return_to=show"}>
variant="primary"
navigate={~p"/custom_field_values/#{@custom_field_value}/edit?return_to=show"}
>
<.icon name="hero-pencil-square" /> Edit Custom field value <.icon name="hero-pencil-square" /> Edit Custom field value
</.button> </.button>
</:actions> </:actions>
@ -65,3 +62,4 @@ defmodule MvWeb.CustomFieldValueLive.Show do
defp page_title(:show), do: "Show Custom field value" defp page_title(:show), do: "Show Custom field value"
defp page_title(:edit), do: "Edit Custom field value" defp page_title(:edit), do: "Edit Custom field value"
end end

View file

@ -58,8 +58,7 @@ defmodule MvWeb.MemberLive.Form do
<h3 class="mt-8 mb-2 text-lg font-semibold">{gettext("Custom Field Values")}</h3> <h3 class="mt-8 mb-2 text-lg font-semibold">{gettext("Custom Field Values")}</h3>
<.inputs_for :let={f_custom_field_value} field={@form[:custom_field_values]}> <.inputs_for :let={f_custom_field_value} field={@form[:custom_field_values]}>
<% type = <% type = Enum.find(@custom_fields, &(&1.id == f_custom_field_value[:custom_field_id].value)) %>
Enum.find(@custom_fields, &(&1.id == f_custom_field_value[:custom_field_id].value)) %>
<.inputs_for :let={value_form} field={f_custom_field_value[:value]}> <.inputs_for :let={value_form} field={f_custom_field_value[:value]}>
<% input_type = <% input_type =
cond do cond do
@ -191,8 +190,7 @@ defmodule MvWeb.MemberLive.Form do
forms: [auto?: true] forms: [auto?: true]
) )
missing_custom_field_values = missing_custom_field_values = Enum.filter(socket.assigns[:initial_custom_field_values], is_missing_custom_field_value)
Enum.filter(socket.assigns[:initial_custom_field_values], is_missing_custom_field_value)
Enum.reduce( Enum.reduce(
missing_custom_field_values, missing_custom_field_values,

View file

@ -11,14 +11,14 @@ defmodule Mv.Repo.Migrations.RenamePropertiesToCustomFields do
# Rename tables # Rename tables
rename table("property_types"), to: table("custom_fields") rename table("property_types"), to: table("custom_fields")
rename table("properties"), to: table("custom_field_values") rename table("properties"), to: table("custom_field_values")
# Rename the foreign key column # Rename the foreign key column
rename table("custom_field_values"), :property_type_id, to: :custom_field_id rename table("custom_field_values"), :property_type_id, to: :custom_field_id
# Drop old foreign key constraints # Drop old foreign key constraints
drop constraint(:custom_field_values, "properties_member_id_fkey") drop constraint(:custom_field_values, "properties_member_id_fkey")
drop constraint(:custom_field_values, "properties_property_type_id_fkey") drop constraint(:custom_field_values, "properties_property_type_id_fkey")
# Add new foreign key constraints with correct names and on_delete behavior # Add new foreign key constraints with correct names and on_delete behavior
alter table(:custom_field_values) do alter table(:custom_field_values) do
modify :member_id, modify :member_id,
@ -38,23 +38,21 @@ defmodule Mv.Repo.Migrations.RenamePropertiesToCustomFields do
prefix: "public" prefix: "public"
) )
end end
# Rename indexes # Rename indexes
execute "ALTER INDEX IF EXISTS property_types_unique_name_index RENAME TO custom_fields_unique_name_index" execute "ALTER INDEX IF EXISTS property_types_unique_name_index RENAME TO custom_fields_unique_name_index"
execute "ALTER INDEX IF EXISTS properties_unique_property_per_member_index RENAME TO custom_field_values_unique_custom_field_per_member_index" execute "ALTER INDEX IF EXISTS properties_unique_property_per_member_index RENAME TO custom_field_values_unique_custom_field_per_member_index"
end end
def down do def down do
# Rename indexes back # Rename indexes back
execute "ALTER INDEX IF EXISTS custom_fields_unique_name_index RENAME TO property_types_unique_name_index" execute "ALTER INDEX IF EXISTS custom_fields_unique_name_index RENAME TO property_types_unique_name_index"
execute "ALTER INDEX IF EXISTS custom_field_values_unique_custom_field_per_member_index RENAME TO properties_unique_property_per_member_index" execute "ALTER INDEX IF EXISTS custom_field_values_unique_custom_field_per_member_index RENAME TO properties_unique_property_per_member_index"
# Drop new foreign key constraints # Drop new foreign key constraints
drop constraint(:custom_field_values, "custom_field_values_member_id_fkey") drop constraint(:custom_field_values, "custom_field_values_member_id_fkey")
drop constraint(:custom_field_values, "custom_field_values_custom_field_id_fkey") drop constraint(:custom_field_values, "custom_field_values_custom_field_id_fkey")
# Add back old foreign key constraints # Add back old foreign key constraints
alter table(:custom_field_values) do alter table(:custom_field_values) do
modify :member_id, modify :member_id,
@ -73,10 +71,10 @@ defmodule Mv.Repo.Migrations.RenamePropertiesToCustomFields do
prefix: "public" prefix: "public"
) )
end end
# Rename the foreign key column back # Rename the foreign key column back
rename table("custom_field_values"), :custom_field_id, to: :property_type_id rename table("custom_field_values"), :custom_field_id, to: :property_type_id
# Rename tables back # Rename tables back
rename table("custom_fields"), to: table("property_types") rename table("custom_fields"), to: table("property_types")
rename table("custom_field_values"), to: table("properties") rename table("custom_field_values"), to: table("properties")