Class: Alchemy::Admin::ResourcesController
Constant Summary
collapse
- COMMON_SEARCH_FILTER_EXCLUDES =
[:id, :utf8, :_method, :_, :format].freeze
Instance Method Summary
collapse
#contains_relations?, #edit_resource_path, #new_resource_path, #render_attribute, #render_resources, #resource_attribute_field_options, #resource_has_tags, #resource_instance_variable, #resource_model, #resource_name, #resource_path, #resource_relations_names, #resource_scope, #resource_url_proxy, #resource_window_size, #resources_instance_variable, #resources_path, #sortable_resource_header_column
#leave
Methods included from Modules
included, #module_definition_for, register_module
#current_ability
#configuration, #multi_language?, #multi_site?, #prefix_locale?
Instance Method Details
#create ⇒ Object
63
64
65
66
67
68
69
70
71
|
# File 'app/controllers/alchemy/admin/resources_controller.rb', line 63
def create
instance_variable_set("@#{resource_handler.resource_name}", resource_handler.model.new(resource_params))
resource_instance_variable.save
render_errors_or_redirect(
resource_instance_variable,
resources_path(resource_instance_variable.class, search_filter_params),
flash_notice_for_resource_action,
)
end
|
#destroy ⇒ Object
82
83
84
85
86
87
88
89
|
# File 'app/controllers/alchemy/admin/resources_controller.rb', line 82
def destroy
resource_instance_variable.destroy
if resource_instance_variable.errors.any?
flash[:error] = resource_instance_variable.errors.full_messages.join(", ")
end
flash_notice_for_resource_action
do_redirect_to resource_url_proxy.url_for(search_filter_params.merge(action: "index"))
end
|
#edit ⇒ Object
61
|
# File 'app/controllers/alchemy/admin/resources_controller.rb', line 61
def edit; end
|
#index ⇒ Object
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
# File 'app/controllers/alchemy/admin/resources_controller.rb', line 25
def index
@query = resource_handler.model.ransack(search_filter_params[:q])
@query.sorts = default_sort_order if @query.sorts.empty?
items = @query.result
if contains_relations?
items = items.includes(*resource_relations_names)
end
if search_filter_params[:tagged_with].present?
items = items.tagged_with(search_filter_params[:tagged_with])
end
if search_filter_params[:filter].present?
items = apply_filters(items)
end
respond_to do |format|
format.html {
items = items.page(params[:page] || 1).per(items_per_page)
instance_variable_set("@#{resource_handler.resources_name}", items)
}
format.csv {
instance_variable_set("@#{resource_handler.resources_name}", items)
}
end
end
|
#new ⇒ Object
53
54
55
|
# File 'app/controllers/alchemy/admin/resources_controller.rb', line 53
def new
instance_variable_set("@#{resource_handler.resource_name}", resource_handler.model.new)
end
|
#resource_filters ⇒ Object
103
104
105
106
107
|
# File 'app/controllers/alchemy/admin/resources_controller.rb', line 103
def resource_filters
return unless resource_has_filters
@_resource_filters ||= deprecated_resource_filters || resource_model.alchemy_resource_filters
end
|
#resource_filters_for_select ⇒ Object
109
110
111
112
113
|
# File 'app/controllers/alchemy/admin/resources_controller.rb', line 109
def resource_filters_for_select
resource_filters.map do |filter|
ResourceFilter.new(filter, resource_handler.resource_name)
end
end
|
#resource_handler ⇒ Object
91
92
93
|
# File 'app/controllers/alchemy/admin/resources_controller.rb', line 91
def resource_handler
@_resource_handler ||= Alchemy::Resource.new(controller_path, alchemy_module)
end
|
#resource_has_deprecated_filters ⇒ Object
99
100
101
|
# File 'app/controllers/alchemy/admin/resources_controller.rb', line 99
def resource_has_deprecated_filters
resource_model.alchemy_resource_filters.any? { |f| !f.is_a?(Hash) }
end
|
#resource_has_filters ⇒ Object
95
96
97
|
# File 'app/controllers/alchemy/admin/resources_controller.rb', line 95
def resource_has_filters
resource_model.respond_to?(:alchemy_resource_filters)
end
|
#show ⇒ Object
57
58
59
|
# File 'app/controllers/alchemy/admin/resources_controller.rb', line 57
def show
render action: "edit"
end
|
#update ⇒ Object
73
74
75
76
77
78
79
80
|
# File 'app/controllers/alchemy/admin/resources_controller.rb', line 73
def update
resource_instance_variable.update(resource_params)
render_errors_or_redirect(
resource_instance_variable,
resources_path(resource_instance_variable.class, search_filter_params),
flash_notice_for_resource_action,
)
end
|