View Source Pyro.Resource.Info (Pyro v0.0.2)

Helpers to introspect the Pyro.Resource Ash extension. Intended for use in components that automatically build UI from resource configuration.

Link to this section Summary

Functions

The label of the action as defined in the Pyro.Resource extension, defaulting to a humanized version of the action name.

Convert a list of actions into a format compatible with Phoenix.HTML.Form.select/4 options.

The same as primary_actions/2, but filtered by those authorized for access for the specified action/actor.

Returns the list of :create type actions of the given resource.

The same as create_actions/1, but filtered by those authorized for access for the specified action/actor.

The default card fields to display as defined in the Pyro.Resource extension, with fallback to all public fields.

Same as default_card_fields/1, but filtered by those authorized for access for the specified action/actor.

The default display mode of the resource as defined in the Pyro.Resource extension, defaulting to :data_table.

Returns the field defined in the Pyro.Resource extension as a default label, falling back to the first single-key identity of the resource, further falling back to the primary key if it's single-keyed.

Return the default page for the given resource/action.

The first single-keyed identity, or the primary ID of the given resource.

The default sort of resource for the given action, falling back to the default provided by the Pyro.Resource extension.

The default table columns to display as defined in the Pyro.Resource extension, with fallback to all public fields.

Same as default_table_columns/1, but filtered by those authorized for access for the specified action/actor.

Returns the list of :destroy type actions of the given resource.

The same as destroy_actions/1, but filtered by those authorized for access for the specified action/actor.

Check if a given field is authorized to be viewed by the actor.

Returns the given field's description.

WIP label for resource fields. In the future it will pull from a resource field property. This will allow different labels based on context.

Returns the form fields defined in the Pyro.Resource extension for the given action.

This is only used for the primary user input. This provides consistency between the input component and other parts of the UI that may want ot provide a link to that user input e.g. to click an error and focus the related input.

Return a boolean indicating if resource is a page as configured in the Pyro.Resource extension.

Returns the list of :read type actions of the given resource, excluding actions that are get?: true.

The same as list_actions/1, but filtered by those authorized for access for the specified action/actor.

Filter the list of fields to those which can be loaded (as opposed to those which can be selected). Basically just filters out attributes from a list of fields.

Return the page limit options for the given resource/action if pagination is configured.

The custom page module of the action as defined in the Pyro.Resource extension, if the resource is configured as a custom page.

The page routing path of the resource as defined in the Pyro.Resource extension, if the resource is configured as a page.

Returns the list of actions of the given resource.

Lists all the public fields of resource.

The same as public_fields/1, but filtered by those authorized for access for the specified action/actor.

Returns the list of :read type actions of the given resource.

The same as read_actions/1, but filtered by those authorized for access for the specified action/actor.

The label of the resource as defined in the Pyro.Resource extension, defaulting to a humanized version of the module name.

Returns the list of :read type actions intended for single-record reads of the given resource.

The same as show_actions/1, but filtered by those authorized for access for the specified action/actor.

List the single-keyed identities of the given resource.

Check if a field is sortable.

Returns the list of :update type actions of the given resource.

The same as update_actions/1, but filtered by those authorized for access for the specified action/actor.

Link to this section Types

@type ash_action_or_name() :: Ash.Resource.Actions.action() | binary() | atom()
@type ash_actor() :: map() | nil
Link to this type

ash_resource_field_or_name()

View Source
@type ash_resource_field_or_name() :: ash_resource_field() | binary() | atom()
@type primary_actions_opt() :: [
  {:exclude_types, [Ash.Resource.Actions.action_type()]}
]
@type select_option() :: [key: binary(), value: binary()]

Link to this section Functions

See Ash.Resource.Info.action/2.

Link to this function

action_label(resource, name)

View Source
@spec action_label(Ash.Resource.t(), ash_action_or_name()) :: binary() | nil

The label of the action as defined in the Pyro.Resource extension, defaulting to a humanized version of the action name.

examples

Examples

iex> action_label(Gage, "calibration_alerts")
"Calibration Alerts"

iex> action_label(Gage, :update)
"Update"

iex> action_label(Gage, %{name: :read})
"Read"
Link to this function

actions_to_select_options(actions, resource)

View Source
@spec actions_to_select_options([Ash.Resource.Actions.action()], Ash.Resource.t()) ::
  [select_option()]

Convert a list of actions into a format compatible with Phoenix.HTML.Form.select/4 options.

examples

Examples

iex> actions_to_select_options(read_actions(Gage), Gage)
[
  [key: "Calibration Alerts", value: "calibration_alerts"],
  [key: "Read", value: "read"]
]
Link to this function

aggregate(resource, name)

View Source

See Ash.Resource.Info.aggregate/2.

Link to this function

attribute(resource, name)

View Source

See Ash.Resource.Info.attribute/2.

Link to this function

authorized_primary_actions(resource, actor, opts \\ [])

View Source

The same as primary_actions/2, but filtered by those authorized for access for the specified action/actor.

examples

Examples

iex> r = authorized_primary_actions(User, nil)
iex> r |> Enum.map(& &1.name)
[]
Link to this function

calculation(resource, name)

View Source

See Ash.Resource.Info.calculation/2.

Link to this function

can_do?(resource, action_or_query, actor, opts)

View Source

See Ash.Policy.Info.can?/4.

Link to this function

create_actions(resource)

View Source
@spec create_actions(Ash.Resource.t()) :: [Ash.Resource.Actions.Create.t()]

Returns the list of :create type actions of the given resource.

examples

Examples

iex> r = create_actions(Gage)
iex> r |> Enum.map(& &1.name)
[:create]
Link to this function

create_actions(resource, actor, opts \\ [])

View Source

The same as create_actions/1, but filtered by those authorized for access for the specified action/actor.

examples

Examples

iex> r = create_actions(Gage, nil)
iex> r |> Enum.map(& &1.name)
[]
Link to this function

default_action_for_live_action(resource, live_action, actor)

View Source
@spec default_action_for_live_action(
  Ash.Resource.t(),
  Pyro.ResourceParams.live_action_type(),
  map() | nil
) :: Ash.Resource.Actions.action()
Link to this function

default_card_fields(resource)

View Source
@spec default_card_fields(Ash.Resource.t()) :: [ash_resource_field()]

The default card fields to display as defined in the Pyro.Resource extension, with fallback to all public fields.

examples

Examples

Explicitly configured

iex> r = default_card_fields(AttendanceRecord)
iex> r |> Enum.map(& &1.name)
[
  :inserted_at,
  :updated_at,
  :in,
  :out,
  :duration_hours,
  :type_label,
  :employee_code,
  :employee_name_formal,
  :notes
]
Link to this function

default_card_fields(resource, action, actor)

View Source
@spec default_card_fields(Ash.Resource.t(), Ash.Resource.Action.t(), ash_actor()) :: [
  ash_resource_field()
]

Same as default_card_fields/1, but filtered by those authorized for access for the specified action/actor.

examples

Examples

iex> r = default_card_fields(Gage, :calibration_alerts, nil)
iex> r |> Enum.map(& &1.name)
[]
Link to this function

default_display_mode(resource)

View Source
@spec default_display_mode(Ash.Resource.t()) :: binary()

The default display mode of the resource as defined in the Pyro.Resource extension, defaulting to :data_table.

examples

Examples

iex> default_display_mode(User)
:card_grid
Link to this function

default_foreign_label(resource)

View Source
@spec default_foreign_label(Ash.Resource.t()) :: atom()

Returns the field defined in the Pyro.Resource extension as a default label, falling back to the first single-key identity of the resource, further falling back to the primary key if it's single-keyed.

examples

Examples

iex> default_foreign_label(AttendanceType)
:label

iex> default_foreign_label(Gage)
:name
Link to this function

default_page_limit(resource, action_name)

View Source
@spec default_page_limit(Ash.Resource.t(), atom() | binary()) :: pos_integer()

Return the default page for the given resource/action.

examples

Examples

iex> default_page_limit(AttendanceType, :read)
25
Link to this function

default_single_field_identity_key(resource)

View Source
@spec default_single_field_identity_key(Ash.Resource.t()) :: :atom

The first single-keyed identity, or the primary ID of the given resource.

examples

Examples

iex> default_single_field_identity_key(User) :email

Link to this function

default_sort(resource, action)

View Source
@spec default_sort(Ash.Resource.t(), atom()) :: binary()

The default sort of resource for the given action, falling back to the default provided by the Pyro.Resource extension.

This is useful for extracting default sorts from preparations.

examples

Examples

iex> default_sort(Gage, :calibration_alerts)
"++calibration_status_expiration,calibration_status,name"

iex> default_sort(AttendanceRecord, :read)
"-in"

iex> default_sort(AttendanceRecord, :current_attendance)
"in"
Link to this function

default_table_columns(resource)

View Source
@spec default_table_columns(Ash.Resource.t()) :: [ash_resource_field()]

The default table columns to display as defined in the Pyro.Resource extension, with fallback to all public fields.

examples

Examples

Explicitly configured

iex> r = default_table_columns(User)
iex> r |> Enum.map(& &1.name)
[:name, :email, :notes]
Link to this function

default_table_columns(resource, action, actor)

View Source
@spec default_table_columns(Ash.Resource.t(), Ash.Resource.Action.t(), ash_actor()) ::
  [
    ash_resource_field()
  ]

Same as default_table_columns/1, but filtered by those authorized for access for the specified action/actor.

examples

Examples

iex> r = default_table_columns(Gage, :calibration_alerts, nil)
iex> r |> Enum.map(& &1.name)
[]
Link to this function

destroy_actions(resource)

View Source
@spec destroy_actions(Ash.Resource.t()) :: [Ash.Resource.Actions.Destroy.t()]

Returns the list of :destroy type actions of the given resource.

examples

Examples

iex> r = destroy_actions(Gage)
iex> r |> Enum.map(& &1.name)
[:destroy]
Link to this function

destroy_actions(resource, actor, opts \\ [])

View Source

The same as destroy_actions/1, but filtered by those authorized for access for the specified action/actor.

examples

Examples

iex> r = destroy_actions(Gage, nil)
iex> r |> Enum.map(& &1.name)
[]

See Ash.Resource.Info.field/2.

Link to this function

field(resource, field, action, actor, opts \\ [])

View Source
Link to this function

field_authorized?(field, resource, action, actor, opts \\ [])

View Source

Check if a given field is authorized to be viewed by the actor.

examples

Examples

iex> field_authorized?("name", Gage, "read", nil)
false

iex> field_authorized?(:owner, Gage, :read, %{roles: [:Employee], active: true})
true

Note:

Currently, fields that may be authorized depending on actor's attributes are authorized. We may eventually want to more intelligently deal with this, because currently a nil actor will return true. This particular case will handled when #372 is closed. This is mostly UI concern, because the query will still be safely validated and would fail, but we don't want to clutter the UI with fields that can't actually be loaded.

iex> field_authorized?(:owner, Gage, :read, nil)
false

Note:

We are not currently handling field-level authz for create/update types. This can probably be done by leveraging Ash.Generator to seed changeset data for the given field. This should allow determine e.g. if a relationship is editable by the actor, allow forms to hide relationships that an actor can't edit.

Link to this function

field_description(resource, name)

View Source
@spec field_description(
  Ash.Resource.t(),
  ash_resource_field_or_name()
) :: atom()

Returns the given field's description.

examples

Examples

iex> field_description(AttendanceType, :clockable)
"Clockable types are available for employees to punch in/out at kiosks and workstations."
Link to this function

field_label(resource, action, field)

View Source

WIP label for resource fields. In the future it will pull from a resource field property. This will allow different labels based on context.

Link to this function

form_for(resource, action_name)

View Source
@spec form_for(Ash.Resource.t(), atom()) :: [
  Pyro.Resource.Form.Field.t() | Pyro.Resource.Form.FieldGroup.t()
]

Returns the form fields defined in the Pyro.Resource extension for the given action.

examples

Examples

iex> form_for(AttendanceRecord, :create) |> Enum.map(& &1.name)
[:notes, :employee_id, :type_id]
@spec input_id(AshPhoenix.Form.t(), atom()) :: binary()

This is only used for the primary user input. This provides consistency between the input component and other parts of the UI that may want ot provide a link to that user input e.g. to click an error and focus the related input.

examples

Examples

iex> form = AshPhoenix.Form.for_create(AttendanceType, :create)
iex> input_id(form, :label)
"form_label"
@spec is_page?(Ash.Resource.t()) :: boolean()

Return a boolean indicating if resource is a page as configured in the Pyro.Resource extension.

examples

Examples

iex> is_page?(AttendanceType)
true
@spec list_actions(Ash.Resource.t()) :: [Ash.Resource.Actions.Read.t()]

Returns the list of :read type actions of the given resource, excluding actions that are get?: true.

examples

Examples

iex> r = list_actions(Gage)
iex> r |> Enum.map(& &1.name)
[:calibration_alerts, :read]
Link to this function

list_actions(resource, actor, opts \\ [])

View Source

The same as list_actions/1, but filtered by those authorized for access for the specified action/actor.

examples

Examples

iex> r = list_actions(Gage, nil)
iex> r |> Enum.map(& &1.name)
[]
Link to this function

loadable_fields(fields, resource)

View Source
@spec loadable_fields([ash_resource_field()], Ash.Resource.t()) :: [atom()]

Filter the list of fields to those which can be loaded (as opposed to those which can be selected). Basically just filters out attributes from a list of fields.

examples

Examples

Explicitly configured

iex> default_table_columns(User) |> loadable_fields(User)
[:best_friend]
Link to this function

multitenancy_strategy(resource)

View Source

See Ash.Resource.Info.multitenancy_strategy/1.

Link to this function

page_limit_options(resource, action_name)

View Source
@spec page_limit_options(Ash.Resource.t(), atom() | binary()) :: [pos_integer()]

Return the page limit options for the given resource/action if pagination is configured.

examples

Examples

iex> page_limit_options(AttendanceType, :read)
[10, 25, 50, 100, 250]
@spec page_module(Ash.Resource.t()) :: module() | nil

The custom page module of the action as defined in the Pyro.Resource extension, if the resource is configured as a custom page.

examples

Examples

iex> page_module(User)
nil
Link to this function

page_route_path(resource)

View Source
@spec page_route_path(Ash.Resource.t()) :: binary() | nil

The page routing path of the resource as defined in the Pyro.Resource extension, if the resource is configured as a page.

examples

Examples

iex> page_route_path(AttendanceType)
"attendance-types"

See Ash.Policy.Info.policies/1.

Link to this function

primary_action(resource, type)

View Source

See Ash.Resource.Info.primary_action/2.

Link to this function

primary_actions(resource, opts \\ [])

View Source

Returns the list of actions of the given resource.

Passing exclude_types: [...] will filter out the specified action types from the list.

examples

Examples

iex> r = primary_actions(User)
iex> r |> Enum.map(& &1.name)
[:update, :create, :read]


iex> r = primary_actions(User, exclude_types: [:create, :update])
iex> r |> Enum.map(& &1.name)
[:read]
Link to this function

public_aggregates(resource)

View Source

See Ash.Resource.Info.public_aggregates/1.

Link to this function

public_attributes(resource)

View Source

See Ash.Resource.Info.public_attributes/1.

Link to this function

public_calculations(resource)

View Source

See Ash.Resource.Info.public_calculations/1.

@spec public_fields(Ash.Resource.t()) :: [ash_resource_field()]

Lists all the public fields of resource.

examples

Examples

iex> public_fields(AttendanceType) |> Enum.map(& &1.name)
[
  :label,
  :order,
  :shortcut,
  :notes,
  :inserted_at,
  :updated_at,
  :id,
  :records_count,
  :records
]
Link to this function

public_fields(resource, action, actor)

View Source
@spec public_fields(
  Ash.Resource.t(),
  ash_action_or_name(),
  ash_actor()
) :: [ash_resource_field()]

The same as public_fields/1, but filtered by those authorized for access for the specified action/actor.

examples

Examples

iex> public_fields(AttendanceType, :read, nil) |> Enum.map(& &1.name)
[]
@spec read_actions(Ash.Resource.t()) :: [Ash.Resource.Actions.Read.t()]

Returns the list of :read type actions of the given resource.

examples

Examples

iex> r = read_actions(Gage)
iex> r |> Enum.map(& &1.name)
[:calibration_alerts, :read]
Link to this function

read_actions(resource, actor, opts \\ [])

View Source

The same as read_actions/1, but filtered by those authorized for access for the specified action/actor.

examples

Examples

iex> r = read_actions(Gage, nil)
iex> r |> Enum.map(& &1.name)
[]

See Ash.Resource.Info.related/2.

Link to this function

relationship(resource, path)

View Source

See Ash.Resource.Info.relationship/2.

See Ash.Resource.Info.resource?/1.

Link to this function

resource_by_path(resource, list)

View Source
@spec resource_by_path(Ash.Resource.t(), [atom() | binary()]) :: Ash.Resource.t()
Link to this function

resource_description(resource)

View Source

See Ash.Resource.Info.description/1.

Link to this function

resource_label(resource)

View Source
@spec resource_label(Ash.Resource.t()) :: binary() | nil

The label of the resource as defined in the Pyro.Resource extension, defaulting to a humanized version of the module name.

examples

Examples

iex> resource_label(User)
"User"
Link to this function

reverse_relationship(resource, path)

View Source

See Ash.Resource.Info.reverse_relationship/2.

@spec show_actions(Ash.Resource.t()) :: [Ash.Resource.Actions.Read.t()]

Returns the list of :read type actions intended for single-record reads of the given resource.

examples

Examples

iex> r = show_actions(Record)
iex> r |> Enum.map(& &1.name)
[:show]
Link to this function

show_actions(resource, actor, opts \\ [])

View Source

The same as show_actions/1, but filtered by those authorized for access for the specified action/actor.

examples

Examples

iex> r = show_actions(Record, nil)
iex> r |> Enum.map(& &1.name)
[]
Link to this function

single_field_identities(resource)

View Source
@spec single_field_identities(Ash.Resource.t()) :: [Ash.Resource.Identity.t()]

List the single-keyed identities of the given resource.

examples

Examples

iex> single_field_identities(User)
[
  %Ash.Resource.Identity{
    description: nil,
    eager_check_with: nil,
    keys: [:email],
    name: :name,
    pre_check_with: nil
  }
]
Link to this function

sortable_field?(resource, field)

View Source
@spec sortable_field?(
  Ash.Resource.t(),
  ash_resource_field_or_name()
) :: boolean()

Check if a field is sortable.

examples

Examples

iex> sortable_field?(User, field(User, :email))
true

iex> sortable_field?(User, :name)
true
Link to this function

update_actions(resource)

View Source
@spec update_actions(Ash.Resource.t()) :: [Ash.Resource.Actions.Update.t()]

Returns the list of :update type actions of the given resource.

examples

Examples

iex> r = update_actions(Gage)
iex> r |> Enum.map(& &1.name)
[:update]
Link to this function

update_actions(resource, actor, opts \\ [])

View Source

The same as update_actions/1, but filtered by those authorized for access for the specified action/actor.

examples

Examples

iex> r = update_actions(Gage, nil)
iex> r |> Enum.map(& &1.name)
[]