View Source Torch.FilterView (Torch v5.1.2)

Provides input generators for Torch's filter sidebar.

Summary

Functions

Generates a select box for a belongs_to association.

Generates a filter select box for a boolean field.

Generates a "before/after" filter type select box for a given date or datetime field.

Generates a filter input for a number field.

Generates a "contains/equals" filter type select box for a given string or text field.

Generates a filter input for a string field.

Generates a number filter type select box for a given number field.

Types

@type field() :: atom() | String.t()
@type input_type() :: atom() | String.t()
@type prefix() :: atom() | String.t()

Functions

Link to this function

filter_assoc_select(prefix, field, options, params)

View Source
@spec filter_assoc_select(prefix(), field(), list(), map()) :: Phoenix.HTML.safe()

Generates a select box for a belongs_to association.

Example

iex> params = %{"post" => %{"category_id_equals" => 1}}
...> filter_assoc_select(:post, :category_id, [{"Articles", 1}], params) |> safe_to_string()
"<select id=\"post_category_id_equals\" name=\"post[category_id_equals]\"><option value=\"\">Choose one</option><option selected value=\"1\">Articles</option></select>"
Link to this function

filter_boolean_input(prefix, field, params)

View Source
@spec filter_boolean_input(prefix(), field(), map()) :: Phoenix.HTML.safe()

Generates a filter select box for a boolean field.

Example

iex> params = %{"post" => %{"draft_equals" => "false"}}
iex> filter_boolean_input(:post, :draft, params) |> safe_to_string()
"<select class=\"boolean-type\" id=\"post_draft_equals\" name=\"post[draft_equals]\"><option value=\"any\"></option><option value=\"true\">True</option><option selected value=\"false\">False</option></select>"
Link to this function

filter_date_input(prefix, field, params, input_type \\ :range)

View Source
@spec filter_date_input(prefix(), field(), map(), input_type()) :: Phoenix.HTML.safe()

Generates a filter datepicker input.

Example

iex> params = %{"post" => %{"inserted_at_between" => %{"start" => "01/01/2018", "end" => "01/31/2018"}}}
...> filter_date_input(:post, :inserted_at, params) |> safe_to_string()
"<input class=\"datepicker start\" name=\"post[inserted_at_between][start]\" placeholder=\"Select Start Date\" type=\"text\" value=\"01/01/2018\"><input class=\"datepicker end\" name=\"post[inserted_at_between][end]\" placeholder=\"Select End Date\" type=\"text\" value=\"01/31/2018\">"

iex> params = %{"post" => %{"inserted_at_between" => %{"start" => "01/01/2018", "end" => "01/31/2018"}}}
...> filter_date_input(:post, :inserted_at, params, :range) |> safe_to_string()
"<input class=\"datepicker start\" name=\"post[inserted_at_between][start]\" placeholder=\"Select Start Date\" type=\"text\" value=\"01/01/2018\"><input class=\"datepicker end\" name=\"post[inserted_at_between][end]\" placeholder=\"Select End Date\" type=\"text\" value=\"01/31/2018\">"

iex> params = %{"post" => %{"inserted_at_before" => "01/01/2018"}}
...> filter_date_input(:post, :inserted_at, params, :select) |> safe_to_string()
"<input class=\"datepicker\" name=\"post[inserted_at_before]\" placeholder=\"Select Date\" type=\"text\" value=\"01/01/2018\">"

iex> params = %{"post" => %{"inserted_at_after" => "01/01/2018"}}
...> filter_date_input(:post, :inserted_at, params, :select) |> safe_to_string()
"<input class=\"datepicker\" name=\"post[inserted_at_after]\" placeholder=\"Select Date\" type=\"text\" value=\"01/01/2018\">"
Link to this function

filter_date_select(prefix, field, params)

View Source
@spec filter_date_select(prefix(), field(), map()) :: Phoenix.HTML.safe()

Generates a "before/after" filter type select box for a given date or datetime field.

Example

iex> params = %{"post" => %{"updated_at_after" => "01/01/2019"}}
...> filter_date_select(:post, :updated_at, params) |> safe_to_string()
"<select class=\"filter-type\" id=\"filters_\" name=\"filters[]\"><option value=\"post[updated_at_before]\">Before</option><option selected value=\"post[updated_at_after]\">After</option></select>"
Link to this function

filter_number_input(prefix, field, params)

View Source
@spec filter_number_input(prefix(), field(), map()) :: Phoenix.HTML.safe()

Generates a filter input for a number field.

Example

iex> params = %{"post" => %{"rating_equals" => 5}}
...> filter_number_input(:post, :rating, params) |> safe_to_string()
"<input id=\"post_rating_equals\" name=\"post[rating_equals]\" type=\"number\" value=\"5\">"

iex> params = %{"post" => %{"rating_greater_than_or" => 15}}
...> filter_number_input(:post, :rating, params) |> safe_to_string()
"<input id=\"post_rating_greater_than_or\" name=\"post[rating_greater_than_or]\" type=\"number\" value=\"15\">"

iex> params = %{"post" => %{"rating_greater_than" => 15}}
...> filter_number_input(:post, :rating, params) |> safe_to_string()
"<input id=\"post_rating_greater_than\" name=\"post[rating_greater_than]\" type=\"number\" value=\"15\">"

iex> params = %{"post" => %{"rating_less_than" => 18}}
...> filter_number_input(:post, :rating, params) |> safe_to_string()
"<input id=\"post_rating_less_than\" name=\"post[rating_less_than]\" type=\"number\" value=\"18\">"
Link to this function

filter_select(prefix, field, params)

View Source
@spec filter_select(prefix(), field(), map()) :: Phoenix.HTML.safe()

Generates a "contains/equals" filter type select box for a given string or text field.

Example

iex> params = %{"post" => %{"title_contains" => "test"}}
...> filter_select(:post, :title, params) |> safe_to_string()
"<select class=\"filter-type\" id=\"filters_\" name=\"filters[]\"><option selected value=\"post[title_contains]\">Contains</option><option value=\"post[title_equals]\">Equals</option></select>"
Link to this function

filter_string_input(prefix, field, params)

View Source
@spec filter_string_input(prefix(), field(), map()) :: Phoenix.HTML.safe()

Generates a filter input for a string field.

Example

iex> params = %{"post" => %{"title_contains" => "test"}}
iex> filter_string_input(:post, :title, params) |> safe_to_string()
"<input id=\"post_title_contains\" name=\"post[title_contains]\" type=\"text\" value=\"test\">"

iex> params = %{"post" => %{"board_title_contains" => "board test", "title_contains" => "test"}}
iex> filter_string_input(:post, :title, params) |> safe_to_string()
"<input id=\"post_title_contains\" name=\"post[title_contains]\" type=\"text\" value=\"test\">"
Link to this function

number_filter_select(prefix, field, params)

View Source
@spec number_filter_select(prefix(), field(), map()) :: Phoenix.HTML.safe()

Generates a number filter type select box for a given number field.

Example

iex> params = %{"post" => %{"rating_greater_than" => 0}}
...> number_filter_select(:post, :rating, params) |> safe_to_string()
"<select class=\"filter-type\" id=\"filters_\" name=\"filters[]\"><option value=\"post[rating_equals]\">Equals</option><option selected value=\"post[rating_greater_than]\">Greater Than</option><option value=\"post[rating_greater_than_or]\">Greater Than Or Equal</option><option value=\"post[rating_less_than]\">Less Than</option></select>"