Class: SolidusAdmin::UI::Table::Component
- Inherits:
-
BaseComponent
- Object
- BaseComponent
- SolidusAdmin::UI::Table::Component
- Defined in:
- app/components/solidus_admin/ui/table/component.rb
Instance Method Summary collapse
- #batch_actions_form_id ⇒ Object
-
#initialize(id:, model_class:, rows:, search_key:, search_url:, fade_row_proc: nil, columns: [], batch_actions: [], filters: [], prev_page_link: nil, next_page_link: nil) ⇒ Component
constructor
A new instance of Component.
- #render_batch_action_button(batch_action) ⇒ Object
- #render_data_cell(cell, data) ⇒ Object
- #render_header_cell(cell, **attrs) ⇒ Object
- #resource_plural_name ⇒ Object
- #row_class_for(row) ⇒ Object
- #search_form_id ⇒ Object
- #selectable_column ⇒ Object
- #table_frame_id ⇒ Object
Constructor Details
#initialize(id:, model_class:, rows:, search_key:, search_url:, fade_row_proc: nil, columns: [], batch_actions: [], filters: [], prev_page_link: nil, next_page_link: nil) ⇒ Component
Returns a new instance of Component.
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'app/components/solidus_admin/ui/table/component.rb', line 30 def initialize( id:, model_class:, rows:, search_key:, search_url:, fade_row_proc: nil, columns: [], batch_actions: [], filters: [], prev_page_link: nil, next_page_link: nil ) @columns = columns.map { Column.new(**_1) } @batch_actions = batch_actions.map { BatchAction.new(**_1) } @filters = filters.map { Filter.new(**_1) } @id = id @model_class = model_class @rows = rows @fade_row_proc = fade_row_proc @search_key = search_key @search_url = search_url @prev_page_link = prev_page_link @next_page_link = next_page_link @columns.unshift selectable_column if batch_actions.present? end |
Instance Method Details
#batch_actions_form_id ⇒ Object
86 87 88 |
# File 'app/components/solidus_admin/ui/table/component.rb', line 86 def batch_actions_form_id @batch_actions_form_id ||= "#{stimulus_id}--batch-actions-#{@id}" end |
#render_batch_action_button(batch_action) ⇒ Object
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'app/components/solidus_admin/ui/table/component.rb', line 98 def (batch_action) render component("ui/button").new( name: request_forgery_protection_token, value: form_authenticity_token(form_options: { action: batch_action.action, method: batch_action.method, }), formaction: batch_action.action, formmethod: batch_action.method, form: batch_actions_form_id, type: :submit, icon: batch_action.icon, text: batch_action.display_name, scheme: :secondary, ) end |
#render_data_cell(cell, data) ⇒ Object
131 132 133 134 135 136 137 |
# File 'app/components/solidus_admin/ui/table/component.rb', line 131 def render_data_cell(cell, data) cell = cell.call(data) if cell.respond_to?(:call) cell = data.public_send(cell) if cell.is_a?(Symbol) cell = cell.render_in(self) if cell.respond_to?(:render_in) content_tag(:td, content_tag(:div, cell, class: "flex items-center gap-1.5"), class: "py-2 px-4 h-10 vertical-align-middle leading-none") end |
#render_header_cell(cell, **attrs) ⇒ Object
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'app/components/solidus_admin/ui/table/component.rb', line 115 def render_header_cell(cell, **attrs) cell = cell.call if cell.respond_to?(:call) cell = @model_class.human_attribute_name(cell) if cell.is_a?(Symbol) cell = cell.render_in(self) if cell.respond_to?(:render_in) content_tag(:th, cell, class: %{ border-b border-gray-100 px-4 h-9 font-semibold vertical-align-middle leading-none }, **attrs) end |
#resource_plural_name ⇒ Object
58 59 60 |
# File 'app/components/solidus_admin/ui/table/component.rb', line 58 def resource_plural_name @model_class.model_name.human.pluralize end |
#row_class_for(row) ⇒ Object
139 140 141 142 143 144 |
# File 'app/components/solidus_admin/ui/table/component.rb', line 139 def row_class_for(row) classes = ['border-b', 'border-gray-100'] classes << ['bg-gray-15', 'text-gray-700'] if @fade_row_proc&.call(row) classes.join(' ') end |
#search_form_id ⇒ Object
94 95 96 |
# File 'app/components/solidus_admin/ui/table/component.rb', line 94 def search_form_id @search_form_id ||= "#{stimulus_id}--search-form-#{@id}" end |
#selectable_column ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'app/components/solidus_admin/ui/table/component.rb', line 62 def selectable_column @selectable_column ||= Column.new( header: -> { component("ui/forms/checkbox").new( form: batch_actions_form_id, "data-action": "#{stimulus_id}#selectAllRows", "data-#{stimulus_id}-target": "headerCheckbox", "aria-label": t('.select_all'), ) }, data: ->(data) { component("ui/forms/checkbox").new( name: "id[]", form: batch_actions_form_id, value: data.id, "data-action": "#{stimulus_id}#selectRow", "data-#{stimulus_id}-target": "checkbox", "aria-label": t('.select_row'), ) }, class_name: 'w-[52px]', ) end |
#table_frame_id ⇒ Object
90 91 92 |
# File 'app/components/solidus_admin/ui/table/component.rb', line 90 def table_frame_id @table_frame_id ||= "#{stimulus_id}--table-frame-#{@id}" end |