View Source ExTeal.Resource.Index behaviour (ExTeal v0.27.0)

Behavior for handling index requests for a given resource

Summary

Callbacks

Returns the actions available for a resource

Returns the models to be represented by this resource.

Returns the models to be represented by this resource via a relationship.

Defines the search adapter to use while building a search query

Callbacks

@callback actions(Plug.Conn.t()) :: [module()]

Returns the actions available for a resource

Default implementation is an empty array.

@callback handle_index(Plug.Conn.t(), map()) :: Plug.Conn.t() | ExTeal.records()

Returns the models to be represented by this resource.

Default implementation is the result of the ExTeal.Resource.Records.records/2 callback. Usually a module or an %Ecto.Query{}.

The results of this callback are passed to the filter and sort callbacks before the query is executed.

handle_index/2 can alternatively return a conn with any response/body.

Example custom implementation:

def handle_index(conn, _params) do
  case conn.assigns[:current_user] do
    nil  -> App.Post
    user -> User.own_posts(user)
  end
end

In most cases ExTeal.Resource.Records.records/1, filter/4, and sort/4 are the better customization hooks.

@callback handle_related(Plug.Conn.t(), map()) :: Plug.Conn.t() | ExTeal.records()

Returns the models to be represented by this resource via a relationship.

Default implementation is the result of the ExTeal.Resource.Records.records/2 callback returning an ecto query with the fields necessary to display the title.

handle_related/2 can alternatively return a conn with any response/body.

Example custom implementation:

def handle_related(conn, _params) do
  case conn.assigns[:current_user] do
    nil  -> App.Post
    user -> User.own_posts(user)
  end
end
Link to this callback

search_adapter(t, module, map)

View Source
@callback search_adapter(Ecto.Query.t(), module(), map()) :: Ecto.Query.t()

Defines the search adapter to use while building a search query:

Defaults to the ExTeal.Search.SimpleSearch module

Functions

Link to this function

field_filters(query, conn, resource)

View Source
Link to this function

filter_via_relationships(query, arg2)

View Source
Link to this function

query_by_related(query, arg2, arg3)

View Source
Link to this function

query_for_related(resource, conn)

View Source

Callback implementation for ExTeal.Resource.Repo.repo/0.

Link to this function

reversed_query(rel, query, resource_id, related_resource)

View Source
Link to this function

search(query, params, resource)

View Source
Link to this function

sort(query, conn, resource)

View Source
Link to this function

with_pivot_fields(query, arg2, resource)

View Source