Skip to main content

Views

Basic views can be declared using symbols:

views [:list, :show, :create, :edit]

For full control, pass view objects directly:

views [
Habarico::ListView.new(
boxes: [:id, :product, :customer, :status, :placed_at],
filters: [],
toolbar_filters: [:status, :category],
row_actions: [:show, :edit, :delete],
toolbar_actions: [:create],
default_sorting: 'placed_at:desc',
),
Habarico::ShowView.new,
Habarico::CreateView.new,
Habarico::EditView.new,
]

You can create custom view using Habarico::ActionView class:

Habarico::ActionView.new(
name: 'refund',
label: 'Pay back guarantee',
view_mode: :dialog,
is_detail: true,
boxes: [:refund_amount, :refund_reason],
model: RefundRequest,
endpoint_action_name: 'refund',
endpoint_method: :put,
)
caution

endpoint_action_name is what makes an action view routable — it is the URL segment appended after the record. endpoint_reference is a different thing: the other resource the action is served by. A view with neither gets no path in its schema and never becomes an action route.

View attributes​

Every view class accepts the same set:

AttributeDescription
nameView name; also the schema key the frontend routes by
labelHeading of the view
is_detailWhether the view needs a record
view_mode:redirect (default), :dialog or :sidepanel
boxesFields and boxes the view renders
boxA single root box, instead of the boxes list
filters / toolbar_filtersList views: the drawer filters and the always-visible ones
default_sorting'field:asc' / 'field:desc'
row_actions / toolbar_actions / list_actionsThe three action slots
single_click_action / double_click_actionRow activation
endpoint_methodHTTP method of the view's endpoint
endpoint_action_nameAction segment of the URL — required for an action view
endpoint_referenceAnother resource serving this view
modelModel the view's fields are read from, when it differs from the resource's
permissionPermission checked before the view is offered (:read, :create, …)
caution

A key that is not on that list is silently dropped — Habarico::View only assigns the attributes it declares. There is no icon: on a view, for instance; the icon belongs to the action or the menu item.

Available view classes:

ClassSymbolHTTP methodRequires record?
Habarico::ListView:listGETNo
Habarico::ShowView:showGETYes
Habarico::CreateView:createPOSTNo
Habarico::EditView:editPATCHYes
Habarico::ActionView(none)AnyConfigurable