Compare commits
1 commit
dc438863d3
...
8400e727a7
| Author | SHA1 | Date | |
|---|---|---|---|
| 8400e727a7 |
10 changed files with 40 additions and 25 deletions
|
|
@ -86,4 +86,3 @@ defmodule Mv.Membership.CustomField do
|
|||
identity :unique_name, [:name]
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -81,4 +81,3 @@ defmodule Mv.Membership.CustomFieldValue do
|
|||
identity :unique_custom_field_per_member, [:member_id, :custom_field_id]
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -137,4 +137,3 @@ defmodule MvWeb.CustomFieldLive.Form do
|
|||
defp return_path("index", _custom_field), do: ~p"/custom_fields"
|
||||
defp return_path("show", custom_field), do: ~p"/custom_fields/#{custom_field.id}"
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -86,4 +86,3 @@ defmodule MvWeb.CustomFieldLive.Index do
|
|||
{:noreply, stream_delete(socket, :custom_fields, custom_field)}
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -64,4 +64,3 @@ defmodule MvWeb.CustomFieldLive.Show do
|
|||
|> assign(:custom_field, Ash.get!(Mv.Membership.CustomField, id))}
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -38,7 +38,9 @@ defmodule MvWeb.CustomFieldValueLive.Form do
|
|||
<Layouts.app flash={@flash} current_user={@current_user}>
|
||||
<.header>
|
||||
{@page_title}
|
||||
<:subtitle>{gettext("Use this form to manage custom_field_value records in your database.")}</:subtitle>
|
||||
<:subtitle>
|
||||
{gettext("Use this form to manage custom_field_value records in your database.")}
|
||||
</:subtitle>
|
||||
</.header>
|
||||
|
||||
<.form for={@form} id="custom_field_value-form" phx-change="validate" phx-submit="save">
|
||||
|
|
@ -235,7 +237,10 @@ defmodule MvWeb.CustomFieldValueLive.Form do
|
|||
|
||||
socket =
|
||||
socket
|
||||
|> put_flash(:info, gettext("Custom field value %{action} successfully", action: action))
|
||||
|> put_flash(
|
||||
:info,
|
||||
gettext("Custom field value %{action} successfully", action: action)
|
||||
)
|
||||
|> push_navigate(to: return_path(socket.assigns.return_to, custom_field_value))
|
||||
|
||||
{:noreply, socket}
|
||||
|
|
@ -260,16 +265,23 @@ defmodule MvWeb.CustomFieldValueLive.Form do
|
|||
%{}
|
||||
end
|
||||
|
||||
AshPhoenix.Form.for_update(custom_field_value, :update, as: "custom_field_value", params: params)
|
||||
AshPhoenix.Form.for_update(custom_field_value, :update,
|
||||
as: "custom_field_value",
|
||||
params: params
|
||||
)
|
||||
else
|
||||
AshPhoenix.Form.for_create(Mv.Membership.CustomFieldValue, :create, as: "custom_field_value")
|
||||
AshPhoenix.Form.for_create(Mv.Membership.CustomFieldValue, :create,
|
||||
as: "custom_field_value"
|
||||
)
|
||||
end
|
||||
|
||||
assign(socket, form: to_form(form))
|
||||
end
|
||||
|
||||
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
|
||||
defp custom_field_options(custom_fields) do
|
||||
|
|
@ -280,4 +292,3 @@ defmodule MvWeb.CustomFieldValueLive.Form do
|
|||
Enum.map(members, &{"#{&1.first_name} #{&1.last_name}", &1.id})
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -39,7 +39,11 @@ defmodule MvWeb.CustomFieldValueLive.Index do
|
|||
<.table
|
||||
id="custom_field_values"
|
||||
rows={@streams.custom_field_values}
|
||||
row_click={fn {_id, custom_field_value} -> JS.navigate(~p"/custom_field_values/#{custom_field_value}") end}
|
||||
row_click={
|
||||
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>
|
||||
|
||||
|
|
@ -80,4 +84,3 @@ defmodule MvWeb.CustomFieldValueLive.Index do
|
|||
{:noreply, stream_delete(socket, :custom_field_values, custom_field_value)}
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -33,7 +33,10 @@ defmodule MvWeb.CustomFieldValueLive.Show do
|
|||
<.button navigate={~p"/custom_field_values"}>
|
||||
<.icon name="hero-arrow-left" />
|
||||
</.button>
|
||||
<.button variant="primary" navigate={~p"/custom_field_values/#{@custom_field_value}/edit?return_to=show"}>
|
||||
<.button
|
||||
variant="primary"
|
||||
navigate={~p"/custom_field_values/#{@custom_field_value}/edit?return_to=show"}
|
||||
>
|
||||
<.icon name="hero-pencil-square" /> Edit Custom field value
|
||||
</.button>
|
||||
</:actions>
|
||||
|
|
@ -62,4 +65,3 @@ defmodule MvWeb.CustomFieldValueLive.Show do
|
|||
defp page_title(:show), do: "Show Custom field value"
|
||||
defp page_title(:edit), do: "Edit Custom field value"
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -58,7 +58,8 @@ defmodule MvWeb.MemberLive.Form do
|
|||
|
||||
<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]}>
|
||||
<% type = Enum.find(@custom_fields, &(&1.id == f_custom_field_value[:custom_field_id].value)) %>
|
||||
<% type =
|
||||
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]}>
|
||||
<% input_type =
|
||||
cond do
|
||||
|
|
@ -190,7 +191,8 @@ defmodule MvWeb.MemberLive.Form do
|
|||
forms: [auto?: true]
|
||||
)
|
||||
|
||||
missing_custom_field_values = Enum.filter(socket.assigns[:initial_custom_field_values], is_missing_custom_field_value)
|
||||
missing_custom_field_values =
|
||||
Enum.filter(socket.assigns[:initial_custom_field_values], is_missing_custom_field_value)
|
||||
|
||||
Enum.reduce(
|
||||
missing_custom_field_values,
|
||||
|
|
|
|||
|
|
@ -11,14 +11,14 @@ defmodule Mv.Repo.Migrations.RenamePropertiesToCustomFields do
|
|||
# Rename tables
|
||||
rename table("property_types"), to: table("custom_fields")
|
||||
rename table("properties"), to: table("custom_field_values")
|
||||
|
||||
|
||||
# Rename the foreign key column
|
||||
rename table("custom_field_values"), :property_type_id, to: :custom_field_id
|
||||
|
||||
|
||||
# Drop old foreign key constraints
|
||||
drop constraint(:custom_field_values, "properties_member_id_fkey")
|
||||
drop constraint(:custom_field_values, "properties_property_type_id_fkey")
|
||||
|
||||
|
||||
# Add new foreign key constraints with correct names and on_delete behavior
|
||||
alter table(:custom_field_values) do
|
||||
modify :member_id,
|
||||
|
|
@ -38,21 +38,23 @@ defmodule Mv.Repo.Migrations.RenamePropertiesToCustomFields do
|
|||
prefix: "public"
|
||||
)
|
||||
end
|
||||
|
||||
|
||||
# Rename indexes
|
||||
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"
|
||||
end
|
||||
|
||||
def down do
|
||||
# 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_field_values_unique_custom_field_per_member_index RENAME TO properties_unique_property_per_member_index"
|
||||
|
||||
|
||||
# Drop new foreign key constraints
|
||||
drop constraint(:custom_field_values, "custom_field_values_member_id_fkey")
|
||||
drop constraint(:custom_field_values, "custom_field_values_custom_field_id_fkey")
|
||||
|
||||
|
||||
# Add back old foreign key constraints
|
||||
alter table(:custom_field_values) do
|
||||
modify :member_id,
|
||||
|
|
@ -71,10 +73,10 @@ defmodule Mv.Repo.Migrations.RenamePropertiesToCustomFields do
|
|||
prefix: "public"
|
||||
)
|
||||
end
|
||||
|
||||
|
||||
# Rename the foreign key column back
|
||||
rename table("custom_field_values"), :custom_field_id, to: :property_type_id
|
||||
|
||||
|
||||
# Rename tables back
|
||||
rename table("custom_fields"), to: table("property_types")
|
||||
rename table("custom_field_values"), to: table("properties")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue