<% exceptions ||= ['created_at', 'updated_at', 'deleted_at'] %> <% excluded_columns ||= [] %> <% additional_columns ||= [] %> <% additional_actions ||= [] %> <% hide_actions ||= false %> <% sort_fields ||= [] %> <% sort_all ||= false %> <% table_class ||= 'datatables styletable' %> <% box_class ||= 'primary' %> <% card_class ||= 'primary' %> <% show_columns ||= [] %> <% hide_read_action ||= false %> <% hide_edit_action ||= false %> <% hide_destroy_action ||= false %> <% if show_columns.empty? %> <% show_columns = list.klass.column_names - exceptions - excluded_columns + additional_columns %> <% end %> <% show_columns.each do |column| %> <% column_method = nil %> <% column_name = column %> <% column_align = ''%> <% if column.class == Hash %> <% column_name = column[:attribute] %> <% column_method = column[:method] %> <% column_align = column[:align] %> <% column_title = column[:title] %> <% end %> <% next if /_currency$/ =~ column_name %> <% end %> <% unless hide_actions %> <% end %> <% list.each do |object| %> <% show_columns.each do |column| %> <% column_method = nil %> <% column_name = column %> <% if column.class == Hash %> <% column_name = column[:attribute] %> <% column_method = column[:method] %> <% column_format = column[:format] %> <% end %> <% next if /_currency$/ =~ column_name %> <% end %> <% unless hide_actions %> <% end %> <% end %>
<% if sort_all || sort_fields.include?(column_name) %> <% if column_name.include?('.') %> <% mname = column_name.split('.')[-2]&.camelize %> <% cname = column_name.split('.')[-1] %> <% model = Kernel.const_get(mname) %> <%= sort_link(@q, column_name.split('.').join('_'), column_title || "#{model.model_name.human} (#{model.human_attribute_name(cname)})") %> <% elsif /_id$/ =~ column_name %> <%= sort_link(@q, column_name, column_title || list.klass.human_attribute_name(column_name.split("_id")[0])) %> <% elsif /_cents$/ =~ column_name %> <%= sort_link(@q, column_name, column_title || list.klass.human_attribute_name(column_name.split("_cents")[0])) %> <% elsif /_currency$/ =~ column_name %> <% elsif column_name == 'id' %> <%= sort_link(@q, column_name, column_title || '#') %> <% else %> <%= sort_link(@q, column_name, column_title || list.klass.human_attribute_name(column_name)) %> <% end %> <% else %> <% if column_name.include?('.') %> <% s_name = column_title || column_method || column_name %> <%= "#{s_name.split('.')[-2]&.camelize} (#{s_name.split('.')[-1]})" %> <% elsif /_id$/ =~ column_name %> <%= column_title || list.klass.human_attribute_name(column_name.split("_id")[0]) %> <% elsif /_cents$/ =~ column_name %> <%= column_title || list.klass.human_attribute_name(column_name.split("_cents")[0]) %> <% elsif /_currency$/ =~ column_name %> <% elsif column_name == 'id' %> <%= column_title || "#" %> <% else %> <%= column_title || list.klass.human_attribute_name(column_name) %> <% end %> <% end %> Ações
<% if column_name.include?('.') %> <% if column_method.nil? %> <% o = object %> <% column_name.split('.').each{|m| o = o.send(m) if o } %> <%= o %> <% else %> <%= object.send(column_method) %> <% end %> <% elsif object.send(column_name).class == Date or object.send(column_name).class == DateTime or object.send(column_name).class == ActiveSupport::TimeWithZone or object.send(column_name).class == Time %> <% if column_format %> <%= l(object.send(column_name), format: (column_format.is_a?(Symbol) ? column_format : column_format.to_sym)) %> <% else %> <%=l object.send(column_name) %> <% end %> <% elsif object.send(column_name).respond_to? 'attached?' %> <% if object.send(column_name).class == ActiveStorage::Attached::One %> <% if object.send(column_name).attached? %> <%= link_to rails_blob_path(object.send(column_name)), class: "btn btn-#{box_class} #{card_class} btn-xs", target: '_blank' do %> Arquivo <% end %> <% end %> <% end %> <% elsif /_id$/ =~ column_name && object.respond_to?(column_name.split('_id')[0]) %> <%= object.send(column_name.split("_id")[0])&.name %> <% elsif /_cents$/ =~ column_name %> <%= number_to_currency object.send(column_name.split("_cents")[0]) %> <% elsif /_currency$/ =~ column_name %> <% elsif column_name.include?(".") %> <%= eval("object.#{column_name}") %> <% elsif column_name == 'id' %> <%= link_to object.id, object %> <% else %> <%= object.send(column_method || column_name) %> <% end %> <%= render 'shared/action_links', object: object, additional_actions: additional_actions, hide_read_action: hide_read_action, hide_edit_action: hide_edit_action, hide_destroy_action: hide_destroy_action %>