Aurora. Uix. Templates. Basic. Handlers. IndexImpl behaviour
(Aurora UIX v0.1.4-rc.8)
Copy Markdown
Behaviour and macro for implementing index page handlers in Aurora UIX LiveView templates.
Provides a set of callbacks and a __using__/1 macro to standardize the handling of mount,
parameter changes, events, info messages, and action application for index pages.
Key Features
- Defines required callbacks for index page lifecycle and event handling
- Supplies a macro to inject default implementations and imports for LiveView modules
- Integrates with Aurora UIX context and module generators for dynamic entity management
- Supports streaming, patching, and navigation for index resources
- Handles pagination, filtering, and item selection for large datasets
- Provides async operations for bulk actions (select all, delete all)
Key Constraints
- Expects the
:auixassign to be present in the LiveView socket - Designed for use with Phoenix LiveView and Aurora UIX context modules
- Assumes certain structure in the
auixassign (e.g.,modules.context,source_key, etc.) - Requires resource modules to implement CRUD operations via Aurora.Uix.Integration.Crud
Summary
Callbacks
Applies the given action to the socket.
Handles async task results for the index LiveView.
Internally handles all LiveView events for the index page.
Handles info messages for the index LiveView.
Handles URL parameter changes, updates routing stack, and assigns form component.
Initializes the LiveView socket for the index page.
Functions
Applies the given action to the socket state.
Handles async results for selection operations.
Handles LiveView events for the index page.
Handles info messages for the LiveView.
Handles URL parameter changes and updates socket state.
Initializes the LiveView socket for the index page by streaming entities.
Callbacks
@callback apply_action( socket :: Phoenix.LiveView.Socket.t(), params :: map() ) :: Phoenix.LiveView.Socket.t()
Applies the given action to the socket.
Parameters
socket(Socket.t()) - LiveView socket.params(map()) - Action parameters.
Returns
Socket.t() - Updated socket with action-specific assigns.
@callback auix_handle_async( task :: atom(), result :: term(), socket :: Phoenix.LiveView.Socket.t() ) :: {:noreply, Phoenix.LiveView.Socket.t()}
Handles async task results for the index LiveView.
Parameters
task(atom()) - Task name.result(term()) - Async task result.socket(Socket.t()) - LiveView socket.
Returns
{:noreply, Socket.t()} - Updated socket after handling async result.
@callback auix_handle_event( event :: binary(), params :: map(), socket :: Phoenix.LiveView.Socket.t() ) :: {:noreply, Phoenix.LiveView.Socket.t()}
Internally handles all LiveView events for the index page.
Parameters
event(binary()) - Event name.params(map()) - Event parameters.socket(Socket.t()) - LiveView socket.
Returns
{:noreply, Socket.t()} - Updated socket after event handling.
@callback auix_handle_info(message :: term(), socket :: Phoenix.LiveView.Socket.t()) :: {:noreply, Phoenix.LiveView.Socket.t()}
Handles info messages for the index LiveView.
Parameters
message(term()) - Info message.socket(Socket.t()) - LiveView socket.
Returns
{:noreply, Socket.t()} - Updated socket after handling message.
@callback auix_handle_params( params :: map(), url :: binary(), socket :: Phoenix.LiveView.Socket.t() ) :: {:noreply, Phoenix.LiveView.Socket.t()}
Handles URL parameter changes, updates routing stack, and assigns form component.
Parameters
params(map()) - URL/query parameters.url(binary()) - Current URL.socket(Socket.t()) - LiveView socket with:auixassigns.
Returns
{:noreply, Socket.t()} - Updated socket with routing stack and form component.
@callback auix_mount( params :: map(), session :: map(), socket :: Phoenix.LiveView.Socket.t() ) :: {:ok, Phoenix.LiveView.Socket.t()}
Initializes the LiveView socket for the index page.
Parameters
params(map()) - URL/query parameters.session(map()) - Session data.socket(Socket.t()) - LiveView socket with:auixassigns.
Returns
{:ok, Socket.t()} - The initialized socket with streamed entities from context.
Functions
@spec apply_action(Phoenix.LiveView.Socket.t(), map()) :: Phoenix.LiveView.Socket.t()
Applies the given action to the socket state.
Handles :edit, :show, :show_edit actions by fetching and assigning entity, :new action
by creating new entity, and :index action by clearing entity assignment or paginating.
Parameters
socket(Socket.t()) - LiveView socket.params(map()) - Action parameters containing entity ID for actions that require it.
Returns
Socket.t() - Updated socket with action-specific entity assignment.
@spec auix_handle_async(atom(), term(), Phoenix.LiveView.Socket.t()) :: {:noreply, Phoenix.LiveView.Socket.t()}
Handles async results for selection operations.
Selecting all items in large datasets is time consuming, therefore it is handled asynchronously.
Parameters
task(atom()) - Task name (:auix_selection_toggle_allor:auix_selection_delete_all).result(term()) - Result of the async task.socket(Socket.t()) - LiveView socket.
Returns
{:noreply, Socket.t()} - Updated socket with the new selection.
@spec auix_handle_event(binary(), map(), Phoenix.LiveView.Socket.t()) :: {:noreply, Phoenix.LiveView.Socket.t()}
Handles LiveView events for the index page.
Supports delete events with custom context/functions or default auix context, forward/back navigation events, routing events, filtering, pagination, and selection.
Parameters
event(binary()) - Event name.params(map()) - Event parameters.socket(Socket.t()) - LiveView socket.
Returns
{:noreply, Socket.t()} - Updated socket after event handling.
@spec auix_handle_info(term(), Phoenix.LiveView.Socket.t()) :: {:noreply, Phoenix.LiveView.Socket.t()}
Handles info messages for the LiveView.
Processes save notifications by inserting entities into the stream, ignores other messages.
Parameters
event_info(term()) - Info message, typically{component, {:saved, entity}}.socket(Socket.t()) - LiveView socket.
Returns
{:noreply, Socket.t()} - Updated socket with entity inserted into stream or unchanged.
@spec auix_handle_params(map(), binary(), Phoenix.LiveView.Socket.t()) :: {:noreply, Phoenix.LiveView.Socket.t()}
Handles URL parameter changes and updates socket state.
Updates routing stack, assigns form component, and applies the current action based on live_action and parameters.
Parameters
params(map()) - URL/query parameters.url(binary()) - Current URL.socket(Socket.t()) - LiveView socket with:auixassigns.
Returns
{:noreply, Socket.t()} - Updated socket with routing stack, form component, and action applied.
@spec auix_mount(map(), map(), Phoenix.LiveView.Socket.t()) :: {:ok, Phoenix.LiveView.Socket.t()}
Initializes the LiveView socket for the index page by streaming entities.
Parameters
params(map()) - URL/query parameters.session(map()) - Session data.socket(Socket.t()) - LiveView socket with:auixassigns.
Returns
{:ok, Socket.t()} - The initialized socket with streamed entities from context.