Class: TaxonNameClassificationsController

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



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'app/controllers/taxon_name_classifications_controller.rb', line 91

def autocomplete
  # TODO: make reasonable, if used
  @taxon_name_classifications = TaxonNameClassification.where(id: params[:term]).with_project_id(params[:project_id])
  data                        = @taxon_name_classifications.collect do |t|
    {id:              t.id,
     label:           TaxonNameClassificationsHelper.taxon_name_classification_tag(t),
     response_values: {
       params[:method] => t.id
     },
     label_html:      TaxonNameClassificationsHelper.taxon_name_classification_tag(t) #  render_to_string(:partial => 'shared/autocomplete/taxon_name.html', :object => t)
    }
  end

  render :json => data
end

- (Object) create

POST /taxon_name_classifications POST /taxon_name_classifications.json



26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'app/controllers/taxon_name_classifications_controller.rb', line 26

def create
  @taxon_name_classification = TaxonNameClassification.new(taxon_name_classification_params)

  respond_to do |format|
    if @taxon_name_classification.save
      format.html {redirect_to @taxon_name_classification.taxon_name.metamorphosize, notice: 'Taxon name classification was successfully created.'}
      format.json { render :show, status: :created, location: @taxon_name_classification.metamorphosize }
    else
      format.html {redirect_back(fallback_location: (request.referer || root_path), notice: 'Taxon name classification was NOT successfully created.')}
      format.json {render json: @taxon_name_classification.errors, status: :unprocessable_entity}
    end
  end
end

- (Object) destroy

DELETE /taxon_name_classifications/1 DELETE /taxon_name_classifications/1.json



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

def destroy
  @taxon_name_classification.destroy
  respond_to do |format|
    format.html {redirect_back(fallback_location: (request.referer || root_path), notice: 'Taxon name classification was successfully destroyed.')}
    format.json {head :no_content}
  end
end

- (Object) download

GET /taxon_name_classifications/download



108
109
110
# File 'app/controllers/taxon_name_classifications_controller.rb', line 108

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

- (Object) filter_params (private)



118
119
120
# File 'app/controllers/taxon_name_classifications_controller.rb', line 118

def filter_params
  params.permit(:taxon_name_id)
end

- (Object) index

GET /taxon_name_relationships GET /taxon_name_relationships.json



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

def index
  respond_to do |format|
    format.html do
      @recent_objects = TaxonNameClassification.recent_from_project_id(sessions_current_project_id).order(updated_at: :desc).limit(10)
      render '/shared/data/all/index'
    end
    format.json {
      @taxon_name_classifications = TaxonNameClassification.where(filter_params).with_project_id(sessions_current_project_id)
    }
  end
end

- (Object) list



78
79
80
# File 'app/controllers/taxon_name_classifications_controller.rb', line 78

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

- (Object) new



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

def new
  taxon_name_id = params[:taxon_name_classification].try(:[], :taxon_name_id)

  taxon_name = TaxonName.where(
    id:         taxon_name_id,
    project_id: sessions_current_project_id
  ).first

  @taxon_name_classification = TaxonNameClassification.new(
    taxon_name: taxon_name ? taxon_name : TaxonName.new()
  )
end

- (Object) search

GET /taxon_name_classifications/search



83
84
85
86
87
88
89
# File 'app/controllers/taxon_name_classifications_controller.rb', line 83

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

- (Object) set_taxon_name_classification (private)



122
123
124
# File 'app/controllers/taxon_name_classifications_controller.rb', line 122

def set_taxon_name_classification
  @taxon_name_classification = TaxonNameClassification.with_project_id(sessions_current_project_id).find(params[:id])
end

- (Object) show

GET /taxon_name_relationships/:id.json



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

def show
end

- (Object) taxon_name_classification_params (private)



126
127
128
129
130
# File 'app/controllers/taxon_name_classifications_controller.rb', line 126

def taxon_name_classification_params
  params.require(:taxon_name_classification).permit(
    :taxon_name_id, :type,
    origin_citation_attributes: [:id, :_destroy, :source_id, :pages])
end

- (Object) taxon_name_classification_types



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

def taxon_name_classification_types
  render json: TAXON_NAME_CLASSIFICATION_JSON
end

- (Object) update

PATCH/PUT /taxon_name_classifications/1 PATCH/PUT /taxon_name_classifications/1.json



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

def update
  respond_to do |format|
    if @taxon_name_classification.update(taxon_name_classification_params)
      @taxon_name_classification.reload
      format.html {redirect_back(fallback_location: (request.referer || root_path), notice: 'Taxon name classification was successfully updated.')}
      format.json { render :show, status: :ok, location: @taxon_name_classification.metamorphosize }
    else
      format.html {redirect_back(fallback_location: (request.referer || root_path), notice: 'Taxon name classification was NOT successfully updated.')}
      format.json {render json: @taxon_name_classification.errors, status: :unprocessable_entity}
    end
  end
end