Class: ActiveAdmin::Views::IndexAsDynamicTable::IndexDynamicTableFor
- Inherits:
-
IndexTableFor
- Object
- IndexTableFor
- ActiveAdmin::Views::IndexAsDynamicTable::IndexDynamicTableFor
- Defined in:
- lib/activeadmin_dynamic_table/views/index_as_dynamic_table.rb
Instance Method Summary collapse
- #build(configurator, *args, &block) ⇒ Object
- #build_table_header(col) ⇒ Object
-
#id_column(*args) ⇒ Object
Display a column for the id.
- #index_column(*args) ⇒ Object
- #options_for_col(col, sort_key) ⇒ Object
-
#selectable_column ⇒ Object
Display a column for checkbox.
Instance Method Details
#build(configurator, *args, &block) ⇒ Object
6 7 8 9 |
# File 'lib/activeadmin_dynamic_table/views/index_as_dynamic_table.rb', line 6 def build(configurator, *args, &block) @configurator = configurator super(*args, &block) end |
#build_table_header(col) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/activeadmin_dynamic_table/views/index_as_dynamic_table.rb', line 11 def build_table_header(col) sort_key = sortable? && col.sortable? && col.sort_key params = request.query_parameters.except :page, :order, :commit, :format = (col, sort_key) if sort_key th do span do link_to col.pretty_title, params: params, order: "#{sort_key}_#{order_for_sort_key(sort_key)}" end end else th do span col.pretty_title end end end |
#id_column(*args) ⇒ Object
Display a column for the id
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/activeadmin_dynamic_table/views/index_as_dynamic_table.rb', line 63 def id_column(*args) raise "#{resource_class.name} has no primary_key!" unless resource_class.primary_key data = args[1] || args[0] = { sortable: resource_class.primary_key, 'data-column-key': data[:key], **data, } column(resource_class.human_attribute_name(resource_class.primary_key), ) do |resource| if controller.action_methods.include?("show") link_to resource.id, resource_path(resource), class: "resource_id_link" elsif controller.action_methods.include?("edit") link_to resource.id, edit_resource_path(resource), class: "resource_id_link" else resource.id end end end |
#index_column(*args) ⇒ Object
84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/activeadmin_dynamic_table/views/index_as_dynamic_table.rb', line 84 def index_column(*args) data = args[1] || args[0] start_value = data.delete(:start_value) || 1 = { class: "col-index", sortable: false, **data, } column "#", do |resource| @collection.offset_value + @collection.index(resource) + start_value end end |
#options_for_col(col, sort_key) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/activeadmin_dynamic_table/views/index_as_dynamic_table.rb', line 29 def (col, sort_key) classes = Arbre::HTML::ClassList.new classes << "sortable" if sort_key classes << "sorted-#{current_sort[1]}" if sort_key && current_sort[0] == sort_key classes << "reorder" classes << col.html_class = col.instance_variable_get(:@options) style = [:style] || '' style = "width: #{@configurator.width_for([:key])}px" if [:key].present? { class: classes, style: style, 'data-column-key': [:key], } end |
#selectable_column ⇒ Object
Display a column for checkbox
48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/activeadmin_dynamic_table/views/index_as_dynamic_table.rb', line 48 def selectable_column return unless active_admin_config.batch_actions.any? = { style: "width: 30px", class: "col-selectable", sortable: false, } column resource_selection_toggle_cell, do |resource| resource_selection_cell resource end end |