Class: Admin::AssetsController
- Inherits:
-
ResourceController
- Object
- ActionController::Base
- ApplicationController
- ResourceController
- Admin::AssetsController
- Defined in:
- app/controllers/admin/assets_controller.rb
Constant Summary collapse
- COMPRESS_FILE_TYPE =
['image/jpeg', 'image/png', 'image/gif', 'image/svg+xml'].freeze
- APPROVED_CONTENT_TYPES =
Asset::APPROVED_CONTENT_TYPES
Instance Attribute Summary
Attributes inherited from ApplicationController
#cache, #pagination_parameters, #trusty_config
Instance Method Summary collapse
Methods inherited from ResourceController
#destroy, model_class, paginate_models, #paginated?, #pagination_parameters, #will_paginate_options
Methods included from TrustyCms::ResourceResponses
Methods inherited from ApplicationController
#after_sign_in_path_for, #initialize, #template_name
Methods included from LoginSystem
Constructor Details
This class inherits a constructor from ApplicationController
Instance Method Details
#create ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'app/controllers/admin/assets_controller.rb', line 50 def create @assets = [] @page_attachments = [] uploads = Array(asset_params.dig('asset', 'asset')).reject(&:blank?) uploads.each do |uploaded_asset| result = process_uploaded_asset(uploaded_asset) if result[:asset] @asset = result[:asset] if params[:for_attachment] @page = Page.find_by_id(params[:page_id]) || Page.new @page_attachments << (@page_attachment = @asset..build(page: @page)) end @assets << @asset else flash[result.fetch(:flash_type, :error)] = result[:error] end end if asset_params[:for_attachment] render partial: 'admin/page_attachments/attachment', collection: @page_attachments else response_for :create end end |
#index ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'app/controllers/admin/assets_controller.rb', line 6 def index assets = Asset.order('created_at DESC') @page = Page.find(params[:page_id]) if params[:page_id] @term = assets.ransack(params[:search] || '') assets = @term.result(distinct: true) @types = params[:filter] ? params[:filter].split(',') : [] if @types.include?('all') params[:filter] = nil elsif @types.any? assets = assets.of_types(@types) end @assets = paginated? ? assets.paginate(pagination_parameters) : assets.all respond_to do |format| format.js do @page = Page.find_by_id(params[:page_id]) render partial: 'asset_table', locals: { with_pagination: true } end format.html do render end end end |
#refresh ⇒ Object
77 78 79 80 81 82 83 84 85 86 |
# File 'app/controllers/admin/assets_controller.rb', line 77 def refresh if asset_params[:id] @asset = Asset.find(params[:id]) @asset.asset.reprocess! flash[:notice] = t('clipped_extension.thumbnails_refreshed') redirect_to edit_admin_asset_path(@asset) else render end end |
#uploader ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'app/controllers/admin/assets_controller.rb', line 32 def uploader @page_attachments = [] result = process_uploaded_asset(asset_params[:upload]) if result[:asset] @asset = result[:asset] if params[:for_attachment] @page = Page.find_by_id(params[:page_id]) || Page.new @page_attachments << (@page_attachment = @asset..build(page: @page)) end render json: { url: @asset.asset.url } else flash[result.fetch(:flash_type, :error)] = result[:error] render json: { error: result[:error] }, status: result.fetch(:status, :unprocessable_entity) end end |