Class: Tasks::Gis::AssertedDistributionController

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

Instance Method Summary (collapse)

Methods included from TaskControllerConfiguration

#set_is_task_controller

Instance Method Details

- (Object) asserted_distribution_params (protected)



87
88
89
90
91
92
93
94
# File 'app/controllers/tasks/gis/asserted_distribution_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

- (Object) build_locks (protected)



50
51
52
# File 'app/controllers/tasks/gis/asserted_distribution_controller.rb', line 50

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

- (Object) create

POST /asserted_distributions



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

- (Object) generate_choices

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/gis/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

- (Hash) lock_params (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



56
57
58
# File 'app/controllers/tasks/gis/asserted_distribution_controller.rb', line 56

def lock_params
  params.permit(locks: {asserted_distribution: [:otu_id, :source_id]})[:locks]
end

- (Hash) locked_params(locks: nil) (protected)

Returns the values of the locked params, nil if not locked

Returns:

  • (Hash)

    the values of the locked params, nil if not locked



62
63
64
65
66
67
# File 'app/controllers/tasks/gis/asserted_distribution_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

- (Object) new

GET /new



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

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

- (Otu#id?) otu_id_param (protected)

Returns:

  • (Otu#id, nil)


70
71
72
73
74
75
76
# File 'app/controllers/tasks/gis/asserted_distribution_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?) source_id_param (protected)

Returns:



79
80
81
82
83
84
85
# File 'app/controllers/tasks/gis/asserted_distribution_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