View Source Torch.TableView (Torch v5.4.0)

Helpers for rendering Torch-generated tables.

Summary

Functions

Takes an existing URI query string and adds or replaces the page, sort_field, direction with an updated query string value.

Prettifies and associated struct for display.

Generates a sortable link for a table heading.

Functions

Takes an existing URI query string and adds or replaces the page, sort_field, direction with an updated query string value.

Examples

iex> querystring("", %{}, %{page: 1})
"page=1"

iex> querystring("foo=bar", %{}, %{page: 2})
"foo=bar&page=2"

iex> querystring("foo=bar&page=14", %{}, %{page: 3})
"foo=bar&page=3"

iex> querystring("foo=bar", %{"sort_direction" => "asc", "sort_field" => "name"}, %{page: 4})
"foo=bar&page=4&sort_direction=asc&sort_field=name"

iex> querystring("foo=bar", %{"sort_direction" => "asc", "sort_field" => "name"}, %{page: 4, sort_direction: "desc"})
"foo=bar&page=4&sort_direction=desc&sort_field=name"

iex> querystring("foo=bar", %{"sort_direction" => "asc", "sort_field" => "name"}, %{page: 4, sort_direction: "desc", sort_field: "id"})
"foo=bar&page=4&sort_direction=desc&sort_field=id"
Link to this function

querystring(conn_query_string, conn_params, opts)

View Source
@spec querystring(String.t(), %{optional(binary()) => term()}, %{
  optional(atom()) => term()
}) ::
  String.t()
Link to this function

table_assoc_display_name(struct, field, options)

View Source
@spec table_assoc_display_name(struct(), atom(), Keyword.t()) :: String.t()

Prettifies and associated struct for display.

Displays the model's name or "None", rather than the struct's ID.

Examples

iex> table_assoc_display_name(%{category_id: 1}, :category_id, [{"Articles", 1}])
"Articles"

iex> table_assoc_display_name(%{category_id: nil}, :category_id, [{"Articles", 1}])
"None"
Link to this function

table_link(conn, text, field)

View Source
@spec table_link(Plug.Conn.t(), String.t(), atom()) :: Phoenix.HTML.safe()

Generates a sortable link for a table heading.

Clicking on the link will trigger a sort on that field. Clicking again will reverse the sort.

Example

iex> conn = %Plug.Conn{params: %{"sort_field" => "name", "sort_direction" => "asc"}}
...> table_link(conn, "Name", :name) |> safe_to_string()
"<a class=\"active asc\" href=\"?sort_direction=desc&amp;sort_field=name\">Name<span class=\"caret\"></span></a>"