### Install AshAdmin with Igniter Source: https://github.com/ash-project/ash_admin/blob/main/documentation/tutorials/getting-started-with-ash-admin.md Use the Igniter mix task to automatically install AshAdmin, recommended for a streamlined setup. ```bash mix igniter.install ash_admin ``` -------------------------------- ### Start AshAdmin Development Server Source: https://github.com/ash-project/ash_admin/blob/main/documentation/tutorials/contributing-to-ash-admin.md Command to start the AshAdmin application server for local development. ```bash mix dev ``` -------------------------------- ### Ash Admin Integration Example for Phoenix Application Source: https://github.com/ash-project/ash_admin/blob/main/_autodocs/api-reference/ash-admin-router.md Complete setup for integrating Ash Admin into a new Phoenix application, including router pipelines and scopes. ```elixir defmodule MyAppWeb.Router do use Phoenix.Router import MyAppWeb.CoreComponents import AshAdmin.Router pipeline :browser do plug :accepts, ["html"] plug :fetch_session plug :fetch_live_flash plug :put_root_layout, html: {MyAppWeb.Layouts, :root} plug :protect_from_forgery plug :put_secure_browser_headers end pipeline :require_admin do plug MyApp.AdminAuth end scope "/", MyAppWeb do pipe_through :browser get "/", PageController, :home end scope "/admin", MyAppWeb do pipe_through [:browser, :require_admin] ash_admin "/", live_session_name: :ash_admin end ``` -------------------------------- ### Blog Post Form Configuration Example Source: https://github.com/ash-project/ash_admin/blob/main/_autodocs/api-reference/ash-admin-resource-field.md Example of configuring fields for a blog post form, including text types, markdown, file uploads, and datetime. ```elixir admin do form do field :title field :slug field :description, type: :short_text field :content, type: :markdown field :excerpt, type: :long_text field :cover_image, accepted_extensions: ["image/*"], max_file_size: 5_242_880 field :published_at field :featured?, type: :default end end ``` -------------------------------- ### User Registration Form Configuration Example Source: https://github.com/ash-project/ash_admin/blob/main/_autodocs/api-reference/ash-admin-resource-field.md Example of configuring fields for a user registration form, including long text for bio and file upload constraints. ```elixir admin do form do field :email field :first_name field :last_name field :bio, type: :long_text field :avatar, accepted_extensions: ["image/jpeg", "image/png"], max_file_size: 2_097_152 # 2MB field :phone end end ``` -------------------------------- ### Event Management Form Configuration Example Source: https://github.com/ash-project/ash_admin/blob/main/_autodocs/api-reference/ash-admin-resource-field.md Example of configuring fields for an event management form, including custom datetime step for time precision. ```elixir admin do form do field :name field :description, type: :long_text field :location field :start_time, datetime_step: "900" # 15-min increments field :end_time, datetime_step: "900" field :capacity field :is_public end end ``` -------------------------------- ### Ash Filter Format Example: Simple Key Source: https://github.com/ash-project/ash_admin/blob/main/_autodocs/types.md Example of the filter format for a simple primary key. ```elixir # Simple key [{:id, "550e8400-e29b-41d4-a716-446655440000"}] ``` -------------------------------- ### Example Tenant Options Configuration Source: https://github.com/ash-project/ash_admin/blob/main/_autodocs/types.md Illustrates a list of tenant option maps as they might appear in configuration. Each map provides a human-readable label and a string value. ```elixir # From configuration [ %{label: "Production", value: "prod"}, %{label: "Staging", value: "staging"}, %{label: "Development", value: "dev"} ] ``` -------------------------------- ### Basic AshAdmin Plug Setup in Phoenix Router Source: https://github.com/ash-project/ash_admin/blob/main/_autodocs/api-reference/ash-admin-plugs.md Demonstrates how to integrate AshAdmin.SessionPlug and AshAdmin.ActorPlug into a Phoenix router pipeline for admin routes. ```elixir defmodule MyAppWeb.Router do use Phoenix.Router import AshAdmin.Router pipeline :admin do plug AshAdmin.SessionPlug plug AshAdmin.ActorPlug end scope "/admin" do pipe_through [:browser, :admin] ash_admin "/", on_mount: {AshAdmin.ActorPlug, :on_mount, []} end end ``` -------------------------------- ### Get Resources to Show Source: https://github.com/ash-project/ash_admin/blob/main/_autodocs/api-reference/ash-admin-domain.md Retrieves the list of resources to include in the admin dashboard for a given domain. Can return all resources or a specific list. ```elixir # Get resources for a domain resources = AshAdmin.Domain.show_resources(Demo.Accounts.Domain) # => [Demo.Accounts.User, Demo.Accounts.Role] # With wildcard (default) resources = AshAdmin.Domain.show_resources(Demo.Tickets.Domain) # => :* (all resources in domain) ``` -------------------------------- ### Initialize AshAdmin ActorPlug Source: https://github.com/ash-project/ash_admin/blob/main/_autodocs/api-reference/ash-admin-plugs.md Initializes the ActorPlug with provided options. This function is typically called once during application setup. ```elixir def init(opts) :: list ``` -------------------------------- ### Ash Filter Format Example: Composite Key Source: https://github.com/ash-project/ash_admin/blob/main/_autodocs/types.md Example of the filter format for a composite primary key. ```elixir # Composite key [{:user_id, 1}, {:org_id, 42}] ``` -------------------------------- ### Custom Actor Plug Configuration Source: https://github.com/ash-project/ash_admin/blob/main/_autodocs/api-reference/ash-admin-plugs.md Shows how to configure AshAdmin to use a custom actor plug implementation and provides an example of a custom plug module. ```elixir # config/runtime.exs config :ash_admin, :actor_plug, MyApp.CustomActorPlug # lib/my_app/custom_actor_plug.ex defmodule MyApp.CustomActorPlug do @behaviour AshAdmin.ActorPlug @impl true def set_actor_session(conn) do # Custom implementation conn end @impl true def actor_assigns(socket, session) do # Custom implementation [] end end ``` -------------------------------- ### Valid File Upload Constraints Example Source: https://github.com/ash-project/ash_admin/blob/main/_autodocs/api-reference/transformers-and-verifiers.md Demonstrates correct configuration of file upload constraints for a resource attribute. Ensures that `max_file_size` and `accepted_extensions` are applied to a valid file type attribute. ```elixir defmodule MyApp.Posts.Post do use Ash.Resource, extensions: [AshAdmin.Resource] admin do form do # Valid - attachment is an Ash.Type.File attribute field :attachment, max_file_size: 10_485_760, accepted_extensions: [".pdf", ".doc"] end end attributes do uuid_primary_key :id attribute :attachment, :file end actions do create :create do accept [:attachment] end end end ``` -------------------------------- ### admin_browser_pipeline/1 Source: https://github.com/ash-project/ash_admin/blob/main/_autodocs/api-reference/ash-admin-router.md Creates a browser pipeline with necessary plugs and configuration for the AshAdmin LiveView interface. It simplifies the setup of session handling, CSRF protection, and LiveView configuration. ```APIDOC ## admin_browser_pipeline/1 ### Description Creates a browser pipeline with all necessary plugs and configuration for the AshAdmin LiveView interface. This is a convenience macro that sets up the standard browser pipeline including session handling, CSRF protection, and LiveView configuration. ### Signature ```elixir defmacro admin_browser_pipeline(name \ :browser) ``` ### Parameters #### Path Parameters - **name** (atom) - Optional - Default: `:browser` - Pipeline name ### What It Does The generated pipeline includes: - `plug(:accepts, ["html"])` - Accept HTML requests - `plug(:fetch_session)` - Fetch session from cookies - `plug(:fetch_live_flash)` - Fetch LiveView flash messages - `plug(:put_root_layout, html: {AshAdmin.Layouts, :root})` - Set root layout - `plug(:protect_from_forgery)` - CSRF protection - `plug(:put_secure_browser_headers)` - Security headers ### Example ```elixir defmodule MyAppWeb.Router do use Phoenix.Router import AshAdmin.Router # Create default :browser pipeline admin_browser_pipeline() scope "/" do pipe_through [:browser] ash_admin "/admin" end end ``` ### Example with Custom Pipeline Name ```elixir defmodule MyAppWeb.Router do use Phoenix.Router import AshAdmin.Router # Create custom pipeline admin_browser_pipeline :admin_pipeline scope "/" do pipe_through [:admin_pipeline] ash_admin "/admin" end end ``` ``` -------------------------------- ### Get Create Actions for a Resource Source: https://github.com/ash-project/ash_admin/blob/main/_autodocs/api-reference/ash-admin-resource.md Retrieves the list of atoms representing available create actions for a given resource in the Ash Admin UI. ```elixir def create_actions(resource :: atom) :: list(atom) ``` -------------------------------- ### name/1 Source: https://github.com/ash-project/ash_admin/blob/main/_autodocs/api-reference/ash-admin-resource.md Gets the display name for a resource. Returns explicit name or derives from module name. Special handling for versioned resources. ```APIDOC ## name/1 ### Description Gets the display name for a resource. Returns explicit name or derives from module name. Special handling for versioned resources. ### Signature def name(resource :: atom) :: String.t() ### Parameters #### Path Parameters - **resource** (Atom) - Required - Resource module name ### Returns String representation of resource name. ### Example ```elixir AshAdmin.Resource.name(Demo.Accounts.User) # => "User" AshAdmin.Resource.name(Demo.Accounts.UserVersion) # => "Accounts.User" ``` ``` -------------------------------- ### Configure Ash Domain for Admin Source: https://github.com/ash-project/ash_admin/blob/main/_autodocs/api-reference/ash-admin-domain.md Example of how to configure AshAdmin.Domain extension within an Ash domain definition, setting name, visibility, resources, and group labels. ```elixir defmodule MyApp.Accounts.Domain do use Ash.Domain, extensions: [AshAdmin.Domain] admin do name "User Management" show? true show_resources [ MyApp.Accounts.User, MyApp.Accounts.Role ] resource_group_labels( core: "Core", integrations: "Integrations" ) end resources do resource MyApp.Accounts.User resource MyApp.Accounts.Role end end ``` -------------------------------- ### Get Show Calculations for a Resource Source: https://github.com/ash-project/ash_admin/blob/main/_autodocs/api-reference/ash-admin-resource.md Retrieves the list of calculation atoms to be loaded when displaying a single resource. Defaults to an empty list. ```elixir def show_calculations(resource :: atom) :: list(atom) ``` -------------------------------- ### Get Fields for a Resource Source: https://github.com/ash-project/ash_admin/blob/main/_autodocs/api-reference/ash-admin-resource.md Retrieves a list of all configured field overrides for the admin form for a given resource. ```elixir def fields(resource :: atom) :: list(AshAdmin.Resource.Field) ``` -------------------------------- ### Compilation Error Example Source: https://github.com/ash-project/ash_admin/blob/main/_autodocs/api-reference/transformers-and-verifiers.md Illustrates a typical compilation error related to invalid table columns. This error prevents the application from compiling. ```bash $ mix compile ** (RuntimeError) Invalid table columns: [:bad_column] Only attributes, has_one, or belongs_to relationships are allowed. Valid columns: [:id, :email, :name, :created_at] ``` -------------------------------- ### Get Available Read Actions Source: https://github.com/ash-project/ash_admin/blob/main/_autodocs/api-reference/ash-admin-resource.md Returns a list of read actions available for the resource in the admin UI. If not explicitly configured, it returns all read actions, with the primary action listed first. ```elixir actions = AshAdmin.Resource.read_actions(Demo.Accounts.User) # => [:read, :read_all] ``` -------------------------------- ### Get Show Action for a Resource Source: https://github.com/ash-project/ash_admin/blob/main/_autodocs/api-reference/ash-admin-resource.md Retrieves the atom representing the action used for viewing single records. Defaults to the primary read action if not explicitly configured. ```elixir def show_action(resource :: atom) :: atom | nil ``` -------------------------------- ### Authorization Failures Example Source: https://github.com/ash-project/ash_admin/blob/main/_autodocs/README.md Illustrates handling authorization failures, which are standard Ash Forbidden errors. This typically involves setting up authorization policies and configuring actor context. ```elixir # Set up authorization policies on resources # Configure actor context via AshAdmin.ActorPlug ``` -------------------------------- ### Get Format Fields for a Resource Source: https://github.com/ash-project/ash_admin/blob/main/_autodocs/api-reference/ash-admin-resource.md Retrieves formatting rules for fields within a resource. This returns a keyword list mapping field names to MFA (Module, Function, Arguments) tuples for custom formatting. ```elixir formats = AshAdmin.Resource.format_fields(Demo.Accounts.User) # => [updated_at: {Timex, :format!, ["{0D}-{0M}-{YYYY} {h12}:{m} {AM}"]}] ``` -------------------------------- ### Set Up AshAdmin Development Environment Source: https://github.com/ash-project/ash_admin/blob/main/documentation/tutorials/contributing-to-ash-admin.md Run these commands to set up the local PostgreSQL database and initialize the development environment for AshAdmin. ```bash mix ash_postgres.create ``` ```bash mix migrate ``` ```bash mix migrate_tenants ``` ```bash mix setup ``` -------------------------------- ### Get Polymorphic Tables for a Resource Source: https://github.com/ash-project/ash_admin/blob/main/_autodocs/api-reference/ash-admin-resource.md Retrieves all available tables for a polymorphic resource. This includes explicitly configured tables and those inferred from relationships. Ensure the provided domains contain resources with relevant relationships. ```elixir tables = AshAdmin.Resource.polymorphic_tables( Demo.Polymorphic.Vehicle, [Demo.Domain] ) # => ["vehicles", "cars", "trucks"] ``` -------------------------------- ### Ash Resource with AshAdmin Extension Source: https://github.com/ash-project/ash_admin/blob/main/_autodocs/api-reference/ash-admin-resource.md Example of adding the AshAdmin extension to an Ash resource and configuring its admin settings. This includes defining table columns, relationship display fields, label fields, sensitive fields, and form configurations. ```elixir defmodule MyApp.Accounts.User do use Ash.Resource, extensions: [AshAdmin.Resource] admin do name "User" actor? true table_columns [:id, :email, :name, :created_at] relationship_display_fields [:email, :name] label_field :email show_sensitive_fields [:ssn] form do field :email, type: :default field :bio, type: :long_text field :avatar, accepted_extensions: [".jpg", ".png"] end end attributes do uuid_primary_key :id attribute :email, :string, allow_nil?: false attribute :name, :string attribute :bio, :string attribute :ssn, :string, sensitive?: true end end ``` -------------------------------- ### Create Default Browser Pipeline Source: https://github.com/ash-project/ash_admin/blob/main/_autodocs/api-reference/ash-admin-router.md Use this macro to set up the standard browser pipeline with session handling, CSRF protection, and LiveView configuration for AshAdmin. ```elixir defmodule MyAppWeb.Router do use Phoenix.Router import AshAdmin.Router # Create default :browser pipeline admin_browser_pipeline() scope "/" do pipe_through [:browser] ash_admin "/admin" end end ``` -------------------------------- ### Configure Tenant Selection Dropdown Source: https://github.com/ash-project/ash_admin/blob/main/documentation/tutorials/getting-started-with-ash-admin.md Set up a dropdown for tenant selection by configuring the :list_tenants config with a function that returns a list of tenants. ```elixir config :ash_admin, :list_tenants, {MyApp.Tenants, :list_tenants, []} ``` ```elixir defmodule MyApp.Tenants do def list_tenants do [ %{label: "Dev Lab", value: "1"}, %{label: "Production Lab", value: "2"} ] end end ``` -------------------------------- ### resource_group/1 Source: https://github.com/ash-project/ash_admin/blob/main/_autodocs/api-reference/ash-admin-resource.md Gets the resource group identifier for organizing resources in the admin dropdown. ```APIDOC ## resource_group/1 ### Description Gets the resource group identifier for organizing resources in the admin dropdown. ### Signature def resource_group(resource :: atom) :: atom | nil ### Parameters #### Path Parameters - **resource** (Atom) - Required - Resource module name ### Returns Atom identifying the group or nil. ``` -------------------------------- ### label_field/1 Source: https://github.com/ash-project/ash_admin/blob/main/_autodocs/api-reference/ash-admin-resource.md Gets the field to use as the label when this resource appears in relationship selectors and typeahead fields. ```APIDOC ## label_field/1 ### Description Gets the field to use as the label when this resource appears in relationship selectors and typeahead fields. ### Signature def label_field(resource :: atom) :: atom | nil ### Parameters #### Path Parameters - **resource** (Atom) - Required - Resource module name ### Returns Atom identifying the label attribute or nil (defaults to resource name). ### Example ```elixir label = AshAdmin.Resource.label_field(Demo.Accounts.User) # => :email ``` ``` -------------------------------- ### Upgrade Heroicons In-Place Source: https://github.com/ash-project/ash_admin/blob/main/assets/vendor/heroicons/UPGRADE.md Run this command to upgrade Heroicons to the version specified by the HERO_VSN environment variable. Ensure the HERO_VSN variable is set before execution. ```bash export HERO_VSN="2.0.16" ; \ curl -L "https://github.com/tailwindlabs/heroicons/archive/refs/tags/v${HERO_VSN}.tar.gz" | \ tar -xvz --strip-components=1 heroicons-${HERO_VSN}/optimized ``` -------------------------------- ### Configure Tenant Listing for Dropdown Mode Source: https://github.com/ash-project/ash_admin/blob/main/_autodocs/configuration.md Sets up an MFA tuple for fetching available tenants to populate the tenant selection UI in dropdown mode. The function must be exported at compile time. ```elixir # config/config.exs config :ash_admin, list_tenants: {MyApp.Tenants, :list_all, []} # lib/my_app/tenants.ex defmodule MyApp.Tenants do # Must be exported at compile time for dropdown detection def list_all do ["production", "staging", "development"] end end ``` -------------------------------- ### actor_load/1 Source: https://github.com/ash-project/ash_admin/blob/main/_autodocs/api-reference/ash-admin-resource.md Gets the load statement to apply when fetching an actor from this resource. Typically used to preload relationships needed for authorization. ```APIDOC ## actor_load/1 ### Description Gets the load statement to apply when fetching an actor from this resource. Typically used to preload relationships needed for authorization. ### Signature def actor_load(resource :: atom) :: list | any ### Parameters #### Path Parameters - **resource** (Atom) - Required - Resource module name ### Returns Ash load statement or empty list. ### Example ```elixir loads = AshAdmin.Resource.actor_load(Demo.Accounts.User) # => [roles: [:permissions]] ``` ``` -------------------------------- ### relationship_select_max_items/1 Source: https://github.com/ash-project/ash_admin/blob/main/_autodocs/api-reference/ash-admin-resource.md Gets the maximum number of items to show in a relationship select dropdown before switching to typeahead search. Defaults to 50. ```APIDOC ## relationship_select_max_items/1 ### Description Gets the maximum number of items to show in a relationship select dropdown before switching to typeahead search. Defaults to 50. ### Signature def relationship_select_max_items(resource :: atom) :: integer ### Parameters #### Path Parameters - **resource** (Atom) - Required - Resource module name ### Returns Integer representing maximum items in dropdown. ``` -------------------------------- ### list_tenants/0 Source: https://github.com/ash-project/ash_admin/blob/main/_autodocs/api-reference/ash-admin-core.md Fetches all available tenants from the configured tenant listing function. The returned list of tenant options is normalized to include `:label` and `:value` keys. ```APIDOC ## list_tenants/0 ### Description Fetches all available tenants from the configured tenant listing function. Returns a list of tenant options normalized to include `:label` and `:value` keys. ### Signature ```elixir def list_tenants() :: list(map) ``` ### Returns List of maps with `label` (string) and `value` (string) keys representing available tenants. ### Example ```elixir tenants = AshAdmin.list_tenants() # => [%{label: "Tenant A", value: "tenant-a"}, ...] ``` ``` -------------------------------- ### Get Specific Field Configuration Source: https://github.com/ash-project/ash_admin/blob/main/_autodocs/api-reference/ash-admin-resource.md Retrieves a specific field configuration by its name for a given resource. Returns nil if the field is not found. ```elixir def field(resource :: atom, name :: atom) :: AshAdmin.Resource.Field | nil ``` ```elixir field = AshAdmin.Resource.field(Demo.Accounts.User, :email) # => %AshAdmin.Resource.Field{name: :email, type: :default} ``` -------------------------------- ### Datetime Configuration: Datetime Step Source: https://github.com/ash-project/ash_admin/blob/main/_autodocs/api-reference/ash-admin-resource-field.md Illustrates configuring the step precision for datetime inputs, affecting increments like minutes or seconds. ```elixir # Minute precision (default) field :scheduled_at, datetime_step: "60" # Second precision field :precise_time, datetime_step: "1" # 15-minute increments field :appointment_time, datetime_step: "900" ``` -------------------------------- ### File Upload Configuration: Accepted Extensions Source: https://github.com/ash-project/ash_admin/blob/main/_autodocs/api-reference/ash-admin-resource-field.md Shows how to configure accepted file extensions or MIME types for file upload fields. ```elixir # File extensions field :document, accepted_extensions: [".pdf", ".doc", ".docx"] # MIME types field :image, accepted_extensions: ["image/jpeg", "image/png"] # Wildcard MIME types field :media, accepted_extensions: ["image/*", "video/*"] # Any file accepted field :attachment, accepted_extensions: :any ``` -------------------------------- ### Fixing Unknown Resource in show_resources Source: https://github.com/ash-project/ash_admin/blob/main/_autodocs/api-reference/transformers-and-verifiers.md Demonstrates how to correctly specify resources for `show_resources`, ensuring the path is accurate and the resource is declared in the `resources` block. ```elixir # Wrong: typo or not declared admin do show_resources [MyApp.Accouts.User] # Typo! end # Right: correct path and must be in resources block admin do show_resources [MyApp.Accounts.User] end resources do resource MyApp.Accounts.User end ``` -------------------------------- ### Get Resource Group Labels Source: https://github.com/ash-project/ash_admin/blob/main/_autodocs/api-reference/ash-admin-domain.md Retrieves humanized labels for resource groups within a domain. Used for navigation dropdowns and sorting. ```elixir labels = AshAdmin.Domain.resource_group_labels(Demo.Accounts.Domain) # => [core: "Core Resources", integrations: "Third Party"] ``` -------------------------------- ### AshAdmin.ActorPlug.init/1 Source: https://github.com/ash-project/ash_admin/blob/main/_autodocs/api-reference/ash-admin-plugs.md Initializes the ActorPlug with provided options. This function is used to configure the plug before it's used in the pipeline. ```APIDOC ## init/1 ### Description Initializes the plug with options. ### Signature def init(opts) ### Parameters #### Path Parameters - **opts** (list) - Required - Plug options ### Returns Options unchanged. ``` -------------------------------- ### Raise and Catch NotFound Exception Source: https://github.com/ash-project/ash_admin/blob/main/_autodocs/errors.md Demonstrates how to raise the custom NotFound exception with specific details and how to catch it using a try/rescue block. ```elixir # User not found raise AshAdmin.Errors.NotFound, thing: "User", key: "550e8400-e29b-41d4-a716-446655440000" # Message: "User 550e8400-e29b-41d4-a716-446655440000 not found" # Resource not found raise AshAdmin.Errors.NotFound, thing: "Resource", key: :demo_accounts_user # Message: "Resource demo_accounts_user not found" ``` ```elixir try do # admin code rescue e in AshAdmin.Errors.NotFound -> # Handle not found Logger.error("#{e.message}") end ``` -------------------------------- ### Get Domain Display Name Source: https://github.com/ash-project/ash_admin/blob/main/_autodocs/api-reference/ash-admin-domain.md Retrieves the display name for a domain in the admin dashboard. It can be explicitly configured or derived from the module name. ```elixir AshAdmin.Domain.name(Demo.Accounts.Domain) # => "Accounts" AshAdmin.Domain.name(Demo.Services) # => "Services" # With explicit name config AshAdmin.Domain.name(Demo.Accounts.Domain) # => "User Management" (if configured) ``` -------------------------------- ### Configure Tenant Listing for Typeahead Mode Source: https://github.com/ash-project/ash_admin/blob/main/_autodocs/configuration.md Sets up an MFA tuple for fetching available tenants to populate the tenant selection UI in typeahead mode, enabling search-based selection. The function does not need to be exported. ```elixir # config/config.exs config :ash_admin, list_tenants: {MyApp.Tenants, :list_tenants, []} # lib/my_app/tenants.ex defmodule MyApp.Tenants do # Can be non-exported for typeahead def list_tenants(search \ "") do MyApp.Repo.all(MyApp.Tenant) |> Stream.filter(&String.contains?(String.downcase(&1.name), String.downcase(search))) |> Enum.map(&%{label: &1.name, value: &1.id}) end end ``` -------------------------------- ### Get Table Filterable Columns Source: https://github.com/ash-project/ash_admin/blob/main/_autodocs/api-reference/ash-admin-resource.md Retrieves the list of columns that support filtering in the table view for a resource. If nil, all columns are considered filterable. ```elixir def table_filterable_columns(resource :: atom) :: list(atom) | nil ``` -------------------------------- ### Get Table Sortable Columns Source: https://github.com/ash-project/ash_admin/blob/main/_autodocs/api-reference/ash-admin-resource.md Retrieves the list of columns that support sorting in the table view for a resource. If nil, all columns are considered sortable. ```elixir def table_sortable_columns(resource :: atom) :: list(atom) | nil ``` -------------------------------- ### AshAdmin Project Directory Structure Source: https://github.com/ash-project/ash_admin/blob/main/_autodocs/COMPLETENESS.md Illustrates the organization of the generated documentation files for the AshAdmin project, including main documents and API reference subdirectories. ```bash /workspace/home/output/ ├── README.md (Overview, setup, navigation) ├── configuration.md (Setup and options) ├── types.md (Data structures) ├── errors.md (Error reference) ├── MANIFEST.md (Contents summary) └── api-reference/ ├── INDEX.md (API index) ├── ash-admin-core.md ├── ash-admin-domain.md ├── ash-admin-resource.md ├── ash-admin-resource-field.md ├── ash-admin-router.md ├── ash-admin-plugs.md ├── ash-admin-helpers.md └── transformers-and-verifiers.md ``` -------------------------------- ### Get Destroy Actions for a Resource Source: https://github.com/ash-project/ash_admin/blob/main/_autodocs/api-reference/ash-admin-resource.md Retrieves the list of atoms representing available destroy actions for a given resource in the Ash Admin UI. ```elixir def destroy_actions(resource :: atom) :: list(atom) ``` -------------------------------- ### Get Update Actions for a Resource Source: https://github.com/ash-project/ash_admin/blob/main/_autodocs/api-reference/ash-admin-resource.md Retrieves the list of atoms representing available update actions for a given resource in the Ash Admin UI. ```elixir def update_actions(resource :: atom) :: list(atom) ``` -------------------------------- ### File Upload Configuration: Max File Size Source: https://github.com/ash-project/ash_admin/blob/main/_autodocs/api-reference/ash-admin-resource-field.md Demonstrates setting the maximum allowed file size in bytes for file upload fields. ```elixir field :photo, max_file_size: 5_242_880 # 5MB ``` -------------------------------- ### show_sensitive_fields/1 Source: https://github.com/ash-project/ash_admin/blob/main/_autodocs/api-reference/ash-admin-resource.md Gets the list of sensitive fields to unhide in the admin UI. Fields marked sensitive in Ash are normally redacted unless listed here. ```APIDOC ## show_sensitive_fields/1 ### Description Gets the list of sensitive fields to unhide in the admin UI. Fields marked sensitive in Ash are normally redacted unless listed here. ### Signature def show_sensitive_fields(resource :: atom) :: list(atom) ### Parameters #### Path Parameters - **resource** (Atom) - Required - Resource module name ### Returns List of attribute atoms to display despite sensitive marking. ### Example ```elixir visible = AshAdmin.Resource.show_sensitive_fields(Demo.Accounts.User) # => [:ssn, :phone] ``` ``` -------------------------------- ### Ash Admin Global Configuration Source: https://github.com/ash-project/ash_admin/blob/main/_autodocs/configuration.md Sets up global Ash Admin configuration, including a list of Ash domains, tenant listing function, and Ecto repositories. ```elixir config :ash_admin, ash_domains: [ MyApp.Accounts.Domain, MyApp.Tickets.Domain ], list_tenants: {MyApp.Tenants, :list_all, []}, ecto_repos: [MyApp.Repo] ``` -------------------------------- ### Get Sensitive Fields to Show Source: https://github.com/ash-project/ash_admin/blob/main/_autodocs/api-reference/ash-admin-resource.md Returns a list of attribute atoms that should be displayed even if marked as sensitive in Ash. Fields not in this list will be redacted. ```elixir visible = AshAdmin.Resource.show_sensitive_fields(Demo.Accounts.User) # => [:ssn, :phone] ``` -------------------------------- ### AshAdmin.Router Macros Source: https://github.com/ash-project/ash_admin/blob/main/_autodocs/api-reference/INDEX.md Macros for integrating AshAdmin into Phoenix routers. ```APIDOC ## AshAdmin.Router ### Description Macros for integrating AshAdmin into Phoenix routers. ### Macros - `admin_browser_pipeline/1` - Create browser pipeline with plugs - `ash_admin/2` - Mount dashboard at path ### Options for ash_admin/2 - `:live_socket_path` - WebSocket path - `:on_mount` - Mount hooks - `:session` - Session provider - `:csp_nonce_assign_key` - CSP nonce configuration - `:live_session_name` - LiveView session name ``` -------------------------------- ### Split description into first sentence/line and the rest Source: https://github.com/ash-project/ash_admin/blob/main/_autodocs/api-reference/ash-admin-helpers.md This function splits a description string at the first sentence or newline. It's useful for creating truncated previews with a "read more" option. Returns `{:not_split, text}` if no split point is found, or `{:split, first, rest}` otherwise. Handles nil input gracefully. ```elixir # Sentence split AshAdmin.Helpers.short_description("First sentence. More text here.") # => {:split, "First sentence.", " More text here."} # Newline split AshAdmin.Helpers.short_description("First line\nSecond line") # => {:split, "First line\n", "Second line"} # No split AshAdmin.Helpers.short_description("Single line") # => {:not_split, "Single line"} # Nil input AshAdmin.Helpers.short_description(nil) # => {:not_split, nil} ``` -------------------------------- ### Get Generic Actions for a Resource Source: https://github.com/ash-project/ash_admin/blob/main/_autodocs/api-reference/ash-admin-resource.md Retrieves the list of atoms representing generic (non-CRUD) actions available for a given resource in the Ash Admin UI. ```elixir def generic_actions(resource :: atom) :: list(atom) ``` -------------------------------- ### AshAdmin API Reference Overview Source: https://github.com/ash-project/ash_admin/blob/main/_autodocs/MANIFEST.md This section provides an overview of the AshAdmin API documentation structure, highlighting key areas such as core modules, DSL extensions for domains and resources, router integration, and utility functions. It directs users to specific markdown files for detailed API information. ```APIDOC ## AshAdmin API Reference Documentation This section details the publicly available API functions and DSL extensions for AshAdmin. ### Core Module (`ash-admin-core.md`) - **Description**: Provides core functions for tenant management. - **Exported Functions**: 4 public functions. ### Domain DSL (`ash-admin-domain.md`) - **Description**: Offers DSL extensions for domain-level configuration. - **Exported Functions**: 4 configuration functions. ### Resource DSL (`ash-admin-resource.md`) - **Description**: Provides DSL extensions for resource-level configuration. - **Exported Functions**: 22 configuration functions. ### Router Macros (`ash-admin-router.md`) - **Description**: Macros for mounting the AshAdmin dashboard within a Phoenix application. - **Exported Functions**: 2 macros. ### Plugs (`ash-admin-plugs.md`) - **Description**: Manages session and actor context for authenticated requests. - **Exported Functions**: 6 functions. ### Helpers (`ash-admin-helpers.md`) - **Description**: Utility functions for rendering data and handling common tasks. - **Exported Functions**: 9 utility functions. ### Index (`api-reference/INDEX.md`) - **Description**: A comprehensive index of all public APIs, organized by category, serving as a starting point for API exploration. ``` -------------------------------- ### read_actions/1 Source: https://github.com/ash-project/ash_admin/blob/main/_autodocs/api-reference/ash-admin-resource.md Gets the list of read actions available in the admin UI. Returns explicitly configured list or all read actions sorted by primary first. ```APIDOC ## read_actions/1 ### Description Gets the list of read actions available in the admin UI. Returns explicitly configured list or all read actions sorted by primary first. ### Signature def read_actions(resource :: atom) :: list(atom) ### Parameters #### Path Parameters - **resource** (Atom) - Required - Resource module name ### Returns List of read action atoms. ### Example ```elixir actions = AshAdmin.Resource.read_actions(Demo.Accounts.User) # => [:read, :read_all] ``` ``` -------------------------------- ### Get Actor Load Statement Source: https://github.com/ash-project/ash_admin/blob/main/_autodocs/api-reference/ash-admin-resource.md Retrieves the load statement to be applied when fetching an actor from this resource. This is typically used for preloading relationships necessary for authorization. ```elixir loads = AshAdmin.Resource.actor_load(Demo.Accounts.User) # => [roles: [:permissions]] ``` -------------------------------- ### Define Admin-Only Mount Function Source: https://github.com/ash-project/ash_admin/blob/main/documentation/tutorials/getting-started-with-ash-admin.md Implement the `on_mount` function to check user authentication and role, redirecting unauthorized users or unauthenticated users to the appropriate pages. ```elixir def on_mount(:admin_only, _params, _session, socket) do # If the user is logged in, check the user role is admin. Continue if so, # otherwise redirect to main page or a 403 page if socket.assigns[:current_user] do if socket.assigns[:current_user].role == :admin do {:cont, socket} else {:halt, Phoenix.LiveView.redirect(socket, to: ~p"/")} end # If user isn't logged in, redirect to sign in page else {:halt, Phoenix.LiveView.redirect(socket, to: ~p"/sign-in")} end end ``` -------------------------------- ### Generate Migrations for Dev Resources Source: https://github.com/ash-project/ash_admin/blob/main/documentation/tutorials/contributing-to-ash-admin.md Use this command when changes are made to the development resources to generate necessary database migrations. ```bash mix generate_migrations ``` -------------------------------- ### create_actions/1 Source: https://github.com/ash-project/ash_admin/blob/main/_autodocs/api-reference/ash-admin-resource.md Retrieves the list of available create actions for a given resource in the admin UI. ```APIDOC ## create_actions/1 ### Description Gets the list of create actions available in the admin UI. ### Method Elixir Function ### Parameters #### Path Parameters - **resource** (Atom) - Required - Resource module name ### Returns List of create action atoms. ``` -------------------------------- ### Configure Tenant Listing Function Source: https://github.com/ash-project/ash_admin/blob/main/_autodocs/errors.md Ensure your Ash Admin configuration for listing tenants matches your application's reality. Verify that the specified module and function exist and are exported. ```elixir config :ash_admin, list_tenants: {MyApp.Tenants, :list_all, []} defmodule MyApp.Tenants do def list_all, do: [...] # Must return list of valid tenant options def list_all(search), do: [...] # If search is needed end ``` -------------------------------- ### Get Relationship Select Max Items Source: https://github.com/ash-project/ash_admin/blob/main/_autodocs/api-reference/ash-admin-resource.md Determines the maximum number of items to display in a relationship select dropdown before switching to typeahead search. Defaults to 50. ```elixir AshAdmin.Resource.relationship_select_max_items(Demo.Accounts.User) ``` -------------------------------- ### Mount AshAdmin with Session Configuration Source: https://github.com/ash-project/ash_admin/blob/main/_autodocs/api-reference/ash-admin-router.md Integrates custom session data handling by specifying a module, function, and arguments for session configuration when mounting AshAdmin. ```elixir defmodule MyAppWeb.Router do use Phoenix.Router import AshAdmin.Router scope "/" do pipe_through [:browser] ash_admin "/admin", session: {MyApp.AshAdmin.Session, :add_session_data, []} end end ``` -------------------------------- ### Get Label Field for Resource Source: https://github.com/ash-project/ash_admin/blob/main/_autodocs/api-reference/ash-admin-resource.md Retrieves the atom identifying the attribute to use as the label for this resource in relationship selectors and typeahead fields. Defaults to the resource name if not specified. ```elixir label = AshAdmin.Resource.label_field(Demo.Accounts.User) # => :email ``` -------------------------------- ### Configure ShowResourcesTransformer Source: https://github.com/ash-project/ash_admin/blob/main/_autodocs/errors.md Configures the ShowResourcesTransformer to list resources to be displayed. It requires valid Ash.Resource modules to be included in the domain's resources. ```elixir defmodule Demo.Accounts.Domain do use Ash.Domain, extensions: [AshAdmin.Domain] admin do show_resources [Demo.Accounts.User, Invalid.Resource] end end ``` -------------------------------- ### Get Resource Group Identifier Source: https://github.com/ash-project/ash_admin/blob/main/_autodocs/api-reference/ash-admin-resource.md Retrieves the atom identifier for the resource group, used for organizing resources in the admin dropdown. Returns nil if no group is explicitly defined. ```elixir AshAdmin.Resource.resource_group(Demo.Accounts.User) ``` -------------------------------- ### Configure Multi-Tenancy Source: https://github.com/ash-project/ash_admin/blob/main/_autodocs/README.md Set up multi-tenancy by providing a module and function to list tenants. This allows the admin interface to handle multi-tenant applications. ```elixir config :ash_admin, list_tenants: {MyApp.Tenants, :list_all, []} ``` ```elixir defmodule MyApp.Tenants do def list_all do ["production", "staging", "development"] end end ``` -------------------------------- ### Get Resource Display Name Source: https://github.com/ash-project/ash_admin/blob/main/_autodocs/api-reference/ash-admin-resource.md Retrieves the display name for a given resource. Handles explicit names and derives from module names, with special logic for versioned resources. ```elixir AshAdmin.Resource.name(Demo.Accounts.User) # => "User" AshAdmin.Resource.name(Demo.Accounts.UserVersion) # => "Accounts.User" ``` -------------------------------- ### Create Custom Browser Pipeline Source: https://github.com/ash-project/ash_admin/blob/main/_autodocs/api-reference/ash-admin-router.md This macro allows for a custom pipeline name when setting up the browser pipeline for AshAdmin, enabling more specific routing configurations. ```elixir defmodule MyAppWeb.Router do use Phoenix.Router import AshAdmin.Router # Create custom pipeline admin_browser_pipeline :admin_pipeline scope "/" do pipe_through [:admin_pipeline] ash_admin "/admin" end end ``` -------------------------------- ### table_columns/1 Source: https://github.com/ash-project/ash_admin/blob/main/_autodocs/api-reference/ash-admin-resource.md Gets the list of attributes to be displayed in the resource's table view. If not configured, it defaults to showing all attributes. Only attributes, `:one` relationships, calculations, and aggregates are valid. ```APIDOC ## table_columns/1 ### Description Gets the list of attributes to display in the resource table view. Defaults to all attributes if not configured. Only attributes, `:one` relationships, calculations, and aggregates are valid. ### Signature ```elixir def table_columns(resource :: atom) :: list(atom) ``` ### Parameters #### Path Parameters * **resource** (Atom) - Required - Resource module name ### Returns List of attribute/relationship/calculation atoms to display. ### Example ```elixir columns = AshAdmin.Resource.table_columns(Demo.Accounts.User) # => [:id, :email, :name, :created_at] ``` ### Source `lib/ash_admin/resource/resource.ex:169-172` ``` -------------------------------- ### Configure Tenant Selection Typeahead Source: https://github.com/ash-project/ash_admin/blob/main/documentation/tutorials/getting-started-with-ash-admin.md Implement a typeahead input for tenant selection by configuring :list_tenants with a function that accepts search text. ```elixir config :ash_admin, :list_tenants, {MyApp.Tenants, :search_tenants, []} ``` ```elixir defmodule MyApp.Tenants do def search_tenants(""), do: [] def search_tenants(search) do MyApp.Repo.all( from t in "tenants", where: ilike(t.name, ^"%#{search}%%"), select: %{label: t.name, value: t.id} ) end end ``` -------------------------------- ### Get Primary Create Action for a Resource Source: https://github.com/ash-project/ash_admin/blob/main/_autodocs/api-reference/ash-admin-helpers.md Retrieves the primary create action for a given Ash resource. This is useful for determining the default action to use when creating a new record. ```elixir action = AshAdmin.Helpers.primary_action(Demo.Accounts.User, :create) # => %Ash.Resource.Actions.Create{name: :create, ...} ``` -------------------------------- ### AshAdmin Core Module Source: https://github.com/ash-project/ash_admin/blob/main/_autodocs/api-reference/INDEX.md Provides core functions for tenant management and runtime configuration within AshAdmin. ```APIDOC ## AshAdmin (Core Module) ### Description Main entry point for tenant management and runtime configuration. ### Public Functions - `tenant_mode/0` - Determine tenant selection UI mode - `list_tenants/0` - Fetch all available tenants - `search_tenants/1` - Search tenants by name - `normalize_tenant_options/1` - Normalize tenant option format ``` -------------------------------- ### AshAdmin Transformer and Verifier Extension Definition Source: https://github.com/ash-project/ash_admin/blob/main/_autodocs/api-reference/transformers-and-verifiers.md Shows an example of how AshAdmin transformers and verifiers are configured within a Spark DSL extension definition. This includes specifying the transformers and verifiers to be used. ```elixir use Spark.Dsl.Extension, sections: [@admin], transformers: [ AshAdmin.Resource.Transformers.ValidateTableColumns, AshAdmin.Resource.Transformers.AddPositionSortCalculation ], verifiers: [ AshAdmin.Resource.Verifiers.VerifyFileArgumentsExist ] ``` -------------------------------- ### ash_admin/2 Source: https://github.com/ash-project/ash_admin/blob/main/_autodocs/api-reference/ash-admin-router.md Mounts the AshAdmin LiveView dashboard at the specified path. It configures the LiveView socket, session handling, and CSP nonce support. ```APIDOC ## ash_admin/2 ### Description Mounts the AshAdmin LiveView dashboard at the specified path. Configures the LiveView socket, session handling, and CSP nonce support. ### Signature ```elixir defmacro ash_admin(path, opts \ []) ``` ### Parameters #### Path Parameters - **path** (String.t) - Required - URL path where dashboard is mounted - **opts** (keyword) - Optional - Default: `[]` - Configuration options ### Options - **`:live_socket_path`** (String.t) - Default: `"/live"` - WebSocket path for LiveView - **`:on_mount`** (list(atom)) - Default: `[]` - LiveView mount hooks - **`:session`** (list | {module, func, args}) - Default: `[]` - Extra session data - **`:csp_nonce_assign_key`** (atom | map) - Default: `ash_admin-Ed55GFnX` - CSP nonce key(s) - **`:live_session_name`** (atom) - Default: `:ash_admin` - LiveView session name #### `csp_nonce_assign_key` Details Controls Content Security Policy nonce injection for inline scripts and styles. Can be: 1. **Single atom** - Uses same nonce for all script, style, and img tags: ```elixir ash_admin "/admin", csp_nonce_assign_key: :csp_nonce # All assign(:csp_nonce, value) ``` 2. **Map with per-type keys** - Different nonces for different CSP directives: ```elixir ash_admin "/admin", csp_nonce_assign_key: %{ script: :script_nonce, style: :style_nonce, img: :img_nonce } # assign(:script_nonce, value) # assign(:style_nonce, value) # assign(:img_nonce, value) ``` Default for backwards compatibility: `ash_admin-Ed55GFnX` for all types. ### Example: Basic Mount ```elixir defmodule MyAppWeb.Router do use Phoenix.Router import AshAdmin.Router scope "/" do pipe_through [:browser] ash_admin "/admin" end end ``` ### Example: Custom Socket Path ```elixir defmodule MyAppWeb.Router do use Phoenix.Router import AshAdmin.Router scope "/" do pipe_through [:browser] ash_admin "/admin", live_socket_path: "/socket" end end ``` ### Example: Session Configuration with MFA ```elixir defmodule MyAppWeb.Router do use Phoenix.Router import AshAdmin.Router scope "/" do pipe_through [:browser] ash_admin "/admin", session: {MyApp.AshAdmin.Session, :add_session_data, []} end end ``` ``` -------------------------------- ### Configure Resource for AshAdmin Source: https://github.com/ash-project/ash_admin/blob/main/_autodocs/README.md Configure a resource module to include AshAdmin extensions and define admin-specific settings like actor association and table columns. ```elixir defmodule MyApp.Accounts.User do use Ash.Resource, extensions: [AshAdmin.Resource] admin do actor? true table_columns [:id, :email, :name] label_field :email end # ... attributes, actions, etc. end ``` -------------------------------- ### Validate show_resources in Domain Source: https://github.com/ash-project/ash_admin/blob/main/_autodocs/api-reference/transformers-and-verifiers.md Ensures resources referenced in `show_resources` exist and expands wildcards. Runs during domain compilation. ```elixir defmodule MyApp.Accounts.Domain do use Ash.Domain, extensions: [AshAdmin.Domain] admin do show_resources [MyApp.Accounts.User] # ✓ Valid # show_resources [Invalid.Module] # ✗ Would raise error end resources do resource MyApp.Accounts.User resource MyApp.Accounts.Role end end ``` -------------------------------- ### Get Relationship Display Fields for a Resource Source: https://github.com/ash-project/ash_admin/blob/main/_autodocs/api-reference/ash-admin-resource.md Retrieves the attributes to display when a resource is shown in relationship tables on another resource's datatable. This helps in providing a concise view of related data. ```elixir # Display user's email and name when shown in relationship tables fields = AshAdmin.Resource.relationship_display_fields(Demo.Accounts.User) # => [:email, :name] ``` -------------------------------- ### Fetch All Tenants Source: https://github.com/ash-project/ash_admin/blob/main/_autodocs/api-reference/ash-admin-core.md Call this function to retrieve a list of all available tenants. The results are normalized to include `:label` and `:value` keys. ```elixir tenants = AshAdmin.list_tenants() # => [%{label: "Tenant A", value: "tenant-a"}, ...] ``` -------------------------------- ### Basic AshAdmin Domain Configuration Source: https://github.com/ash-project/ash_admin/blob/main/_autodocs/configuration.md Expose specific Ash domains to the AshAdmin dashboard by listing their modules. ```elixir config :ash_admin, ash_domains: [ MyApp.Accounts.Domain, MyApp.Tickets.Domain ] ``` -------------------------------- ### Recompile Assets for AshAdmin Source: https://github.com/ash-project/ash_admin/blob/main/documentation/tutorials/contributing-to-ash-admin.md Run this command after making changes to assets (CSS, JavaScript) or updating dependencies that include assets, to recompile them. ```bash mix assets.deploy ``` -------------------------------- ### Get Table Columns for a Resource Source: https://github.com/ash-project/ash_admin/blob/main/_autodocs/api-reference/ash-admin-resource.md Retrieves the list of attributes to be displayed in the resource's table view. If not explicitly configured, it defaults to showing all attributes. Only attributes, :one relationships, calculations, and aggregates are valid for display. ```elixir columns = AshAdmin.Resource.table_columns(Demo.Accounts.User) # => [:id, :email, :name, :created_at] ``` -------------------------------- ### Ash Admin Router with All Options Combined Source: https://github.com/ash-project/ash_admin/blob/main/_autodocs/api-reference/ash-admin-router.md Configure the Ash Admin router with multiple options including live socket path, session name, mount hooks, session management, and CSP nonces. ```elixir defmodule MyAppWeb.Router do use Phoenix.Router import AshAdmin.Router scope "/management" do pipe_through [:browser, :require_admin] ash_admin "/dashboard", live_socket_path: "/live", live_session_name: :admin_dashboard, on_mount: [{MyAppWeb.Auth, :check_admin}], session: {MyApp.Session, :load_context, []}, csp_nonce_assign_key: %{ script: :script_nonce, style: :style_nonce, img: :img_nonce } end end ``` -------------------------------- ### Get the primary action for a resource type Source: https://github.com/ash-project/ash_admin/blob/main/_autodocs/api-reference/ash-admin-helpers.md Retrieves the primary action of a specified type (read, create, update, destroy) that is enabled in AshAdmin for a given resource. It prioritizes actions explicitly configured in `AshAdmin.Resource` over Ash's default primary action. ```elixir # Get primary read action action = AshAdmin.Helpers.primary_action(Demo.Accounts.User, :read) # => %Ash.Resource.Actions.Read{name: :read, ...} ``` -------------------------------- ### Ash Admin Router with Mount Hooks Source: https://github.com/ash-project/ash_admin/blob/main/_autodocs/api-reference/ash-admin-router.md Configure mount hooks for authentication and organization loading in the Ash Admin router. ```elixir defmodule MyAppWeb.Router do use Phoenix.Router import AshAdmin.Router scope "/" do pipe_through [:browser] ash_admin "/admin", on_mount: [ {MyAppWeb.Auth, :user_required}, {MyAppWeb.Organization, :load_org} ] end end ``` -------------------------------- ### Mount AshAdmin with Default Browser Pipeline Source: https://github.com/ash-project/ash_admin/blob/main/_autodocs/configuration.md Integrates AshAdmin into the Phoenix router using the `admin_browser_pipeline` macro. The dashboard is mounted at the `/admin` path. ```elixir defmodule MyAppWeb.Router do use Phoenix.Router import AshAdmin.Router # Default pipeline name :browser admin_browser_pipeline() scope "/" do pipe_through [:browser] ash_admin "/admin" end end ```