Class: ObservationMatricesController
Constant Summary
ProjectsHelper::CLASSIFIER, ProjectsHelper::CLASSIFIER_ANNOTATION
Instance Method Summary
collapse
#annotator_params
#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, #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
#intercept_api
#intercept_project, #intercept_user, #intercept_user_or_project, #project_token_authenticate, #token_authenticate
Instance Method Details
#api_index ⇒ Object
GET /api/v1/observation_matrices
219
220
221
222
223
224
225
|
# File 'app/controllers/observation_matrices_controller.rb', line 219
def api_index
@observation_matrices = Queries::ObservationMatrix::Filter.new(params.merge!(api: true)).all
.where(project_id: sessions_current_project_id)
.page(params[:page])
.per(params[:per])
render '/observation_matrices/api/v1/index'
end
|
#api_show ⇒ Object
GET /api/v1/observation_matrices/:id
228
229
230
|
# File 'app/controllers/observation_matrices_controller.rb', line 228
def api_show
render '/observation_matrices/api/v1/show'
end
|
#autocomplete ⇒ Object
97
98
99
|
# File 'app/controllers/observation_matrices_controller.rb', line 97
def autocomplete
@observation_matrices = ObservationMatrix.where(project_id: sessions_current_project_id).where('name ilike ?', "%#{params[:term]}%")
end
|
#column ⇒ Object
192
193
194
|
# File 'app/controllers/observation_matrices_controller.rb', line 192
def column
@observation_matrix_column = ObservationMatrixColumn.where(project_id: sessions_current_project_id).find(params.require(:observation_matrix_column_id))
end
|
#column_labels ⇒ Object
113
114
|
# File 'app/controllers/observation_matrices_controller.rb', line 113
def column_labels
end
|
#create ⇒ Object
POST /observation_matrices POST /observation_matrices.json
47
48
49
50
51
52
53
54
55
56
57
58
59
|
# File 'app/controllers/observation_matrices_controller.rb', line 47
def create
@observation_matrix = ObservationMatrix.new(observation_matrix_params)
respond_to do |format|
if @observation_matrix.save
format.html { redirect_to @observation_matrix, notice: 'Matrix was successfully created.' }
format.json { render :show, status: :created, location: @observation_matrix }
else
format.html { render :new }
format.json { render json: @observation_matrix.errors, status: :unprocessable_entity }
end
end
end
|
#csv ⇒ Object
164
165
166
167
168
169
170
171
172
173
|
# File 'app/controllers/observation_matrices_controller.rb', line 164
def csv
respond_to do |format|
base = '/observation_matrices/export/csv/'
format.html { render base + 'index' }
format.text {
s = render_to_string(partial: base + 'csv', locals: { as_file: true }, layout: false, formats: [:html])
send_data(s, filename: "csv_#{DateTime.now}.csv", type: 'text/plain')
}
end
end
|
#descriptor_list ⇒ Object
142
143
144
145
146
147
148
149
150
151
|
# File 'app/controllers/observation_matrices_controller.rb', line 142
def descriptor_list
respond_to do |format|
base = '/observation_matrices/export/descriptor_list/'
format.html { render base + 'index' }
format.text {
s = render_to_string(partial: base + 'descriptor_list', locals: { as_file: true }, layout: false, formats: [:html])
send_data(s, filename: "descriptor_list_#{DateTime.now}.csv", type: 'text/plain')
}
end
end
|
#destroy ⇒ Object
DELETE /observation_matrices/1 DELETE /observation_matrices/1.json
89
90
91
92
93
94
95
|
# File 'app/controllers/observation_matrices_controller.rb', line 89
def destroy
@observation_matrix.destroy
respond_to do |format|
format.html { redirect_to observation_matrices_url, notice: 'Matrix was successfully destroyed.' }
format.json { head :no_content }
end
end
|
#download ⇒ Object
196
197
198
|
# File 'app/controllers/observation_matrices_controller.rb', line 196
def download
send_data Export::Download.generate_csv(ObservationMatrix.where(project_id: sessions_current_project_id)), type: 'text', filename: "observation_matrices_#{DateTime.now}.csv"
end
|
#download_contents ⇒ Object
200
201
202
|
# File 'app/controllers/observation_matrices_controller.rb', line 200
def download_contents
send_data Export::Download.generate_csv(ObservationMatrix.where(project_id: sessions_current_project_id)), type: 'text', filename: "observation_matrices_#{DateTime.now}.csv"
end
|
#edit ⇒ Object
GET /observation_matrices/1/edit
42
43
|
# File 'app/controllers/observation_matrices_controller.rb', line 42
def edit
end
|
#index ⇒ Object
GET /observation_matrices GET /observation_matrices.json
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
# File 'app/controllers/observation_matrices_controller.rb', line 12
def index
respond_to do |format|
format.html do
@recent_objects = ObservationMatrix.recent_from_project_id(sessions_current_project_id).order(updated_at: :desc).limit(10)
render '/shared/data/all/index'
end
format.json {
@observation_matrices = ::Queries::ObservationMatrix::Filter.new(params).all
.where(project_id: sessions_current_project_id)
.page(params[:page])
.per(params[:per])
}
end
end
|
#list ⇒ Object
32
33
34
|
# File 'app/controllers/observation_matrices_controller.rb', line 32
def list
@observation_matrices = ObservationMatrix.with_project_id(sessions_current_project_id).page(params[:page]).per(params[:per])
end
|
#new ⇒ Object
GET /observation_matrices/new
37
38
39
|
# File 'app/controllers/observation_matrices_controller.rb', line 37
def new
redirect_to new_matrix_task_path, notice: 'Redirecting to new task.'
end
|
#nexml ⇒ Object
TODO export formats can move to a concern controller
118
119
120
121
122
123
124
125
126
127
128
|
# File 'app/controllers/observation_matrices_controller.rb', line 118
def nexml
@options = nexml_params
respond_to do |format|
base = '/observation_matrices/export/nexml/nexml'
format.html { render base }
format.text {
s = render_to_string(base, layout: false, formats: [:rdf])
send_data(s, filename: "nexml_#{DateTime.now}.xml", type: 'text/plain')
}
end
end
|
#nexml_params ⇒ Object
TODO: Not all params are supported yet.
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
|
# File 'app/controllers/observation_matrices_controller.rb', line 235
def nexml_params
{ observation_matrix: @observation_matrix,
target: '',
include_otus: 'true',
include_collection_objects: 'true',
include_descriptors: 'true',
include_otu_depictions: 'true',
include_matrix: 'true',
include_trees: 'false',
rdf: false }.merge!(
params.permit(
:include_otus,
:include_collection_objects,
:include_descriptors,
:include_matrix,
:include_trees,
:rdf
).to_h
)
end
|
#nexus ⇒ Object
175
176
177
178
179
180
181
182
183
184
|
# File 'app/controllers/observation_matrices_controller.rb', line 175
def nexus
respond_to do |format|
base = '/observation_matrices/export/nexus/'
format.html { render base + 'index' }
format.text {
s = render_to_string(partial: base + 'nexus', locals: { as_file: true }, layout: false, formats: [:html])
send_data(s, filename: "nexus_#{DateTime.now}.nex", type: 'text/plain')
}
end
end
|
#observation_matrix_params ⇒ Object
289
290
291
|
# File 'app/controllers/observation_matrices_controller.rb', line 289
def observation_matrix_params
params.require(:observation_matrix).permit(:name)
end
|
#otu_contents ⇒ Object
130
131
132
133
134
135
136
137
138
139
140
|
# File 'app/controllers/observation_matrices_controller.rb', line 130
def otu_contents
@options = otu_contents_params
respond_to do |format|
base = '/observation_matrices/export/otu_content/index'
format.html { render base }
format.text {
s = render_to_string(base, layout: false)
send_data(s, filename: "otu_contents_#{DateTime.now}.csv", type: 'text/plain')
}
end
end
|
#otu_contents_params ⇒ Object
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
|
# File 'app/controllers/observation_matrices_controller.rb', line 256
def otu_contents_params
{ observation_matrix: @observation_matrix,
target: '',
include_otus: 'true',
include_collection_objects: 'false',
include_contents: 'true',
include_distribution: 'true',
include_type: 'true',
taxon_name: 'true',
include_nomenclature: 'true',
include_autogenerated_description: 'true',
include_depictions: 'true',
rdf: false }.merge!(
params.permit(
:include_otus,
:include_collection_objects,
:include_matrix,
:include_contents,
:include_distribution,
:include_type,
:taxon_name,
:include_nomenclature,
:include_autogenerated_description,
:include_depictions,
:rdf
).to_h
)
end
|
#otus_used_in_matrices ⇒ Object
204
205
206
207
208
209
210
211
212
213
214
215
216
|
# File 'app/controllers/observation_matrices_controller.rb', line 204
def otus_used_in_matrices
if !params[:otu_ids].blank?
p = ObservationMatrix.with_otu_id_array(params[:otu_ids].split('|')).pluck(:id)
if p.nil?
render json: {otus_used_in_matrices: ''}.to_json
else
render json: {otus_used_in_matrices: p}.to_json
end
else
render json: {otus_used_in_matrices: ''}.to_json
end
end
|
#reorder_columns ⇒ Object
83
84
85
|
# File 'app/controllers/observation_matrices_controller.rb', line 83
def reorder_columns
@observation_matrix.reorder_columns(params.require(:by))
end
|
#reorder_rows ⇒ Object
75
76
77
78
79
80
81
|
# File 'app/controllers/observation_matrices_controller.rb', line 75
def reorder_rows
if @observation_matrix.reorder_rows(params.require(:by))
render json: :success
else
render json: :error, status: :unprocessable_entity
end
end
|
#row ⇒ Object
GET /observation_matrices/row.json?observation_matrix_row_id=1 TODO: Why is this here? (used in Matrix Row Coder)
188
189
190
|
# File 'app/controllers/observation_matrices_controller.rb', line 188
def row
@observation_matrix_row = ObservationMatrixRow.where(project_id: sessions_current_project_id).find(params.require(:observation_matrix_row_id))
end
|
#row_labels ⇒ Object
110
111
|
# File 'app/controllers/observation_matrices_controller.rb', line 110
def row_labels
end
|
#search ⇒ Object
102
103
104
105
106
107
108
|
# File 'app/controllers/observation_matrices_controller.rb', line 102
def search
if params[:id].blank?
redirect_to observation_matrices_path, alert: 'You must select an item from the list with a click or tab press before clicking show.'
else
redirect_to observation_matrix_path(params[:id])
end
end
|
#set_observation_matrix ⇒ Object
285
286
287
|
# File 'app/controllers/observation_matrices_controller.rb', line 285
def set_observation_matrix
@observation_matrix = ObservationMatrix.where(project_id: sessions_current_project_id).find(params[:id])
end
|
#show ⇒ Object
GET /observation_matrices/1 GET /observation_matrices/1.json
29
30
|
# File 'app/controllers/observation_matrices_controller.rb', line 29
def show
end
|
#tnt ⇒ Object
153
154
155
156
157
158
159
160
161
162
|
# File 'app/controllers/observation_matrices_controller.rb', line 153
def tnt
respond_to do |format|
base = '/observation_matrices/export/tnt/'
format.html { render base + 'index' }
format.text {
s = render_to_string(partial: base + 'tnt', locals: { as_file: true }, layout: false, formats: [:html])
send_data(s, filename: "tnt_#{DateTime.now}.tnt", type: 'text/plain')
}
end
end
|
#update ⇒ Object
PATCH/PUT /observation_matrices/1 PATCH/PUT /observation_matrices/1.json
63
64
65
66
67
68
69
70
71
72
73
|
# File 'app/controllers/observation_matrices_controller.rb', line 63
def update
respond_to do |format|
if @observation_matrix.update(observation_matrix_params)
format.html { redirect_to @observation_matrix, notice: 'Matrix was successfully updated.' }
format.json { render :show, status: :ok, location: @observation_matrix }
else
format.html { render :edit }
format.json { render json: @observation_matrix.errors, status: :unprocessable_entity }
end
end
end
|