Class: ErpApp::Desktop::FileManager::BaseController
- Inherits:
-
BaseController
- Object
- ActionController::Base
- ApplicationController
- BaseController
- ErpApp::Desktop::FileManager::BaseController
- Defined in:
- app/controllers/erp_app/desktop/file_manager/base_controller.rb
Constant Summary collapse
- ROOT_NODE =
'root_node'
Instance Method Summary collapse
- #base_path ⇒ Object
- #create_file ⇒ Object
- #create_folder ⇒ Object
- #delete_file ⇒ Object
-
#download_file ⇒ Object
This method downloads a file directly from file storage (bypassing file_assets) to download thru file_assets, use erp_app/public#download.
- #expand_directory ⇒ Object
- #get_contents ⇒ Object
- #rename_file ⇒ Object
- #save_move ⇒ Object
- #update_file ⇒ Object
- #upload_file ⇒ Object
Methods inherited from BaseController
Instance Method Details
#base_path ⇒ Object
12 13 14 |
# File 'app/controllers/erp_app/desktop/file_manager/base_controller.rb', line 12 def base_path @base_path ||= Rails.root.to_s end |
#create_file ⇒ Object
24 25 26 27 28 29 30 31 |
# File 'app/controllers/erp_app/desktop/file_manager/base_controller.rb', line 24 def create_file path = (params[:path] == ROOT_NODE) ? base_path : params[:path] name = params[:name] @file_support.create_file(path, name, "#Empty File") render :json => {:success => true, :node => @file_support.find_node(File.join(path, name), {keep_full_path: true})} end |
#create_folder ⇒ Object
33 34 35 36 37 38 39 |
# File 'app/controllers/erp_app/desktop/file_manager/base_controller.rb', line 33 def create_folder path = (params[:path] == ROOT_NODE) ? base_path : params[:path] name = params[:name] @file_support.create_folder(path, name) render :json => {:success => true, :node => @file_support.find_node(File.join(path, name))} end |
#delete_file ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'app/controllers/erp_app/desktop/file_manager/base_controller.rb', line 76 def delete_file = [] nodes_to_delete = (params[:selected_nodes] ? JSON(params[:selected_nodes]) : [params[:node]]) begin nodes_to_delete.each do |path| result, = @file_support.delete_file(path) << end render :json => {:success => true, :msg => .join(',')} rescue Exception => e render :json => {:success => false, :error => ex.} end end |
#download_file ⇒ Object
This method downloads a file directly from file storage (bypassing file_assets) to download thru file_assets, use erp_app/public#download
43 44 45 46 47 |
# File 'app/controllers/erp_app/desktop/file_manager/base_controller.rb', line 43 def download_file path = params[:path] contents, = @file_support.get_contents(path) send_data contents, :filename => File.basename(path), :disposition => :attachment end |
#expand_directory ⇒ Object
91 92 93 94 |
# File 'app/controllers/erp_app/desktop/file_manager/base_controller.rb', line 91 def path = (params[:node] == ROOT_NODE) ? base_path : params[:node] render :json => @file_support.build_tree(path) end |
#get_contents ⇒ Object
96 97 98 99 100 101 102 103 104 105 106 |
# File 'app/controllers/erp_app/desktop/file_manager/base_controller.rb', line 96 def get_contents path = params[:node] contents, = @file_support.get_contents(path) if contents.nil? render :text => else render :text => contents end end |
#rename_file ⇒ Object
67 68 69 70 71 72 73 74 |
# File 'app/controllers/erp_app/desktop/file_manager/base_controller.rb', line 67 def rename_file path = params[:node] name = params[:file_name] result, = @file_support.rename_file(path, name) render :json => {:success => result, :msg => } end |
#save_move ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'app/controllers/erp_app/desktop/file_manager/base_controller.rb', line 49 def save_move = [] nodes_to_move = (params[:selected_nodes] ? JSON(params[:selected_nodes]) : [params[:node]]) begin nodes_to_move.each do |node| path = node new_parent_path = (params[:parent_node] == ROOT_NODE) ? base_path : params[:parent_node] new_parent_path = new_parent_path.gsub(base_path,'') # target path must be relative result, = @file_support.save_move(path, new_parent_path) << end render :json => {:success => true, :msg => .join(',')} rescue => ex render :json => {:success => false, :error => ex.} end end |
#update_file ⇒ Object
16 17 18 19 20 21 22 |
# File 'app/controllers/erp_app/desktop/file_manager/base_controller.rb', line 16 def update_file path = params[:node] content = params[:content] @file_support.update_file(path, content) render :json => {:success => true} end |
#upload_file ⇒ Object
108 109 110 111 112 113 114 115 |
# File 'app/controllers/erp_app/desktop/file_manager/base_controller.rb', line 108 def upload_file upload_path = params[:directory] upload_path = base_path if upload_path == ROOT_NODE result = upload_file_to_path(upload_path) render :inline => result.to_json end |