Class: Tasks::CollectionObjects::FilterController

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

Instance Method Summary (collapse)

Methods included from TaskControllerConfiguration

#set_is_task_controller

Instance Method Details

- (Object) collection_objects (protected)



53
54
55
56
57
58
# File 'app/controllers/tasks/collection_objects/filter_controller.rb', line 53

def collection_objects
  Queries::CollectionObjectFilterQuery.new(filter_params)
    .result
    .with_project_id(sessions_current_project_id)
    .includes(:repository, {taxon_determinations: [{otu: :taxon_name}]}, :identifiers)
end

- (Object) download



14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'app/controllers/tasks/collection_objects/filter_controller.rb', line 14

def download
  scope = DwcOccurrence.collection_objects_join
    .where(dwc_occurrence_object_id: collection_objects.pluck(:id)) # !! see if we can get rid of pluck, shouldn't need it, but maybe complex join is not collapsabele to collection object id 
    .where(project_id: sessions_current_project_id)
    .order('dwc_occurrences.id')

  # If failing remove begin/ensure/end to report Raised errors
  begin
    data = Dwca::Packer::Data.new(scope)
    send_data(data.getzip, :type => 'application/zip', filename: data.filename)
  ensure
    data.cleanup
  end
end

- (Object) filter_params (protected)



60
61
62
# File 'app/controllers/tasks/collection_objects/filter_controller.rb', line 60

def filter_params
  params.permit(:drawn_area_shape, :search_start_date, :search_end_date, :partial_overlap, :otu_id, :descendants, :page, geographic_area_ids: [])
end

- (Object) find

POST



10
11
12
# File 'app/controllers/tasks/collection_objects/filter_controller.rb', line 10

def find
  @collection_objects = collection_objects.order('collection_objects.id').page(params[:page])
end

- (Object) index

GET



5
6
7
# File 'app/controllers/tasks/collection_objects/filter_controller.rb', line 5

def index
  @collection_objects = CollectionObject.none
end

- (Object) set_area

GET



30
31
32
# File 'app/controllers/tasks/collection_objects/filter_controller.rb', line 30

def set_area
  render json: {html: collection_objects.count.to_s}
end

- (Object) set_date

GET



35
36
37
38
39
40
41
42
43
44
# File 'app/controllers/tasks/collection_objects/filter_controller.rb', line 35

def set_date
  chart  = render_to_string(
    partial: 'stats',
    locals:  {
      count: collection_objects.count,
      objects: collection_objects
    }
  )
  render json: {html: collection_objects.count.to_s, chart: chart}
end

- (Object) set_otu

GET



47
48
49
# File 'app/controllers/tasks/collection_objects/filter_controller.rb', line 47

def set_otu
  render json: {html: collection_objects.count}
end