app/datatables/olivander/datatable.rb in five-two-nw-olivander-0.1.2.10 vs app/datatables/olivander/datatable.rb in five-two-nw-olivander-0.1.2.11

- old
+ new

@@ -13,25 +13,34 @@ end link_to r.send(field), send(path, args) end end - def self.auto_datatable(klazz, link_path: nil, only: []) + def self.auto_datatable(klazz, link_path: nil, only: [], except: [], hide: [], show: []) + Rails.logger.debug "initializing datatable for #{klazz}" + + attributes = klazz.new.attributes.select{ |x| x[0] } + attributes &&= only if only.size.positive? + attributes -= except if except.size.positive? + + default_hidden = %w[id created updated created_at updated_at deleted_at current_user current_action] + collection do klazz.all end datatable do + puts 'and also too' bulk_actions_col - klazz.new.attributes.each do |att| - key = att[0] - next if only.size.positive? && !only.include?(key) + attributes.each do |key| + puts "handling key: #{key}" + sym = key.gsub('_id', '').to_sym - visible = !['created', 'updated', 'created_at', 'updated_at', 'deleted_at', 'current_user', 'current_action'].include?(key) + visible = show.include?(key) || !(default_hidden.include?(key) || hide.include?(key)) if link_path.present? && sym == :id link_col sym, link_path, :id elsif link_path.present? && sym == :name - link_col sym, link_path, [:id, :name] + link_col sym, link_path, %i[id name] else col sym, visible: visible end end actions_col