Class: CamaleonCms::Admin::MediaController
- Inherits:
-
CamaleonCms::AdminController
- Object
- CamaleonCms::AdminController
- CamaleonCms::Admin::MediaController
- Defined in:
- app/controllers/camaleon_cms/admin/media_controller.rb
Overview
Camaleon CMS is a content management system
Copyright (C) 2015 by Owen Peredo Diaz
Email: [email protected]
This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Affero General Public License (GPLv3) for more details.
Instance Method Summary collapse
-
#actions ⇒ Object
do background actions in fog.
-
#ajax ⇒ Object
render media for modal content.
-
#crop ⇒ Object
crop a image to save as a new file.
-
#index ⇒ Object
render media section.
- #search ⇒ Object
-
#upload(settings = {}) ⇒ Object
upload files from media uploader.
Instance Method Details
#actions ⇒ Object
do background actions in fog
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'app/controllers/camaleon_cms/admin/media_controller.rb', line 56 def actions :manager, :media params[:folder] = params[:folder].gsub("//", "/") if params[:folder].present? case params[:media_action] when "new_folder" cama_uploader_add_folder(params[:folder]) render partial: "render_folder_item", locals: { fname: params[:folder].split("/").last} when "del_folder" cama_uploader_destroy_folder(params[:folder]) render inline: "" when "del_file" cama_uploader_destroy_file(params[:folder].gsub("//", "/")) render inline: "" when 'crop_url' params[:url] = Rails.public_path.join(params[:url].sub(current_site.the_url, '')).to_s if params[:url].include?(current_site.the_url) # local file r = cama_tmp_upload(params[:url], formats: params[:formats]) unless r[:error].present? params[:file_upload] = r[:file_path] upload({remove_source: true}) else render inline: r[:error] end end end |
#ajax ⇒ Object
render media for modal content
48 49 50 51 52 53 |
# File 'app/controllers/camaleon_cms/admin/media_controller.rb', line 48 def ajax if params[:partial].present? render partial: "files_list", locals: { files: @tree[:files], folders: @tree[:folders] } end render "index", layout: false unless params[:partial].present? end |
#crop ⇒ Object
crop a image to save as a new file
32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'app/controllers/camaleon_cms/admin/media_controller.rb', line 32 def crop path_image = Rails.root.join("tmp", File.basename(params[:cp_img_path])).to_s if current_site.get_option("filesystem_type", "local") == "local" FileUtils.cp(Rails.root.join("public", "media", params[:cp_img_path].scan(/\/media\/(.*)/).first.first).to_s, path_image) else File.open(path_image, 'wb'){ |fo| fo.write(open(params[:cp_img_path]).read) } end crop_path = cama_crop_image(path_image, params[:ic_w], params[:ic_h], params[:ic_x], params[:ic_y]) res = upload_file(crop_path, {remove_source: true}) if params[:saved_avatar].present? CamaleonCms::User.find(params[:saved_avatar]).('avatar', res["url"]) end render text: res["url"] end |
#index ⇒ Object
render media section
16 17 18 19 20 |
# File 'app/controllers/camaleon_cms/admin/media_controller.rb', line 16 def index :manager, :media @show_file_actions = true I18n.t("camaleon_cms.admin.sidebar.media") end |
#search ⇒ Object
22 23 24 25 26 27 28 29 |
# File 'app/controllers/camaleon_cms/admin/media_controller.rb', line 22 def search :manager, :media @tree = { files: cama_media_search_file(params[:q]), folders: [] } @search = params[:q] I18n.t("camaleon_cms.admin.sidebar.media") params[:q] render 'index' end |
#upload(settings = {}) ⇒ Object
upload files from media uploader
82 83 84 85 86 87 88 89 90 |
# File 'app/controllers/camaleon_cms/admin/media_controller.rb', line 82 def upload(settings = {}) f = {error: "File not found."} if params[:file_upload].present? f = upload_file(params[:file_upload], {folder: params[:folder], dimension: params['dimension'], formats: params[:formats]}.merge(settings)) end render(partial: "render_file_item", locals:{ file: f }) unless f[:error].present? render inline: f[:error] if f[:error].present? end |