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
- #is_permanent? ⇒ Boolean
- #resource_path(item) ⇒ 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.
7 8 9 |
# File 'app/components/express_admin/smart_table.rb', line 7 def columns @columns end |
Instance Method Details
#actions_column(item) ⇒ Object
68 69 70 71 72 73 74 |
# File 'app/components/express_admin/smart_table.rb', line 68 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
46 47 48 |
# File 'app/components/express_admin/smart_table.rb', line 46 def actions_header th(class: 'actions') { 'Actions' } end |
#cell_value(item, accessor) ⇒ Object
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'app/components/express_admin/smart_table.rb', line 92 def cell_value(item, accessor) if accessor.respond_to?(:call) value = begin eval "(#{accessor.source}).call(item).to_s" rescue 'Error: '+$!.to_s end elsif attrib = accessor.to_s.match(/(\w+)_link$/).try(:[], 1) # TODO: only works with non-namespaced routes value = helpers.link_to item.send(attrib), resource_path(item) elsif attrib = accessor.to_s.match(/(\w+)_in_words/).try(:[], 1) value = 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 value = 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
123 124 125 |
# File 'app/components/express_admin/smart_table.rb', line 123 def columns_hidden? !specified_columns? && columns.size > MAX_COLS_TO_SHOW_IDX+1 end |
#display_columns ⇒ Object
119 120 121 |
# File 'app/components/express_admin/smart_table.rb', line 119 def display_columns specified_columns? ? columns : columns.slice(1..MAX_COLS_TO_SHOW_IDX) end |
#hidden_column_cell ⇒ Object
154 155 156 |
# File 'app/components/express_admin/smart_table.rb', line 154 def hidden_column_cell td(class: 'more-columns-indicator') end |
#hidden_columns_header_indicator ⇒ Object
148 149 150 151 152 |
# File 'app/components/express_admin/smart_table.rb', line 148 def hidden_columns_header_indicator th(class: 'more-columns-indicator') { "..." } end |
#is_permanent? ⇒ Boolean
84 85 86 |
# File 'app/components/express_admin/smart_table.rb', line 84 def is_permanent? config[:permanent].nil? || (config[:permanent].present? && config[:permanent]) end |
#resource_path(item) ⇒ Object
54 55 56 |
# File 'app/components/express_admin/smart_table.rb', line 54 def resource_path(item) helpers.send(resource_path_helper, item.to_param) end |
#row_class(item) ⇒ Object
76 77 78 79 80 81 82 |
# File 'app/components/express_admin/smart_table.rb', line 76 def row_class(item) if config[:row_class].try(:respond_to?, :call) config[:row_class].call(item) else item.eql?(helpers.resource) ? 'current' : '' end end |
#row_id(item) ⇒ Object
88 89 90 |
# File 'app/components/express_admin/smart_table.rb', line 88 def row_id(item) "#{collection_member_name}:#{item.to_param}" end |
#scroll_table ⇒ Object
40 41 42 43 44 |
# File 'app/components/express_admin/smart_table.rb', line 40 def scroll_table script { %Q($('\##{my[:id]}').scrollTableBody()) } end |
#should_show_actions? ⇒ Boolean
50 51 52 |
# File 'app/components/express_admin/smart_table.rb', line 50 def should_show_actions? config[:actions].nil? || !!config[:actions] end |
#should_show_delete?(item) ⇒ Boolean
58 59 60 61 62 63 64 65 66 |
# File 'app/components/express_admin/smart_table.rb', line 58 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
144 145 146 |
# File 'app/components/express_admin/smart_table.rb', line 144 def specified_columns config[:columns] end |
#specified_columns? ⇒ Boolean
140 141 142 |
# File 'app/components/express_admin/smart_table.rb', line 140 def specified_columns? !!specified_columns end |