Class: BiologicalRelationshipsController

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



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'app/controllers/biological_relationships_controller.rb', line 20

def api_index
  q =  BiologicalRelationship
    .where(project_id: sessions_current_project_id)
    .order(:name)

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

#autocompleteObject



107
108
109
# File 'app/controllers/biological_relationships_controller.rb', line 107

def autocomplete
  @biological_relationships = Queries::BiologicalRelationship::Autocomplete.new( params.require(:term), project_id: sessions_current_project_id).all
end

#biological_relationship_paramsObject (private)



121
122
123
124
125
126
127
# File 'app/controllers/biological_relationships_controller.rb', line 121

def biological_relationship_params
  params.require(:biological_relationship).permit(
    :name, :inverted_name, :is_transitive, :is_reflexive, :definition,
    biological_relationship_types_attributes: [:id, :_destroy, :type, :biological_property_id],
    origin_citation_attributes: [:id, :_destroy, :source_id, :pages]
  )
end

#createObject

POST /biological_relationships POST /biological_relationships.json



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

def create
  @biological_relationship = BiologicalRelationship.new(biological_relationship_params)

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

#destroyObject

DELETE /biological_relationships/1 DELETE /biological_relationships/1.json



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

def destroy
  @biological_relationship.destroy
  respond_to do |format|
    format.html { redirect_to biological_relationships_url, notice: 'Biological relationship was successfully destroyed.' }
    format.json { head :no_content }
  end
end

#editObject

GET /biological_relationships/1/edit



52
53
# File 'app/controllers/biological_relationships_controller.rb', line 52

def edit
end

#indexObject

GET /biological_relationships GET /biological_relationships.json



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

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

#listObject



55
56
57
# File 'app/controllers/biological_relationships_controller.rb', line 55

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

#newObject

GET /biological_relationships/new



47
48
49
# File 'app/controllers/biological_relationships_controller.rb', line 47

def new
  @biological_relationship = BiologicalRelationship.new
end

#searchObject



99
100
101
102
103
104
105
# File 'app/controllers/biological_relationships_controller.rb', line 99

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

#select_optionsObject



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

def select_options
  @biological_relationships = BiologicalRelationship.select_optimized(sessions_current_user_id, sessions_current_project_id)
end

#set_biological_relationshipObject (private)



117
118
119
# File 'app/controllers/biological_relationships_controller.rb', line 117

def set_biological_relationship
  @biological_relationship = BiologicalRelationship.where(project_id: sessions_current_project_id).find(params[:id])
end

#showObject

GET /biological_relationships/1 GET /biological_relationships/1.json



43
44
# File 'app/controllers/biological_relationships_controller.rb', line 43

def show
end

#updateObject

PATCH/PUT /biological_relationships/1 PATCH/PUT /biological_relationships/1.json



77
78
79
80
81
82
83
84
85
86
87
# File 'app/controllers/biological_relationships_controller.rb', line 77

def update
  respond_to do |format|
    if @biological_relationship.update(biological_relationship_params)
      format.html { redirect_to @biological_relationship, notice: 'Biological relationship was successfully updated.' }
      format.json { render :show, status: :ok, location: @biological_relationship }
    else
      format.html { render :edit }
      format.json { render json: @biological_relationship.errors, status: :unprocessable_entity }
    end
  end
end