Class: RailsFilemanager::FilemanagerFilesController

Inherits:
ApplicationController show all
Defined in:
app/controllers/rails_filemanager/filemanager_files_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'app/controllers/rails_filemanager/filemanager_files_controller.rb', line 45

def create
  file_params = filemanager_file_params
  file_params['parent_id'] = @current_owner.rails_filemanager_files.first.id if file_params['parent_id'].to_i == 0 || file_params['parent_id'].blank?
  #file_params.delete_if{|k, v| k == 'parent_id' && (v.to_i == 0 || v.blank?) }
  logger.debug file_params.inspect
  @upload = FilemanagerFile.new file_params
  @upload.owner = @current_owner

  respond_to do |format|
    if @upload.save
      format.html {
        render json: [@upload.to_jq_upload].to_json,
        content_type: 'text/html',
        layout: false
      }
      format.json { render json: { files: [@upload.to_jq_upload]}, status: :created}
    else
      format.html { render action: 'new' }
      format.json { render json: { status: 'ERROR', errors: @upload.errors.full_messages }, status: :unprocessable_entity }
    end
  end
end

#destroyObject



72
73
74
75
76
77
78
79
80
81
82
# File 'app/controllers/rails_filemanager/filemanager_files_controller.rb', line 72

def destroy
  @file = FilemanagerFile.find_by id: params[:id]
  
  if @file == nil
    head :not_found
  elsif @file.destroy
    head :ok
  else
    head :internal_server_error
  end
end

#indexObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'app/controllers/rails_filemanager/filemanager_files_controller.rb', line 10

def index
  respond_to do |format|

    format.html
    format.json do


      # if params[:dir_id].present? && params[:dir_id] != '0'
      #   @directory = MediaManagerFile.find_by id: params[:dir_id]
      # else
      #   @directory = @choir.media_manager_files.root_dir.first
      #   unless @directory
      #     @directory = @choir.media_manager_files.create name: @choir.name
      #   end
      # end
      #
      if params[:dir_id].present? && params[:dir_id] != '0'
        @directory = FilemanagerFile.find_by id: params[:dir_id]
      else
        @directory = @current_owner.rails_filemanager_files.root_dir.first
        unless @directory
          @directory = @current_owner.rails_filemanager_files.create name: 'root'
        end
      end

      logger.debug @directory.inspect
      logger.debug @directory.children.inspect

      @uploads = @directory.children.sort_named

      render json: { directory_name: @directory.name, files: @uploads.map{|upload| upload.to_jq_upload } }
    end
  end
end

#storage_freeObject



68
69
70
# File 'app/controllers/rails_filemanager/filemanager_files_controller.rb', line 68

def storage_free
  render json: { storage_free: (@current_owner.send(owner.class.storage_limit_method) - @current_owner.total_storage_used) }
end