feat: property value as Union type
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
c91f65d04c
commit
d085d80f74
6 changed files with 40 additions and 7 deletions
|
|
@ -16,8 +16,16 @@ defmodule Mv.Membership.Property do
|
||||||
attributes do
|
attributes do
|
||||||
uuid_primary_key :id
|
uuid_primary_key :id
|
||||||
|
|
||||||
attribute :value, :string,
|
attribute :value, :union,
|
||||||
description: "Speichert den Wert, Typ-Interpretation per property_type.typ"
|
constraints: [
|
||||||
|
storage: :type_and_value,
|
||||||
|
types: [
|
||||||
|
bool: [type: :boolean],
|
||||||
|
date: [type: :date],
|
||||||
|
int: [type: :integer],
|
||||||
|
string: [type: :string]
|
||||||
|
]
|
||||||
|
]
|
||||||
end
|
end
|
||||||
|
|
||||||
relationships do
|
relationships do
|
||||||
|
|
@ -25,4 +33,8 @@ defmodule Mv.Membership.Property do
|
||||||
|
|
||||||
belongs_to :property_type, Mv.Membership.PropertyType
|
belongs_to :property_type, Mv.Membership.PropertyType
|
||||||
end
|
end
|
||||||
|
|
||||||
|
calculations do
|
||||||
|
calculate :value_to_string, :string, expr(value[:value] <> "")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,11 @@ defmodule MvWeb.MemberLive.FormComponent do
|
||||||
Enum.map(property_types, fn pt ->
|
Enum.map(property_types, fn pt ->
|
||||||
%{
|
%{
|
||||||
"property_type_id" => pt.id,
|
"property_type_id" => pt.id,
|
||||||
"value" => nil
|
"value" => %{
|
||||||
|
"type" => String.to_existing_atom(pt.type),
|
||||||
|
"value" => nil,
|
||||||
|
"_union_type" => pt.type
|
||||||
|
}
|
||||||
}
|
}
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
|
@ -34,7 +38,9 @@ defmodule MvWeb.MemberLive.FormComponent do
|
||||||
>
|
>
|
||||||
<.inputs_for :let={f_property} field={@form[:properties]}>
|
<.inputs_for :let={f_property} field={@form[:properties]}>
|
||||||
<% type = Enum.find(@property_types, &(&1.id == f_property[:property_type_id].value)) %>
|
<% type = Enum.find(@property_types, &(&1.id == f_property[:property_type_id].value)) %>
|
||||||
<.input field={f_property[:value]} label={type && type.name} />
|
<.inputs_for :let={value_form} field={f_property[:value]}>
|
||||||
|
<.input field={value_form[:value]} label={type && type.name} />
|
||||||
|
</.inputs_for>
|
||||||
<input
|
<input
|
||||||
type="hidden"
|
type="hidden"
|
||||||
name={f_property[:property_type_id].name}
|
name={f_property[:property_type_id].name}
|
||||||
|
|
@ -95,12 +101,27 @@ defmodule MvWeb.MemberLive.FormComponent do
|
||||||
not Enum.member?(existing_properties, Map.get(i, "property_type_id"))
|
not Enum.member?(existing_properties, Map.get(i, "property_type_id"))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
params = %{
|
||||||
|
"properties" =>
|
||||||
|
Enum.map(member.properties, fn prop ->
|
||||||
|
%{
|
||||||
|
"property_type_id" => prop.property_type_id,
|
||||||
|
"value" => %{
|
||||||
|
"_union_type" => Atom.to_string(prop.value.type),
|
||||||
|
"type" => prop.value.type,
|
||||||
|
"value" => prop.value.value
|
||||||
|
}
|
||||||
|
}
|
||||||
|
end)
|
||||||
|
}
|
||||||
|
|
||||||
form =
|
form =
|
||||||
AshPhoenix.Form.for_update(
|
AshPhoenix.Form.for_update(
|
||||||
member,
|
member,
|
||||||
:update_member,
|
:update_member,
|
||||||
api: Mv.Membership,
|
api: Mv.Membership,
|
||||||
as: "member",
|
as: "member",
|
||||||
|
params: params,
|
||||||
forms: [auto?: true]
|
forms: [auto?: true]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,7 @@ defmodule Mv.Repo.Migrations.InitialMigration do
|
||||||
|
|
||||||
create table(:properties, primary_key: false) do
|
create table(:properties, primary_key: false) do
|
||||||
add :id, :uuid, null: false, default: fragment("gen_random_uuid()"), primary_key: true
|
add :id, :uuid, null: false, default: fragment("gen_random_uuid()"), primary_key: true
|
||||||
add :value, :text
|
add :value, :map
|
||||||
add :member_id, :uuid
|
add :member_id, :uuid
|
||||||
add :property_type_id, :uuid
|
add :property_type_id, :uuid
|
||||||
end
|
end
|
||||||
|
|
@ -18,7 +18,7 @@
|
||||||
"references": null,
|
"references": null,
|
||||||
"size": null,
|
"size": null,
|
||||||
"source": "value",
|
"source": "value",
|
||||||
"type": "text"
|
"type": "map"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"allow_nil?": true,
|
"allow_nil?": true,
|
||||||
|
|
@ -84,7 +84,7 @@
|
||||||
"custom_indexes": [],
|
"custom_indexes": [],
|
||||||
"custom_statements": [],
|
"custom_statements": [],
|
||||||
"has_create_action": true,
|
"has_create_action": true,
|
||||||
"hash": "F2A42A3427E0428637F465E4F357A3BE21B33231F94CF77B4843084128F6BDA5",
|
"hash": "4D127B8DA5051633CE92D4C94B1C3D76FCBD2EE992EF8318B977E5C2B8CF19E4",
|
||||||
"identities": [],
|
"identities": [],
|
||||||
"multitenancy": {
|
"multitenancy": {
|
||||||
"attribute": null,
|
"attribute": null,
|
||||||
Loading…
Add table
Add a link
Reference in a new issue