The records a component shows, read and written the way the Resources
page does: through the host (Alternera.Resource.UI.Host), with the
context's tenant and actor, so the resource's policies decide, the
history records the change, a cached resource drops its key, and every
error is logged.
resource defaults to the context's own resource. Calling Ash directly
on the package's resources with Alternera.Resource.UI.opts/1 is
just as allowed, and reaches what these do not (a custom action, a
calculation, an aggregate); log every {:error, _} there yourself.
Summary
Functions
Every record of resource that opts select (list/3's options but
limit and offset), read a page at a time, up to max: records
(1000 by default): {:ok, %{records, count, truncated?}}, where
truncated? says there are more than max and count how many. Show
the reader when it is true rather than leave the rest out unsaid.
Creates a record from params (attribute name to value).
Deletes record.
An error as %{field, message}, for showing it on the field it names.
A record by {:id, id} or {:key, lookup_key_value}.
A page of records of resource (the context's own when left out); see
Alternera.Resource.UI.Host.list/3 for the options.
Restores the record version holds.
Updates record with params.
The versions of the record with id, newest first.
Functions
@spec all(Alternera.Resource.UI.Context.t(), module() | nil, keyword()) :: {:ok, %{records: list(), count: non_neg_integer(), truncated?: boolean()}} | {:error, term()}
Every record of resource that opts select (list/3's options but
limit and offset), read a page at a time, up to max: records
(1000 by default): {:ok, %{records, count, truncated?}}, where
truncated? says there are more than max and count how many. Show
the reader when it is true rather than leave the rest out unsaid.
{:ok, %{records: units, truncated?: more?}} = Records.all(ctx, MyPackage.Unit)
@spec create(Alternera.Resource.UI.Context.t(), module() | nil, map()) :: {:ok, struct()} | {:error, term()}
Creates a record from params (attribute name to value).
@spec delete(Alternera.Resource.UI.Context.t(), struct()) :: :ok | {:error, term()}
Deletes record.
An error as %{field, message}, for showing it on the field it names.
@spec get( Alternera.Resource.UI.Context.t(), module() | nil, Alternera.Resource.UI.Host.ref() ) :: {:ok, struct()} | {:error, term()}
A record by {:id, id} or {:key, lookup_key_value}.
@spec list(Alternera.Resource.UI.Context.t(), module() | keyword(), keyword()) :: {:ok, %{records: list(), count: non_neg_integer()}} | {:error, term()}
A page of records of resource (the context's own when left out); see
Alternera.Resource.UI.Host.list/3 for the options.
Records.list(ctx, limit: 10)
Records.list(ctx, MyPackage.Currency, search: "kr")
@spec restore(Alternera.Resource.UI.Context.t(), module() | nil, struct()) :: {:ok, struct()} | {:error, term()}
Restores the record version holds.
@spec update(Alternera.Resource.UI.Context.t(), struct(), map()) :: {:ok, struct()} | {:error, term()}
Updates record with params.
@spec versions(Alternera.Resource.UI.Context.t(), module() | nil, term()) :: {:ok, list()} | {:error, term()}
The versions of the record with id, newest first.