Module: Sufia::FilesControllerBehavior
- Extended by:
- ActiveSupport::Concern, Sufia::FilesController::UploadCompleteBehavior
- Includes:
- Breadcrumbs
- Included in:
- GenericFilesController
- Defined in:
- app/controllers/concerns/sufia/files_controller_behavior.rb
Instance Method Summary collapse
-
#audit ⇒ Object
routed to /files/:id/audit (POST).
-
#citation ⇒ Object
routed to /files/:id/citation.
-
#create ⇒ Object
routed to /files (POST).
- #create_from_upload(params) ⇒ Object
-
#destroy ⇒ Object
routed to /files/:id (DELETE).
-
#edit ⇒ Object
routed to /files/:id/edit.
-
#new ⇒ Object
routed to /files/new.
-
#show ⇒ Object
routed to /files/:id.
-
#stats ⇒ Object
routed to /files/:id/stats.
-
#update ⇒ Object
routed to /files/:id (PUT).
Methods included from Sufia::FilesController::UploadCompleteBehavior
destroy_complete_path, upload_complete_path
Methods included from Breadcrumbs
#add_breadcrumb_for_controller, #build_breadcrumbs, #default_trail, #trail_from_referer
Instance Method Details
#audit ⇒ Object
routed to /files/:id/audit (POST)
111 112 113 |
# File 'app/controllers/concerns/sufia/files_controller_behavior.rb', line 111 def audit render json: @generic_file.audit end |
#citation ⇒ Object
routed to /files/:id/citation
97 98 |
# File 'app/controllers/concerns/sufia/files_controller_behavior.rb', line 97 def citation end |
#create ⇒ Object
routed to /files (POST)
70 71 72 |
# File 'app/controllers/concerns/sufia/files_controller_behavior.rb', line 70 def create create_from_upload(params) end |
#create_from_upload(params) ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'app/controllers/concerns/sufia/files_controller_behavior.rb', line 74 def create_from_upload(params) # check error condition No files return json_error("Error! No file to save") if !params.has_key?(:files) file = params[:files].detect {|f| f.respond_to?(:original_filename) } if !file json_error "Error! No file for upload", 'unknown file', status: :unprocessable_entity elsif (empty_file?(file)) json_error "Error! Zero Length File!", file.original_filename elsif (!terms_accepted?) json_error "You must accept the terms of service!", file.original_filename else process_file(file) end rescue => error logger.error "GenericFilesController::create rescued #{error.class}\n\t#{error.to_s}\n #{error.backtrace.join("\n")}\n\n" json_error "Error occurred while creating generic file." ensure # remove the tempfile (only if it is a temp file) file.tempfile.delete if file.respond_to?(:tempfile) end |
#destroy ⇒ Object
routed to /files/:id (DELETE)
63 64 65 66 67 |
# File 'app/controllers/concerns/sufia/files_controller_behavior.rb', line 63 def destroy actor.destroy redirect_to self.class.destroy_complete_path(params), notice: render_to_string(partial: 'generic_files/asset_deleted_flash', locals: { generic_file: @generic_file }) end |
#edit ⇒ Object
routed to /files/:id/edit
52 53 54 55 |
# File 'app/controllers/concerns/sufia/files_controller_behavior.rb', line 52 def edit @generic_file.initialize_fields @groups = current_user.groups end |
#new ⇒ Object
routed to /files/new
47 48 49 |
# File 'app/controllers/concerns/sufia/files_controller_behavior.rb', line 47 def new @batch_noid = Sufia::Noid.noidify(Sufia::IdService.mint) end |
#show ⇒ Object
routed to /files/:id
101 102 103 104 105 106 107 108 |
# File 'app/controllers/concerns/sufia/files_controller_behavior.rb', line 101 def show respond_to do |format| format.html { @events = @generic_file.events(100) } format.endnote { render text: @generic_file.export_as_endnote } end end |
#stats ⇒ Object
routed to /files/:id/stats
58 59 60 |
# File 'app/controllers/concerns/sufia/files_controller_behavior.rb', line 58 def stats @stats = FileUsage.new(params[:id]) end |
#update ⇒ Object
routed to /files/:id (PUT)
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
# File 'app/controllers/concerns/sufia/files_controller_behavior.rb', line 116 def update success = if wants_to_revert? update_version elsif params.has_key? :filedata update_file elsif params.has_key? :generic_file end if success redirect_to sufia.edit_generic_file_path(tab: params[:redirect_tab]), notice: render_to_string(partial: 'generic_files/asset_updated_flash', locals: { generic_file: @generic_file }) else render action: 'edit' end rescue => error flash[:error] = error. logger.error "GenericFilesController::update rescued #{error.class}\n\t#{error.}\n #{error.backtrace.join("\n")}\n\n" render action: 'edit' end |