Class: ExpressAdmin::SmartTable
- Inherits:
-
ExpressTemplates::Components::Configurable
- Object
- ExpressTemplates::Components::Configurable
- ExpressAdmin::SmartTable
- Includes:
- 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(item) ⇒ Object
- #actions_header ⇒ Object
- #cell_value(item, accessor) ⇒ Object
- #columns_hidden? ⇒ Boolean
- #display_columns ⇒ Object
- #hidden_column_cell ⇒ Object
- #hidden_columns_header_indicator ⇒ Object
- #row_class(item) ⇒ Object
- #row_id(item) ⇒ Object
- #scroll_table ⇒ Object
- #should_show_actions? ⇒ Boolean
- #should_show_delete?(item) ⇒ Boolean
- #specified_columns ⇒ Object
- #specified_columns? ⇒ Boolean
Instance Attribute Details
#columns ⇒ Object (readonly)
Returns the value of attribute columns.
9 10 11 |
# File 'app/components/express_admin/smart_table.rb', line 9 def columns @columns end |
Instance Method Details
#actions_column(item) ⇒ Object
95 96 97 98 99 100 101 |
# File 'app/components/express_admin/smart_table.rb', line 95 def actions_column(item) td { if should_show_delete?(item) link_to 'Delete', resource_path(item), method: :delete, data: {confirm: 'Are you sure?'}, class: 'button small secondary' end } end |
#actions_header ⇒ Object
77 78 79 |
# File 'app/components/express_admin/smart_table.rb', line 77 def actions_header th(class: 'actions') { 'Actions' } end |
#cell_value(item, accessor) ⇒ Object
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
# File 'app/components/express_admin/smart_table.rb', line 115 def cell_value(item, accessor) value = if accessor.respond_to?(:call) begin accessor.call(item).try(:html_safe) rescue 'Error: '+$!.to_s end elsif attrib = accessor.to_s.match(/(\w+)_link$/).try(:[], 1) # TODO: only works with non-namespaced routes helpers.link_to item.send(attrib), resource_path(item) elsif attrib = accessor.to_s.match(/(\w+)_in_words/).try(:[], 1) item.send(attrib) ? (helpers.time_ago_in_words(item.send(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 if reflection relation = item.send(relation_name) relation.try(:name) || relation.to_s else item.send(accessor) end end current_arbre_element.add_child value end |
#columns_hidden? ⇒ Boolean
146 147 148 |
# File 'app/components/express_admin/smart_table.rb', line 146 def columns_hidden? !specified_columns? && columns.size > MAX_COLS_TO_SHOW_IDX+1 end |
#display_columns ⇒ Object
142 143 144 |
# File 'app/components/express_admin/smart_table.rb', line 142 def display_columns specified_columns? ? @columns : @columns.slice(1..MAX_COLS_TO_SHOW_IDX) end |
#hidden_column_cell ⇒ Object
173 174 175 |
# File 'app/components/express_admin/smart_table.rb', line 173 def hidden_column_cell td(class: 'more-columns-indicator') end |
#hidden_columns_header_indicator ⇒ Object
167 168 169 170 171 |
# File 'app/components/express_admin/smart_table.rb', line 167 def hidden_columns_header_indicator th(class: 'more-columns-indicator') { "..." } end |
#row_class(item) ⇒ Object
103 104 105 106 107 108 109 |
# File 'app/components/express_admin/smart_table.rb', line 103 def row_class(item) if config[:row_class].try(:respond_to?, :call) config[:row_class].call(item) else item.eql?(resource) ? 'current' : '' end end |
#row_id(item) ⇒ Object
111 112 113 |
# File 'app/components/express_admin/smart_table.rb', line 111 def row_id(item) "#{collection_member_name}:#{item.to_param}" end |
#scroll_table ⇒ Object
71 72 73 74 75 |
# File 'app/components/express_admin/smart_table.rb', line 71 def scroll_table script { %Q($('\##{config[:id]}').scrollTableBody()) } end |
#should_show_actions? ⇒ Boolean
81 82 83 |
# File 'app/components/express_admin/smart_table.rb', line 81 def should_show_actions? !!config[:show_actions] end |
#should_show_delete?(item) ⇒ Boolean
85 86 87 88 89 90 91 92 93 |
# File 'app/components/express_admin/smart_table.rb', line 85 def should_show_delete?(item) if item.respond_to?(:can_delete?) && item.can_delete? true elsif !item.respond_to?(:can_delete?) true else false end end |
#specified_columns ⇒ Object
163 164 165 |
# File 'app/components/express_admin/smart_table.rb', line 163 def specified_columns config[:columns] end |
#specified_columns? ⇒ Boolean
159 160 161 |
# File 'app/components/express_admin/smart_table.rb', line 159 def specified_columns? !!specified_columns end |