Class: TaxonNamesController

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

#polymorphic_filter_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

Methods included from ProjectsHelper

#project_link, #project_tag, #projects_list, #projects_search_form

Instance Method Details

- (Object) autocomplete



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'app/controllers/taxon_names_controller.rb', line 77

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

  data = @taxon_names.collect do |t|
    str = render_to_string(partial: 'autocomplete_tag', locals: {taxon_name: t, term: params[:term] })
    {id:              t.id,
     label:           ApplicationController.helpers.taxon_name_autocomplete_selected_tag(t),
     response_values: {
       params[:method] => t.id
     },
     label_html:       str
    }
  end

  render :json => data
end

- (Object) autocomplete_params



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

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

- (Object) batch_load



113
114
# File 'app/controllers/taxon_names_controller.rb', line 113

def batch_load
end

- (Object) batch_params (private)



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

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
    ).symbolize_keys
end

- (Object) browse



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

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

- (Object) create

POST /taxon_names POST /taxon_names.json



30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'app/controllers/taxon_names_controller.rb', line 30

def create
  @taxon_name = TaxonName.new(taxon_name_params)

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

- (Object) create_castor_batch_load



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

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



127
128
129
130
131
132
133
134
135
136
137
138
139
140
# File 'app/controllers/taxon_names_controller.rb', line 127

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



61
62
63
64
65
66
67
# File 'app/controllers/taxon_names_controller.rb', line 61

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

- (Object) download

GET /taxon_names/download



107
108
109
110
111
# File 'app/controllers/taxon_names_controller.rb', line 107

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

- (Object) edit

GET /taxon_names/1/edit



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

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

- (Object) index

GET /taxon_names GET /taxon_names.json



8
9
10
11
# File 'app/controllers/taxon_names_controller.rb', line 8

def index
  @recent_objects = TaxonName.recent_from_project_id(sessions_current_project_id).order(updated_at: :desc).limit(10)
  render '/shared/data/all/index'
end

- (Object) list



102
103
104
# File 'app/controllers/taxon_names_controller.rb', line 102

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

- (Object) new

GET /taxon_names/new



19
20
21
# File 'app/controllers/taxon_names_controller.rb', line 19

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

- (Object) preview_castor_batch_load



142
143
144
145
146
147
148
149
150
151
# File 'app/controllers/taxon_names_controller.rb', line 142

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



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

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) search



69
70
71
72
73
74
75
# File 'app/controllers/taxon_names_controller.rb', line 69

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) set_taxon_name (private)



174
175
176
177
# File 'app/controllers/taxon_names_controller.rb', line 174

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



15
16
# File 'app/controllers/taxon_names_controller.rb', line 15

def show
end

- (Object) taxon_name_params (private)



179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
# File 'app/controllers/taxon_names_controller.rb', line 179

def taxon_name_params
  params.require(:taxon_name).permit(
    :name,
    :parent_id,
    :year_of_publication,
    :etymology,
    :verbatim_author, :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]
  )
end

- (Object) update

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



47
48
49
50
51
52
53
54
55
56
57
# File 'app/controllers/taxon_names_controller.rb', line 47

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