Aurora.Uix.Templates.Basic.Helpers (Aurora UIX v0.1.0)

Provides utility functions for LiveView components in Aurora UIX.

Includes functions for managing navigation stacks, assigning values to sockets, handling entity relationships, and managing section/tab assignment.

Helper Categories

  • Navigation - Routing and navigation stack management
  • Assign - Assigning values to sockets or assigns maps
  • Entity - Entity creation and relationship handling
  • Error - Error formatting and processing
  • Field - Field configuration retrieval and processing
  • Layout - Layout options assignment and retrieval
  • Action - Action management within assigns maps
  • Path - Path and URL manipulations

Summary

Functions

Adds an action to the specified actions group in the map.

Assigns a value to the auix assigns map in the socket.

Extracts and assigns the current path out of the current url, to the auix map.

Sets the index new link value. Relies on the existence of auix.uri_path key.

Assigns a value to the auix assigns map in the socket only if it does not exist.

Assigns a layout option to the socket's assigns using the LayoutOptions module.

Sets a layout option to the auix entry in the socket's assigns.

Assigns routing stack to the socket. Decodes stack from params or uses default route.

Assigns section configuration to auix assigns map.

Sets a temporary to the auix entry in the socket's assigns. There is no guarantee that the elements here will remain in the socket.

Sets the global uri path, relies on auix_current_path.

Assigns a new entity to the socket based on related parameters.

Assigns parsed options to the auix assigns map in the socket.

Handles backward navigation by popping the last route from the stack.

Handles forward navigation by updating the routing stack and navigating to the new path.

Extracts association fields from preload configuration grouped by association type.

Flattens a nested structure of elements into a list of paths.

A helper that transforms changeset errors into a map of messages.

Retrieves the configuration for a specific resource from the assigns or auix map.

Retrieves and processes field configuration from the resource configurations.

Retrieves the layout tree for a specific resource and layout type.

Retrieves a specific resource configuration key from the assigns or auix map.

Gets select field options and multiple selection flag.

Inserts an action at the beginning of the specified actions group in the assigns map.

Gets the value of an entity's primary key.

Removes an action by name from the specified actions group in the assigns map.

Replaces an action by name in the specified actions group in the map.

Functions

add_auix_action(socket, actions_group, action)

@spec add_auix_action(
  Phoenix.LiveView.Socket.t() | map(),
  atom(),
  Aurora.Uix.Action.t()
) ::
  Phoenix.LiveView.Socket.t() | map()

Adds an action to the specified actions group in the map.

Parameters

  • assigns_or_socket (Phoenix.LiveView.Socket.t() | map()) - The map containing the :auix key.

  • actions_group (atom()) - The group to which the action will be added.
  • action (Action.t()) - The action to add.

Returns

Phoenix.LiveView.Socket.t() | map() - The updated map with the action added to the group.

assign_auix(socket, key, value)

@spec assign_auix(Phoenix.LiveView.Socket.t() | map(), atom(), term()) ::
  Phoenix.LiveView.Socket.t() | map()

Assigns a value to the auix assigns map in the socket.

Parameters

  • socket (Phoenix.LiveView.Socket.t()) - The LiveView socket
  • key (atom()) - Key for storing in auix map
  • value (term()) - Value to store

Returns

  • Phoenix.LiveView.Socket.t()

assign_auix_current_path(socket, url)

@spec assign_auix_current_path(Phoenix.LiveView.Socket.t(), binary() | URI.t() | nil) ::
  Phoenix.LiveView.Socket.t()

Extracts and assigns the current path out of the current url, to the auix map.

Parameters

  • socket (Phoenix.LiveView.Socket.t()) - The LiveView socket
  • url (binary() | nil) - Actual url.

Returns

  • Phoenix.LiveView.Socket.t() - Socket with updated auix assigns

assign_auix_index_new_link(socket)

@spec assign_auix_index_new_link(Phoenix.LiveView.Socket.t()) ::
  Phoenix.LiveView.Socket.t()

Sets the index new link value. Relies on the existence of auix.uri_path key.

Parameters

  • socket (Phoenix.LiveView.Socket.t()) - The LiveView socket

Returns

  • Phoenix.LiveView.Socket.t() - Socket with updated auix assigns

assign_auix_new(socket, key, value)

@spec assign_auix_new(Phoenix.LiveView.Socket.t(), atom(), any()) ::
  Phoenix.LiveView.Socket.t()

Assigns a value to the auix assigns map in the socket only if it does not exist.

Parameters

  • socket (Phoenix.LiveView.Socket.t()) - The LiveView socket
  • key (atom()) - Key for storing in auix map
  • value (term()) - Value to store

Returns

  • Phoenix.LiveView.Socket.t() - Socket with updated auix assigns

assign_auix_option(socket, option)

@spec assign_auix_option(Phoenix.LiveView.Socket.t() | map(), atom()) ::
  Phoenix.LiveView.Socket.t() | map()

Assigns a layout option to the socket's assigns using the LayoutOptions module.

Retrieves the option value using LayoutOptions.get/2. If the option is not found, assigns the socket unchanged. Otherwise, stores the value in the :layout_options key within the auix map.

Parameters

  • socket (Phoenix.LiveView.Socket.t()) - The LiveView socket.
  • option (atom()) - The option key to retrieve and assign.

Returns

Phoenix.LiveView.Socket.t() - The socket with the option assigned in auix.layout_options.

assign_auix_option(socket, option, option_value)

@spec assign_auix_option(Phoenix.LiveView.Socket.t(), atom(), term() | nil) ::
  Phoenix.LiveView.Socket.t()

Sets a layout option to the auix entry in the socket's assigns.

Parameters

  • socket (Phoenix.LiveView.Socket.t()) - The LiveView socket.
  • option (atom()) - The option key to retrieve and assign.
  • option_value term() - The value to put on the option.

Returns

Phoenix.LiveView.Socket.t() - Socket with updated auix assigns

assign_auix_routing_stack(socket, params, default_route \\ nil)

@spec assign_auix_routing_stack(Phoenix.LiveView.Socket.t(), map(), map() | nil) ::
  Phoenix.LiveView.Socket.t()

Assigns routing stack to the socket. Decodes stack from params or uses default route.

Parameters

  • socket (Phoenix.LiveView.Socket.t()) - The LiveView socket.
  • params (map()) - Parameters, may contain "routing_stack" as a key.
  • default_route (map() | nil) - Optional default route to use if no stack is present.

Returns

Phoenix.LiveView.Socket.t() - The socket with updated routing stack.

Examples

iex> params = %{"routing_stack" => encoded_stack}
iex> assign_auix_routing_stack(socket, params, nil)
#=> %Phoenix.LiveView.Socket{assigns: %{routing_stack: %Stack{...}}}

iex> assign_auix_routing_stack(socket, %{}, nil)
#=> %Phoenix.LiveView.Socket{assigns: %{routing_stack: %Stack{}}}

iex> assign_auix_routing_stack(socket, %{}, %{path: "/default"})
#=> %Phoenix.LiveView.Socket{assigns: %{routing_stack: %Stack{...}}}

assign_auix_sections(socket, sections_id, tab_id)

@spec assign_auix_sections(Phoenix.LiveView.Socket.t(), binary(), binary()) ::
  Phoenix.LiveView.Socket.t()

Assigns section configuration to auix assigns map.

Parameters

  • socket (Phoenix.LiveView.Socket.t()) - The LiveView socket
  • sections_id (binary()) - Identifier for the sections group
  • tab_id (binary()) - Identifier for the active tab

Returns

  • Phoenix.LiveView.Socket.t() - Socket with updated auix assigns

assign_auix_temp(socket, key, value)

@spec assign_auix_temp(Phoenix.LiveView.Socket.t(), atom(), any()) :: any()

Sets a temporary to the auix entry in the socket's assigns. There is no guarantee that the elements here will remain in the socket.

Parameters

  • socket (Phoenix.LiveView.Socket.t()) - The LiveView socket.
  • key (atom()) - The key to assign.
  • value term() - The value to put on the temp space.

Returns

Phoenix.LiveView.Socket.t() - Socket with updated auix assigns

assign_auix_uri_path(socket)

@spec assign_auix_uri_path(Phoenix.LiveView.Socket.t()) :: Phoenix.LiveView.Socket.t()

Sets the global uri path, relies on auix_current_path.

Parameters

  • socket (Phoenix.LiveView.Socket.t()) - The LiveView socket

Returns

  • Phoenix.LiveView.Socket.t() - Socket with updated auix assigns

assign_new_entity(socket, arg2, default)

@spec assign_new_entity(Phoenix.LiveView.Socket.t(), map(), struct()) ::
  Phoenix.LiveView.Socket.t()

Assigns a new entity to the socket based on related parameters.

Parameters

  • socket (Phoenix.LiveView.Socket.t()) - The LiveView socket
  • params (map()) - Map containing optional related_key and parent_id for relationships
  • default (struct()) - Default entity struct for new records

Returns

  • Phoenix.LiveView.Socket.t() - Socket with entity assigned to :auix.entity

assign_parsed_opts(socket, parsed_opts)

@spec assign_parsed_opts(Phoenix.LiveView.Socket.t(), map()) ::
  Phoenix.LiveView.Socket.t()

Assigns parsed options to the auix assigns map in the socket.

Parameters

  • socket (Phoenix.LiveView.Socket.t()) - The LiveView socket
  • parsed_opts (map()) - Options to merge with existing auix assigns

Returns

  • Phoenix.LiveView.Socket.t()- Socket with updated auix assigns

auix_route_back(socket)

Handles backward navigation by popping the last route from the stack.

Parameters

  • socket (Phoenix.LiveView.Socket.t()) - The LiveView socket

Returns

  • Phoenix.LiveView.Socket.t()

auix_route_forward(socket, navigation)

@spec auix_route_forward(
  Phoenix.LiveView.Socket.t(),
  keyword()
) :: Phoenix.LiveView.Socket.t()

Handles forward navigation by updating the routing stack and navigating to the new path.

Parameters

  • socket (Phoenix.LiveView.Socket.t()) - The LiveView socket
  • navigation (keyword()) - Navigation options with :navigate or :patch key

Returns

  • Phoenix.LiveView.Socket.t()

extract_association_preload(parsed_opts)

@spec extract_association_preload(map()) :: map()

Extracts association fields from preload configuration grouped by association type.

Parameters

  • parsed_opts (map()) - Configuration map containing preload and resource settings

Returns

  • map() - Map with association field types (:one_to_many, :many_to_one) as keys and lists of field names as values

flatten_layout_tree(elements, result \\ [])

@spec flatten_layout_tree(map() | list(), list()) :: list()

Flattens a nested structure of elements into a list of paths.

Parameters

  • elements (map() | list()) - Nested structure containing inner_elements and tags

  • result (list()) - Accumulated result, defaults to empty list

Returns

  • list() - Flattened list of maps containing tag and name information

format_changeset_errors(changeset)

@spec format_changeset_errors(Ecto.Changeset.t()) :: list()

A helper that transforms changeset errors into a map of messages.

assert {:error, changeset} = Accounts.create_user(%{password: "short"})
assert "password is too short" in errors_on(changeset).password
assert %{password: ["password is too short"]} = errors_on(changeset)

get_configuration(assigns, resource_name)

@spec get_configuration(map(), atom()) :: map()

Retrieves the configuration for a specific resource from the assigns or auix map.

Parameters

  • assigns_or_auix (map()) - The assigns map or auix map containing configurations
  • resource_name (atom()) - The name of the resource to retrieve configuration for

Returns

  • map() - The configuration map for the specified resource, or an empty map if not_found

get_field(field, configurations, resource_name)

@spec get_field(map(), map(), atom()) :: Aurora.Uix.Field.t()

Retrieves and processes field configuration from the resource configurations.

Parameters:

  • field: %{name: atom()} - Map containing the field name and options
  • configurations: map - Global configurations for all resources
  • resource_name: atom - The name of the resource the field belongs to

Returns:

  • Field.t() - A Field struct containing the processed field configuration

get_layout(assigns_or_auix, resource_name, layout_type)

@spec get_layout(map(), atom(), atom()) :: map()

Retrieves the layout tree for a specific resource and layout type.

Parameters

  • assigns_or_auix (map()) - The assigns ma wp or auix map containing configurations
  • resource_name (atom()) - The name of the resource to retrieve layout for
  • layout_type (atom()) - The type of layout to retrieve (e.g., :form, :index)

Returns

  • map() - The layout tree map for the specified resource and layout type, or an empty map if not found

get_resource(assigns_or_auix, resource_name, key)

@spec get_resource(map(), atom(), atom() | list()) :: term()

Retrieves a specific resource configuration key from the assigns or auix map.

Parameters

  • assigns_or_auix (map()) - The assigns map or auix map containing configurations
  • resource_name (atom()) - The name of the resource to retrieve configuration for
  • key (atom()) - The specific key to retrieve from the resource configuration

Returns

  • map() - The value for the specified key in the resource configuration, or an empty map if not found

get_select_options(assigns)

@spec get_select_options(map()) :: map()

Gets select field options and multiple selection flag.

Processes field configuration to generate options for select inputs. Handles different data sources including related resources and hardcoded options.

Parameters

  • assigns (map()) - Assigns map containing field and configuration data

Returns

map() - Map with :options (list of {label, value} tuples) and :multiple (boolean)

insert_auix_action(socket, actions_group, action)

@spec insert_auix_action(
  Phoenix.LiveView.Socket.t() | map(),
  atom(),
  Aurora.Uix.Action.t()
) ::
  Phoenix.LiveView.Socket.t() | map()

Inserts an action at the beginning of the specified actions group in the assigns map.

Parameters

  • assigns_or_socket (Phoenix.LiveView.Socket.t() | map()) - The assigns map containing the :auix key.

  • actions_group (atom()) - The group to which the action will be added.
  • action (Action.t()) - The action to insert.

Returns

Phoenix.LiveView.Socket.t() | map() - The updated map with the action inserted at the beginning of the group.

primary_key_value(entity, primary_key)

@spec primary_key_value(term() | nil, atom() | list()) :: term() | list() | nil

Gets the value of an entity's primary key.

Parameters

  • entity (term()) - The entity that will be primary key value.
  • primary_key (atom() | list()) - The field (or fields) to be gather from the entity.

Returns

term() | list() | nil - Return a single value if the primary key is an atom() or a single element list. Otherwise returns a list of values, each corresponding to each of the primary key list of fields.

remove_auix_action(socket, actions_group, action_name)

@spec remove_auix_action(map(), atom(), atom()) :: map()

Removes an action by name from the specified actions group in the assigns map.

Parameters

  • assigns_or_socket (Phoenix.LiveView.Socket.t() | map()) - The assigns map containing the :auix key.

  • actions_group (atom()) - The group from which the action will be removed.
  • action_name (atom()) - The name of the action to remove.

Returns

Phoenix.LiveView.Socket.t() | map() - The updated assigns map with the action removed from the group.

replace_auix_action(socket, actions_group, action)

@spec replace_auix_action(
  Phoenix.LiveView.Socket.t() | map(),
  atom(),
  Aurora.Uix.Action.t()
) :: map()

Replaces an action by name in the specified actions group in the map.

Parameters

  • assigns_or_socket (Phoenix.LiveView.Socket.t() | map()) - The map containing the :auix key.

  • actions_group (atom()) - The group in which the action will be replaced.
  • action (Action.t()) - The action to replace, must include a :name key.

Returns

Phoenix.LiveView.Socket.t() | map() - The updated map with the action replaced.