-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathbiological_associations_graphs_controller.rb
112 lines (97 loc) · 4.1 KB
/
biological_associations_graphs_controller.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
class BiologicalAssociationsGraphsController < ApplicationController
include DataControllerConfiguration::ProjectDataControllerConfiguration
before_action :set_biological_associations_graph, only: [:show, :edit, :update, :destroy]
after_action -> { set_pagination_headers(:biological_associations_graphs) }, only: [:index], if: :json_request?
# GET /biological_associations_graphs
# GET /biological_associations_graphs.json
def index
respond_to do |format|
format.html do
@recent_objects = BiologicalAssociationsGraph.recent_from_project_id(sessions_current_project_id).order(updated_at: :desc).limit(10)
render '/shared/data/all/index'
end
format.json {
@biological_associations_graphs = ::Queries::BiologicalAssociationsGraph::Filter.new(params).all
.page(params[:page])
.per(params[:per])
}
end
end
# GET /biological_associations_graphs/1
# GET /biological_associations_graphs/1.json
def show
end
# GET /biological_associations_graphs/new
def new
@biological_associations_graph = BiologicalAssociationsGraph.new(origin_citation: Citation.new)
end
# GET /biological_associations_graphs/1/edit
def edit
# @biological_associations_graph.souce = Source.new if !@taxon_name.source
end
def list
@biological_associations_graphs = BiologicalAssociationsGraph.with_project_id(sessions_current_project_id).order(:id).page(params[:page]) #.per(10)
end
# POST /biological_associations_graphs
# POST /biological_associations_graphs.json
def create
@biological_associations_graph = BiologicalAssociationsGraph.new(biological_associations_graph_params)
respond_to do |format|
if @biological_associations_graph.save
format.html { redirect_to @biological_associations_graph, notice: 'Biological associations graph was successfully created.' }
format.json { render :show, status: :created, location: @biological_associations_graph }
else
format.html { render :new }
format.json { render json: @biological_associations_graph.errors, status: :unprocessable_entity }
end
end
end
# PATCH/PUT /biological_associations_graphs/1
# PATCH/PUT /biological_associations_graphs/1.json
def update
respond_to do |format|
if @biological_associations_graph.update(biological_associations_graph_params)
format.html { redirect_to @biological_associations_graph, notice: 'Biological associations graph was successfully updated.' }
format.json { render :show, status: :ok, location: @biological_associations_graph }
else
format.html { render :edit }
format.json { render json: @biological_associations_graph.errors, status: :unprocessable_entity }
end
end
end
# DELETE /biological_associations_graphs/1
# DELETE /biological_associations_graphs/1.json
def destroy
@biological_associations_graph.destroy
respond_to do |format|
format.html { redirect_to biological_associations_graphs_url, notice: 'Biological associations graph was successfully destroyed.' }
format.json { head :no_content }
end
end
def autocomplete
@biological_associations_graphs = Queries::BiologicalAssociationsGraph::Autocomplete.new(
params.require(:term),
project_id: sessions_current_project_id
).autocomplete
end
# TODO: remove!
def search
if params[:id].blank?
redirect_to biological_associations_graphs_path, alert: 'You must select an item from the list with a click or tab press before clicking show.'
else
redirect_to biological_associations_graph_path(params[:id])
end
end
private
def set_biological_associations_graph
@biological_associations_graph = BiologicalAssociationsGraph.where(project_id: sessions_current_project_id).find(params[:id])
end
def biological_associations_graph_params
params.require(:biological_associations_graph).permit(
:name,
:layout,
origin_citation_attributes: [:id, :_destroy, :source_id, :pages] ,
biological_associations_biological_associations_graphs_attributes: [:id, :_destroy, :biological_association_id]
)
end
end