Class: Admin::AssetsController
- Inherits:
-
ResourceController
- Object
- 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
Instance Method Summary collapse
Instance Method Details
#create ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'app/controllers/admin/assets_controller.rb', line 34 def create @assets = [] @page_attachments = [] compress = current_site.try(:compress) ? current_site.compress : true asset_params[:asset][:asset].to_a.each do |uploaded_asset| if uploaded_asset.content_type == 'application/octet-stream' flash[:notice] = 'Please only upload assets that have a valid extension in the name.' else uploaded_asset = compress(uploaded_asset) if $kraken.api_key.present? && COMPRESS_FILE_TYPE.include?(uploaded_asset.content_type) && compress @asset = Asset.create(asset: uploaded_asset, caption: asset_params[:asset][:caption]) set_owner_or_editor 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 end end if asset_params[:for_attachment] render partial: 'admin/page_attachments/attachment', collection: @page_attachments else response_for :create end end |
#index ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'app/controllers/admin/assets_controller.rb', line 8 def index assets = Asset.order('created_at DESC') @page = Page.find(params[:page_id]) if params[:page_id] @term = params[:search] || '' assets = assets.matching(@term) if @term && !@term.blank? @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
59 60 61 62 63 64 65 66 67 68 |
# File 'app/controllers/admin/assets_controller.rb', line 59 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 |