Class: TaxonNamesController

Inherits:
ApplicationController show all
Includes:
DataControllerConfiguration::ProjectDataControllerConfiguration
Defined in:
app/controllers/taxon_names_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) api_index

GET /api/v1/taxon_names



22
23
24
25
26
# File 'app/controllers/taxon_names_controller.rb', line 22

def api_index
  @taxon_names =
    Queries::TaxonName::Filter.new(filter_params).all.page(params[:page]).per([ [(params[:per] || 100).to_i, 1000].min, 1].max)
  render '/taxon_names/api/index.json.jbuilder'
end

- (Object) api_show

GET /api/v1/taxon_names/:id



29
30
31
32
# File 'app/controllers/taxon_names_controller.rb', line 29

def api_show
  @taxon_name = TaxonName.where(project_id: sessions_current_project_id).find(params[:id])
  render '/taxon_names/api/show.json.jbuilder'
end

- (Object) autocomplete



126
127
128
129
130
131
132
# File 'app/controllers/taxon_names_controller.rb', line 126

def autocomplete
  render json: {} and return if params[:term].blank?
  @taxon_names = Queries::TaxonName::Autocomplete.new(
    params[:term],
    autocomplete_params.to_h
  ).autocomplete
end

- (Object) autocomplete_params (private)



243
244
245
# File 'app/controllers/taxon_names_controller.rb', line 243

def autocomplete_params
  params.permit(:valid, :exact, :no_leaves, type: [], parent_id: [], nomenclature_group: []).to_h.symbolize_keys.merge(project_id: sessions_current_project_id)
end

- (Object) batch_load



145
146
# File 'app/controllers/taxon_names_controller.rb', line 145

def batch_load
end

- (Object) batch_params (private)



265
266
267
268
269
270
271
272
273
274
275
# File 'app/controllers/taxon_names_controller.rb', line 265

def batch_params
  params.permit(
    :file,
    :parent_taxon_name_id,
    :nomenclature_code,
    :also_create_otu,
    :import_level).merge(
      user_id: sessions_current_user_id,
      project_id: sessions_current_project_id
    ).to_h.symbolize_keys
end

- (Object) browse



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

def browse
  @data = NomenclatureCatalog.data_for(@taxon_name)
end

- (Object) create

POST /taxon_names POST /taxon_names.json



74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'app/controllers/taxon_names_controller.rb', line 74

def create
  @taxon_name = TaxonName.new(taxon_name_params)
  respond_to do |format|
    if @taxon_name.save
      format.html { redirect_to url_for(@taxon_name.metamorphosize),
                    notice: "Taxon name '#{@taxon_name.name}' was successfully created." }
      format.json { render :show, status: :created, location: @taxon_name.metamorphosize }
    else
      format.html { render action: :new }
      format.json { render json: @taxon_name.errors, status: :unprocessable_entity }
    end
  end
end

- (Object) create_castor_batch_load



210
211
212
213
214
215
216
217
218
219
220
221
222
223
# File 'app/controllers/taxon_names_controller.rb', line 210

def create_castor_batch_load
  if params[:file] && digested_cookie_exists?(params[:file].tempfile, :Castor_taxon_names_md5)
    @result = BatchLoad::Import::TaxonNames::CastorInterpreter.new(batch_params)
    if @result.create
      flash[:notice] = "Successfully proccessed file, #{@result.total_records_created} items were created."
      render 'taxon_names/batch_load/castor/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_simple_batch_load



184
185
186
187
188
189
190
191
192
193
194
195
196
197
# File 'app/controllers/taxon_names_controller.rb', line 184

def create_simple_batch_load
  if params[:file] && digested_cookie_exists?(params[:file].tempfile, :simple_taxon_names_md5)
    @result =  BatchLoad::Import::TaxonifiToTaxonworks.new(batch_params)
    if @result.create
      flash[:notice] = "Successfully proccessed file, #{@result.total_records_created} taxon names were created."
      render 'taxon_names/batch_load/simple/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) destroy

DELETE /taxon_names/1 DELETE /taxon_names/1.json



105
106
107
108
109
110
111
112
113
114
115
116
# File 'app/controllers/taxon_names_controller.rb', line 105

def destroy
  @taxon_name.destroy
  respond_to do |format|
    if @taxon_name.destroyed?
      format.html {redirect_back(fallback_location: (request.referer || root_path), notice: 'TaxonName was successfully destroyed.')}
      format.json {head :no_content}
    else
      format.html {redirect_back(fallback_location: (request.referer || root_path), notice: 'TaxonName was not destroyed, ' + errors.messages)}
      format.json {render json: @taxon_name.errors, status: :unprocessable_entity}
    end
  end
end

- (Object) download

GET /taxon_names/download



139
140
141
142
143
# File 'app/controllers/taxon_names_controller.rb', line 139

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

- (Object) edit

GET /taxon_names/1/edit



68
69
70
# File 'app/controllers/taxon_names_controller.rb', line 68

def edit
  @taxon_name.source = Source.new if !@taxon_name.source
end

- (Object) filter_params



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'app/controllers/taxon_names_controller.rb', line 34

def filter_params
  params.permit(
    :name, :author, :year,
    :leaves,
    :exact,
    :validity,
    :descendants,
    :updated_since,
    :type_metadata,
    :citations,
    :otus,
    :authors,
    :nomenclature_group, # !! different than autocomplete
    :nomenclature_code,
    :taxon_name_type,
    type: [],
    taxon_name_id: [],
    taxon_name_classification: [],
    taxon_name_relationship_type: [],
    taxon_name_relationship: []
  ).to_h.symbolize_keys.merge(project_id: sessions_current_project_id)
end

- (Object) index

GET /taxon_names GET /taxon_names.json



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

def index
  respond_to do |format|
    format.html do
      @recent_objects = TaxonName.recent_from_project_id(sessions_current_project_id).order(updated_at: :desc).limit(10)
      render '/shared/data/all/index'

    end
    format.json {
      @taxon_names = Queries::TaxonName::Filter.new(filter_params).all.page(params[:page]).per(params[:per] || 500)
    }
  end
end

- (Object) list



134
135
136
# File 'app/controllers/taxon_names_controller.rb', line 134

def list
  @taxon_names = TaxonName.with_project_id(sessions_current_project_id).order(:id).page(params[:page])
end

- (Object) new

GET /taxon_names/new



63
64
65
# File 'app/controllers/taxon_names_controller.rb', line 63

def new
  @taxon_name = Protonym.new(source: Source.new)
end

- (Object) parse



229
230
231
232
233
234
# File 'app/controllers/taxon_names_controller.rb', line 229

def parse
  @result = TaxonWorks::Vendor::Biodiversity::Result.new(
    query_string: params.require(:query_string),
    project_id: sessions_current_project_id
  ).result
end

- (Object) preview_castor_batch_load



199
200
201
202
203
204
205
206
207
208
# File 'app/controllers/taxon_names_controller.rb', line 199

def preview_castor_batch_load
  if params[:file]
    @result = BatchLoad::Import::TaxonNames::CastorInterpreter.new(batch_params)
    digest_cookie(params[:file].tempfile, :Castor_taxon_names_md5)
    render 'taxon_names/batch_load/castor/preview'
  else
    flash[:notice] = 'No file provided!'
    redirect_to action: :batch_load
  end
end

- (Object) preview_simple_batch_load



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

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

- (Object) random



152
153
154
155
156
# File 'app/controllers/taxon_names_controller.rb', line 152

def random
  redirect_to browse_nomenclature_task_path(
    taxon_name_id: TaxonName.where(project_id: sessions_current_project_id).order('random()').limit(1).pluck(:id).first
  )
end

- (Object) rank_table



158
159
160
161
162
163
164
165
166
# File 'app/controllers/taxon_names_controller.rb', line 158

def rank_table
  @q = Queries::TaxonName::Tabular.new(
    ancestor_id: params.require(:ancestor_id),
    project_id: sessions_current_project_id, 
    ranks: params.require(:ranks),
    fieldsets: params[:fieldsets],
    limit: params[:limit]
  )
end

- (Object) ranks



148
149
150
# File 'app/controllers/taxon_names_controller.rb', line 148

def ranks
  render json: RANKS_JSON.to_json
end

- (Object) search



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

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

- (Object) select_options

GET /taxon_names/select_options



169
170
171
# File 'app/controllers/taxon_names_controller.rb', line 169

def select_options
  @taxon_names = TaxonName.select_optimized(sessions_current_user_id, sessions_current_project_id)
end

- (Object) set_taxon_name (private)



238
239
240
241
# File 'app/controllers/taxon_names_controller.rb', line 238

def set_taxon_name
  @taxon_name = TaxonName.with_project_id(sessions_current_project_id).includes(:creator, :updater).find(params[:id])
  @recent_object = @taxon_name
end

- (Object) show

GET /taxon_names/1 GET /taxon_names/1.json



59
60
# File 'app/controllers/taxon_names_controller.rb', line 59

def show
end

- (Object) taxon_name_params (private)



247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
# File 'app/controllers/taxon_names_controller.rb', line 247

def taxon_name_params
  params.require(:taxon_name).permit(
    :name,
    :parent_id,
    :year_of_publication,
    :etymology,
    :verbatim_author, :verbatim_name, :rank_class, :type, :masculine_name,
    :feminine_name, :neuter_name, :also_create_otu,
    roles_attributes: [
      :id, :_destroy, :type, :person_id, :position,
      person_attributes: [
        :last_name, :first_name, :suffix, :prefix
      ]
    ],
    origin_citation_attributes: [:id, :_destroy, :source_id, :pages]
  )
end

- (Object) update

PATCH/PUT /taxon_names/1 PATCH/PUT /taxon_names/1.json



90
91
92
93
94
95
96
97
98
99
100
101
# File 'app/controllers/taxon_names_controller.rb', line 90

def update
  respond_to do |format|
    if @taxon_name.update(taxon_name_params)
      @taxon_name.reload
      format.html { redirect_to url_for(@taxon_name.metamorphosize), notice: 'Taxon name was successfully updated.' }
      format.json { render :show, status: :ok, location: @taxon_name.metamorphosize }
    else
      format.html { render action: :edit }
      format.json { render json: @taxon_name.errors, status: :unprocessable_entity }
    end
  end
end