Class: Administrate::BaseDashboard
- Inherits:
-
Object
- Object
- Administrate::BaseDashboard
show all
- Includes:
- Administrate
- Defined in:
- lib/administrate/base_dashboard.rb
Constant Summary
collapse
- DASHBOARD_SUFFIX =
"Dashboard".freeze
VERSION
Class Method Summary
collapse
Instance Method Summary
collapse
deprecator, warn_of_deprecated_authorization_method, warn_of_deprecated_method, warn_of_deprecated_option, warn_of_missing_resource_class
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_not_found_message(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
|
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
120
121
122
123
124
125
126
127
|
# File 'lib/administrate/base_dashboard.rb', line 120
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
|
#item_includes ⇒ Object
114
115
116
117
118
|
# File 'lib/administrate/base_dashboard.rb', line 114
def item_includes
Administrate.warn_of_deprecated_method(self.class, :item_includes)
attribute_includes(show_page_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
|
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
|