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

Instance Method Details

- (Object) autocomplete



107
108
109
# File 'app/controllers/otus_controller.rb', line 107

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

- (Object) batch_load



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

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

- (Object) batch_params (private)



246
247
248
249
250
251
252
253
254
255
256
# File 'app/controllers/otus_controller.rb', line 246

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

- (Object) by_name

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



226
227
228
229
# File 'app/controllers/otus_controller.rb', line 226

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

- (Object) collection_objects

GET /api/v1/otus/1/collection_objects



94
95
96
# File 'app/controllers/otus_controller.rb', line 94

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

- (Object) create

POST /otus POST /otus.json



41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'app/controllers/otus_controller.rb', line 41

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

- (Object) create_data_attributes_batch_load

TODO: AUTOGENERATED STUB, check and update



203
204
205
206
207
208
209
210
211
212
213
214
215
216
# File 'app/controllers/otus_controller.rb', line 203

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

- (Object) create_identifiers_batch_load



150
151
152
153
154
155
156
157
158
159
160
161
162
# File 'app/controllers/otus_controller.rb', line 150

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

- (Object) create_simple_batch_file_load



175
176
177
178
179
180
181
182
183
184
185
186
187
188
# File 'app/controllers/otus_controller.rb', line 175

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

- (Object) create_simple_batch_load



126
127
128
129
130
131
132
133
134
135
136
137
# File 'app/controllers/otus_controller.rb', line 126

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

- (Object) destroy

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



72
73
74
75
76
77
78
# File 'app/controllers/otus_controller.rb', line 72

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

- (Object) download

GET /otus/download



219
220
221
222
223
# File 'app/controllers/otus_controller.rb', line 219

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

- (Object) edit

GET /otus/1/edit



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

def edit
end

- (Object) filter_params (private)



258
259
260
261
262
263
264
265
266
# File 'app/controllers/otus_controller.rb', line 258

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

- (Object) index

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

- (Object) list



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

- (Object) new

GET /otus/new



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

def new
  @otu = Otu.new
end

- (Object) otu_params (private)



242
243
244
# File 'app/controllers/otus_controller.rb', line 242

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

- (Object) preview_data_attributes_batch_load

TODO: AUTOGENERATED STUB, check and update



191
192
193
194
195
196
197
198
199
200
# File 'app/controllers/otus_controller.rb', line 191

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

- (Object) preview_identifiers_batch_load



139
140
141
142
143
144
145
146
147
148
# File 'app/controllers/otus_controller.rb', line 139

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

- (Object) preview_simple_batch_file_load



164
165
166
167
168
169
170
171
172
173
# File 'app/controllers/otus_controller.rb', line 164

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

- (Object) preview_simple_batch_load



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

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

- (Object) search



98
99
100
101
102
103
104
105
# File 'app/controllers/otus_controller.rb', line 98

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

- (Object) select_options



231
232
233
# File 'app/controllers/otus_controller.rb', line 231

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

- (Object) set_otu (private)



237
238
239
240
# File 'app/controllers/otus_controller.rb', line 237

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

- (Object) show

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



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

def show
end

- (Object) update

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



58
59
60
61
62
63
64
65
66
67
68
# File 'app/controllers/otus_controller.rb', line 58

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

- (Object) user_map (private)

rubocop:disable Style/StringHashKeys



269
270
271
# File 'app/controllers/otus_controller.rb', line 269

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