Class: DwcOccurrencesController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- DwcOccurrencesController
- Defined in:
- app/controllers/dwc_occurrences_controller.rb
Constant Summary
Constants included from ProjectsHelper
ProjectsHelper::CLASSIFIER, ProjectsHelper::CLASSIFIER_ANNOTATION
Instance Method Summary collapse
- #api_index ⇒ Object
-
#attributes ⇒ Object
TODO: extract this all, unify with Concerns::IsData model, and re-use in DwcOccurrence.
- #collector_id_metadata ⇒ Object
-
#download ⇒ Object
GET /dwc_occurence/download.
-
#index ⇒ Object
.json only.
- #metadata ⇒ Object
- #predicates ⇒ Object
- #set_object ⇒ Object protected
- #status ⇒ Object
-
#sweep ⇒ Object
POST /dwc_occurrence/sweep (admin).
Methods included from DataControllerConfiguration::ProjectDataControllerConfiguration
Methods included from RedirectHelper
Methods included from RequestType
Methods included from LogRecent
Methods included from Cookies
#digest_cookie, #digested_cookie_exists?
Methods included from Whitelist
Methods included from ProjectsHelper
#cumulative_gb_per_year, #document_cumulative_gb_per_year, #document_gb_per_year, #gb_per_year, #image_cumulative_gb_per_year, #image_gb_per_year, #invalid_object, #project_classification, #project_link, #project_matches, #project_tag, #projects_list, #projects_search_form, #taxonworks_classification, #week_in_review_graphs
Methods included from Api::Intercept
Methods included from TokenAuthentication
#intercept_project, #intercept_user, #intercept_user_or_project, #project_token_authenticate, #token_authenticate
Instance Method Details
#api_index ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'app/controllers/dwc_occurrences_controller.rb', line 17 def api_index q = Queries::DwcOccurrence::Filter.new(params.merge!(api: true)).all .where(project_id: sessions_current_project_id) .page(params[:page]).per(params[:per]) respond_to do |format| format.json { @dwc_occurrences = q render '/dwc_occurrences/api/v1/index' } format.csv { @dwc_occurrences = q.limit(100000) send_data Export::CSV.generate_csv( @dwc_occurrences, exclude_columns: %w{updated_by_id created_by_id project_id, is_flagged_for_rebuild}, ), type: 'text', filename: "dwc_occurrences_#{DateTime.now}.tsv" } end end |
#attributes ⇒ Object
TODO: extract this all, unify with Concerns::IsData model, and re-use in DwcOccurrence
73 74 75 76 77 78 |
# File 'app/controllers/dwc_occurrences_controller.rb', line 73 def attributes i = Queries::DwcOccurrence::Filter::ATTRIBUTES render json: ::DwcOccurrence.columns.select{ |a| i.include?(a.name.to_sym) }.collect{|b| {'name' => b.name, 'type' => b.type } } end |
#collector_id_metadata ⇒ Object
56 57 58 |
# File 'app/controllers/dwc_occurrences_controller.rb', line 56 def render json: helpers. end |
#download ⇒ Object
GET /dwc_occurence/download
61 62 63 64 |
# File 'app/controllers/dwc_occurrences_controller.rb', line 61 def download send_data Export::CSV.generate_csv( DwcOccurrence.where(project_id: sessions_current_project_id)), type: 'text', filename: "dwc_occurrence_#{DateTime.now}.tsv" end |
#index ⇒ Object
.json only
10 11 12 13 14 15 |
# File 'app/controllers/dwc_occurrences_controller.rb', line 10 def index @dwc_occurrences = Queries::DwcOccurrence::Filter.new(params).all .where(project_id: sessions_current_project_id) .page(params[:page]) .per(params[:per] || 1) end |
#metadata ⇒ Object
37 38 39 |
# File 'app/controllers/dwc_occurrences_controller.rb', line 37 def @dwc_occurrences = DwcOccurrence.where(project_id: sessions_current_project_id) end |
#predicates ⇒ Object
41 42 |
# File 'app/controllers/dwc_occurrences_controller.rb', line 41 def predicates end |
#set_object ⇒ Object (protected)
82 83 84 85 86 87 88 |
# File 'app/controllers/dwc_occurrences_controller.rb', line 82 def set_object @object = GlobalID::Locator.locate(params[:object_global_id]) if @object.nil? || (@object.project_id != sessions_current_project_id) render status: :not_found and return end end |
#status ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 |
# File 'app/controllers/dwc_occurrences_controller.rb', line 44 def status if @object render json: { object: params[:object_global_id], id: @object.dwc_occurrence&.id, updated_at: @object.dwc_occurrence&.updated_at } else render json: {}, status: :unprocessable_entity end end |
#sweep ⇒ Object
POST /dwc_occurrence/sweep (admin)
67 68 69 70 |
# File 'app/controllers/dwc_occurrences_controller.rb', line 67 def sweep DwcOccurrence.sweep redirect_to administration_data_health_task_path and return end |