Class: OtusController

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

Instance Method Summary collapse

Methods included from DataControllerConfiguration::ProjectDataControllerConfiguration

#annotator_params

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

#invalid_object, #project_link, #project_matches, #project_tag, #projects_list, #projects_search_form

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

#autocompleteObject


127
128
129
# File 'app/controllers/otus_controller.rb', line 127

def autocomplete
  @otus = Queries::Otu::Autocomplete.new(params.require(:term), project_id: sessions_current_project_id).autocomplete
end

#batch_loadObject


131
132
133
# File 'app/controllers/otus_controller.rb', line 131

def batch_load
  # see app/views/otus/batch_load.html.erb
end

#batch_paramsObject (private)


267
268
269
270
271
272
273
274
275
276
277
# File 'app/controllers/otus_controller.rb', line 267

def batch_params
  params.permit(
    :name, :file, :import_level,
    :create_new_otu, :source_id, :type_select, :create_new_predicate,
    files: [])
    .merge(
      user_id: sessions_current_user_id,
      project_id: sessions_current_project_id)
    .to_h
    .symbolize_keys
end

GET /otus/1/navigation.json


55
56
57
# File 'app/controllers/otus_controller.rb', line 55

def breadcrumbs 
  render json: :not_found and return if @otu.nil?
end

#by_nameObject

GET api/v1/otus/by_name/:name?token=:token&project_id=:id


246
247
248
249
# File 'app/controllers/otus_controller.rb', line 246

def by_name
  @otu_name = params.require(:name)
  @otu_ids = Queries::Otu::Autocomplete.new(@otu_name, project_id: params.require(:project_id)).all.pluck(:id)
end

#collection_objectsObject

GET /api/v1/otus/1/collection_objects


114
115
116
# File 'app/controllers/otus_controller.rb', line 114

def collection_objects
  @collection_objects = Otu.find(params[:id]).collection_objects.pluck(:id)
end

#coordinateObject

GET /otus/1/coordinate.json


49
50
51
52
# File 'app/controllers/otus_controller.rb', line 49

def coordinate
  @otus = Otu.coordinate_otus(@otu.id)
  render :index
end

#createObject

POST /otus POST /otus.json


61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'app/controllers/otus_controller.rb', line 61

def create
  @otu = Otu.new(otu_params)

  respond_to do |format|
    if @otu.save
      format.html { redirect_to @otu,
                    notice: "Otu '#{@otu.name}' was successfully created." }
      format.json { render action: :show, status: :created, location: @otu }
    else
      format.html { render action: 'new' }
      format.json { render json: @otu.errors, status: :unprocessable_entity }
    end
  end
end

#create_data_attributes_batch_loadObject

TODO: AUTOGENERATED STUB, check and update


223
224
225
226
227
228
229
230
231
232
233
234
235
236
# File 'app/controllers/otus_controller.rb', line 223

def create_data_attributes_batch_load
  if params[:file] && digested_cookie_exists?(params[:file].tempfile, :data_attributes_batch_load_otus_md5)
    @result = BatchLoad::Import::Otus::DataAttributesInterpreter.new(**batch_params)
    if @result.create
      flash[:notice] = "Successfully proccessed file, #{@result.total_records_created} TODO RECORD TYPES were created."
      render 'otus/batch_load/data_attributes/create' and return
    else
      flash[:alert] = 'Batch import failed.'
    end
  else
    flash[:alert] = 'File to batch upload must be supplied.'
  end
  render :batch_load
end

#create_identifiers_batch_loadObject


170
171
172
173
174
175
176
177
178
179
180
181
182
# File 'app/controllers/otus_controller.rb', line 170

def create_identifiers_batch_load
  if params[:file] && digested_cookie_exists?(params[:file].tempfile, :batch_load_otus_identifiers_md5)
    @result = BatchLoad::Import::Otus::IdentifiersInterpreter.new(**batch_params)
    if @result.create
      flash[:notice] = "Successfully processed file, #{@result.total_records_created} otus were created."
      render('otus/batch_load/identifiers/create')
      return
    else
      flash[:alert] = 'Batch import failed.'
    end
    render(:batch_load)
  end
end

#create_simple_batch_file_loadObject


195
196
197
198
199
200
201
202
203
204
205
206
207
208
# File 'app/controllers/otus_controller.rb', line 195

def create_simple_batch_file_load
  if params[:files] && digested_cookie_exists?(params[:files][0].tempfile, :batch_file_load_simple_md5)
    @result = BatchFileLoad::Import::Otus::SimpleInterpreter.new(**batch_params)

    if @result.create
      flash[:notice] = "Successfully processed #{@result.total_files_processed} file(s), #{@result.total_records_created} otus were created."
      render 'otus/batch_file_load/simple/create'
      return
    else
      flash[:alert] = 'Batch import failed.'
      render :batch_load
    end
  end
end

#create_simple_batch_loadObject


146
147
148
149
150
151
152
153
154
155
156
157
# File 'app/controllers/otus_controller.rb', line 146

def create_simple_batch_load
  if params[:file] && digested_cookie_exists?(params[:file].tempfile, :batch_otus_md5)
    @result = BatchLoad::Import::Otus.new(batch_params.merge(user_map))
    if @result.create
      flash[:notice] = "Successfully processed file, #{@result.total_records_created} otus were created."
      render('otus/batch_load/simple/create') and return
    else
      flash[:alert] = 'Batch import failed.'
    end
    render(:batch_load)
  end
end

#destroyObject

DELETE /otus/1 DELETE /otus/1.json


92
93
94
95
96
97
98
# File 'app/controllers/otus_controller.rb', line 92

def destroy
  @otu.destroy
  respond_to do |format|
    format.html { redirect_to otus_url }
    format.json { head :no_content }
  end
end

#downloadObject

GET /otus/download


239
240
241
242
243
# File 'app/controllers/otus_controller.rb', line 239

def download
  send_data Export::Download.generate_csv(Otu.where(project_id: sessions_current_project_id)),
    type: 'text',
    filename: "otus_#{DateTime.now}.csv"
end

#editObject

GET /otus/1/edit


32
33
# File 'app/controllers/otus_controller.rb', line 32

def edit
end

#filter_paramsObject (private)


279
280
281
282
283
284
285
286
287
# File 'app/controllers/otus_controller.rb', line 279

def filter_params
  params.permit(
    :taxon_name_id, :otu_id,
    biological_association_ids: [], taxon_name_ids: [], otu_ids: [],
    taxon_name_relationship_ids: [],taxon_name_classification_ids: [],
    asserted_distribution_ids: [],
    data_attributes_attributes: [ :id, :_destroy, :controlled_vocabulary_term_id, :type, :attribute_subject_id, :attribute_subject_type, :value ]
  )
end

#indexObject

GET /otus GET /otus.json


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

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

#listObject


35
36
37
# File 'app/controllers/otus_controller.rb', line 35

def list
  @otus = Otu.with_project_id(sessions_current_project_id).page(params[:page]).per(params[:per])
end

GET /otus/1/navigation.json


45
46
# File 'app/controllers/otus_controller.rb', line 45

def navigation
end

#newObject

GET /otus/new


27
28
29
# File 'app/controllers/otus_controller.rb', line 27

def new
  @otu = Otu.new
end

#otu_paramsObject (private)


263
264
265
# File 'app/controllers/otus_controller.rb', line 263

def otu_params
  params.require(:otu).permit(:name, :taxon_name_id)
end

#preview_data_attributes_batch_loadObject

TODO: AUTOGENERATED STUB, check and update


211
212
213
214
215
216
217
218
219
220
# File 'app/controllers/otus_controller.rb', line 211

def preview_data_attributes_batch_load
  if params[:file]
    @result = BatchLoad::Import::Otus::DataAttributesInterpreter.new(**batch_params)
    digest_cookie(params[:file].tempfile, :data_attributes_batch_load_otus_md5)
    render 'otus/batch_load/data_attributes/preview'
  else
    flash[:notice] = "No file provided!"
    redirect_to action: :batch_load
  end
end

#preview_identifiers_batch_loadObject


159
160
161
162
163
164
165
166
167
168
# File 'app/controllers/otus_controller.rb', line 159

def preview_identifiers_batch_load
  if params[:file]
    @result = BatchLoad::Import::Otus::IdentifiersInterpreter.new(**batch_params)
    digest_cookie(params[:file].tempfile, :batch_load_otus_identifiers_md5)
    render('otus/batch_load/identifiers/preview')
  else
    flash[:notice] = 'No file provided!'
    redirect_to action: :batch_load
  end
end

#preview_simple_batch_file_loadObject


184
185
186
187
188
189
190
191
192
193
# File 'app/controllers/otus_controller.rb', line 184

def preview_simple_batch_file_load
  if params[:files]
    @result = BatchFileLoad::Import::Otus::SimpleInterpreter.new(**batch_params)
    digest_cookie(params[:files][0].tempfile, :batch_file_load_simple_md5)
    render 'otus/batch_file_load/simple/preview'
  else
    flash[:notice] = 'No file(s) provided!'
    redirect_to action: :batch_load
  end
end

#preview_simple_batch_loadObject


135
136
137
138
139
140
141
142
143
144
# File 'app/controllers/otus_controller.rb', line 135

def preview_simple_batch_load
  if params[:file]
    @result = BatchLoad::Import::Otus.new(batch_params.merge(user_map))
    digest_cookie(params[:file].tempfile, :batch_otus_md5)
    render('otus/batch_load/simple/preview')
  else
    flash[:notice] = 'No file provided!'
    redirect_to action: :batch_load
  end
end

#searchObject


118
119
120
121
122
123
124
125
# File 'app/controllers/otus_controller.rb', line 118

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

#select_optionsObject

GET /otus/select_options?target=TaxonDetermination


252
253
254
# File 'app/controllers/otus_controller.rb', line 252

def select_options
  @otus = Otu.select_optimized(sessions_current_user_id, sessions_current_project_id, params.require(:target))
end

#set_otuObject (private)


258
259
260
261
# File 'app/controllers/otus_controller.rb', line 258

def set_otu
  @otu = Otu.where(project_id: sessions_current_project_id).find(params[:id])
  @recent_object = @otu
end

#showObject

GET /otus/1 GET /otus/1.json


23
24
# File 'app/controllers/otus_controller.rb', line 23

def show
end

#timelineObject

GET /otus/1/timeline.json


40
41
42
# File 'app/controllers/otus_controller.rb', line 40

def timeline
  @catalog = Catalog::Timeline.new(targets: [@otu])
end

#updateObject

PATCH/PUT /otus/1 PATCH/PUT /otus/1.json


78
79
80
81
82
83
84
85
86
87
88
# File 'app/controllers/otus_controller.rb', line 78

def update
  respond_to do |format|
    if @otu.update(otu_params)
      format.html { redirect_to @otu, notice: 'Otu was successfully updated.' }
      format.json { render :show, location: @otu }
    else
      format.html { render action: 'edit' }
      format.json { render json: @otu.errors, status: :unprocessable_entity }
    end
  end
end

#user_mapObject (private)


289
290
291
# File 'app/controllers/otus_controller.rb', line 289

def user_map
  {user_header_map: {'otu' => 'otu_name'}}
end