Class: OtusController

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

Instance Attribute Summary

Attributes inherited from ApplicationController

#is_data_controller, #is_task_controller, #meta_data, #meta_description, #meta_keywords, #meta_title, #page_title, #site_name

Instance Method Summary (collapse)

Methods included from DataControllerConfiguration::ProjectDataControllerConfiguration

#annotator_params

Methods inherited from ApplicationController

#digest_cookie, #digested_cookie_exists?, #disable_turbolinks, #invalid_object, #is_data_controller?, #is_task_controller?, #log_user_recent_route, #project_matches, #record_not_found, #set_project_from_params

Methods included from Whitelist

#whitelist_constantize

Methods included from ProjectsHelper

#project_link, #project_tag, #projects_list, #projects_search_form

Methods included from InterceptApi

#intercept_api, #token_authenticate

Instance Method Details

- (Object) autocomplete



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

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

- (Object) batch_load



98
99
100
# File 'app/controllers/otus_controller.rb', line 98

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

- (Object) batch_params (private)



233
234
235
236
237
238
239
240
241
242
# File 'app/controllers/otus_controller.rb', line 233

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



213
214
215
216
# File 'app/controllers/otus_controller.rb', line 213

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



81
82
83
# File 'app/controllers/otus_controller.rb', line 81

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

- (Object) create

POST /otus POST /otus.json



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

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



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

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



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

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



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

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



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

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

rubocop:disable Rails/SaveBang 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



206
207
208
209
210
# File 'app/controllers/otus_controller.rb', line 206

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



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

def edit
end

- (Object) filter_params (private)



244
245
246
247
248
249
250
251
# File 'app/controllers/otus_controller.rb', line 244

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: []
  )
end

- (Object) index

GET /otus GET /otus.json



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

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.page(params[:page]).per(500)
    }
  end
end

- (Object) list



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

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

- (Object) new

GET /otus/new



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

def new
  @otu = Otu.new
end

- (Object) otu_params (private)



229
230
231
# File 'app/controllers/otus_controller.rb', line 229

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

- (Object) preview_data_attributes_batch_load

TODO: AUTOGENERATED STUB, check and update



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

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



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

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



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

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



102
103
104
105
106
107
108
109
110
111
# File 'app/controllers/otus_controller.rb', line 102

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



85
86
87
88
89
90
91
92
# File 'app/controllers/otus_controller.rb', line 85

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



218
219
220
# File 'app/controllers/otus_controller.rb', line 218

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

- (Object) set_otu (private)



224
225
226
227
# File 'app/controllers/otus_controller.rb', line 224

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



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

def show
end

- (Object) update

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



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

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



254
255
256
# File 'app/controllers/otus_controller.rb', line 254

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