Class: TaxonNameRelationshipsController

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



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

def autocomplete
  @taxon_name_relationships = TaxonNameRelationship.find_for_autocomplete(params.merge(project_id: sessions_current_project_id))
  data = @taxon_name_relationships.collect do |t|
    n = ApplicationController.helpers.taxon_name_relationship_tag(t)
    {id: t.id,
     label: n,
     response_values: {
         params[:method] => t.id
     },
     label_html: n
    }
  end

  render :json => data
end

- (Object) create

POST /taxon_name_relationships POST /taxon_name_relationships.json



37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'app/controllers/taxon_name_relationships_controller.rb', line 37

def create
  @taxon_name_relationship = TaxonNameRelationship.new(taxon_name_relationship_params)

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

- (Object) destroy

DELETE /taxon_name_relationships/1 DELETE /taxon_name_relationships/1.json



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

def destroy
  @taxon_name_relationship.destroy
  respond_to do |format|
    format.html { redirect_to taxon_name_relationships_url, notice: 'Taxon name relationship was successfully destroyed.' }
    format.json { head :no_content }
  end
end

- (Object) download

GET /taxon_name_relationships/download



106
107
108
# File 'app/controllers/taxon_name_relationships_controller.rb', line 106

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

- (Object) edit

GET /taxon_name_relationships/1/edit



31
32
33
# File 'app/controllers/taxon_name_relationships_controller.rb', line 31

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

- (Object) filter_sql (private)



132
133
134
135
# File 'app/controllers/taxon_name_relationships_controller.rb', line 132

def filter_sql
    h = params.permit(:taxon_name_id, :as_object, :as_subject, of_type: []).to_h.symbolize_keys
    Queries::TaxonNameRelationshipsFilterQuery.new(h).where_sql
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_relationships_controller.rb', line 8

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

- (Object) list



76
77
78
# File 'app/controllers/taxon_name_relationships_controller.rb', line 76

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

- (Object) new

GET /taxon_name_relationships/new



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

def new
  @taxon_name_relationship = TaxonNameRelationship.new
end

- (Object) search

GET /taxon_name_relationships/search



81
82
83
84
85
86
87
# File 'app/controllers/taxon_name_relationships_controller.rb', line 81

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

- (Object) set_taxon_name_relationship (private)



121
122
123
# File 'app/controllers/taxon_name_relationships_controller.rb', line 121

def set_taxon_name_relationship
  @taxon_name_relationship = TaxonNameRelationship.with_project_id(sessions_current_project_id).find(params[:id])
end

- (Object) show

GET /taxon_name_relationships/1 GET /taxon_name_relationships/1.json



22
23
# File 'app/controllers/taxon_name_relationships_controller.rb', line 22

def show
end

- (Object) taxon_name_relationship_params (private)



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

def taxon_name_relationship_params
  params.require(:taxon_name_relationship).permit(
    :subject_taxon_name_id, :object_taxon_name_id, :type,
    origin_citation_attributes: [:id, :_destroy, :source_id, :pages] 
  ) 
end

- (Object) taxon_name_relationship_types

GET /taxon_name_relationships/taxon_name_relationship_types



116
117
118
# File 'app/controllers/taxon_name_relationships_controller.rb', line 116

def taxon_name_relationship_types
  render json: TAXON_NAME_RELATIONSHIPS_JSON
end

- (Object) type_relationships

GET /taxon_name_relationships/type_relationships



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

def type_relationships
  render json: TAXON_NAME_RELATIONSHIPS_TYPE_JSON
end

- (Object) update

PATCH/PUT /taxon_name_relationships/1 PATCH/PUT /taxon_name_relationships/1.json



53
54
55
56
57
58
59
60
61
62
63
64
# File 'app/controllers/taxon_name_relationships_controller.rb', line 53

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