Class: TaxonDeterminationsController

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

#autocompleteObject



87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'app/controllers/taxon_determinations_controller.rb', line 87

def autocomplete
  @taxon_determinations = taxon_determination.find_for_autocomplete(params.merge(project_id: sessions_current_project_id))
  data = @taxon_determinations.collect do |t|
    {id: t.id,
     label: TaxonDeterminationsHelper.taxon_determination_tag(t),
     response_values: {
         params[:method] => t.id
     },
     label_html: TaxonDeterminationsHelper.taxon_determination_tag(t) #  render_to_string(:partial => 'shared/autocomplete/taxon_name.html', :object => t)
    }
  end

  render json: data
end

#createObject

POST /taxon_determinations POST /taxon_determinations.json



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

def create
  @taxon_determination = TaxonDetermination.new(taxon_determination_params)

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

#destroyObject

DELETE /taxon_determinations/1 DELETE /taxon_determinations/1.json



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

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

#downloadObject

GET /taxon_determinations/download



103
104
105
106
107
# File 'app/controllers/taxon_determinations_controller.rb', line 103

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

#editObject

GET /taxon_determinations/1/edit



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

def edit
end

#filter_paramsObject (private)



123
124
125
# File 'app/controllers/taxon_determinations_controller.rb', line 123

def filter_params
  params.permit(:collection_object_id, otu_ids: [], determiner_ids: [], biological_collection_object_ids: [])
end

#indexObject

GET /taxon_determinations GET /taxon_determinations.json



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

def index
  respond_to do |format|
    format.html {
      @recent_objects = TaxonDetermination.recent_from_project_id(sessions_current_project_id).order(updated_at: :desc).limit(10)
      render '/shared/data/all/index'
    }
    format.json {
      @taxon_determinations = Queries::TaxonDetermination::Filter.new(filter_params).all.with_project_id(sessions_current_project_id).page(params[:page]).per(params[:per] || 500)
    }
  end
end

#listObject



20
21
22
# File 'app/controllers/taxon_determinations_controller.rb', line 20

def list
  @taxon_determinations = TaxonDetermination.with_project_id(sessions_current_project_id).order(:id).page(params[:page]) #.per(10) #.per(3)
end

#newObject

GET /taxon_determinations/new



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

def new
  @taxon_determination = TaxonDetermination.new
end

#searchObject

GET /taxon_determinations/search



79
80
81
82
83
84
85
# File 'app/controllers/taxon_determinations_controller.rb', line 79

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

#set_taxon_determinationObject (private)



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

def set_taxon_determination
  @taxon_determination = TaxonDetermination.with_project_id(sessions_current_project_id).find(params[:id])
  @recent_object = @taxon_determination
end

#showObject

GET /taxon_determinations/1 GET /taxon_determinations/1.json



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

def show
end

#taxon_determination_paramsObject (private)



115
116
117
118
119
120
121
# File 'app/controllers/taxon_determinations_controller.rb', line 115

def taxon_determination_params
  params.require(:taxon_determination).permit(
    :biological_collection_object_id, :otu_id, :year_made, :month_made, :day_made, :position,
    roles_attributes: [:id, :_destroy, :type, :person_id, :position, person_attributes: [:last_name, :first_name, :suffix, :prefix]],
    otu_attributes: [:id, :_destroy, :name, :taxon_name_id]
  )
end

#updateObject

PATCH/PUT /taxon_determinations/1 PATCH/PUT /taxon_determinations/1.json



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

def update
  respond_to do |format|
    if @taxon_determination.update(taxon_determination_params)
      format.html { redirect_to @taxon_determination, notice: 'Taxon determination was successfully updated.' }
      format.json { render action: 'show', status: :created, location: @taxon_determination }
    else
      format.html { render action: 'edit' }
      format.json { render json: @taxon_determination.errors, status: :unprocessable_entity }
    end
  end
end