Class: Administrate::BaseDashboard
- Inherits:
-
Object
- Object
- Administrate::BaseDashboard
- Includes:
- Administrate
- Defined in:
- lib/administrate/base_dashboard.rb
Constant Summary collapse
- DASHBOARD_SUFFIX =
"Dashboard".freeze
Constants included from Administrate
Class Method Summary collapse
Instance Method Summary collapse
- #all_attributes ⇒ Object
- #attribute_type_for(attribute_name) ⇒ Object
- #attribute_types ⇒ Object
- #attribute_types_for(attribute_names) ⇒ Object
- #collection_attributes ⇒ Object
- #collection_includes ⇒ Object
- #display_resource(resource) ⇒ Object
- #form_attributes(action = nil) ⇒ Object
- #item_associations ⇒ Object
- #permitted_attributes(action = nil) ⇒ Object
- #search_attributes ⇒ Object
- #show_page_attributes ⇒ Object
- #specific_form_attributes_for(action) ⇒ Object
Methods included from Administrate
Class Method Details
.model ⇒ Object
25 26 27 |
# File 'lib/administrate/base_dashboard.rb', line 25 def model to_s.chomp(DASHBOARD_SUFFIX).classify.constantize end |
.resource_name(opts) ⇒ Object
29 30 31 |
# File 'lib/administrate/base_dashboard.rb', line 29 def resource_name(opts) model.model_name.human(opts) end |
Instance Method Details
#all_attributes ⇒ Object
50 51 52 |
# File 'lib/administrate/base_dashboard.rb', line 50 def all_attributes attribute_types.keys end |
#attribute_type_for(attribute_name) ⇒ Object
38 39 40 41 42 |
# File 'lib/administrate/base_dashboard.rb', line 38 def attribute_type_for(attribute_name) attribute_types.fetch(attribute_name) do fail (attribute_name) end end |
#attribute_types ⇒ Object
34 35 36 |
# File 'lib/administrate/base_dashboard.rb', line 34 def attribute_types self.class::ATTRIBUTE_TYPES end |
#attribute_types_for(attribute_names) ⇒ Object
44 45 46 47 48 |
# File 'lib/administrate/base_dashboard.rb', line 44 def attribute_types_for(attribute_names) attribute_names.each_with_object({}) do |name, attributes| attributes[name] = attribute_type_for(name) end end |
#collection_attributes ⇒ Object
92 93 94 95 96 97 98 |
# File 'lib/administrate/base_dashboard.rb', line 92 def collection_attributes if self.class::COLLECTION_ATTRIBUTES.is_a?(Hash) self.class::COLLECTION_ATTRIBUTES.values.flatten else self.class::COLLECTION_ATTRIBUTES end end |
#collection_includes ⇒ Object
110 111 112 |
# File 'lib/administrate/base_dashboard.rb', line 110 def collection_includes attribute_includes(collection_attributes) end |
#display_resource(resource) ⇒ Object
106 107 108 |
# File 'lib/administrate/base_dashboard.rb', line 106 def display_resource(resource) "#{resource.class} ##{resource.id}" end |
#form_attributes(action = nil) ⇒ Object
54 55 56 57 58 59 60 61 62 |
# File 'lib/administrate/base_dashboard.rb', line 54 def form_attributes(action = nil) action = case action when "update" then "edit" when "create" then "new" else action end specific_form_attributes_for(action) || self.class::FORM_ATTRIBUTES end |
#item_associations ⇒ Object
114 115 116 117 118 119 120 121 |
# File 'lib/administrate/base_dashboard.rb', line 114 def item_associations attributes = if show_page_attributes.is_a?(Hash) show_page_attributes.values.flatten else show_page_attributes end attribute_associated attributes end |
#permitted_attributes(action = nil) ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/administrate/base_dashboard.rb', line 72 def permitted_attributes(action = nil) attributes = form_attributes action if attributes.is_a? Hash attributes = attributes.values.flatten end attributes.map do |attr| attribute_types[attr].permitted_attribute( attr, resource_class: self.class.model, action: action ) end.uniq end |
#search_attributes ⇒ Object
100 101 102 103 104 |
# File 'lib/administrate/base_dashboard.rb', line 100 def search_attributes attribute_types.keys.select do |attribute| attribute_types[attribute].searchable? end end |
#show_page_attributes ⇒ Object
88 89 90 |
# File 'lib/administrate/base_dashboard.rb', line 88 def show_page_attributes self.class::SHOW_PAGE_ATTRIBUTES end |
#specific_form_attributes_for(action) ⇒ Object
64 65 66 67 68 69 70 |
# File 'lib/administrate/base_dashboard.rb', line 64 def specific_form_attributes_for(action) return unless action cname = "FORM_ATTRIBUTES_#{action.upcase}" self.class.const_get(cname) if self.class.const_defined?(cname) end |