Class: ExpressAdmin::Components::Presenters::SmartTable
- Inherits:
-
ExpressTemplates::Components::Configurable
- Object
- ExpressTemplates::Components::Configurable
- ExpressAdmin::Components::Presenters::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- MAX_ROWS_TO_SHOW_IDX =
10
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
- #collection ⇒ Object
- #columns_hidden? ⇒ Boolean
- #display_columns ⇒ Object
- #hidden_column_cell ⇒ Object
- #hidden_columns_header_indicator ⇒ Object
- #index_page ⇒ Object
- #pagination ⇒ Object
- #route_set ⇒ 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
- #specified_rows ⇒ Object
- #table_classes ⇒ Object
Instance Attribute Details
#columns ⇒ Object (readonly)
Returns the value of attribute columns.
12 13 14 |
# File 'app/components/express_admin/smart_table.rb', line 12 def columns @columns end |
Instance Method Details
#actions_column(item) ⇒ Object
130 131 132 133 134 135 136 |
# File 'app/components/express_admin/smart_table.rb', line 130 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
112 113 114 |
# File 'app/components/express_admin/smart_table.rb', line 112 def actions_header th(class: 'actions') { 'Actions' } end |
#cell_value(item, accessor) ⇒ Object
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 |
# File 'app/components/express_admin/smart_table.rb', line 150 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+)_checkmark/).try(:[], 1) "<i class='ion-checkmark-round'></i>".html_safe if item.send(attrib) elsif attrib = accessor.to_s.match(/(\w+)_in_words/).try(:[], 1) if item.send(attrib) if item.send(attrib) < DateTime.now "#{helpers.time_ago_in_words(item.send(attrib))} ago" else "in #{helpers.time_ago_in_words(item.send(attrib))}" end else 'never' end 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 |
#collection ⇒ Object
97 98 99 100 |
# File 'app/components/express_admin/smart_table.rb', line 97 def collection collections = super.kind_of?(Array) ? Kaminari.paginate_array(super) : super collections.page(index_page).per(specified_rows) end |
#columns_hidden? ⇒ Boolean
191 192 193 |
# File 'app/components/express_admin/smart_table.rb', line 191 def columns_hidden? !specified_columns? && columns.size > MAX_COLS_TO_SHOW_IDX+1 end |
#display_columns ⇒ Object
187 188 189 |
# File 'app/components/express_admin/smart_table.rb', line 187 def display_columns specified_columns? ? @columns : @columns.slice(1..MAX_COLS_TO_SHOW_IDX) end |
#hidden_column_cell ⇒ Object
218 219 220 |
# File 'app/components/express_admin/smart_table.rb', line 218 def hidden_column_cell td(class: 'more-columns-indicator') end |
#hidden_columns_header_indicator ⇒ Object
212 213 214 215 216 |
# File 'app/components/express_admin/smart_table.rb', line 212 def hidden_columns_header_indicator th(class: 'more-columns-indicator') { "..." } end |
#index_page ⇒ Object
102 103 104 |
# File 'app/components/express_admin/smart_table.rb', line 102 def index_page helpers.params[:page] || 1 # Default page is 1 end |
#pagination ⇒ Object
85 86 87 |
# File 'app/components/express_admin/smart_table.rb', line 85 def pagination paginate collection, :route_set => route_set end |
#route_set ⇒ Object
93 94 95 |
# File 'app/components/express_admin/smart_table.rb', line 93 def route_set namespace.nil? ? namespace : eval(namespace) end |
#row_class(item) ⇒ Object
138 139 140 141 142 143 144 |
# File 'app/components/express_admin/smart_table.rb', line 138 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
146 147 148 |
# File 'app/components/express_admin/smart_table.rb', line 146 def row_id(item) "#{collection_member_name}:#{item.to_param}" end |
#scroll_table ⇒ Object
106 107 108 109 110 |
# File 'app/components/express_admin/smart_table.rb', line 106 def scroll_table script { %Q($('\##{config[:id]}').scrollTableBody()) } end |
#should_show_actions? ⇒ Boolean
116 117 118 |
# File 'app/components/express_admin/smart_table.rb', line 116 def should_show_actions? !!config[:show_actions] end |
#should_show_delete?(item) ⇒ Boolean
120 121 122 123 124 125 126 127 128 |
# File 'app/components/express_admin/smart_table.rb', line 120 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
208 209 210 |
# File 'app/components/express_admin/smart_table.rb', line 208 def specified_columns config[:columns] end |
#specified_columns? ⇒ Boolean
204 205 206 |
# File 'app/components/express_admin/smart_table.rb', line 204 def specified_columns? !!specified_columns end |
#specified_rows ⇒ Object
222 223 224 |
# File 'app/components/express_admin/smart_table.rb', line 222 def specified_rows config[:rows] || MAX_ROWS_TO_SHOW_IDX end |
#table_classes ⇒ Object
89 90 91 |
# File 'app/components/express_admin/smart_table.rb', line 89 def table_classes 'table striped' end |