Class: Avo::ViewTypes::TableComponent
- Inherits:
-
BaseViewTypeComponent
- Object
- ViewComponent::Base
- BaseComponent
- BaseViewTypeComponent
- Avo::ViewTypes::TableComponent
- Includes:
- ApplicationHelper
- Defined in:
- app/components/avo/view_types/table_component.rb
Constant Summary
Constants included from Concerns::FindAssociationField
Concerns::FindAssociationField::ASSOCIATIONS
Instance Attribute Summary collapse
-
#pagy ⇒ Object
readonly
Returns the value of attribute pagy.
-
#query ⇒ Object
readonly
Returns the value of attribute query.
Instance Method Summary collapse
- #before_render ⇒ Object
- #cache_table_rows ⇒ Object
- #encrypted_query ⇒ Object
- #generate_table_row_components ⇒ Object
- #selected_all_label ⇒ Object
- #selected_page_label ⇒ Object
-
#table_attrs ⇒ Object
ARIA grid affordances and the row-navigator binding are only added on top-level index pages.
Methods included from ApplicationHelper
#a_button, #a_link, #body_classes, #button_classes, #chart_color, #container_classes, #d, #decode_filter_params, #e, #editor_file_path, #editor_url, #empty_state, #encode_filter_params, #frame_id, #get_model_class, #input_classes, #manual_frame_cookie_name, #manual_frame_remembered?, #mount_path, #number_to_social, #possibly_rails_authentication?, #render_header_menu_items, #render_license_warning, #root_path_without_url, #rtl?, #safe_blob_path, #safe_blob_representation_url, #safe_blob_url, #text_direction, #ui, #wrap_in_modal
Methods included from SummaryChartHelper
Methods included from ResourcesHelper
#field_wrapper, #filter_wrapper, #index_field_wrapper, #item_selector_data_attributes, #record_path, #record_title, #resource_for_record, #resource_grid, #resource_show_path, #resource_table
Methods inherited from BaseViewTypeComponent
Methods inherited from BaseComponent
#component_name, #hotkey_badge
Methods included from Concerns::FindAssociationField
Instance Attribute Details
#pagy ⇒ Object (readonly)
Returns the value of attribute pagy.
5 6 7 |
# File 'app/components/avo/view_types/table_component.rb', line 5 def pagy @pagy end |
#query ⇒ Object (readonly)
Returns the value of attribute query.
5 6 7 |
# File 'app/components/avo/view_types/table_component.rb', line 5 def query @query end |
Instance Method Details
#before_render ⇒ Object
7 8 9 |
# File 'app/components/avo/view_types/table_component.rb', line 7 def before_render @header_fields, @table_row_components = cache_table_rows end |
#cache_table_rows ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'app/components/avo/view_types/table_component.rb', line 53 def cache_table_rows # Cache the execution of the following block if caching is enabled in Avo configuration cache_if Avo.configuration.cache_resources_on_index_view, @resource.cache_hash(@parent_record), expires_in: 1.day do header_fields, table_row_components = generate_table_row_components # Create an array of header field labels used for each row to render values on the right column header_fields_ids = header_fields.map(&:table_header_label) # Assign header field IDs to each TableRowComponent # We assign it here because only complete header fields array after last table row. table_row_components.map { |table_row_component| table_row_component.header_fields = header_fields_ids } # Return header fields and table row components return [header_fields, table_row_components] end end |
#encrypted_query ⇒ Object
26 27 28 29 30 31 32 33 34 35 |
# File 'app/components/avo/view_types/table_component.rb', line 26 def encrypted_query # TODO: move this to the resource where we can apply the adapter pattern if Module.const_defined?("Ransack::Search") && @query.instance_of?(Ransack::Search) @query = @query.result end Avo::Services::EncryptionService.encrypt(message: @query, purpose: :select_all, serializer: Marshal) rescue disable_select_all end |
#generate_table_row_components ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'app/components/avo/view_types/table_component.rb', line 70 def generate_table_row_components # Initialize arrays to hold header fields and table row components header_fields = [] table_row_components = [] # Loop through each resource in @resources @resources.each_with_index do |resource, index| # Get fields for the current resource and concat them to the @header_fields row_fields = resource.get_fields(reflection: @reflection, only_root: true) header_fields.concat row_fields # Create a TableRowComponent instance for the resource and add it to @table_row_components table_row_components << resource.resolve_component(Avo::Index::TableRowComponent).new( resource: resource, fields: row_fields, reflection: @reflection, parent_record: @parent_record, parent_resource: @parent_resource, actions: @actions, index: ) end # Remove duplicate header fields based on table_header_label header_fields.uniq!(&:table_header_label) [header_fields, table_row_components] end |
#selected_all_label ⇒ Object
45 46 47 48 49 50 51 |
# File 'app/components/avo/view_types/table_component.rb', line 45 def selected_all_label if @resource.pagination_type.countless? t "avo.records_selected_from_all_pages_html" else t "avo.x_records_selected_from_all_pages_html", count: @pagy.count end end |
#selected_page_label ⇒ Object
37 38 39 40 41 42 43 |
# File 'app/components/avo/view_types/table_component.rb', line 37 def selected_page_label if @resource.pagination_type.countless? t "avo.x_records_selected_from_page_html", selected: @pagy.in else t "avo.x_records_selected_from_a_total_of_x_html", selected: @pagy.in, count: @pagy.count end end |
#table_attrs ⇒ Object
ARIA grid affordances and the row-navigator binding are only added on top-level index pages. On a parent record’s show view (where @reflection is present), the has-many table is not keyboard-navigable as a grid, so the global Shift+T / j / k shortcuts find no target.
15 16 17 18 19 20 21 22 23 24 |
# File 'app/components/avo/view_types/table_component.rb', line 15 def table_attrs return {} if @reflection.present? { tabindex: "0", role: "grid", "aria-label": @resource.plural_name, data: {"index-row-navigator-target": "table", "content-focus": ""} } end |