Class: ExpressAdmin::SmartTable
- Inherits:
-
ExpressTemplates::Components::Base
- Object
- ExpressTemplates::Components::Base
- ExpressAdmin::SmartTable
- Includes:
- ExpressTemplates::Components::Capabilities::Configurable, ExpressTemplates::Components::Capabilities::Resourceful
- Defined in:
- app/components/express_admin/smart_table.rb
Defined Under Namespace
Classes: Column
Constant Summary collapse
- MAX_COLS_TO_SHOW_IDX =
5
Instance Attribute Summary collapse
-
#columns ⇒ Object
readonly
Returns the value of attribute columns.
Instance Method Summary collapse
- #actions_column ⇒ Object
- #actions_header ⇒ Object
- #cell_value(accessor) ⇒ Object
- #columns_hidden? ⇒ Boolean
- #display_columns ⇒ Object
- #hidden_column_cell ⇒ Object
- #hidden_columns_header_indicator ⇒ Object
- #is_permanent? ⇒ Boolean
- #row_args ⇒ Object
- #row_class ⇒ Object
- #row_id ⇒ Object
- #scroll_table ⇒ Object
- #should_show_actions? ⇒ Boolean
- #specified_columns ⇒ Object
- #specified_columns? ⇒ Boolean
Instance Attribute Details
#columns ⇒ Object (readonly)
Returns the value of attribute columns.
8 9 10 |
# File 'app/components/express_admin/smart_table.rb', line 8 def columns @columns end |
Instance Method Details
#actions_column ⇒ Object
55 56 57 58 59 |
# File 'app/components/express_admin/smart_table.rb', line 55 def actions_column td { link_to 'Delete', "{{#{resource_path}}}", method: :delete, data: {confirm: 'Are you sure?'}, class: 'button small secondary' } end |
#actions_header ⇒ Object
47 48 49 |
# File 'app/components/express_admin/smart_table.rb', line 47 def actions_header th.actions { 'Actions' } end |
#cell_value(accessor) ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'app/components/express_admin/smart_table.rb', line 79 def cell_value(accessor) if accessor.respond_to?(:call) value = "(begin #{accessor.source}.call(#{collection_member_name}).to_s rescue 'Error: '+$!.to_s ; end)" elsif attrib = accessor.to_s.match(/(\w+)_link$/).try(:[], 1) value = "(link_to #{collection_member_name}.#{attrib}, #{collection_member_name}_path(#{collection_member_name}.id))" elsif attrib = accessor.to_s.match(/(\w+)_in_words/).try(:[], 1) value = "(#{collection_member_name}.#{attrib} ? time_ago_in_words(#{collection_member_name}.#{attrib})+' ago' : 'never')" else if relation_name = accessor.to_s.match(/(.*)_id$/).try(:[], 1) reflection = resource_class.reflect_on_association(relation_name.to_sym) end value = if reflection relation = "#{collection_member_name}.#{relation_name}" "#{relation}.try(:name) || #{relation}.to_s" else "#{collection_member_name}.#{accessor}" end end span { "{{#{value}}}" } end |
#columns_hidden? ⇒ Boolean
107 108 109 |
# File 'app/components/express_admin/smart_table.rb', line 107 def columns_hidden? !specified_columns? && columns.size > MAX_COLS_TO_SHOW_IDX+1 end |
#display_columns ⇒ Object
103 104 105 |
# File 'app/components/express_admin/smart_table.rb', line 103 def display_columns specified_columns? ? columns : columns.slice(1..MAX_COLS_TO_SHOW_IDX) end |
#hidden_column_cell ⇒ Object
138 139 140 |
# File 'app/components/express_admin/smart_table.rb', line 138 def hidden_column_cell td._more_columns_indicator end |
#hidden_columns_header_indicator ⇒ Object
132 133 134 135 136 |
# File 'app/components/express_admin/smart_table.rb', line 132 def hidden_columns_header_indicator th._more_columns_indicator { "..." } end |
#is_permanent? ⇒ Boolean
67 68 69 |
# File 'app/components/express_admin/smart_table.rb', line 67 def is_permanent? @config[:permanent].nil? || (@config[:permanent].present? && @config[:permanent]) end |
#row_args ⇒ Object
75 76 77 |
# File 'app/components/express_admin/smart_table.rb', line 75 def row_args {id: row_id, class: row_class} end |
#row_class ⇒ Object
61 62 63 64 65 |
# File 'app/components/express_admin/smart_table.rb', line 61 def row_class @config[:row_class].try(:respond_to?, :call) ? "{{#{@config[:row_class].source}.call(#{collection_member_name})}}" : "{{#{collection_member_name}.eql?(@#{resource_name}) ? 'current' : ''}}" end |
#row_id ⇒ Object
71 72 73 |
# File 'app/components/express_admin/smart_table.rb', line 71 def row_id "#{collection_member_name}:{{#{collection_member_name}.id}}" end |
#scroll_table ⇒ Object
41 42 43 44 45 |
# File 'app/components/express_admin/smart_table.rb', line 41 def scroll_table script { %Q($('\##{my[:id]}').scrollTableBody()) } end |
#should_show_actions? ⇒ Boolean
51 52 53 |
# File 'app/components/express_admin/smart_table.rb', line 51 def should_show_actions? @config[:actions].nil? || !!@config[:actions] end |
#specified_columns ⇒ Object
128 129 130 |
# File 'app/components/express_admin/smart_table.rb', line 128 def specified_columns @config[:columns] end |
#specified_columns? ⇒ Boolean
124 125 126 |
# File 'app/components/express_admin/smart_table.rb', line 124 def specified_columns? !!specified_columns end |