Class: GeographicAreasController

Inherits:
ApplicationController show all
Includes:
DataControllerConfiguration::SharedDataControllerConfiguration
Defined in:
app/controllers/geographic_areas_controller.rb

Instance Attribute Summary

Attributes inherited from ApplicationController

#is_data_controller, #is_task_controller, #meta_data, #meta_description, #meta_keywords, #meta_title, #page_title, #site_name

Instance Method Summary (collapse)

Methods included from DataControllerConfiguration::SharedDataControllerConfiguration

#set_is_shared_data_model

Methods inherited from ApplicationController

#clear_project_and_user_variables, #digest_cookie, #digested_cookie_exists?, #disable_turbolinks, #intercept_api, #invalid_object, #is_data_controller?, #is_task_controller?, #log_user_recent_route, #notice_user, #project_matches, #record_not_found, #set_project_and_user_variables, #set_project_from_params, #token_authenticate

Methods included from ProjectsHelper

#project_link, #project_tag, #projects_list, #projects_search_form

Instance Method Details

- (Object) autocomplete



43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'app/controllers/geographic_areas_controller.rb', line 43

def autocomplete
  @geographic_areas = Queries::GeographicAreaAutocompleteQuery.new(params[:term]).all
  data              = @geographic_areas.collect do |t|
    show_this = render_to_string(partial: 'autocomplete_geographic_area', locals: {term: params[:term], geographic_area: t } ) 
    {id:              t.id,
     label:           t.name,
     response_values: {
       params[:method] => t.id
     },
     label_html:    show_this
    }
  end
  render :json => data
end

- (Object) display_coordinates



25
26
27
28
29
# File 'app/controllers/geographic_areas_controller.rb', line 25

def display_coordinates
  @asserted_distribution = AssertedDistribution.new
  @json_coors            = params.to_json
  render partial: '/asserted_distributions/quick_form'
end

- (Object) download

GET /geographic_areas/download



59
60
61
# File 'app/controllers/geographic_areas_controller.rb', line 59

def download
  send_data GeographicArea.generate_download(GeographicArea.all), type: 'text', filename: "geographic_areas_#{DateTime.now.to_s}.csv"
end

- (Object) geographic_area_params (private)

Never trust parameters from the scary internet, only allow the white list through.



74
75
76
77
78
# File 'app/controllers/geographic_areas_controller.rb', line 74

def geographic_area_params
  params.require(:geographic_area).permit(:name, :level0_id, :level1_id, :level2_id, :parent_id,
                                          :geographic_area_type_id, :iso_3166_a2, :iso_3166_a3, :tdwgID,
                                          :data_origin)
end

- (Object) index

GET /geographic_areas GET /geographic_areas.json



9
10
11
12
# File 'app/controllers/geographic_areas_controller.rb', line 9

def index
  @recent_objects = GeographicArea.updated_in_last(2.months).order(updated_at: :desc).limit(10)
  render '/shared/data/all/index'
end

- (Object) list



31
32
33
# File 'app/controllers/geographic_areas_controller.rb', line 31

def list
  @geographic_areas = GeographicArea.order(:id).page(params[:page])
end

- (Object) new

GET /geographic_areas/new



21
22
23
# File 'app/controllers/geographic_areas_controller.rb', line 21

def new
  @geographic_area = GeographicArea.new
end

- (Object) search



35
36
37
38
39
40
41
# File 'app/controllers/geographic_areas_controller.rb', line 35

def search
  if params[:id].blank?
    redirect_to geographic_areas_path, notice: 'You must select an item from the list with a click or tab press before clicking show.'
  else
    redirect_to geographic_area_path(params[:id])
  end
end

- (Object) set_geographic_area (private)

Use callbacks to share common setup or constraints between actions.



68
69
70
71
# File 'app/controllers/geographic_areas_controller.rb', line 68

def set_geographic_area
  @geographic_area = GeographicArea.find(params[:id])
  @recent_object   = @geographic_area
end

- (Object) show

GET /geographic_areas/1 GET /geographic_areas/1.json



16
17
18
# File 'app/controllers/geographic_areas_controller.rb', line 16

def show
  # GeographicArea.idontknow()
end