"""
end
end
end
defp render_attribute(assigns, _resource, record, %{name: name, type: Ash.Type.Boolean}, _) do
case Map.get(record, name) do
true ->
~H"""
"""
false ->
~H"""
"""
nil ->
~H"""
"""
end
end
defp render_attribute(assigns, resource, record, attribute, nested?) do
if Ash.Type.embedded_type?(attribute.type) do
both_classes = "ml-1 pl-2 pr-2"
if Map.get(record, attribute.name) in [nil, []] do
~H"""
None
"""
else
if nested? do
~H"""
"""
end
end
else
if attribute.type == Ash.Type.String do
cond do
short_text?(resource, attribute) ->
~H"""
{{ value!(Map.get(record, attribute.name)) }}
"""
long_text?(resource, attribute) ->
~H"""
"""
true ->
~H"""
"""
end
else
~H"{{ value!(Map.get(record, attribute.name)) }}"
end
end
end
def handle_event("load", %{"relationship" => relationship}, socket) do
record = socket.assigns.record
api = socket.assigns.api
relationship = String.to_existing_atom(relationship)
case api.load(
record,
relationship,
actor: socket.assigns[:actor],
authorize?: socket.assigns[:authorizing]
) do
{:ok, loaded} ->
{:noreply, assign(socket, record: loaded)}
{:error, errors} ->
{:noreply,
assign(socket, load_errors: Map.put(socket.assigns.load_errors, relationship, errors))}
end
end
def handle_event("unload", %{"relationship" => relationship}, socket) do
record = socket.assigns.record
relationship = String.to_existing_atom(relationship)
unloaded = Map.put(record, relationship, Map.get(record.__struct__.__struct__, relationship))
{:noreply, assign(socket, record: unloaded)}
end
defp loaded?(record, relationship) do
case Map.get(record, relationship) do
%Ash.NotLoaded{} -> false
_ -> true
end
end
defp value!(value) do
Phoenix.HTML.Safe.to_iodata(value)
rescue
_ ->
"..."
end
defp short_text?(resource, attribute) do
case AshAdmin.Resource.field(resource, attribute.name) do
%{type: :short_text} ->
true
_ ->
false
end
end
defp long_text?(resource, attribute) do
case AshAdmin.Resource.field(resource, attribute.name) do
%{type: :long_text} ->
true
_ ->
false
end
end
defp destroy?(resource) do
resource
|> Ash.Resource.Info.actions()
|> Enum.any?(&(&1.type == :destroy))
end
defp update?(resource) do
resource
|> Ash.Resource.Info.actions()
|> Enum.any?(&(&1.type == :update))
end
end