Class: Tasks::AssertedDistributions::NewFromMapController

Inherits:
ApplicationController
  • Object
show all
Includes:
TaskControllerConfiguration
Defined in:
app/controllers/tasks/asserted_distributions/asserted_distribution_controller.rb,
app/controllers/tasks/asserted_distributions/new_from_map_controller.rb

Instance Method Summary collapse

Methods included from TaskControllerConfiguration

#set_is_task_controller

Instance Method Details

#asserted_distribution_paramsObject (protected)


88
89
90
91
92
93
94
95
# File 'app/controllers/tasks/asserted_distributions/asserted_distribution_controller.rb', line 88

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_locksObject (protected)


51
52
53
# File 'app/controllers/tasks/asserted_distributions/asserted_distribution_controller.rb', line 51

def build_locks
  @locks = Forms::FieldLocks.new(lock_params || {})
end

#createObject

POST /asserted_distributions


13
14
15
16
17
18
19
20
21
22
# File 'app/controllers/tasks/asserted_distributions/asserted_distribution_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_choicesObject

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
47
# File 'app/controllers/tasks/asserted_distributions/asserted_distribution_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_paramsHash (protected)

Returns the state of the locks, values are 1 for locked locks.

Returns:

  • (Hash)

    the state of the locks, values are 1 for locked locks


57
58
59
# File 'app/controllers/tasks/asserted_distributions/asserted_distribution_controller.rb', line 57

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.

Returns:

  • (Hash)

    the values of the locked params, nil if not locked


63
64
65
66
67
68
# File 'app/controllers/tasks/asserted_distributions/asserted_distribution_controller.rb', line 63

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

#newObject

GET /new


7
8
9
10
# File 'app/controllers/tasks/asserted_distributions/asserted_distribution_controller.rb', line 7

def new
  @asserted_distribution = AssertedDistribution.new(asserted_distribution_params)
  @asserted_distribution.origin_citation ||= Citation.new
end

#otu_id_paramOtu#id? (protected)

Returns:

  • (Otu#id, nil)

71
72
73
74
75
76
77
# File 'app/controllers/tasks/asserted_distributions/asserted_distribution_controller.rb', line 71

def otu_id_param
  begin
    params.require(:asserted_distribution).permit(:otu_id)[:otu_id]
  rescue ActionController::ParameterMissing
    return nil
  end
end

#source_id_paramSource#id? (protected)

Returns:


80
81
82
83
84
85
86
# File 'app/controllers/tasks/asserted_distributions/asserted_distribution_controller.rb', line 80

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