Class: Tasks::AssertedDistributions::NewFromMapController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- Tasks::AssertedDistributions::NewFromMapController
- Includes:
- TaskControllerConfiguration
- Defined in:
- app/controllers/tasks/asserted_distributions/new_from_map_controller.rb
Instance Method Summary collapse
- #asserted_distribution_params ⇒ Object protected
- #build_locks ⇒ Object protected
-
#create ⇒ Object
POST /asserted_distributions.
-
#generate_choices ⇒ Object
GET /generate_choices.
-
#lock_params ⇒ Hash
protected
The state of the locks, values are 1 for locked locks.
-
#locked_params(locks: nil) ⇒ Hash
protected
The values of the locked params, nil if not locked.
-
#new ⇒ Object
GET /new.
- #otu_id_param ⇒ Otu#id? protected
- #source_id_param ⇒ Source#id? protected
Methods included from TaskControllerConfiguration
Instance Method Details
#asserted_distribution_params ⇒ Object (protected)
87 88 89 90 91 92 93 94 |
# File 'app/controllers/tasks/asserted_distributions/new_from_map_controller.rb', line 87 def asserted_distribution_params begin params.require(:asserted_distribution).permit(:otu_id, :geographic_area_id, :is_absent, origin_citation_attributes: [:source_id]) rescue ActionController::ParameterMissing return ActionController::Parameters.new(AssertedDistribution.new.attributes).permit! end end |
#build_locks ⇒ Object (protected)
50 51 52 |
# File 'app/controllers/tasks/asserted_distributions/new_from_map_controller.rb', line 50 def build_locks @locks = Forms::FieldLocks.new(lock_params || {}) end |
#create ⇒ Object
POST /asserted_distributions
13 14 15 16 17 18 19 20 21 22 |
# File 'app/controllers/tasks/asserted_distributions/new_from_map_controller.rb', line 13 def create @asserted_distribution = AssertedDistribution.new(asserted_distribution_params) if @asserted_distribution.save flash[:notice] = 'Asserted distribution was successfully created.' @asserted_distribution = AssertedDistribution.stub(defaults: locked_params(locks: @locks)) else flash[:notice] = 'Failed to create asserted distribution.' end render :new end |
#generate_choices ⇒ Object
GET /generate_choices
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'app/controllers/tasks/asserted_distributions/new_from_map_controller.rb', line 25 def generate_choices geographic_areas = GeographicArea.find_by_lat_long( params.permit(:latitude)['latitude'].to_f, params.permit(:longitude)['longitude'].to_f ) feature_collection = ::Gis::GeoJSON.feature_collection(geographic_areas) asserted_distributions = AssertedDistribution.stub_new( otu_id: otu_id_param, source_id: source_id_param, geographic_areas: geographic_areas ) render json: { html: render_to_string( partial:'asserted_distributions/quick_new_asserted_distribution_form', collection: asserted_distributions, as: :asserted_distribution, ), feature_collection: feature_collection } end |
#lock_params ⇒ Hash (protected)
Returns the state of the locks, values are 1 for locked locks.
56 57 58 |
# File 'app/controllers/tasks/asserted_distributions/new_from_map_controller.rb', line 56 def lock_params params.permit(locks: {asserted_distribution: [:otu_id, :source_id]})[:locks] end |
#locked_params(locks: nil) ⇒ Hash (protected)
Returns the values of the locked params, nil if not locked.
62 63 64 65 66 67 |
# File 'app/controllers/tasks/asserted_distributions/new_from_map_controller.rb', line 62 def locked_params(locks: nil) { source_id: locks.resolve(:asserted_distribution, :source_id, source_id_param), otu_id: locks.resolve(:asserted_distribution, :otu_id, otu_id_param), } end |
#new ⇒ Object
GET /new
7 8 9 10 |
# File 'app/controllers/tasks/asserted_distributions/new_from_map_controller.rb', line 7 def new @asserted_distribution = AssertedDistribution.new(asserted_distribution_params) @asserted_distribution.origin_citation ||= Citation.new end |
#otu_id_param ⇒ Otu#id? (protected)
70 71 72 73 74 75 76 |
# File 'app/controllers/tasks/asserted_distributions/new_from_map_controller.rb', line 70 def otu_id_param begin params.require(:asserted_distribution).permit(:otu_id)[:otu_id] rescue ActionController::ParameterMissing return nil end end |
#source_id_param ⇒ Source#id? (protected)
79 80 81 82 83 84 85 |
# File 'app/controllers/tasks/asserted_distributions/new_from_map_controller.rb', line 79 def source_id_param begin params.require(:asserted_distribution).require(:origin_citation_attributes).permit(:source_id)[:source_id] rescue ActionController::ParameterMissing return nil end end |