View Source Pageantry.Page (Pageantry v0.5.2)

Combination of user preferences, user input, validation requirements, result output, and the Ecto query for generating the output of a paged/sorted/filtered list.

Fields

  • query : Ecto query for generating output.
  • prefs : User preferences.
  • input : User input.
  • validation : Validation definitions and restrictions to apply when adding user input to base query.
  • output : Output results.

Summary

Functions

Executes count query and updates output total with the result.

Filters the output items.

Creates new Page struct with input defaults.

Creates new Page struct with input defaults.

Adds join clause from user input and validation requirements to Ecto query.

Adds limit from user input and validation requirements to Ecto query.

Maps each output item with the specified function and updates the output struct.

Creates new Page struct with all defaults.

Creates new Page struct with specified prefs.

Creates new Page struct with prefs and parses params.

Adds offset from user input and validation requirements to Ecto query.

Adds order by from user input and validation requirements to Ecto query.

Creates new Page struct with parsed user input.

Adds parsed user input to page struct.

Adds output items to page struct.

Adds user prefs to page struct.

Adds Ecto query to page struct.

Adds Ecto repo and query to page struct.

Adds Ecto repo to page struct.

Adds validation definitions and restrictions to page struct.

Updates query in page struct with paging/sorting/filtering from input, executes query, and updates output struct with result.

Updates page struct with the specified query, updates query with paging/sorting/filtering from input, executes query, and updates output struct with result.

Updates page struct with the specified repo and query, updates query with paging/sorting/filtering from input, executes query, and updates output struct with result.

Updates page struct with the specified repo and query and validation, updates query with paging/sorting/filtering from input, executes query, and updates output struct with result.

Updates page struct with the specified repo and query and validation and request parameters, updates query with paging/sorting/filtering from input, executes query, and updates output struct with result.

Updates page struct with the specified repo and query and validation and request parameters and user prefs, updates query with paging/sorting/filtering from input, executes query, and updates output struct with result.

Executes select query and updates output items with the result.

Filters, sorts, and slices output items.

Updates page struct with the specified output items, and filters, sort, and slices the items.

Updates page struct with the specified output items and validation, and filters, sort, and slices the items.

Updates page struct with the specified output items and validation and request parameters, and filters, sort, and slices the items.

Applies offset and max length to the output items.

Sorts the output items.

Adds where clause from user input and validation requirements to Ecto query.

Types

@type t() :: %Pageantry.Page{
  input: Pageantry.Input.t(),
  output: Pageantry.Output.t(),
  prefs: Pageantry.Prefs.t(),
  query: Ecto.Query.t(),
  repo: Ecto.Repo.t(),
  validation: Pageantry.Validation.t()
}

Functions

@spec count(t()) :: t()

Executes count query and updates output total with the result.

@spec filter_output(t()) :: t()

Filters the output items.

@spec input(integer()) :: t()

Creates new Page struct with input defaults.

Examples

iex> import Pageantry.Page
iex> input(100).input
%Pageantry.Input{off: 0, max: 100, sort: [], filter: []}
Link to this function

input(max, sort \\ [], filter)

View Source
@spec input(integer(), keyword(), keyword()) :: t()

Creates new Page struct with input defaults.

Examples

iex> import Pageantry.Page
iex> input(100, name: "foo").input
%Pageantry.Input{max: 100, filter: [name: "foo"]}
iex> input(100, [desc: :created], [created: "today"]).input
%Pageantry.Input{off: 0, max: 100, sort: [desc: :created], filter: [created: "today"]}
@spec join(t()) :: t()

Adds join clause from user input and validation requirements to Ecto query.

@spec limit(t()) :: t()

Adds limit from user input and validation requirements to Ecto query.

@spec map(t(), (... -> any())) :: t()

Maps each output item with the specified function and updates the output struct.

Examples

iex> import Pageantry.Page
iex> page = %Pageantry.Page{output: %Pageantry.Output{items: [1, 2, 3]}}
iex> map(page, &to_string/1).output.items
["1", "2", "3"]
@spec new() :: t()

Creates new Page struct with all defaults.

Examples

iex> import Pageantry.Page
iex> new()
%Pageantry.Page{}
@spec new(Pageantry.Prefs.t()) :: t()

Creates new Page struct with specified prefs.

Examples

iex> import Pageantry.Page
iex> new(%Pageantry.Prefs{tz: "America/New_York"})
%Pageantry.Page{prefs: %Pageantry.Prefs{tz: "America/New_York"}}
@spec new(Pageantry.Prefs.t(), map()) :: t()

Creates new Page struct with prefs and parses params.

Examples

iex> import Pageantry.Page
iex> page = new(%Pageantry.Prefs{tz: "America/New_York"}, %{"off" => "100"})
iex> page.prefs.tz
"America/New_York"
iex> page.input.off
100
@spec offset(t()) :: t()

Adds offset from user input and validation requirements to Ecto query.

@spec order_by(t()) :: t()

Adds order by from user input and validation requirements to Ecto query.

@spec parse(map()) :: t()

Creates new Page struct with parsed user input.

Examples

iex> import Pageantry.Page
iex> parse(%{"max" => "100", "field" => "name", "q" => "foo"}).input
%Pageantry.Input{max: 100, filter: [name: "foo"]}
@spec parse(t(), map()) :: t()

Adds parsed user input to page struct.

Examples

iex> import Pageantry.Page
iex> parse(input(100), %{"field" => "name", "q" => "foo"}).input
%Pageantry.Input{max: 100, filter: [name: "foo"]}
@spec put_output(t(), list()) :: t()

Adds output items to page struct.

@spec put_prefs(t(), Pageantry.Prefs.t()) :: t()

Adds user prefs to page struct.

Examples

iex> import Pageantry.Page
iex> page = new() |> put_prefs(%Pageantry.Prefs{tz: "America/New_York"})
iex> page.prefs.weekstart
:sun
iex> page.prefs.tz
"America/New_York"
@spec put_query(t(), Ecto.Query.t()) :: t()

Adds Ecto query to page struct.

Link to this function

put_query(page, repo, query)

View Source
@spec put_query(t(), Ecto.Repo.t(), Ecto.Query.t()) :: t()

Adds Ecto repo and query to page struct.

@spec put_repo(t(), Ecto.Repo.t()) :: t()

Adds Ecto repo to page struct.

Link to this function

put_validation(page, validation)

View Source
@spec put_validation(t(), Pageantry.Validation.t()) :: t()

Adds validation definitions and restrictions to page struct.

Examples

iex> import Pageantry.Page
iex> v = %Pageantry.Validation{max_max: 100, base_filter: [active: true]}
iex> page = new() |> put_validation(v)
iex> page.validation.max_off
0
iex> page.validation.max_max
100
iex> page.validation.base_filter
[active: true]
@spec query(t()) :: t()

Updates query in page struct with paging/sorting/filtering from input, executes query, and updates output struct with result.

@spec query(t(), Ecto.Query.t()) :: t()

Updates page struct with the specified query, updates query with paging/sorting/filtering from input, executes query, and updates output struct with result.

Link to this function

query(page, repo, query)

View Source
@spec query(t(), Ecto.Repo.t(), Ecto.Query.t()) :: t()

Updates page struct with the specified repo and query, updates query with paging/sorting/filtering from input, executes query, and updates output struct with result.

Link to this function

query(page, repo, query, validation)

View Source
@spec query(t(), Ecto.Repo.t(), Ecto.Query.t(), Pageantry.Validation.t()) :: t()

Updates page struct with the specified repo and query and validation, updates query with paging/sorting/filtering from input, executes query, and updates output struct with result.

Link to this function

query(page, repo, query, validation, params)

View Source
@spec query(t(), Ecto.Repo.t(), Ecto.Query.t(), Pageantry.Validation.t(), map()) ::
  t()

Updates page struct with the specified repo and query and validation and request parameters, updates query with paging/sorting/filtering from input, executes query, and updates output struct with result.

Link to this function

query(page, repo, query, validation, params, prefs)

View Source
@spec query(
  t(),
  Ecto.Repo.t(),
  Ecto.Query.t(),
  Pageantry.Validation.t(),
  map(),
  Pageantry.Prefs.t()
) ::
  t()

Updates page struct with the specified repo and query and validation and request parameters and user prefs, updates query with paging/sorting/filtering from input, executes query, and updates output struct with result.

@spec select(t()) :: t()

Executes select query and updates output items with the result.

@spec slice(t()) :: t()

Filters, sorts, and slices output items.

@spec slice(t(), list()) :: t()

Updates page struct with the specified output items, and filters, sort, and slices the items.

Link to this function

slice(page, items, validation)

View Source
@spec slice(t(), list(), Pageantry.Validation.t()) :: t()

Updates page struct with the specified output items and validation, and filters, sort, and slices the items.

Link to this function

slice(page, items, validation, params)

View Source
@spec slice(t(), list(), Pageantry.Validation.t(), map()) :: t()

Updates page struct with the specified output items and validation and request parameters, and filters, sort, and slices the items.

@spec slice_output(t()) :: t()

Applies offset and max length to the output items.

@spec sort_output(t()) :: t()

Sorts the output items.

@spec where(t()) :: t()

Adds where clause from user input and validation requirements to Ecto query.