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]
|
identity :unique_name, [:name]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -81,4 +81,3 @@ 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
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -137,4 +137,3 @@ 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
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -86,4 +86,3 @@ 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
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -64,4 +64,3 @@ 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
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -38,7 +38,9 @@ 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>{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>
|
</.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">
|
||||||
|
|
@ -235,7 +237,10 @@ defmodule MvWeb.CustomFieldValueLive.Form do
|
||||||
|
|
||||||
socket =
|
socket =
|
||||||
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))
|
|> push_navigate(to: return_path(socket.assigns.return_to, custom_field_value))
|
||||||
|
|
||||||
{:noreply, socket}
|
{:noreply, socket}
|
||||||
|
|
@ -260,16 +265,23 @@ defmodule MvWeb.CustomFieldValueLive.Form do
|
||||||
%{}
|
%{}
|
||||||
end
|
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
|
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
|
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
|
||||||
|
|
@ -280,4 +292,3 @@ 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
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,11 @@ 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={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>
|
<: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)}
|
{:noreply, stream_delete(socket, :custom_field_values, custom_field_value)}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,10 @@ 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 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
|
<.icon name="hero-pencil-square" /> Edit Custom field value
|
||||||
</.button>
|
</.button>
|
||||||
</:actions>
|
</:actions>
|
||||||
|
|
@ -62,4 +65,3 @@ 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
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -58,7 +58,8 @@ 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 = 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]}>
|
<.inputs_for :let={value_form} field={f_custom_field_value[:value]}>
|
||||||
<% input_type =
|
<% input_type =
|
||||||
cond do
|
cond do
|
||||||
|
|
@ -190,7 +191,8 @@ defmodule MvWeb.MemberLive.Form do
|
||||||
forms: [auto?: true]
|
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(
|
Enum.reduce(
|
||||||
missing_custom_field_values,
|
missing_custom_field_values,
|
||||||
|
|
|
||||||
|
|
@ -41,12 +41,14 @@ defmodule Mv.Repo.Migrations.RenamePropertiesToCustomFields do
|
||||||
|
|
||||||
# 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
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue