Class: BiologicalAssociationsController
Constant Summary
ProjectsHelper::CLASSIFIER, ProjectsHelper::CLASSIFIER_ANNOTATION
Instance Method Summary
collapse
#annotator_params
#set_time_zone
#destroy_redirect
#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
#cumulative_gb_per_year, #cumulative_projects_created_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_initials, #project_link, #project_login_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
#intercept_api
#intercept_project, #intercept_user, #intercept_user_or_project, #project_token_authenticate, #token_authenticate
Instance Method Details
#api_globi ⇒ Object
137
138
139
|
# File 'app/controllers/biological_associations_controller.rb', line 137
def api_globi
render json: @biological_association.globi_extension_json, status: :ok
end
|
#api_index ⇒ Object
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
|
# File 'app/controllers/biological_associations_controller.rb', line 145
def api_index
q = ::Queries::BiologicalAssociation::Filter.new(params.merge!(api: true)).all
.where(project_id: sessions_current_project_id)
.order('biological_associations.id')
respond_to do |format|
format.json {
@biological_associations = q.page(params[:page]).per(params[:per])
render '/biological_associations/api/v1/index'
}
format.csv {
@biological_associations = q
send_data Export::CSV.generate_csv(
@biological_associations,
exclude_columns: %w{updated_by_id created_by_id project_id},
), type: 'text',
filename: "biological_associations_#{DateTime.now}.tsv"
}
format.globi {
if q.page(params[:page]).per(params[:per]).count < 1001
send_data Export::CSV::Globi.csv(q.page(params[:page]).per(params[:per])),
type: 'text',
filename: "biological_associations_globi_#{DateTime.now}.tsv"
else
render json: { msg: 'At present this format is only allowed for 1000 or less records.' }, status: :unprocessable_content
end
}
end
end
|
#api_index_basic ⇒ Object
213
214
215
216
217
218
219
220
221
222
223
224
|
# File 'app/controllers/biological_associations_controller.rb', line 213
def api_index_basic
@biological_associations = ::Queries::BiologicalAssociation::Filter.new(params.merge!(api: true))
.all
.where(project_id: sessions_current_project_id)
.select('biological_associations.id')
.includes(:biological_association_index)
.order('biological_associations.id')
.page(params[:page])
.per(params[:per])
render '/biological_associations/api/v1/basic'
end
|
#api_index_extended ⇒ Object
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
|
# File 'app/controllers/biological_associations_controller.rb', line 195
def api_index_extended
@biological_associations = ::Queries::BiologicalAssociation::Filter.new(params.merge!(api: true))
.all
.where(project_id: sessions_current_project_id)
.order('biological_associations.id')
.page(params[:page])
.per(params[:per])
respond_to do |format|
format.json { render '/biological_associations/api/v1/extended' and return }
format.csv {
send_data Export::CSV::BiologicalAssociations::Extended.csv(@biological_associations),
type: 'text',
filename: "biological_associations_extended_#{DateTime.now}.tsv"
}
end
end
|
#api_index_simple ⇒ Object
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
|
# File 'app/controllers/biological_associations_controller.rb', line 177
def api_index_simple
@biological_associations = ::Queries::BiologicalAssociation::Filter.new(params.merge!(api: true))
.all
.where(project_id: sessions_current_project_id)
.order('biological_associations.id')
.page(params[:page])
.per(params[:per])
respond_to do |format|
format.json { render '/biological_associations/api/v1/simple' and return }
format.csv {
send_data Export::CSV::BiologicalAssociations::Simple.csv(@biological_associations),
type: 'text',
filename: "biological_associations_simple_#{DateTime.now}.tsv"
}
end
end
|
#api_resource_relationship ⇒ Object
141
142
143
|
# File 'app/controllers/biological_associations_controller.rb', line 141
def api_resource_relationship
render json: @biological_association.globi_extension_json, status: :ok
end
|
#api_show ⇒ Object
133
134
135
|
# File 'app/controllers/biological_associations_controller.rb', line 133
def api_show
render '/biological_associations/api/v1/show'
end
|
#autocomplete ⇒ Object
240
241
242
243
244
245
246
|
# File 'app/controllers/biological_associations_controller.rb', line 240
def autocomplete
@biological_associations =
::Queries::BiologicalAssociation::Autocomplete.new(
params.require(:term),
project_id: sessions_current_project_id,
).autocomplete
end
|
#batch_update ⇒ Object
PATCH /biological_associations/batch_update.json?biological_association_query=<>&biological_association={}
227
228
229
230
231
232
233
234
235
236
237
238
|
# File 'app/controllers/biological_associations_controller.rb', line 227
def batch_update
if r = BiologicalAssociation.batch_update(
preview: params[:preview],
biological_association: biological_association_params.merge(by: sessions_current_user_id),
biological_association_query: params[:biological_association_query],
user_id: sessions_current_user_id,
project_id: sessions_current_project_id)
render json: r.to_json, status: :ok
else
render json: {}, status: :unprocessable_content
end
end
|
#biological_association_params ⇒ Object
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
|
# File 'app/controllers/biological_associations_controller.rb', line 301
def biological_association_params
params.require(:biological_association).permit(
:biological_relationship_id, :biological_association_subject_id, :biological_association_subject_type,
:biological_association_object_id, :biological_association_object_type,
:subject_global_id,
:object_global_id,
:rotate,
subject_anatomical_part_attributes: [:name, :uri, :uri_label, :is_material, :preparation_type_id],
object_anatomical_part_attributes: [:name, :uri, :uri_label, :is_material, :preparation_type_id],
subject_taxon_determination_attributes: [:otu_id],
object_taxon_determination_attributes: [:otu_id],
origin_citation_attributes: [:id, :_destroy, :source_id, :pages],
citations_attributes: [:id, :is_original, :_destroy, :source_id, :pages, :citation_object_id, :citation_object_type],
)
end
|
#create ⇒ Object
POST /biological_associations
POST /biological_associations.json
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
|
# File 'app/controllers/biological_associations_controller.rb', line 77
def create
if create_with_anatomical_parts?
@biological_association = ::BiologicalAssociations::CreateWithAnatomicalParts.new(biological_association_params).call
else
@biological_association = BiologicalAssociation.new(biological_association_params)
@biological_association.save
end
respond_to do |format|
if @biological_association.persisted?
format.html { redirect_to @biological_association, notice: 'Biological association was successfully created.' }
format.json { render :show, status: :created, location: @biological_association }
else
format.html { render :new }
format.json { render json: { errors: @biological_association.errors.full_messages }, status: :unprocessable_content }
end
end
end
|
#create_with_anatomical_parts? ⇒ Boolean
317
318
319
320
|
# File 'app/controllers/biological_associations_controller.rb', line 317
def create_with_anatomical_parts?
p = biological_association_params
p[:subject_anatomical_part_attributes].present? || p[:object_anatomical_part_attributes].present?
end
|
#destroy ⇒ Object
DELETE /biological_associations/1
DELETE /biological_associations/1.json
112
113
114
115
116
117
118
119
120
121
122
123
|
# File 'app/controllers/biological_associations_controller.rb', line 112
def destroy
@biological_association.destroy
respond_to do |format|
if @biological_association.destroyed?
format.html { redirect_to biological_associations_url, notice: 'Biological association was successfully destroyed.' }
format.json { head :no_content }
else
format.html { destroy_redirect @biological_association, notice: 'Biological association was not destroyed: ' + @biological_association.errors.full_messages.join('; ') }
format.json { render json: @biological_association.errors, status: :unprocessable_content }
end
end
end
|
#edit ⇒ Object
GET /biological_associations/1/edit
68
69
|
# File 'app/controllers/biological_associations_controller.rb', line 68
def edit
end
|
#index ⇒ Object
GET /biological_associations
GET /biological_associations.json
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
|
# File 'app/controllers/biological_associations_controller.rb', line 11
def index
respond_to do |format|
format.html {
@recent_objects = BiologicalAssociation.recent_from_project_id(sessions_current_project_id).order(updated_at: :desc).limit(10)
render '/shared/data/all/index'
}
format.json {
@biological_associations = Queries::BiologicalAssociation::Filter.new(params)
.all
.where(project_id: sessions_current_project_id)
.includes(
citations: [:source, { citation_topics: :topic }],
biological_relationship: :biological_relationship_types
)
.preload(:biological_association_subject, :biological_association_object)
.page(params[:page])
.per(params[:per])
.load
co_fo_subjects = @biological_associations
.filter_map { |ba| ba.biological_association_subject if ['CollectionObject', 'FieldOccurrence'].include?(ba.biological_association_subject_type) }
ActiveRecord::Associations::Preloader.new(records: co_fo_subjects, associations: [:taxon_determinations, :identifiers]).call unless co_fo_subjects.empty?
co_fo_objects = @biological_associations
.filter_map { |ba| ba.biological_association_object if ['CollectionObject', 'FieldOccurrence'].include?(ba.biological_association_object_type) }
ActiveRecord::Associations::Preloader.new(records: co_fo_objects, associations: [:taxon_determinations, :identifiers]).call unless co_fo_objects.empty?
otu_subjects = @biological_associations
.filter_map { |ba| ba.biological_association_subject if ba.biological_association_subject_type == 'Otu' }
ActiveRecord::Associations::Preloader.new(records: otu_subjects, associations: [:taxon_name]).call unless otu_subjects.empty?
otu_objects = @biological_associations
.filter_map { |ba| ba.biological_association_object if ba.biological_association_object_type == 'Otu' }
ActiveRecord::Associations::Preloader.new(records: otu_objects, associations: [:taxon_name]).call unless otu_objects.empty?
ap_subjects = @biological_associations
.filter_map { |ba| ba.biological_association_subject if ba.biological_association_subject_type == 'AnatomicalPart' }
ActiveRecord::Associations::Preloader.new(records: ap_subjects, associations: [:inbound_origin_relationship]).call unless ap_subjects.empty?
ap_objects = @biological_associations
.filter_map { |ba| ba.biological_association_object if ba.biological_association_object_type == 'AnatomicalPart' }
ActiveRecord::Associations::Preloader.new(records: ap_objects, associations: [:inbound_origin_relationship]).call unless ap_objects.empty?
}
end
end
|
#list ⇒ Object
71
72
73
|
# File 'app/controllers/biological_associations_controller.rb', line 71
def list
@biological_associations = BiologicalAssociation.with_project_id(sessions_current_project_id).order(:id).page(params[:page]) end
|
#navigation ⇒ Object
GET /biological_associations/1/navigation.json
258
259
|
# File 'app/controllers/biological_associations_controller.rb', line 258
def navigation
end
|
#new ⇒ Object
GET /biological_associations/new
63
64
65
|
# File 'app/controllers/biological_associations_controller.rb', line 63
def new
redirect_to new_biological_association_task_path
end
|
#origin_subject_index ⇒ Object
GET /biological_associations/origin_subject_index.json?origin_object_id=1&origin_object_type=Otu
Returns BiologicalAssociations whose subject is an AnatomicalPart originated
from the base object.
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
|
# File 'app/controllers/biological_associations_controller.rb', line 276
def origin_subject_index
object_id = params.require(:origin_object_id).to_i
object_type = params.require(:origin_object_type).to_s
@biological_associations = BiologicalAssociation
.joins("INNER JOIN origin_relationships ap_origin_relationships ON ap_origin_relationships.new_object_id = biological_associations.biological_association_subject_id")
.where(project_id: sessions_current_project_id)
.where(biological_association_subject_type: 'AnatomicalPart')
.where("ap_origin_relationships.new_object_type = 'AnatomicalPart'")
.where(
'ap_origin_relationships.old_object_id = ? AND ap_origin_relationships.old_object_type = ?',
object_id,
object_type
)
.order('biological_associations.updated_at DESC')
render '/biological_associations/index'
end
|
#search ⇒ Object
125
126
127
128
129
130
131
|
# File 'app/controllers/biological_associations_controller.rb', line 125
def search
if params[:id].blank?
redirect_to biological_associations_path, alert: 'You must select an item from the list with a click or tab press before clicking show.'
else
redirect_to biological_association_path(params[:id])
end
end
|
#select_options ⇒ Object
261
262
263
|
# File 'app/controllers/biological_associations_controller.rb', line 261
def select_options
@biological_associations = BiologicalAssociation.select_optimized(sessions_current_user_id, sessions_current_project_id, params.require(:target))
end
|
#set_biological_association ⇒ Object
297
298
299
|
# File 'app/controllers/biological_associations_controller.rb', line 297
def set_biological_association
@biological_association = BiologicalAssociation.where(project_id: sessions_current_project_id).find(params[:id])
end
|
#show ⇒ Object
GET /biological_associations/1
GET /biological_associations/1.json
59
60
|
# File 'app/controllers/biological_associations_controller.rb', line 59
def show
end
|
#subject_object_types ⇒ Object
265
266
267
268
269
270
271
|
# File 'app/controllers/biological_associations_controller.rb', line 265
def subject_object_types
hash = BIOLOGICALLY_RELATABLE_TYPES.reduce({}) do |h, val|
h[val] = val.tableize
h
end
render json: hash
end
|
#update ⇒ Object
PATCH/PUT /biological_associations/1
PATCH/PUT /biological_associations/1.json
98
99
100
101
102
103
104
105
106
107
108
|
# File 'app/controllers/biological_associations_controller.rb', line 98
def update
respond_to do |format|
if @biological_association.update(biological_association_params)
format.html { redirect_to @biological_association, notice: 'Biological association was successfully updated.' }
format.json { render :show, status: :ok, location: @biological_association }
else
format.html { render :edit }
format.json { render json: @biological_association.errors, status: :unprocessable_content }
end
end
end
|