View Source Backpex.HTML.Resource (Backpex v0.10.0)

Contains all Backpex resource components.

Summary

Components

Renders an edit panel.

Renders an info block to indicate that no items are found.

Renders the index filters if the filter/0 callback is defined in the resource.

Renders form with a search field. Emits the simple-search-input event on change.

Renders a link to change the order direction for a given column.

Renders pagination buttons. You are required to provide a :page pattern in the URL. It will be replaced with the corresponding page number.

Renders pagination info about the current page.

Renders a button group with create and resource action buttons.

Renders the field of the given resource.

Renders the input fields for filters and search.

Renders a resource form field.

Renders the main resource index content.

Renders a resource table.

Renders the metrics area for the current resource.

Renders a show card.

Renders a select per page button.

Renders a show panel.

Renders the toggle columns dropdown.

Renders the toggle columns inputs.

Functions

Creates a list of pagination items based on the current page and the total number of pages. A maximum of five pages will be displayed.

Components

edit_panel(assigns)

Renders an edit panel.

Attributes

  • form (:any)
  • class (:string) - extra class to be added. Defaults to "".
  • panel_fields (:list) (required) - list of fields to be rendered in the panel.
  • label (:any) - optional label for the panel. Defaults to nil.

empty_state(assigns)

Renders an info block to indicate that no items are found.

Attributes

  • socket (:any) (required)
  • live_resource (:atom) (required) - live resource module.
  • params (:map) (required) - query params.
  • singular_name (:string) (required) - singular name of the resource.

index_filter(assigns)

Renders the index filters if the filter/0 callback is defined in the resource.

Attributes

  • live_resource (:any) (required) - module of the live resource.
  • filter_options (:map) (required) - filter options.
  • filters (:list) (required) - list of active filters.

index_search_form(assigns)

Renders form with a search field. Emits the simple-search-input event on change.

Attributes

  • searchable_fields (:list) - The fields that can be searched. Here only used to hide the component when empty. Defaults to [].
  • full_text_search (:string) - full text search column name. Defaults to nil.
  • value (:string) (required) - value binding for the search input.
  • placeholder (:string) (required) - placeholder for the search input.

order_link(assigns)

Renders a link to change the order direction for a given column.

Attributes

  • socket (:map) (required)
  • live_resource (:any) (required) - module of the live resource.
  • params (:string) (required) - query parameters.
  • query_options (:map) (required) - query options.
  • label (:string) (required) - label to be displayed on the link.
  • name (:atom) (required) - name of the column the link should change order for.

pagination(assigns)

Renders pagination buttons. You are required to provide a :page pattern in the URL. It will be replaced with the corresponding page number.

Attributes

  • current_page (:integer) (required) - current page number.
  • total_pages (:integer) (required) - number of total pages.
  • path (:string) (required) - path to be used for page links.

pagination_info(assigns)

Renders pagination info about the current page.

Attributes

  • total (:integer) (required) - total number of items.
  • query_options (:map) (required) - query options.

resource_buttons(assigns)

Renders a button group with create and resource action buttons.

Attributes

  • socket (:any) (required)
  • live_resource (:any) (required) - module of the live resource.
  • params (:string) (required) - query parameters.
  • query_options (:map) - query options. Defaults to %{}.
  • resource_actions (:list) - list of all resource actions provided by the resource configuration. Defaults to [].
  • singular_name (:string) (required) - singular name of the resource.

resource_field(assigns)

Renders the field of the given resource.

Attributes

  • name (:string) (required) - name / key of the item field.
  • item (:map) (required) - the item which provides the value to be rendered.
  • fields (:list) (required) - list of all fields provided by the resource configuration.

resource_filters(assigns)

Renders the input fields for filters and search.

Attributes

  • live_resource (:any) (required) - module of the live resource.
  • searchable_fields (:list) - The fields that can be searched. Here only used to hide the component when empty. Defaults to [].
  • full_text_search (:string) - full text search column name. Defaults to nil.
  • query_options (:map) - query options. Defaults to %{}.
  • search_placeholder (:string) (required) - placeholder for the search input.

resource_form_field(assigns)

Renders a resource form field.

Attributes

  • name (:string) (required) - name / key of the item field.
  • form (:map) (required) - form that will be used by the form field.
  • repo (:any) - ecto repo.
  • uploads (:map) - map that contains upload information. Defaults to %{}.
  • fields (:list) (required) - list of all fields provided by the resource configuration.

resource_index_main(assigns)

Renders the main resource index content.

Attributes

  • socket (:any) (required)
  • live_resource (:any) (required) - module of the live resource.
  • params (:string) (required) - query parameters.
  • query_options (:map) - query options. Defaults to %{}.
  • total_pages (:integer) - amount of total pages. Defaults to 1.
  • resource_actions (:list) - list of all resource actions provided by the resource configuration. Defaults to [].
  • singular_name (:string) (required) - singular name of the resource.
  • orderable_fields (:list) - list of orderable fields. Defaults to [].
  • items (:list) - items that will be displayed in the table. Defaults to [].
  • fields (:list) - list of fields to be displayed in the table on index view. Defaults to [].

resource_index_table(assigns)

Renders a resource table.

Attributes

  • socket (:any) (required)
  • live_resource (:any) (required) - module of the live resource.
  • params (:string) (required) - query parameters.
  • query_options (:map) - query options. Defaults to %{}.
  • fields (:list) (required) - list of fields to be displayed in the table on index view.
  • orderable_fields (:list) - list of orderable fields. Defaults to [].
  • searchable_fields (:list) - list of searchable fields. Defaults to [].
  • items (:list) - items that will be displayed in the table. Defaults to [].
  • active_fields (:list) (required) - list of active fields.
  • selected_items (:list) (required) - list of selected items.

resource_metrics(assigns)

Renders the metrics area for the current resource.

Attributes

  • metrics (:list) - list of metrics to be displayed. Defaults to [].

resource_show_main(assigns)

Renders a show card.

Attributes

  • socket (:any) (required)
  • live_resource (:any) (required) - module of the live resource.
  • params (:string) (required) - query parameters.
  • item (:map) (required) - item that will be rendered on the card.
  • fields (:list) (required) - list of fields to be displayed on the card.

select_per_page(assigns)

Renders a select per page button.

Attributes

  • options (:list) (required) - A list of per page options.
  • query_options (:map) - The query options. Defaults to %{}.
  • class (:string) - Extra class to be added to the select. Defaults to "".

show_panel(assigns)

Renders a show panel.

Attributes

  • panel_fields (:list) (required) - list of fields to be rendered in the panel.
  • class (:string) - extra class to be added. Defaults to "".
  • label (:any) - optional label for the panel. Defaults to nil.

toggle_columns(assigns)

Renders the toggle columns dropdown.

Attributes

  • socket (:any) (required)
  • active_fields (:list) (required) - list of active fields.
  • live_resource (:atom) (required) - the live resource.
  • current_url (:string) (required) - the current url.
  • class (:string) - additional class to be added to the component. Defaults to "".
  • x_style (:string) - alpine-bound inline styles for the root div. Defaults to "".

toggle_columns_inputs(assigns)

Renders the toggle columns inputs.

Attributes

  • form (:any) (required) - the form.
  • active_fields (:list) (required) - list of active fields to be displayed.

Functions

form_component(assigns)

pagination_items(current_page, total_pages)

Creates a list of pagination items based on the current page and the total number of pages. A maximum of five pages will be displayed.

Example

iex> Backpex.HTML.Resource.pagination_items(1, 1)
[%{type: :number, number: 1}]

iex> Backpex.HTML.Resource.pagination_items(1, 2)
[%{type: :number, number: 1}, %{type: :number, number: 2}, %{type: :next, number: nil}]

iex> Backpex.HTML.Resource.pagination_items(2, 2)
[%{type: :prev, number: nil}, %{type: :number, number: 1}, %{type: :number, number: 2}]

iex> Backpex.HTML.Resource.pagination_items(2, 8)
[%{type: :prev, number: nil}, %{type: :number, number: 1}, %{type: :number, number: 2}, %{type: :number, number: 3}, %{type: :number, number: 4}, %{type: :placeholder, number: nil}, %{type: :number, number: 8}, %{type: :next, number: nil}]

iex> Backpex.HTML.Resource.pagination_items(5, 10)
[%{type: :prev, number: nil}, %{type: :number, number: 1}, %{type: :placeholder, number: nil}, %{type: :number, number: 4}, %{type: :number, number: 5}, %{type: :number, number: 6}, %{type: :placeholder, number: nil}, %{type: :number, number: 10}, %{type: :next, number: nil}]

iex> Backpex.HTML.Resource.pagination_items(9, 10)
[%{type: :prev, number: nil}, %{type: :number, number: 1}, %{type: :placeholder, number: nil}, %{type: :number, number: 7}, %{type: :number, number: 8}, %{type: :number, number: 9}, %{type: :number, number: 10}, %{type: :next, number: nil}]

resource_form(assigns)

resource_form_main(assigns)

resource_index(assigns)

resource_show(assigns)