Class: FieldOccurrencesController

Inherits:
ApplicationController show all
Includes:
DataControllerConfiguration::ProjectDataControllerConfiguration
Defined in:
app/controllers/field_occurrences_controller.rb

Constant Summary

Constants included from ProjectsHelper

ProjectsHelper::CLASSIFIER, ProjectsHelper::CLASSIFIER_ANNOTATION

Instance Method Summary collapse

Methods included from DataControllerConfiguration::ProjectDataControllerConfiguration

#annotator_params

Methods included from RedirectHelper

#destroy_redirect

Methods included from RequestType

#json_request?

Methods included from LogRecent

#log_user_recent_route

Methods included from Cookies

#digest_cookie, #digested_cookie_exists?

Methods included from Whitelist

#whitelist_constantize

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, #sound_cumulative_gb_per_year, #sound_gb_per_year, #taxonworks_classification, #week_in_review_graphs

Methods included from Api::Intercept

#intercept_api

Methods included from TokenAuthentication

#intercept_project, #intercept_user, #intercept_user_or_project, #project_token_authenticate, #token_authenticate

Instance Method Details

#api_dwcObject

GET /api/v1/field_occurrences/123/dwc

[View source]

104
105
106
107
108
109
# File 'app/controllers/field_occurrences_controller.rb', line 104

def api_dwc
  ActiveRecord::Base.connection_pool.with_connection do
    @field_occurrence.get_dwc_occurrence
    render json: @field_occurrence.dwc_occurrence_attributes
  end
end

#autocompleteObject

[View source]

79
80
81
82
83
84
# File 'app/controllers/field_occurrences_controller.rb', line 79

def autocomplete
  @field_occurrences = ::Queries::FieldOccurrence::Autocomplete.new(
    params[:term],
    project_id: sessions_current_project_id
  ).autocomplete
end

#createObject

POST /field_occurrences or /field_occurrences.json

[View source]

37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'app/controllers/field_occurrences_controller.rb', line 37

def create
  @field_occurrence = ::FieldOccurrence.new(field_occurrence_params)

  respond_to do |format|
    if @field_occurrence.save
      format.html { redirect_to field_occurrence_url(@field_occurrence), notice: 'Field occurrence was successfully created.' }
      format.json { render :show, status: :created, location: @field_occurrence }
    else
      format.html { render :new, status: :unprocessable_entity }
      format.json { render json: @field_occurrence.errors, status: :unprocessable_entity }
    end
  end
end

#destroyObject

DELETE /field_occurrences/1 or /field_occurrences/1.json

[View source]

65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'app/controllers/field_occurrences_controller.rb', line 65

def destroy
  @field_occurrence.destroy

  respond_to do |format|
    if @field_occurrence.destroyed?
      format.html { destroy_redirect @field_occurrence, notice: 'Field occurrence was successfully destroyed.' }
      format.json { head :no_content}
    else
      format.html { destroy_redirect @field_occurrence, notice: 'Field occurrence was not destroyed, ' + @field_occurrence.errors.full_messages.join('; ') }
      format.json { render json: @field_occurrence.errors, status: :unprocessable_entity }
    end
  end
end

#editObject

GET /field_occurrences/1/edit

[View source]

33
34
# File 'app/controllers/field_occurrences_controller.rb', line 33

def edit
end

#field_occurrence_paramsObject (private)

[View source]

121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
# File 'app/controllers/field_occurrences_controller.rb', line 121

def field_occurrence_params
  params.require(:field_occurrence).permit(
    :total, :is_absent,
    :ranged_lot_category_id,
    :collecting_event_id,
    :taxon_determination_id,
    collecting_event_attributes: [],  # needs to be filled out!
    data_attributes_attributes: [ :id, :_destroy, :controlled_vocabulary_term_id, :type, :value ],
    tags_attributes: [:id, :_destroy, :keyword_id],
    depictions_attributes: [:id, :_destroy, :svg_clip, :svg_view_box, :position, :caption, :figure_label, :image_id],
    identifiers_attributes: [
      :id,
      :_destroy,
      :identifier,
      :namespace_id,
      :type,
      labels_attributes: [
        :text,
        :type,
        :text_method,
        :total
      ]
    ],
    taxon_determinations_attributes: [
      :id, :_destroy, :otu_id, :year_made, :month_made, :day_made, :position,
      roles_attributes: [:id, :_destroy, :type, :organization_id, :person_id, :position, person_attributes: [:last_name, :first_name, :suffix, :prefix]],
      otu_attributes: [:id, :_destroy, :name, :taxon_name_id]
    ],
    biocuration_classifications_attributes: [
      :id, :_destroy, :biocuration_class_id
    ])
end

#indexObject

GET /field_occurrences or /field_occurrences.json

[View source]

9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'app/controllers/field_occurrences_controller.rb', line 9

def index
  respond_to do |format|
    format.html do
      @recent_objects = FieldOccurrence.recent_from_project_id(sessions_current_project_id).order(updated_at: :desc).limit(10)
      render '/shared/data/all/index'
    end
    format.json {
      @field_occurrences = ::Queries::FieldOccurrence::Filter.new(params).all
        .page(params[:page])
        .per(params[:per])
    }
  end
end

#listObject

GET /collection_objects/list

[View source]

87
88
89
90
91
# File 'app/controllers/field_occurrences_controller.rb', line 87

def list
  @field_occurrences = FieldOccurrence.with_project_id(sessions_current_project_id)
    .order(:id)
    .page(params[:page]) #.per(10) #.per(3)
end

#newObject

GET /field_occurrences/new

[View source]

28
29
30
# File 'app/controllers/field_occurrences_controller.rb', line 28

def new
  redirect_to new_field_occurrence_task_path
end

#searchObject

[View source]

93
94
95
96
97
98
99
100
101
# File 'app/controllers/field_occurrences_controller.rb', line 93

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

#select_optionsObject

[View source]

111
112
113
# File 'app/controllers/field_occurrences_controller.rb', line 111

def select_options
  @field_occurrences = FieldOccurrence.select_optimized(sessions_current_user_id, sessions_current_project_id, params[:target], params['ba_target'])
end

#set_field_occurrenceObject (private)

[View source]

117
118
119
# File 'app/controllers/field_occurrences_controller.rb', line 117

def set_field_occurrence
  @field_occurrence = FieldOccurrence.where(project_id: sessions_current_project_id).find(params[:id])
end

#showObject

GET /field_occurrences/1 or /field_occurrences/1.json

[View source]

24
25
# File 'app/controllers/field_occurrences_controller.rb', line 24

def show
end

#updateObject

PATCH/PUT /field_occurrences/1 or /field_occurrences/1.json

[View source]

52
53
54
55
56
57
58
59
60
61
62
# File 'app/controllers/field_occurrences_controller.rb', line 52

def update
  respond_to do |format|
    if @field_occurrence.update(field_occurrence_params)
      format.html { redirect_to field_occurrence_url(@field_occurrence), notice: 'Field occurrence was successfully updated.' }
      format.json { render :show, status: :ok, location: @field_occurrence }
    else
      format.html { render :edit, status: :unprocessable_entity }
      format.json { render json: @field_occurrence.errors, status: :unprocessable_entity }
    end
  end
end