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)



104
105
106
107
108
109
110
# File 'app/controllers/tasks/collection_objects/filter_controller.rb', line 104

def collection_objects
  scope = Queries::CollectionObjectFilterQuery.new(filter_params)
            .result
            .with_project_id(sessions_current_project_id)
            .includes(:repository, {taxon_determinations: [{otu: :taxon_name}]}, :identifiers)
  scope
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)



112
113
114
115
116
117
# File 'app/controllers/tasks/collection_objects/filter_controller.rb', line 112

def filter_params
  params.permit(:drawn_area_shape, :search_start_date, :search_end_date,
                :id_range_start, :id_range_stop, :id_namespace,
                :user, :date_type_select, :user_date_range_end, :user_date_range_start,
                :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) get_created_at (protected)



87
88
89
90
91
92
93
# File 'app/controllers/tasks/collection_objects/filter_controller.rb', line 87

def get_created_at
  render json: {first_date: CollectionObject.in_project(sessions_current_project_id)
                              .first_created.created_at.to_date.to_s.gsub('-', '/'),
                last_date:  CollectionObject.in_project(sessions_current_project_id)
                              .last_created.created_at.to_date.to_s.gsub('-', '/')
  }
end

- (Object) get_dates_of_type

GET



74
75
76
77
78
79
80
81
82
83
# File 'app/controllers/tasks/collection_objects/filter_controller.rb', line 74

def get_dates_of_type
  case params[:date_type_select]
    when 'updated_at'
      get_updated_at
    when 'created_at'
      get_created_at
    # else
      #
  end
end

- (Object) get_updated_at (protected)



95
96
97
98
99
100
101
# File 'app/controllers/tasks/collection_objects/filter_controller.rb', line 95

def get_updated_at
  render json: {first_date: CollectionObject.in_project(sessions_current_project_id)
                              .first_updated.updated_at.to_date.to_s.gsub('-', '/'),
                last_date:  CollectionObject.in_project(sessions_current_project_id)
                              .last_updated.updated_at.to_date.to_s.gsub('-', '/')
  }
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



43
44
45
# File 'app/controllers/tasks/collection_objects/filter_controller.rb', line 43

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

- (Object) set_date

GET



48
49
50
51
52
53
54
55
56
# File 'app/controllers/tasks/collection_objects/filter_controller.rb', line 48

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_id_range

GET



64
65
66
# File 'app/controllers/tasks/collection_objects/filter_controller.rb', line 64

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

- (Object) set_otu

GET



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

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

- (Object) set_user_date_range

GET



69
70
71
# File 'app/controllers/tasks/collection_objects/filter_controller.rb', line 69

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

- (Object) tag_all

POST /tags/tag_all?keyword_id=123



30
31
32
33
34
35
36
37
38
39
40
# File 'app/controllers/tasks/collection_objects/filter_controller.rb', line 30

def tag_all
  if collection_objects.count < 2000
    if Tag.tag_objects( collection_objects, params.require(:keyword_id) )
      render json: { result: 'good' }
    else
      render json: { result: 'bad, error tagging objects' }
    end 
  else
    render json: { result: 'Limited to tagging 2000 objects, refine result.' }
  end
end