-
Notifications
You must be signed in to change notification settings - Fork 329
List Action Flow
Sergio Cambra edited this page May 6, 2024
·
2 revisions
These methods are called in the following order:
-
list_authorized_filter
called as before_action-
list_authorized?
is called to check the permission. If this method returns false,list_authorized_filter
will raise ActiveScaffold::ActionNotAllowed.
-
-
index
-
row
if request is XHR, and params[:id] is present and it isn't an array, so it's just refreshing a row.-
get_row
-
set_includes_for_columns
which setupactive_scaffold_references
(used withincludes
andreferences
methods when building the query) andactive_scaffold_preload
(used withpreload
method when building the query), based on the includes of the list columns, depending if column is used in the sorting (so it must be added to join in the query, so will be used in includes and references) or can be loaded in a separate query (so will be used in preload). -
beginning_of_chain
, used as param for the next method to load the record. -
find_if_allowed
to load the record to be edited into @record instance variable, checking :read permission.
-
-
respond_to_action
, which will call the corresponding response method for row action and the requested format.
-
-
list
otherwise.-
do_list
which sets @records with the records for the current page and @page with the page object generated withPaginator
class.-
current_page
-
set_includes_for_columns
which setupactive_scaffold_references
(used withincludes
andreferences
methods when building the query) andactive_scaffold_preload
(used withpreload
method when building the query), based on the includes of the list columns, depending if column is used in the sorting (so it must be added to join in the query, so will be used in includes and references) or can be loaded in a separate query (so will be used in preload). -
find_page_options
which generates the options to pass tofind_page
method (:sorting
,:per_page
and:page
, and:select
ifauto_select_columns
is enabled in list action). -
find_page
-
finder_options
to return a hash with options used to call methods in the relation object when building the query, the key matching the method name (:reorder
,:joins
,:left_joins
,:preload
,:includes
,:references
,:select
) and:conditions
used withwhere
method.-
custom_finder_options
which must return a hash to merge into the result returned byfinder_options
.
-
-
beginning_of_chain
, used as the relation object to build the query. -
count_items
to run a COUNT query to count the total items when pagination is used, and it isn't set as :infinite, and calculate the number of pages. -
append_to_query
to build the query with the options hash returned byfinder_options
-
-
-
cache_column_counts
, receive the records set bydo_list
, and set @counts, which is a hash with column names as keys, and counts for each column as values. It uses a query to get the counts on all listed records for an association column, using group, instead of sending a count query for each record, when the column is a collection association and it has no includes defined (includes = nil
) and it's set to display the number of associated records (associated_number = true
, enabled by default). It's useful for associations which have many associated record, and want to display the number without displaying any other info for associated records (associated_limit = 0
), so there is no need to load any associated record, just the count.-
columns_to_cache_counts
which return the columns to cache counts for. -
count_query_for_column
to return the query to callcount
on it (ormongoid_count_for_column
if the model uses Mongoid instead of ActiveRecord, returning the count).
-
-
-
respond_to_action
, which will call the corresponding response method for list action and the requested format.
-
-
These methods can be overrided:
-
do_list
can be overrided, for example to change some values or params before calling super, to affect the query generation, or load some more data into instance variables which may be used later by helpers. -
beginning_of_chain
can be overrided to add conditions loading the record or records, supporting scopes usage. -
conditions_for_collection
can be overrided to add conditions loading the records, only whenlist
is used (not refreshing a row), but it don't support scopes usage, it must return hash or array to be used withwhere
method. -
set_includes_for_columns
may be overrided to alter what associations are loaded with joins or separate queries, or add more associations toactive_scaffold_references
,active_scaffold_preload
oractive_scaffold_outer_joins
. -
custom_finder_options
may be overrided to add return other keys to call methods of ActiveRecord::Relation when building the query, e.g.:having
,:group
,:order
(to add more clauses toorder by
),:limit
,:offset
,:lock
,:readonly
,:from
. The same keys which returnfinder_options
can be used too, to override the values generated by ActiveScaffold. -
cache_column_counts
may be overrided to add counts for more columns, e.g. if they don't have associated_limit 0 but includes is cleared. -
columns_to_cache_counts
may be overrided to return other columns to cache counts for. -
count_query_for_column
may be overrided to change how count query is built, e.g. adding some conditions to the query to count only records matching some conditions.
def count_query_for_column(column, records)
if column == :alerts
super.where(cleared: false) # count only active alerts
else
super
end
end
When row
is used, the action will render these views:
- row.js.erb
- _list_record.html.erb, with local variable
record
- _update_calculations.js.erb
- _list_calculations.html.erb
- _list_record.html.erb, with local variable
When list
is used, the action will render these views:
- list.html.erb (only on HTML request, or loading embedded scaffold)
- _list_with_header.html.erb
- _list_header.html.erb, which renders the list title and the collection action links (using
display_action_links
helper) - active_scaffold_config.list.search_partial, which may be _search.html.erb or _field_search.html.erb, if
always_show_search
is enabled in list config. See Search action flow to other views used by these partials. - _create_form_on_list.html.erb if always_show_create is enabled in list config, and create action is authorized. It will render _base_form partial, as _create_form partial does, but defaults to render without cancel button. See Create action flow for other partials used to render the form.
- _list.html.erb to render the table with header and rows.
- _messages.html.erb to render flash messages and internal error message, if
messages_above_header
is enabled in list config. - _list_column_headings.html.erb to render the
th
tags for the list header, with the local variablecolumns
. - _list_messages.html.erb to render the tbody with other messages, filtered or empty list messages. It will render internal error and flash messages unless
messages_above_header
is enabled in list config. - _list_record.html.erb with the collection @page.items, if the page is not empty, with the locals
columns
andaction_links
with the member action links. It renders thetr
rows in thetbody
tag with class records. - _list_calculations.html.erb if any column has calculation setting, with the local variable
columns
. - _list_pagination.html.erb to render the list footer, with the records count unless pagination is set to
:infinite
in list config, and the page links.- _list_pagination_links.html.erb, with the local variable
current_page
, if the pagination is enabled in list config and pagination is:infinite
or has more than one page.
- _list_pagination_links.html.erb, with the local variable
- _messages.html.erb to render flash messages and internal error message, if
- _list_header.html.erb, which renders the list title and the collection action links (using
- _list_with_header.html.erb
These partials can be overrided to change how list is rendered, and list_record partial supports calling render :super
with some local variables to change some defaults:
-
columns
to use other columns to render, build the object withactive_scaffold_config.build_action_columns :list, [list of columns]
. -
row_id
with the ID attribute for the tr tag, instead of default ID generated withelement_row_id
helper, for action:list
. -
tr_class
with the class attribute for the tr tag, which defaults toeven-record
on even rows, and the result oflist_row_class
helper. -
action_links
to change the links rendered in the list, e.g. filtering some links out. -
data_refresh
with the value of thedata-refresh
attribute for the tr tag, which defaults torecord.to_param
.