Current section

Files

Jump to
arke lib arke core link.ex
Raw

lib/arke/core/link.ex

defmodule Arke.Core.Link do
@moduledoc false
use Arke.System
alias Arke.Boundary.{ArkeManager, GroupManager}
arke id: :arke_link, label: "Arke Link", type: "table" do
parameter :parent_id, :string, is_primary: true, required: true, persistence: "table_column"
parameter :child_id, :string, is_primary: true, required: true, persistence: "table_column"
parameter :type, :string, required: true, persistence: "table_column"
parameter :configuration, :dict, is_primary: true, default_dict: %{}, persistence: "table_column"
end
def on_create(%{data: %{type: "parameter", parent_id: parent_id, child_id: child_id}, metadata: %{project: project}=metadata}=unit) do
ArkeManager.add_link(String.to_existing_atom(parent_id), project, :parameters, String.to_existing_atom(child_id), metadata)
{:ok, unit}
end
def on_create(%{data: %{type: "group", parent_id: parent_id, child_id: child_id}, metadata: %{project: project}=metadata}=unit) do
GroupManager.add_link(String.to_existing_atom(parent_id), project, :arke_list, String.to_existing_atom(child_id), metadata)
{:ok, unit}
end
def on_delete(%{data: %{type: "parameter", parent_id: parent_id, child_id: child_id}, metadata: %{project: project}=metadata}=unit) do
ArkeManager.remove_link(String.to_existing_atom(parent_id), project, :parameters, String.to_existing_atom(child_id))
{:ok, unit}
end
def on_delete(%{data: %{type: "group", parent_id: parent_id, child_id: child_id}, metadata: %{project: project}=metadata}=unit) do
GroupManager.remove_link(String.to_existing_atom(parent_id), project, :arke_list, String.to_existing_atom(child_id))
{:ok, unit}
end
end