Class: Tasks::Dwc::DashboardController

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

Instance Method Summary collapse

Methods included from TaskControllerConfiguration

#set_is_task_controller

Instance Method Details

#create_indexObject



35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'app/controllers/tasks/dwc/dashboard_controller.rb', line 35

def create_index

  q = ::Queries::CollectionObject::Filter.new(params)
  q.project_id = nil

  if q.all(true)
    q.project_id = sessions_current_project_id
     = ::Export::Dwca.build_index_async(CollectionObject, q.all)
    render json: , status: :ok
  else
    render json: {}, status: :unprocessable_entity
  end
end

#generate_downloadObject

/tasks/dwc/dashboard/generate_download.json !! Run rails jobs:work in the terminal to complete builds



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'app/controllers/tasks/dwc/dashboard_controller.rb', line 10

def generate_download
  # TODO: to support scoping by other filters
  # we will have to scope all filter params throughout by their target base
  # e.g. collection_object[param]
  a = nil

  q = ::Queries::CollectionObject::Filter.new(params)
  q.project_id = nil

  if q.all(true)
    q.project_id = sessions_current_project_id
    a = DwcOccurrence.by_collection_object_filter(
      filter_scope: q.all,
      project_id: sessions_current_project_id)
  else
    a = DwcOccurrence.where(project_id: sessions_current_project_id)
    if params[:dwc_occurrence_start_date]
      a = a.where('dwc_occurrences.updated_at < ? and dwc_occurrences.updated_at > ?', params[:dwc_occurrence_start_date], params[:dwc_occurrence_end_date])
    end
  end

  @download = ::Export::Dwca.download_async(a, request.url, predicate_extension_params: predicate_extension_params )
  render '/downloads/show'
end

#indexObject

DWC_TASK



5
6
# File 'app/controllers/tasks/dwc/dashboard_controller.rb', line 5

def index
end

#index_versionsObject



49
50
51
# File 'app/controllers/tasks/dwc/dashboard_controller.rb', line 49

def index_versions
  render json: ::Export::Dwca::INDEX_VERSION, status: :ok
end

#predicate_extension_paramsObject (private)



55
56
57
# File 'app/controllers/tasks/dwc/dashboard_controller.rb', line 55

def predicate_extension_params
  params.permit(collecting_event_predicate_id: [], collection_object_predicate_id: [] ).to_h.symbolize_keys
end