Class: Tasks::Accessions::Quick::SimpleController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- Tasks::Accessions::Quick::SimpleController
- Includes:
- TaskControllerConfiguration
- Defined in:
- app/controllers/tasks/accessions/quick/simple_controller.rb
Instance Method Summary collapse
- #build_locks ⇒ Object protected
- #collecting_event_id_param ⇒ Object protected
- #collecting_event_params ⇒ Hash protected
- #collecting_events ⇒ Object
-
#create ⇒ Object
POST /tasks/accessions/simple/create.json POST /tasks/accessions/simple/create.html.
- #get_recent ⇒ Object protected
- #identifier_param ⇒ Object protected
- #lock_params ⇒ Object protected
- #locked_params(locks: nil) ⇒ Object protected
- #namespace_id_param ⇒ Object protected
-
#new ⇒ Object
POST /tasks/accessions/simple/new.html.
- #next_identifier ⇒ Object protected
- #otu_id_param ⇒ Id? protected
- #preparation_type_id_param ⇒ Id? protected
- #recursive_images_params ⇒ Object protected
- #specimen_params ⇒ Object protected
-
#stub(defaults: {}) ⇒ Object
protected
TODO: move this to model!.
Methods included from TaskControllerConfiguration
Instance Method Details
#build_locks ⇒ Object (protected)
37 38 39 |
# File 'app/controllers/tasks/accessions/quick/simple_controller.rb', line 37 def build_locks @locks = Forms::FieldLocks.new(lock_params || {}) end |
#collecting_event_id_param ⇒ Object (protected)
148 149 150 151 152 153 154 155 |
# File 'app/controllers/tasks/accessions/quick/simple_controller.rb', line 148 def collecting_event_id_param id = params[:specimen].try(:collecting_event_id) if id.blank? @specimen.collecting_event_id if @specimen else id end end |
#collecting_event_params ⇒ Hash (protected)
112 113 114 115 116 117 118 119 |
# File 'app/controllers/tasks/accessions/quick/simple_controller.rb', line 112 def collecting_event_params begin id = params[:specimen].require(:collecting_event_id) {collecting_event_id: id} rescue ActionController::ParameterMissing params.require(:specimen).permit(collecting_event_attributes: [:id, :_destroy, :verbatim_locality, :verbatim_label, :geographic_area_id]).reject{|k,v| v.blank?} end end |
#collecting_events ⇒ Object
31 32 33 |
# File 'app/controllers/tasks/accessions/quick/simple_controller.rb', line 31 def collecting_events @collecting_events = CollectingEvent.where(project_id: sessions_current_project_id).where('verbatim_locality ILIKE ?', "%#{params[:term]}%").limit(10) end |
#create ⇒ Object
POST /tasks/accessions/simple/create.json POST /tasks/accessions/simple/create.html
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'app/controllers/tasks/accessions/quick/simple_controller.rb', line 13 def create @specimen = Specimen.new(specimen_params) if @specimen.save flash[:notice] = 'Specimen was successfully created.' @locked_params = locked_params(locks: @locks) respond_to do |format| format.html { @specimen = stub(defaults: @locked_params) render :new } format.json { render json: @locked_params } end else flash[:notice] = "Specimen was NOT created. #{@specimen.errors.}" render :new end end |
#get_recent ⇒ Object (protected)
41 42 43 |
# File 'app/controllers/tasks/accessions/quick/simple_controller.rb', line 41 def get_recent @recent = CollectionObject.created_last(5).where(created_by_id: sessions_current_user_id, project_id: sessions_current_project_id) end |
#identifier_param ⇒ Object (protected)
129 130 131 |
# File 'app/controllers/tasks/accessions/quick/simple_controller.rb', line 129 def identifier_param params[:specimen].try(:[], :identifiers_attributes).try(:[], '0').try(:[], :identifier) end |
#lock_params ⇒ Object (protected)
121 122 123 |
# File 'app/controllers/tasks/accessions/quick/simple_controller.rb', line 121 def lock_params params.permit(locks: {specimen: [:preparation_type_id], identifier: [:namespace_id, :increment], taxon_determination: [:otu_id], collecting_event: [:collecting_event_id] })[:locks] end |
#locked_params(locks: nil) ⇒ Object (protected)
66 67 68 69 70 71 72 73 |
# File 'app/controllers/tasks/accessions/quick/simple_controller.rb', line 66 def locked_params(locks: nil) { collecting_event_id: locks.resolve(:collecting_event, :collecting_event_id, collecting_event_id_param), namespace_id: locks.resolve(:identifier, :namespace_id, namespace_id_param ), otu_id: locks.resolve(:taxon_determination, :otu_id, otu_id_param), preparation_type_id: locks.resolve(:specimen, :preparation_type_id, preparation_type_id_param) } end |
#namespace_id_param ⇒ Object (protected)
125 126 127 |
# File 'app/controllers/tasks/accessions/quick/simple_controller.rb', line 125 def namespace_id_param params[:specimen].try(:[], :identifiers_attributes).try(:[], '0').try(:[], :namespace_id) end |
#new ⇒ Object
POST /tasks/accessions/simple/new.html
7 8 9 |
# File 'app/controllers/tasks/accessions/quick/simple_controller.rb', line 7 def new @specimen = stub(defaults: locked_params(locks: @locks)) end |
#next_identifier ⇒ Object (protected)
61 62 63 64 |
# File 'app/controllers/tasks/accessions/quick/simple_controller.rb', line 61 def next_identifier return nil if !@locks.locked?('identifier', 'increment') Utilities::Strings.increment_contained_integer(identifier_param) end |
#otu_id_param ⇒ Id? (protected)
139 140 141 142 143 144 145 146 |
# File 'app/controllers/tasks/accessions/quick/simple_controller.rb', line 139 def otu_id_param id = params[:specimen].try(:[], :taxon_determinations_attributes).try(:[], '0').try(:[], 'otu_id') if id.blank? @specimen.try(:taxon_determinations).try(:first).try(:otu_id) else id end end |
#preparation_type_id_param ⇒ Id? (protected)
102 103 104 105 106 107 108 109 |
# File 'app/controllers/tasks/accessions/quick/simple_controller.rb', line 102 def preparation_type_id_param begin params.require(:specimen).require(:preparation_type_id) rescue ActionController::ParameterMissing @specimen.preparation_type_id if @specimen end end |
#recursive_images_params ⇒ Object (protected)
90 91 92 93 94 95 96 97 98 99 |
# File 'app/controllers/tasks/accessions/quick/simple_controller.rb', line 90 def recursive_images_params return [] if params[:specimen].try(:[], :image_array).blank? keys = [] params.require(:specimen).permit(image_array: {})[:image_array].each do |key, value| if Utilities::Strings.is_i?(key) && value.is_a?(ActionDispatch::Http::UploadedFile) keys.push key end end keys end |
#specimen_params ⇒ Object (protected)
75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'app/controllers/tasks/accessions/quick/simple_controller.rb', line 75 def specimen_params params.require(:specimen).permit( # :collecting_event_id, :preparation_type_id, identifiers_attributes: [:id, :namespace_id, :identifier, :type, :_destroy], tags_attributes: [:id, :keyword_id, :_destroy], taxon_determinations_attributes: [:id, :otu_id, :_destroy, otu_attributes: [:id, :_destroy, :name, :taxon_name_id]], notes_attributes: [:id, :text, :_destroy], depictions_attributes: [:_destroy, :image_id, image_attributes: [:id, :image_file]], image_array: [ recursive_images_params ], ).merge(collecting_event_params) end |
#stub(defaults: {}) ⇒ Object (protected)
TODO: move this to model!
46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'app/controllers/tasks/accessions/quick/simple_controller.rb', line 46 def stub(defaults: {}) s = Specimen.new(collecting_event_id: defaults[:collecting_event_id] ) s.preparation_type_id = defaults[:preparation_type_id] s.identifiers << Identifier::Local::CatalogNumber.new( namespace_id: defaults[:namespace_id], identifier: next_identifier ) s.taxon_determinations.build(otu_id: defaults[:otu_id]) s.collecting_event = CollectingEvent.new if s.collecting_event_id.blank? s.depictions << Depiction.new s end |