Class: Georgia::MediaController
Instance Method Summary
collapse
#current_ability, #current_locale
Instance Method Details
#create ⇒ Object
27
28
29
30
31
32
33
34
|
# File 'app/controllers/georgia/media_controller.rb', line 27
def create
@assets = []
params[:assets].each do |asset|
klass = asset.content_type.match(/^image/) ? Ckeditor::Picture : Ckeditor::Asset
@assets << klass.create(data: asset)
end
render layout: false
end
|
#destroy ⇒ Object
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
# File 'app/controllers/georgia/media_controller.rb', line 60
def destroy
@assets = Ckeditor::Asset.where(id: params[:id])
if can?(:destroy, Ckeditor::Asset) and @assets.destroy_all
respond_to do |format|
format.html { redirect_to search_media_index_path, notice: "Assets were successfully deleted." }
format.js { head :ok }
end
else
respond_to do |format|
format.html { redirect_to search_media_index_path, alert: "Oups. Something went wrong." }
format.js { head :internal_server_error }
end
end
end
|
#download ⇒ Object
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
|
# File 'app/controllers/georgia/media_controller.rb', line 78
def download
ids = params[:ids].split(',')
@files = Ckeditor::Asset.find(ids)
t = Tempfile.new("tmp-zip-#{Time.now.to_i}")
Zip::OutputStream.open(t.path) do |zos|
@files.each do |file|
filename = file.filename
zos.put_next_entry(filename)
tmp_file = Tempfile.new(filename)
open(file.url) do |data|
tmp_file.write data.read.force_encoding('UTF-8')
end
zos.print IO.read(tmp_file)
tmp_file.close
end
end
filename = "#{Georgia.title.try(:parameterize) || 'georgia'}_assets_#{Time.now.strftime('%Y%m%d%H%M%S')}.zip"
t.close
send_file t.path, type: "application/zip", disposition: 'attachment', filename: filename
end
|
#edit ⇒ Object
40
41
42
|
# File 'app/controllers/georgia/media_controller.rb', line 40
def edit
@asset = Ckeditor::Asset.find(params[:id])
end
|
#index ⇒ Object
8
9
10
|
# File 'app/controllers/georgia/media_controller.rb', line 8
def index
redirect_to action: :search
end
|
#search ⇒ Object
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
# File 'app/controllers/georgia/media_controller.rb', line 12
def search
@asset = Ckeditor::Asset.new
session[:search_params] = params
@search = Ckeditor::Asset.search do
fulltext params[:query] do
fields(:filename, :tags)
end
with(:extension, params[:e]) unless params[:e].blank?
with(:tags).any_of(params[:tg]) unless params[:tg].blank?
order_by (params[:o] || :updated_at), (params[:dir] || :desc)
paginate(page: params[:page], per_page: (params[:per] || 8))
end
@assets = Ckeditor::AssetDecorator.decorate_collection(@search.results)
end
|
#show ⇒ Object
36
37
38
|
# File 'app/controllers/georgia/media_controller.rb', line 36
def show
redirect_to edit_media_path(id: params[:id])
end
|
#update ⇒ Object
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
# File 'app/controllers/georgia/media_controller.rb', line 44
def update
@asset = Ckeditor::Asset.find(params[:id])
if @asset.update_attributes(params[:asset])
respond_to do |format|
format.html { redirect_to edit_media_path(@asset), notice: "Asset was successfully updated." }
format.js { head :ok }
end
else
respond_to do |format|
format.html { redirect_to edit_media_path(@asset), alert: "Oups. Something went wrong." }
format.js { head :internal_server_error }
end
end
end
|