LiveAdmin
An admin UI for Phoenix applications built on Phoenix LiveView and Ecto.
Significant features:
- First class support for multi tenant applications via Ecto's
prefix
option - Overridable views and API
- Easily add custom actions at the schema and record level
- Ability to edit (nested) embedded schemas
Installation
First, ensure your Phoenix app has been configured to use LiveView.
Add to your app's deps
:
{:live_admin, "~> 0.8.0"}
Add the following to your Phoenix router in any scope ready to serve a live route:
import LiveAdmin.Router
# ...
live_admin "/admin", resources: [MyApp.SomeEctoSchema]
See LiveAdmin.Router.live_admin/2
for full list of options.
To customize a resource, pass a two element tuple when the schema module as the first element, and a keyword list of options is the second: {MyApp.SomeEctoSchema, opts}
Resource specific options:
title_with
- a binary, or MFA that returns a binary, used to identify the resourcelabel_with
- a binary, or MFA that returns a binary, used to identify individual recordslist_with
- an atom or MFA that identifies the function that implements listing a resourcecreate_with
- an atom or MFA that identifies the function that implements creating a resourceupdate_with
- an atom or MFA that identifies the function that implements updating a recorddelete_with
- an atom or MFA that identifies the function that implements deleting a recordvalidate_with
- an atom or MFA that identifies the function that implements validating a changed recordrender_with
- an atom or MFA that identifies the function that implements table field rendering logichidden_fields
- a list of fields that should not be displayed in the UIimmutable_fields
- a list of fields that should not be editable in formsactions
- list of atoms or MFAs that identify a function that operates on a recordtasks
- list atoms or MFAs that identify a function that operates on a resourcecomponents
- keyword list of component module overrides for specific views (:list
,:new
,:edit
,:home
,:nav
,:session
)slug_with
- a binary, atom, or MFA that returns a binary, used to generate url for resource
App config
The following runtime config is supported:
ecto_repo
- the Ecto repo to use for db operationsprefix_options
- a list or MFA specifyingprefix
options to be passed to Ecto functionscss_overrides
- a binary or MFA that returns CSS to be appended to app csssession_store
- a module implementing the LiveAdmin.Session.Store behavior, used to persist session data
In addition to these, most resource configuration can be set here in order to set a global default to apply to all resources unless overridden in their individual config.
Example:
config :live_admin,
ecto_repo: MyApp.Repo,
prefix_options: {MyApp.Accounts, :list_tenant_prefixes, []},
immutable_fields: [:id, :inserted_at, :updated_at],
label_with: :name
See development app for more example configuration.
Development environment
This repo has been configured to run the application in Docker. Simply run docker compose up
and navigate to http://localhost:4000
The Phoenix app is running the app
service, so all mix command should be run there. Examples:
docker compose run web mix test
README generated with docout