-
Notifications
You must be signed in to change notification settings - Fork 332
List Action Flow
Sergio Cambra edited this page May 6, 2024
·
2 revisions
These methods are called in the following order:
-
list_authorized_filtercalled as before_action-
list_authorized?is called to check the permission. If this method returns false,list_authorized_filterwill raise ActiveScaffold::ActionNotAllowed.
-
-
index-
rowif 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_columnswhich setupactive_scaffold_references(used withincludesandreferencesmethods when building the query) andactive_scaffold_preload(used withpreloadmethod 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_allowedto 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.
-
-
listotherwise.-
do_listwhich sets @records with the records for the current page and @page with the page object generated withPaginatorclass.-
current_page-
set_includes_for_columnswhich setupactive_scaffold_references(used withincludesandreferencesmethods when building the query) andactive_scaffold_preload(used withpreloadmethod 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_optionswhich generates the options to pass tofind_pagemethod (:sorting,:per_pageand:page, and:selectifauto_select_columnsis enabled in list action). -
find_page-
finder_optionsto 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:conditionsused withwheremethod.-
custom_finder_optionswhich 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_itemsto 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_queryto 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_countswhich return the columns to cache counts for. -
count_query_for_columnto return the query to callcounton it (ormongoid_count_for_columnif 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_listcan 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_chaincan be overrided to add conditions loading the record or records, supporting scopes usage. -
conditions_for_collectioncan be overrided to add conditions loading the records, only whenlistis used (not refreshing a row), but it don't support scopes usage, it must return hash or array to be used withwheremethod. -
set_includes_for_columnsmay be overrided to alter what associations are loaded with joins or separate queries, or add more associations toactive_scaffold_references,active_scaffold_preloadoractive_scaffold_outer_joins. -
custom_finder_optionsmay 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_optionscan be used too, to override the values generated by ActiveScaffold. -
cache_column_countsmay 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_countsmay be overrided to return other columns to cache counts for. -
count_query_for_columnmay 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
endWhen 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_linkshelper) - active_scaffold_config.list.search_partial, which may be _search.html.erb or _field_search.html.erb, if
always_show_searchis 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_headeris enabled in list config. - _list_column_headings.html.erb to render the
thtags 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_headeris enabled in list config. - _list_record.html.erb with the collection @page.items, if the page is not empty, with the locals
columnsandaction_linkswith the member action links. It renders thetrrows in thetbodytag 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
:infinitein 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:infiniteor 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:
-
columnsto use other columns to render, build the object withactive_scaffold_config.build_action_columns :list, [list of columns]. -
row_idwith the ID attribute for the tr tag, instead of default ID generated withelement_row_idhelper, for action:list. -
tr_classwith the class attribute for the tr tag, which defaults toeven-recordon even rows, and the result oflist_row_classhelper. -
action_linksto change the links rendered in the list, e.g. filtering some links out. -
data_refreshwith the value of thedata-refreshattribute for the tr tag, which defaults torecord.to_param.