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

#clear_project_and_user_variables, #digest_cookie, #digested_cookie_exists?, #disable_turbolinks, #intercept_api, #invalid_object, #is_data_controller?, #is_task_controller?, #log_user_recent_route, #notice_user, #project_matches, #record_not_found, #set_project_and_user_variables, #set_project_from_params, #token_authenticate, #whitelist_constantize

Methods included from ProjectsHelper

#project_link, #project_tag, #projects_list, #projects_search_form

Instance Method Details

- (Object) autocomplete



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

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

- (Object) batch_load



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

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

- (Object) batch_params (private)



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

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



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

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



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

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



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

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



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

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



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

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



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

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



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

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



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

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)



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

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
19
# 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
        .where(project_id: sessions_current_project_id).page(params[:page]).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])
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)



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

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

- (Object) preview_data_attributes_batch_load

TODO: AUTOGENERATED STUB, check and update



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

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



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

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



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

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



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

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



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

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



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

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

- (Object) set_otu (private)



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

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



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

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