MishkaGervaz.Resource (MishkaGervaz v0.0.1-alpha.3)

Copy Markdown View Source

Ash extension for MishkaGervaz admin UI DSL.

Add this extension to your Ash resources to enable declarative admin table and form configuration. The top-level mishka_gervaz block contains two sibling sections — table (admin list view) and form (create/edit form) — which may be used independently or together on a single resource.

Table example

defmodule MyApp.CMS.Component do
  use Ash.Resource,
    domain: MyApp.CMS,
    extensions: [MishkaGervaz.Resource]

  mishka_gervaz do
    table do
      identity do
        route "/admin/components"
      end

      columns do
        column :name, sortable: true
        column :status
      end

      row_actions do
        action :edit, type: :link
        action :delete, type: :destroy
      end
    end
  end

  # ... rest of Ash resource
end

Form example

mishka_gervaz do
  form do
    identity do
      name :component_form
      route "/admin/components"
    end

    source do
      actor_key :current_user
      master_check fn user -> user.role == :admin end

      actions do
        create {:master_create, :create}
        update {:master_update, :update}
        read {:master_get, :read}
      end
    end

    fields do
      field :name, :text, required: true
      field :status, :select
    end
  end
end

Table sections

The following sections live within mishka_gervaz -> table:

Form sections

The following sections live within mishka_gervaz -> form:

Introspection

Use MishkaGervaz.Resource.Info.Table and MishkaGervaz.Resource.Info.Form to introspect the configuration at runtime:

# Table — full compiled config / columns / filters
config  = MishkaGervaz.Resource.Info.Table.config(MyResource)
columns = MishkaGervaz.Resource.Info.Table.columns(MyResource)
filters = MishkaGervaz.Resource.Info.Table.filters(MyResource)

# Form — full compiled config / fields / groups / events / state / data_loader
config      = MishkaGervaz.Resource.Info.Form.config(MyResource)
fields      = MishkaGervaz.Resource.Info.Form.fields(MyResource)
groups      = MishkaGervaz.Resource.Info.Form.groups(MyResource)
events      = MishkaGervaz.Resource.Info.Form.events(MyResource)
state       = MishkaGervaz.Resource.Info.Form.state(MyResource)
data_loader = MishkaGervaz.Resource.Info.Form.data_loader(MyResource)

Summary

Functions

mishka_gervaz(body)

(macro)