-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathfield_occurrences_controller.rb
136 lines (119 loc) · 4.44 KB
/
field_occurrences_controller.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
class FieldOccurrencesController < ApplicationController
include DataControllerConfiguration::ProjectDataControllerConfiguration
before_action :set_field_occurrence, only: %i[ show edit update destroy ]
after_action -> { set_pagination_headers(:field_occurrences) }, only: [:index, :api_index], if: :json_request?
# GET /field_occurrences or /field_occurrences.json
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
# GET /field_occurrences/1 or /field_occurrences/1.json
def show
end
# GET /field_occurrences/new
def new
redirect_to new_field_occurrence_task_path
end
# GET /field_occurrences/1/edit
def edit
end
# POST /field_occurrences or /field_occurrences.json
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
# PATCH/PUT /field_occurrences/1 or /field_occurrences/1.json
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
# DELETE /field_occurrences/1 or /field_occurrences/1.json
def destroy
@field_occurrence.destroy
respond_to do |format|
format.html { redirect_to field_occurrences_url, notice: 'Field occurrence was successfully destroyed.' }
format.json { head :no_content }
end
end
def autocomplete
@field_occurrences = ::Queries::FieldOccurrence::Autocomplete.new(
params[:term],
project_id: sessions_current_project_id
).autocomplete
end
# GET /collection_objects/list
def list
@field_occurrences = FieldOccurrence.with_project_id(sessions_current_project_id)
.order(:id)
.page(params[:page]) #.per(10) #.per(3)
end
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
private
def set_field_occurrence
@field_occurrence = FieldOccurrence.where(project_id: sessions_current_project_id).find(params[:id])
end
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
end