Class: Alchemy::Admin::PicturesController
Constant Summary
ResourceFilter::COMMON_SEARCH_FILTER_EXCLUDES
Instance Method Summary
collapse
#description_field_name_prefix
#assign
#failed_uploader_response, #successful_uploader_response
#edit, #new, #resource_handler
#controller_path_array, #resource_array, #resource_model_name, #resource_name, #resources_name
#contains_relations?, #edit_resource_path, #new_resource_path, #render_attribute, #resource_attribute_field_options, #resource_has_tags, #resource_instance_variable, #resource_model, #resource_path, #resource_relations_names, #resource_scope, #resource_url_proxy, #resource_window_size, #resources_instance_variable, #resources_path
#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
71
72
73
74
75
76
77
78
|
# File 'app/controllers/alchemy/admin/pictures_controller.rb', line 71
def create
@picture = Picture.new(picture_params)
if @picture.save
render successful_uploader_response(file: @picture)
else
render failed_uploader_response(file: @picture)
end
end
|
#default_sort_order ⇒ Object
142
143
144
|
# File 'app/controllers/alchemy/admin/pictures_controller.rb', line 142
def default_sort_order
"created_at desc"
end
|
#delete_multiple ⇒ Object
109
110
111
112
113
114
115
116
117
|
# File 'app/controllers/alchemy/admin/pictures_controller.rb', line 109
def delete_multiple
if params[:picture_ids].present?
params[:picture_ids].each { DeletePictureJob.perform_later(_1) }
flash[:notice] = Alchemy.t(:pictures_will_be_deleted_now)
else
flash[:warn] = Alchemy.t("Could not delete Pictures")
end
redirect_to_index
end
|
#destroy ⇒ Object
119
120
121
122
123
124
125
126
127
|
# File 'app/controllers/alchemy/admin/pictures_controller.rb', line 119
def destroy
name = @picture.name
@picture.destroy
flash[:notice] = Alchemy.t("Picture deleted successfully", name: name)
rescue => e
flash[:error] = e.message
ensure
redirect_to_index
end
|
#edit_multiple ⇒ Object
80
81
82
83
|
# File 'app/controllers/alchemy/admin/pictures_controller.rb', line 80
def edit_multiple
@pictures = Picture.where(id: params[:picture_ids])
@tags = @pictures.collect(&:tag_list).flatten.uniq.join(", ")
end
|
#filtered_pictures(page: 1, per_page: items_per_page) ⇒ Object
129
130
131
132
133
134
135
136
137
138
139
140
|
# File 'app/controllers/alchemy/admin/pictures_controller.rb', line 129
def filtered_pictures(page: 1, per_page: items_per_page)
@query = Picture.ransack(search_filter_params[:q])
@query.sorts = default_sort_order if @query.sorts.empty?
pictures = @query.result
if params[:tagged_with].present?
pictures = pictures.tagged_with(params[:tagged_with])
end
pictures = pictures.page(page).per(per_page)
Alchemy.storage_adapter.preloaded_pictures(pictures)
end
|
#index ⇒ Object
40
41
42
43
44
|
# File 'app/controllers/alchemy/admin/pictures_controller.rb', line 40
def index
if in_overlay?
archive_overlay
end
end
|
#items_per_page ⇒ Object
146
147
148
149
150
151
152
153
154
155
156
157
158
159
|
# File 'app/controllers/alchemy/admin/pictures_controller.rb', line 146
def items_per_page
if in_overlay?
case @size
when "small" then 25
when "large" then 4
else
9
end
else
cookies[:alchemy_pictures_per_page] = params[:per_page] ||
cookies[:alchemy_pictures_per_page] ||
pictures_per_page_for_size
end.to_i
end
|
#items_per_page_options ⇒ Object
161
162
163
164
|
# File 'app/controllers/alchemy/admin/pictures_controller.rb', line 161
def items_per_page_options
per_page = pictures_per_page_for_size
[per_page, per_page * 2, per_page * 4]
end
|
#show ⇒ Object
46
47
48
49
50
51
52
53
54
55
56
57
58
|
# File 'app/controllers/alchemy/admin/pictures_controller.rb', line 46
def show
@pictures = filtered_pictures(page: params[:picture_index], per_page: 1)
@picture = @pictures.first
@previous = @pictures.prev_page
@next = @pictures.next_page
@assignments = @picture.related_ingredients.joins(element: :page).merge(PageVersion.draft)
@picture_description = @picture.descriptions.find_or_initialize_by(
language_id: Alchemy::Current.language.id
)
render action: "show"
end
|
#update ⇒ Object
85
86
87
88
89
90
91
92
93
94
95
96
97
98
|
# File 'app/controllers/alchemy/admin/pictures_controller.rb', line 85
def update
@message = if @picture.update(picture_params)
{
body: Alchemy.t(:picture_updated_successfully, name: @picture.name),
type: "notice"
}
else
{
body: Alchemy.t(:picture_update_failed),
type: "error"
}
end
render :update, status: (@message[:type] == "notice") ? 200 : 422
end
|
#update_multiple ⇒ Object
100
101
102
103
104
105
106
107
|
# File 'app/controllers/alchemy/admin/pictures_controller.rb', line 100
def update_multiple
@pictures = Picture.find(params[:picture_ids])
@pictures.each do |picture|
picture.update_name_and_tag_list!(params)
end
flash[:notice] = Alchemy.t("Pictures updated successfully")
redirect_to_index
end
|
#url ⇒ Object
60
61
62
63
64
65
66
67
68
69
|
# File 'app/controllers/alchemy/admin/pictures_controller.rb', line 60
def url
options = picture_url_params.to_h.symbolize_keys.transform_values! do |value|
value.in?(%w[true false]) ? value == "true" : value
end
render json: {
url: @picture.url(options),
alt: @picture.name,
title: Alchemy.t(:image_name, name: @picture.name)
}
end
|