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"]
Instance Method Summary collapse
Instance Method Details
#create ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'app/controllers/admin/assets_controller.rb', line 32 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]) 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
5 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 5 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 { @page = Page.find_by_id(params[:page_id]) render :partial => 'asset_table', :locals => {:with_pagination => true} } format.html { render } end end |
#refresh ⇒ Object
55 56 57 58 59 60 61 62 63 64 |
# File 'app/controllers/admin/assets_controller.rb', line 55 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 |
#regenerate ⇒ Object
71 72 73 74 75 |
# File 'app/controllers/admin/assets_controller.rb', line 71 def regenerate Asset.all.each { |asset| asset.asset.reprocess! } flash[:notice] = t('clipped_extension.all_thumbnails_refreshed') redirect_to admin_assets_path end |