Class: TaxonNameRelationshipsController

Inherits:
ApplicationController show all
Includes:
DataControllerConfiguration::ProjectDataControllerConfiguration
Defined in:
app/controllers/taxon_name_relationships_controller.rb

Constant Summary

Constants included from ProjectsHelper

ProjectsHelper::CLASSIFIER, ProjectsHelper::CLASSIFIER_ANNOTATION

Instance Method Summary collapse

Methods included from DataControllerConfiguration::ProjectDataControllerConfiguration

#annotator_params

Methods included from RedirectHelper

#destroy_redirect

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

#cumulative_gb_per_year, #document_cumulative_gb_per_year, #document_gb_per_year, #gb_per_year, #image_cumulative_gb_per_year, #image_gb_per_year, #invalid_object, #project_classification, #project_link, #project_matches, #project_tag, #projects_list, #projects_search_form, #taxonworks_classification, #week_in_review_graphs

Methods included from Api::Intercept

#intercept_api

Methods included from TokenAuthentication

#intercept_project, #intercept_user, #intercept_user_or_project, #project_token_authenticate, #token_authenticate

Instance Method Details

#api_indexObject

GET /api/v1/taxon_name_relationships



119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# File 'app/controllers/taxon_name_relationships_controller.rb', line 119

def api_index
  q = Queries::TaxonNameRelationship::Filter.new(params.merge!(api: true)).all
    .where(project_id: sessions_current_project_id)
    .order('taxon_name_relationships.id')

  respond_to do |format|
    format.json {
      @taxon_name_relationships = q.all.page(params[:page]).per(params[:per])
      render '/taxon_name_relationships/api/v1/index'
    }
    format.csv {
      @taxon_name_relationships = q
      send_data Export::CSV.generate_csv(
        @taxon_name_relationships,
        exclude_columns: %w{updated_by_id created_by_id project_id},
      ), type: 'text', filename: "taxon_names_relationships_#{DateTime.now}.tsv"
    }
  end
end

#api_showObject

GET /api/v1/taxon_name_relationships/:id



140
141
142
# File 'app/controllers/taxon_name_relationships_controller.rb', line 140

def api_show
  render '/taxon_name_relationships/api/v1/show'
end

#createObject

POST /taxon_name_relationships POST /taxon_name_relationships.json



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

def create
  @taxon_name_relationship = TaxonNameRelationship.new(taxon_name_relationship_params)

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

#destroyObject

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



73
74
75
76
77
78
79
80
81
82
83
84
# File 'app/controllers/taxon_name_relationships_controller.rb', line 73

def destroy
  @taxon_name_relationship.destroy
  respond_to do |format|
    if @taxon_name_relationship.destroyed?
      format.html { destroy_redirect @taxon_name_relationship, notice: 'Taxon name relationship was successfully destroyed.' }
      format.json { head :no_content}
    else
      format.html { destroy_redirect @taxon_name_relationship, notice: 'Taxon name relationship was not destroyed, ' + @taxon_name_relationship.errors.full_messages.join('; ') }
      format.json { render json: @taxon_name_relationship.errors, status: :unprocessable_entity }
    end
  end
end

#downloadObject

GET /taxon_name_relationships/download



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

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

#editObject

GET /taxon_name_relationships/1/edit



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

def edit
end

#indexObject

GET /taxon_name_relationships GET /taxon_name_relationships.json



9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'app/controllers/taxon_name_relationships_controller.rb', line 9

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 = Queries::TaxonNameRelationship::Filter.new(params).all
        .page(params[:page])
        .per(params[:per])
    }
  end
end

#listObject



86
87
88
89
# File 'app/controllers/taxon_name_relationships_controller.rb', line 86

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

#newObject

GET /taxon_name_relationships/new



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

def new
  @taxon_name_relationship = TaxonNameRelationship.new
end

#searchObject

GET /taxon_name_relationships/search



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

def search
  if params[:id].blank?
    redirect_to taxon_name_relationship_path,
      alert: '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

#set_taxon_name_relationshipObject (private)



146
147
148
# File 'app/controllers/taxon_name_relationships_controller.rb', line 146

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

#showObject

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



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

def show
end

#taxon_name_relationship_paramsObject (private)



150
151
152
153
154
155
# File 'app/controllers/taxon_name_relationships_controller.rb', line 150

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

#taxon_name_relationship_typesObject

GET /api/v1//taxon_name_relationships/taxon_name_relationship_types GET /taxon_name_relationships/taxon_name_relationship_types



114
115
116
# File 'app/controllers/taxon_name_relationships_controller.rb', line 114

def taxon_name_relationship_types
  render json: TAXON_NAME_RELATIONSHIPS_JSON
end

#type_relationshipsObject

GET /taxon_name_relationships/type_relationships



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

def type_relationships
  render json: TAXON_NAME_RELATIONSHIPS_TYPE_JSON
end

#updateObject

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



57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'app/controllers/taxon_name_relationships_controller.rb', line 57

def update
  respond_to do |format|
    if @taxon_name_relationship.update(taxon_name_relationship_params)
      @taxon_name_relationship = TaxonNameRelationship.find(@taxon_name_relationship.id) # reset class
      format.html { redirect_to url_for(@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