Domain DSL
v0.0.1
The MishkaGervaz.Domain extension sets defaults that every resource in an Ash domain inherits. Add it with extensions: [MishkaGervaz.Domain] and declare the defaults in a mishka_gervaz block. A resource sets any key itself and wins per key. This page lists every option of the block. For how inheritance works, see How domain defaults work.
Table defaults
Defaults for every table in the domain. It sits at mishka_gervaz.table.
| Option | Type | Default | Description |
|---|---|---|---|
ui_adapter | atom | MishkaGervaz.UIAdapters.Tailwind | Default UI adapter module. |
ui_adapter_opts | keyword | [] | Default UI adapter options. |
actor_key | atom | :current_user | Default assign key for current user. Stored in the config. The components take the actor from their current_user assign, and no built-in code reads this key. |
master_check | (any -> any) | none | Default function to check if user is master. fn user -> boolean. Stored in the config. The built-in access modules do not call it: they treat a user whose site_id is nil as a master. To change the rule, override master_user?/1 in a custom access module. |
actions
The default read, get and destroy actions. It sits at mishka_gervaz.table.actions.
| Option | Type | Default | Description |
|---|---|---|---|
read | atom | {atom, atom} | none | Default read action. Atom (used for both master and tenant) or tuple {master_action, tenant_action}. Inherited by all resources in the domain. |
get | atom | {atom, atom} | none | Default get action. Atom or tuple {master_action, tenant_action}. Inherited by all resources in the domain. |
destroy | atom | {atom, atom} | none | Default destroy action. Atom or tuple {master_action, tenant_action}. Inherited by all resources in the domain. |
archive
The default archive actions, for resources that use AshArchival.Resource. It sits at mishka_gervaz.table.archive.
| Option | Type | Default | Description |
|---|---|---|---|
enabled | boolean | true | Gervaz does not read the domain value. Archive is on for every resource that uses AshArchival.Resource, unless the resource's own archive block sets enabled false. |
restricted | boolean | false | Default for restricting archive UI to master users only. |
visible | boolean | (any -> any) | mfa | true | Controls the archive toggle. Only a boolean acts. Gervaz does not evaluate a function, and the toggle then shows. |
read_action | atom | {atom, atom} | {:master_archived, :archived} | Default read archived action. Single atom or tuple {master_action, tenant_action}. |
get_action | atom | {atom, atom} | {:master_get_archived, :get_archived} | Default get archived action. |
restore_action | atom | {atom, atom} | {:master_unarchive, :unarchive} | Default restore action. |
destroy_action | atom | {atom, atom} | {:master_permanent_destroy, :permanent_destroy} | Default permanent destroy action. |
realtime
The default realtime settings. It sits at mishka_gervaz.table.realtime.
| Option | Type | Default | Description |
|---|---|---|---|
enabled | boolean | true | Default realtime enabled. When realtime section is defined, enabled is true by default. |
pubsub | atom | none | Default PubSub module. |
theme
The default table theme classes. It sits at mishka_gervaz.table.theme.
| Option | Type | Default | Description |
|---|---|---|---|
header_class | String.t | none | Default header CSS classes. |
row_class | String.t | none | Default row CSS classes. |
border_class | String.t | none | Default border CSS classes. The value is compiled into the config, but no built-in template or handler reads it. |
extra | map | %{} | Default extra theme options. The value is compiled into the config, but no built-in template or handler reads it. |
url_sync
The default URL synchronization. It sits at mishka_gervaz.table.url_sync.
| Option | Type | Default | Description |
|---|---|---|---|
enabled | boolean | true | Enable URL state synchronization. When url_sync section is defined, enabled is true by default. |
mode | :read_only | :bidirectional | :read_only | :read_only (the default) never writes the URL. The table still reads it again whenever the parent passes a new url_state. :bidirectional also updates the URL when the filters, the sort or the page change. |
params | list(:filters | :sort | :page | :page_size | :search | :template) | [:filters, :sort, :page] | Which state to sync to URL params. |
prefix | String.t | none | Prefix for URL params to avoid conflicts. |
refresh
The default auto-refresh. It sits at mishka_gervaz.table.refresh.
| Option | Type | Default | Description |
|---|---|---|---|
enabled | boolean | true | Enable auto-refresh. When refresh section is defined, enabled is true by default. |
interval | pos_integer | 30000 | Refresh interval in milliseconds. Default: 30 seconds. |
pause_on_interaction | boolean | true | Pause auto-refresh when user is interacting (filtering, selecting, etc.). The value is compiled into the config, but no built-in template or handler reads it. |
show_indicator | boolean | true | Show a visual indicator when auto-refresh is active. The value is compiled into the config, but no built-in template or handler reads it. |
pause_on_blur | boolean | true | Pause auto-refresh when browser tab/window loses focus. The value is compiled into the config, but no built-in template or handler reads it. |
pagination
The default pagination. It sits at mishka_gervaz.table.pagination.
| Option | Type | Default | Description |
|---|---|---|---|
enabled | boolean | none | Gervaz does not read it at the domain level. Set enabled false on a resource to turn its pagination off. |
type | :infinite | :numbered | :load_more | :load_more | The pagination style: :numbered (pages), :load_more (a button) or :infinite (loads on scroll). The schema text names :load_more as the default. A domain pagination block without a type gives :load_more, and a resource pagination block without a type, in a domain with no pagination block, gives :numbered. Set it yourself. |
page_size | integer | 20 | Records per page. It must be one of page_size_options when both are set. |
page_size_options | list(integer) | none (no page size selector) | Page sizes the reader can pick. Without a list, the page size selector is not drawn. |
max_page_size | pos_integer | 150 | The largest allowed page size. It clamps a page size that arrives in the URL, and it must be at least the largest entry of page_size_options. |
pagination ui
Labels and options of the pagination controls. It sits at mishka_gervaz.table.pagination.ui.
| Option | Type | Default | Description |
|---|---|---|---|
load_more_label | String.t | "Load More" | Load more button text. The domain does not pass the pagination ui block to a resource. |
loading_text | String.t | "Loading..." | Loading indicator text. The domain does not pass the pagination ui block to a resource. |
show_total | boolean | true | Shows the total record count. A :numbered table counts whatever this says. For :load_more and :infinite, turn it off to skip the count query on a data layer that cannot count. The domain does not pass the pagination ui block to a resource. |
prev_label | String.t | "Previous" | Previous page button text. The domain does not pass the pagination ui block to a resource. |
next_label | String.t | "Next" | Next page button text. The domain does not pass the pagination ui block to a resource. |
first_label | String.t | "First" | First page button text. The domain does not pass the pagination ui block to a resource. |
last_label | String.t | "Last" | Last page button text. The domain does not pass the pagination ui block to a resource. |
page_info_format | String.t | "Page {page} of {total}" | The page info text. Placeholders: {page}, {total} and {count}. Gervaz prints {from} and {to} as they are. The domain does not pass the pagination ui block to a resource. |
Form defaults
Defaults for every form in the domain. It sits at mishka_gervaz.form.
| Option | Type | Default | Description |
|---|---|---|---|
ui_adapter | atom | MishkaGervaz.UIAdapters.Tailwind | Default form UI adapter module. |
ui_adapter_opts | keyword | [] | Default form UI adapter options. The form does not read it. |
actor_key | atom | :current_user | Default assign key for current user. Stored in the config. The components take the actor from their current_user assign, and no built-in code reads this key. |
master_check | (any -> any) | none | Default function to check if user is master. fn user -> boolean. Stored in the config. The built-in access modules do not call it: they treat a user whose site_id is nil as a master. To change the rule, override master_user?/1 in a custom access module. |
template | atom | MishkaGervaz.Form.Templates.Standard | Default template module for form layout. |
features | :all | list(:validation | :uploads | :groups | :wizard | :autosave | :inline_errors) | :all | Default features to enable for forms. The built-in template does not check it. |
actions
The default create, update and read actions. It sits at mishka_gervaz.form.actions.
| Option | Type | Default | Description |
|---|---|---|---|
create | atom | {atom, atom} | none | Default create action. Atom (used for both master and tenant) or tuple {master_action, tenant_action}. Inherited by all form resources in the domain. |
update | atom | {atom, atom} | none | Default update action. Atom or tuple {master_action, tenant_action}. Inherited by all form resources in the domain. |
read | atom | {atom, atom} | none | Default read/get action. Atom or tuple {master_action, tenant_action}. Inherited by all form resources in the domain. |
theme
The default form theme classes. It sits at mishka_gervaz.form.theme.
| Option | Type | Default | Description |
|---|---|---|---|
form_class | String.t | none | Default form CSS classes. The value is compiled into the config, but no built-in template or handler reads it. |
field_class | String.t | none | Default field CSS classes. The value is compiled into the config, but no built-in template or handler reads it. |
label_class | String.t | none | Default label CSS classes. The value is compiled into the config, but no built-in template or handler reads it. |
error_class | String.t | none | Default error message CSS classes. The value is compiled into the config, but no built-in template or handler reads it. |
extra | map | %{} | Default extra theme options. The value is compiled into the config, but no built-in template or handler reads it. |
layout
The default layout settings. It sits at mishka_gervaz.form.layout.
| Option | Type | Default | Description |
|---|---|---|---|
navigation | :sequential | :free | :sequential | Default wizard navigation mode. |
persistence | :none | :ets | :client_token | :none | Default wizard step persistence. The value is compiled into the config, but no built-in template or handler reads it. |
columns | pos_integer | 1 | Default number of form columns. Only 1 to 4 change the grid. Any other value gives one column. |
responsive | boolean | true | Default responsive layout behavior. The value is compiled into the config, but no built-in template or handler reads it. |
submit
The default submit row. Each button merges per button with the resource. See How domain defaults work. It sits at mishka_gervaz.form.submit.
| Option | Type | Default | Description |
|---|---|---|---|
position | :top | :bottom | :both | :bottom | Button position. The value is compiled into the config, but no built-in template or handler reads it. |
submit.create
The create button. It sits at mishka_gervaz.form.submit.create.
| Option | Type | Default | Description |
|---|---|---|---|
label | String.t | (-> any) | none | Button label. String or zero-arity function. |
active | boolean | (any -> any) | true | Whether the button is active. Boolean or fn state -> boolean end. Set to false to suppress a button inherited from the domain. Resource-only. |
disabled | boolean | (any -> any) | false | Disable button. Boolean or fn state -> boolean end. |
visible | boolean | (any -> any) | true | Static or dynamic visibility. fn state -> boolean() end. |
restricted | boolean | (any -> any) | false | Restrict to master users. true or fn state -> boolean() end. |
submit.update
The update button. It sits at mishka_gervaz.form.submit.update.
| Option | Type | Default | Description |
|---|---|---|---|
label | String.t | (-> any) | none | Button label. String or zero-arity function. |
active | boolean | (any -> any) | true | Whether the button is active. Boolean or fn state -> boolean end. Set to false to suppress a button inherited from the domain. Resource-only. |
disabled | boolean | (any -> any) | false | Disable button. Boolean or fn state -> boolean end. |
visible | boolean | (any -> any) | true | Static or dynamic visibility. fn state -> boolean() end. |
restricted | boolean | (any -> any) | false | Restrict to master users. true or fn state -> boolean() end. |
submit.cancel
The cancel button. It sits at mishka_gervaz.form.submit.cancel.
| Option | Type | Default | Description |
|---|---|---|---|
label | String.t | (-> any) | none | Button label. String or zero-arity function. |
active | boolean | (any -> any) | true | Whether the button is active. Boolean or fn state -> boolean end. Set to false to suppress a button inherited from the domain. Resource-only. |
disabled | boolean | (any -> any) | false | Disable button. Boolean or fn state -> boolean end. |
visible | boolean | (any -> any) | true | Static or dynamic visibility. fn state -> boolean() end. |
restricted | boolean | (any -> any) | false | Restrict to master users. true or fn state -> boolean() end. |
submit.ui
Classes for the submit row. It sits at mishka_gervaz.form.submit.ui.
| Option | Type | Default | Description |
|---|---|---|---|
submit_class | String.t | none | Submit button CSS classes. The value is compiled into the config, but no built-in template or handler reads it. |
cancel_class | String.t | none | Cancel button CSS classes. The value is compiled into the config, but no built-in template or handler reads it. |
wrapper_class | String.t | none | Button wrapper CSS classes. The value is compiled into the config, but no built-in template or handler reads it. |
extra | map | %{} | Additional options. The value is compiled into the config, but no built-in template or handler reads it. |
Example
The domain of Mishka Blog sets the table and form defaults once, and every blog resource inherits them.
defmodule MishkaBlog do
use Ash.Domain,
extensions: [MishkaGervaz.Domain]
mishka_gervaz do
table do
actor_key :current_user
ui_adapter MishkaGervaz.UIAdapters.Tailwind
pagination do
type :load_more
page_size 20
page_size_options [20, 50, 100, 150]
end
realtime do
pubsub MishkaCmsCore.PubSub
end
actions do
read {:master_read, :read}
get {:master_get, :read}
destroy {:master_destroy, :destroy}
end
archive do
read_action {:master_archived, :archived}
get_action {:master_get_archived, :get_archived}
restore_action {:master_unarchive, :unarchive}
destroy_action {:master_permanent_destroy, :permanent_destroy}
end
end
form do
actions do
create {:master_create, :create}
update {:master_update, :update}
read {:master_get, :read}
end
submit do
create label: fn -> dgettext("mishka_gervaz", "Create") end
update label: fn -> dgettext("mishka_gervaz", "Save Changes") end
cancel label: fn -> dgettext("mishka_gervaz", "Cancel") end
position :bottom
end
end
end
end