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, #whitelist_constantize

Methods included from ProjectsHelper

#project_link, #project_tag, #projects_list, #projects_search_form

Instance Method Details

- (Object) autocomplete



101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'app/controllers/taxon_name_classifications_controller.rb', line 101

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



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

def create
  @taxon_name_classification = TaxonNameClassification.new(taxon_name_classification_params)

  respond_to do |format|
    if @taxon_name_classification.save
      format.html { redirect_to url_for(@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



76
77
78
79
80
81
82
83
# File 'app/controllers/taxon_name_classifications_controller.rb', line 76

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



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

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

- (Object) filter_params (private)



130
131
132
# File 'app/controllers/taxon_name_classifications_controller.rb', line 130

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
19
20
# 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



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

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

- (Object) new



61
62
63
64
65
66
67
68
69
70
71
72
# File 'app/controllers/taxon_name_classifications_controller.rb', line 61

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



91
92
93
94
95
96
97
98
99
# File 'app/controllers/taxon_name_classifications_controller.rb', line 91

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)



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

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



23
24
# File 'app/controllers/taxon_name_classifications_controller.rb', line 23

def show
end

- (Object) taxon_name_classification_params (private)



138
139
140
141
142
# File 'app/controllers/taxon_name_classifications_controller.rb', line 138

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



124
125
126
# File 'app/controllers/taxon_name_classifications_controller.rb', line 124

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



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

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