Module: CurationConcerns::FileSetsControllerBehavior
- Extended by:
- ActiveSupport::Concern
- Included in:
- FileSetsController
- Defined in:
- app/controllers/concerns/curation_concerns/file_sets_controller_behavior.rb
Instance Method Summary collapse
-
#create ⇒ Object
routed to /files (POST).
- #create_from_upload(params) ⇒ Object
- #curation_concern ⇒ Object
- #destroy ⇒ Object
-
#edit ⇒ Object
routed to /files/:id/edit.
-
#form_class ⇒ Object
Gives the class of the form.
-
#new ⇒ Object
routed to /files/new.
-
#show ⇒ Object
routed to /files/:id.
-
#show_presenter ⇒ Object
Gives the class of the show presenter.
-
#update ⇒ Object
routed to /files/:id (PUT).
-
#update_metadata ⇒ Object
this is provided so that implementing application can override this behavior and map params to different attributes.
- #versions ⇒ Object
Instance Method Details
#create ⇒ Object
routed to /files (POST)
30 31 32 |
# File 'app/controllers/concerns/curation_concerns/file_sets_controller_behavior.rb', line 30 def create create_from_upload(params) end |
#create_from_upload(params) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'app/controllers/concerns/curation_concerns/file_sets_controller_behavior.rb', line 34 def create_from_upload(params) # check error condition No files return render_json_response(response_type: :bad_request, options: { message: 'Error! No file to save' }) unless params.key?(:file_set) && params.fetch(:file_set).key?(:files) file = params[:file_set][:files].detect { |f| f.respond_to?(:original_filename) } if !file render_json_response(response_type: :bad_request, options: { message: 'Error! No file for upload', description: 'unknown file' }) elsif empty_file?(file) render_json_response(response_type: :unprocessable_entity, options: { errors: { files: "#{file.original_filename} has no content! (Zero length file)" }, description: t('curation_concerns.api.unprocessable_entity.empty_file') }) else process_file(file) end rescue RSolr::Error::Http => error logger.error "FileSetController::create rescued #{error.class}\n\t#{error}\n #{error.backtrace.join("\n")}\n\n" render_json_response(response_type: :internal_error, options: { message: 'Error occurred while creating a FileSet.' }) ensure # remove the tempfile (only if it is a temp file) file.tempfile.delete if file.respond_to?(:tempfile) end |
#curation_concern ⇒ Object
16 17 18 |
# File 'app/controllers/concerns/curation_concerns/file_sets_controller_behavior.rb', line 16 def curation_concern @file_set end |
#destroy ⇒ Object
79 80 81 82 83 |
# File 'app/controllers/concerns/curation_concerns/file_sets_controller_behavior.rb', line 79 def destroy parent = @file_set.in_works.first actor.destroy redirect_to [main_app, parent], notice: 'The file has been deleted.' end |
#edit ⇒ Object
routed to /files/:id/edit
25 26 27 |
# File 'app/controllers/concerns/curation_concerns/file_sets_controller_behavior.rb', line 25 def edit initialize_edit_form end |
#form_class ⇒ Object
Gives the class of the form. Override this if you want to use a different form.
75 76 77 |
# File 'app/controllers/concerns/curation_concerns/file_sets_controller_behavior.rb', line 75 def form_class CurationConcerns::Forms::FileSetEditForm end |
#new ⇒ Object
routed to /files/new
21 22 |
# File 'app/controllers/concerns/curation_concerns/file_sets_controller_behavior.rb', line 21 def new end |
#show ⇒ Object
routed to /files/:id
55 56 57 58 59 60 61 62 63 64 65 |
# File 'app/controllers/concerns/curation_concerns/file_sets_controller_behavior.rb', line 55 def show respond_to do |wants| wants.html { presenter } wants.json do # load and authorize @curation_concern manually because it's skipped for html @file_set = curation_concern_type.load_instance_from_solr(params[:id]) unless curation_concern :show, @file_set render :show, status: :ok end end end |
#show_presenter ⇒ Object
Gives the class of the show presenter. Override this if you want to use a different presenter.
69 70 71 |
# File 'app/controllers/concerns/curation_concerns/file_sets_controller_behavior.rb', line 69 def show_presenter CurationConcerns::FileSetPresenter end |
#update ⇒ Object
routed to /files/:id (PUT)
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'app/controllers/concerns/curation_concerns/file_sets_controller_behavior.rb', line 86 def update success = if wants_to_revert? actor.revert_content(params[:revision]) elsif params.key?(:file_set) if params[:file_set].key?(:files) actor.update_content(params[:file_set][:files].first) else end end if success respond_to do |wants| wants.html do redirect_to [main_app, @file_set], notice: "The file #{view_context.link_to(@file_set, [main_app, @file_set])} has been updated." end wants.json { render :show, status: :ok, location: polymorphic_path([main_app, @file_set]) } end else respond_to do |wants| wants.html do initialize_edit_form render 'edit', status: :unprocessable_entity end wants.json { render_json_response(response_type: :unprocessable_entity, options: { errors: @file_set.errors }) } end end rescue RSolr::Error::Http => error flash[:error] = error. logger.error "FileSetsController::update rescued #{error.class}\n\t#{error.}\n #{error.backtrace.join("\n")}\n\n" render action: 'edit' end |
#update_metadata ⇒ Object
this is provided so that implementing application can override this behavior and map params to different attributes
123 124 125 126 |
# File 'app/controllers/concerns/curation_concerns/file_sets_controller_behavior.rb', line 123 def file_attributes = form_class.model_attributes(attributes) actor.(file_attributes) end |
#versions ⇒ Object
118 119 120 |
# File 'app/controllers/concerns/curation_concerns/file_sets_controller_behavior.rb', line 118 def versions @version_list = version_list end |