Module: Para::Admin::BaseHelper
Instance Method Summary
collapse
#export_name_for
#display_admin_flash
Methods included from TreeHelper
#actions, #delete_button, #edit_button, #max_depth_for, #needs_placeholder?
Methods included from TagHelper
#add_button_for, #icon_link_to, #listing_for, #table_for
#alert, #panel, #resources_table
Methods included from FormHelper
#para_form_for
#component_section_active?
#reorder_anchor
#attribute_field_mappings_for, #excerpt_value_for, #field_value_for, #model_field_mappings, #relation_klass_for
#filtered?, #fulltext_search_param_for, #searchable_attributes
Instance Method Details
#find_partial_for(relation, partial, partial_dir: 'admin/resources') ⇒ Object
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
# File 'app/helpers/para/admin/base_helper.rb', line 6
def find_partial_for(relation, partial, partial_dir: 'admin/resources')
relation_class = if relation.kind_of?(ActiveRecord::Base)
relation = relation.class
elsif model?(relation)
relation
end
relation_name = find_relation_name_for(
'admin', plural_file_path_for(relation), partial,
relation_class: relation_class
)
if relation_name
"admin/#{ relation_name }/#{ partial }"
else
"para/#{ partial_dir }/#{ partial }"
end
end
|
#find_relation_name_for(namespace, relation, partial, options = {}) ⇒ Object
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
# File 'app/helpers/para/admin/base_helper.rb', line 25
def find_relation_name_for(namespace, relation, partial, options = {})
return relation if partial_exists?(relation, partial)
return nil unless options[:relation_class]
relation = options[:relation_class].ancestors.find do |ancestor|
next unless model?(ancestor)
break if ancestor == ActiveRecord::Base
ancestor_name = plural_file_path_for(ancestor.name)
partial_exists?(ancestor_name, partial)
end
plural_file_path_for(relation) if relation
end
|
#flash_message(type, resource = nil) ⇒ Object
65
66
67
68
69
70
71
72
73
74
75
|
# File 'app/helpers/para/admin/base_helper.rb', line 65
def flash_message(type, resource = nil)
key = "#{ flash_shared_key }.#{ params[:action] }.#{ type }"
translation = if resource
::I18n.t(key, model: resource.class.model_name.human)
else
::I18n.t(key)
end
flash[type] = translation
end
|
#flash_shared_key ⇒ Object
77
78
79
|
# File 'app/helpers/para/admin/base_helper.rb', line 77
def flash_shared_key
'para.flash.shared'
end
|
#registered_components_options ⇒ Object
56
57
58
59
60
61
62
63
|
# File 'app/helpers/para/admin/base_helper.rb', line 56
def registered_components_options
Para::Component.registered_components.keys.map do |identifier|
[
t("para.component.#{ identifier }.name", default: identifier.to_s.humanize),
identifier
]
end
end
|
#resource_title_for(resource) ⇒ Object
46
47
48
49
50
51
52
53
54
|
# File 'app/helpers/para/admin/base_helper.rb', line 46
def resource_title_for(resource)
if resource.new_record?
t('para.form.shared.new.title', model: resource.class.model_name.human)
else
resource.try(:title).presence ||
resource.try(:name).presence ||
t('para.form.shared.edit.title', model: resource.class.model_name.human)
end
end
|
#template_path_lookup(*paths) ⇒ Object
40
41
42
43
44
|
# File 'app/helpers/para/admin/base_helper.rb', line 40
def template_path_lookup(*paths)
paths.find do |path|
lookup_context.find_all(path).any?
end
end
|