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
24
25
26
|
# File 'lib/administrate/base_dashboard.rb', line 24
def model
to_s.chomp(DASHBOARD_SUFFIX).classify.constantize
end
|
.resource_name(opts) ⇒ Object
28
29
30
|
# File 'lib/administrate/base_dashboard.rb', line 28
def resource_name(opts)
model.model_name.human(opts)
end
|
Instance Method Details
#all_attributes ⇒ Object
49
50
51
|
# File 'lib/administrate/base_dashboard.rb', line 49
def all_attributes
attribute_types.keys
end
|
#attribute_type_for(attribute_name) ⇒ Object
37
38
39
40
41
|
# File 'lib/administrate/base_dashboard.rb', line 37
def attribute_type_for(attribute_name)
attribute_types.fetch(attribute_name) do
fail attribute_not_found_message(attribute_name)
end
end
|
#attribute_types ⇒ Object
33
34
35
|
# File 'lib/administrate/base_dashboard.rb', line 33
def attribute_types
self.class::ATTRIBUTE_TYPES
end
|
#attribute_types_for(attribute_names) ⇒ Object
43
44
45
46
47
|
# File 'lib/administrate/base_dashboard.rb', line 43
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
91
92
93
94
95
96
97
|
# File 'lib/administrate/base_dashboard.rb', line 91
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
109
110
111
|
# File 'lib/administrate/base_dashboard.rb', line 109
def collection_includes
attribute_includes(collection_attributes)
end
|
#display_resource(resource) ⇒ Object
105
106
107
|
# File 'lib/administrate/base_dashboard.rb', line 105
def display_resource(resource)
"#{resource.class} ##{resource.id}"
end
|
53
54
55
56
57
58
59
60
61
|
# File 'lib/administrate/base_dashboard.rb', line 53
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
119
120
121
122
123
124
125
126
|
# File 'lib/administrate/base_dashboard.rb', line 119
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
113
114
115
116
117
|
# File 'lib/administrate/base_dashboard.rb', line 113
def item_includes
Administrate.warn_of_deprecated_method(self.class, :item_includes)
attribute_includes(show_page_attributes)
end
|
#permitted_attributes(action = nil) ⇒ Object
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
# File 'lib/administrate/base_dashboard.rb', line 71
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
99
100
101
102
103
|
# File 'lib/administrate/base_dashboard.rb', line 99
def search_attributes
attribute_types.keys.select do |attribute|
attribute_types[attribute].searchable?
end
end
|
#show_page_attributes ⇒ Object
87
88
89
|
# File 'lib/administrate/base_dashboard.rb', line 87
def show_page_attributes
self.class::SHOW_PAGE_ATTRIBUTES
end
|
63
64
65
66
67
68
69
|
# File 'lib/administrate/base_dashboard.rb', line 63
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
|