Class: BiologicalAssociationsController

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

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 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



95
96
97
98
99
100
101
102
# File 'app/controllers/biological_associations_controller.rb', line 95

def api_index
  @biological_associations = Queries::BiologicalAssociation::Filter.new(params.merge!(api: true)).all
    .where(project_id: sessions_current_project_id)
    .order('biological_associations.id')
    .page(params[:page])
    .per(params[:per])
  render '/biological_associations/api/v1/index'
end

#api_showObject



91
92
93
# File 'app/controllers/biological_associations_controller.rb', line 91

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

#biological_association_paramsObject (private)



110
111
112
113
114
115
116
117
118
119
# File 'app/controllers/biological_associations_controller.rb', line 110

def biological_association_params
  params.require(:biological_association).permit(
    :biological_relationship_id, :biological_association_subject_id, :biological_association_subject_type,
    :biological_association_object_id, :biological_association_object_type,
    :subject_global_id,
    :object_global_id,
    origin_citation_attributes: [:id, :_destroy, :source_id, :pages],
    citations_attributes: [:id, :is_original, :_destroy, :source_id, :pages, :citation_object_id, :citation_object_type],
  )
end

#createObject

POST /biological_associations POST /biological_associations.json



45
46
47
48
49
50
51
52
53
54
55
56
# File 'app/controllers/biological_associations_controller.rb', line 45

def create
  @biological_association = BiologicalAssociation.new(biological_association_params)
  respond_to do |format|
    if @biological_association.save
      format.html { redirect_to @biological_association, notice: 'Biological association was successfully created.' }
      format.json { render :show, status: :created, location: @biological_association }
    else
      format.html { render :new }
      format.json { render json: @biological_association.errors, status: :unprocessable_entity }
    end
  end
end

#destroyObject

DELETE /biological_associations/1 DELETE /biological_associations/1.json



74
75
76
77
78
79
80
# File 'app/controllers/biological_associations_controller.rb', line 74

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

#editObject

GET /biological_associations/1/edit



36
37
# File 'app/controllers/biological_associations_controller.rb', line 36

def edit
end

#indexObject

GET /biological_associations GET /biological_associations.json



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

def index
  respond_to do |format|
    format.html {
      @recent_objects = BiologicalAssociation.recent_from_project_id(sessions_current_project_id).order(updated_at: :desc).limit(10)
      render '/shared/data/all/index'
    }
    format.json {
      @biological_associations = Queries::BiologicalAssociation::Filter.new(params)
        .all
        .where(project_id: sessions_current_project_id)
        .page(params[:page])
        .per(params[:per])
    }
  end
end

#listObject



39
40
41
# File 'app/controllers/biological_associations_controller.rb', line 39

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

#newObject

GET /biological_associations/new



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

def new
  @biological_association = BiologicalAssociation.new
end

#searchObject



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

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

#set_biological_associationObject (private)



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

def set_biological_association
  @biological_association = BiologicalAssociation.where(project_id: sessions_current_project_id).find(params[:id])
end

#showObject

GET /biological_associations/1 GET /biological_associations/1.json



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

def show
end

#updateObject

PATCH/PUT /biological_associations/1 PATCH/PUT /biological_associations/1.json



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

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