Class: Georgia::MediaController

Inherits:
ApplicationController show all
Defined in:
app/controllers/georgia/media_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#current_ability, #current_locale

Instance Method Details

#createObject



17
18
19
20
21
22
23
24
25
26
# File 'app/controllers/georgia/media_controller.rb', line 17

def create
  authorize Ckeditor::Asset
  begin
    @assets = params[:assets].map{|asset| CreateMediaAsset.new(asset).call}
    @assets = Ckeditor::AssetDecorator.decorate_collection(@assets)
  rescue => ex
    flash.now[:alert] = ex.message
  end
  render layout: false
end

#destroyObject

Destroy multiple assets



50
51
52
53
54
55
56
57
58
# File 'app/controllers/georgia/media_controller.rb', line 50

def destroy
  @assets = Ckeditor::Asset.where(id: params[:id])
  authorize @assets
  if @assets.destroy_all
    render_success("Assets were successfully deleted.")
  else
    render_error
  end
end

#downloadObject

Download multiple assets as a zip file TODO: We could send via AJAX with jquery.fileDownload plugin We could then have a download spinner while the request is processing, even a progress bar



63
64
65
66
67
68
69
# File 'app/controllers/georgia/media_controller.rb', line 63

def download
  ids = params[:ids].split(',')
  @files = Ckeditor::Asset.where(id: ids)
  authorize @files
  zip_file = Georgia::CompressFiles.new(@files).file
  send_file zip_file.path, type: "application/zip", disposition: 'attachment', filename: zip_file.filename
end

#editObject



34
35
36
37
# File 'app/controllers/georgia/media_controller.rb', line 34

def edit
  @asset = Ckeditor::Asset.find(params[:id])
  authorize @asset
end

#indexObject



4
5
6
7
# File 'app/controllers/georgia/media_controller.rb', line 4

def index
  authorize Ckeditor::Asset
  redirect_to action: :search
end

#searchObject



9
10
11
12
13
14
15
# File 'app/controllers/georgia/media_controller.rb', line 9

def search
  @asset = Ckeditor::Asset.new
  authorize Ckeditor::Asset
  search_conditions = Georgia::MediaSearch.new(params).definition
  @search = Ckeditor::Asset.search(search_conditions).page(params[:page])
  @assets = Ckeditor::AssetDecorator.decorate_collection(@search.records)
end

#showObject



28
29
30
31
32
# File 'app/controllers/georgia/media_controller.rb', line 28

def show
  @asset = Ckeditor::Asset.find(params[:id])
  authorize @asset
  redirect_to edit_media_path(id: params[:id])
end

#updateObject



39
40
41
42
43
44
45
46
47
# File 'app/controllers/georgia/media_controller.rb', line 39

def update
  @asset = Ckeditor::Asset.find(params[:id])
  authorize @asset
  if @asset.update_attributes(sanitized_asset_params)
    render_success("Asset was successfully updated.")
  else
    render_error
  end
end