Class: ObservationsController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- ObservationsController
- Defined in:
- app/controllers/observations_controller.rb
Instance Method Summary collapse
-
#annotations ⇒ Object
GET /annotations.
- #api_index ⇒ Object
- #api_params ⇒ Object private
- #api_show ⇒ Object
-
#create ⇒ Object
POST /observations POST /observations.json.
-
#destroy ⇒ Object
DELETE /observations/1 DELETE /observations/1.json.
-
#destroy_row ⇒ Object
DELETE /observations/destroy_row.json?observation_matrix_row_id=123.
-
#edit ⇒ Object
GET /observations/1/edit.
- #filter_params ⇒ Object private
-
#index ⇒ Object
GET /observations GET /observations.json.
- #list ⇒ Object
-
#new ⇒ Object
GET /observations/new.
- #observation_params ⇒ Object private
- #set_observation ⇒ Object private
-
#show ⇒ Object
GET /observations/1 GET /observations/1.json.
-
#update ⇒ Object
PATCH/PUT /observations/1 PATCH/PUT /observations/1.json.
Methods included from DataControllerConfiguration::ProjectDataControllerConfiguration
Methods included from RequestType
Methods included from LogRecent
Methods included from Cookies
#digest_cookie, #digested_cookie_exists?
Methods included from Whitelist
Methods included from ProjectsHelper
#invalid_object, #project_link, #project_matches, #project_tag, #projects_list, #projects_search_form
Methods included from Api::Intercept
Methods included from TokenAuthentication
#intercept_project, #intercept_user, #intercept_user_or_project, #project_token_authenticate, #token_authenticate
Instance Method Details
#annotations ⇒ Object
GET /annotations
104 105 106 107 |
# File 'app/controllers/observations_controller.rb', line 104 def annotations @object = @observation render '/shared/data/all/annotations' end |
#api_index ⇒ Object
23 24 25 26 |
# File 'app/controllers/observations_controller.rb', line 23 def api_index @observations = Queries::Observation::Filter.new(api_params).all.with_project_id(sessions_current_project_id) render '/observations/api/index.json.jbuilder' end |
#api_params ⇒ Object (private)
143 144 145 |
# File 'app/controllers/observations_controller.rb', line 143 def api_params params.permit(:otu_id, :descriptor_id, :collection_object_id, :observation_object_global_id).to_h end |
#api_show ⇒ Object
28 29 30 31 |
# File 'app/controllers/observations_controller.rb', line 28 def api_show @observation = Observation.where(project_id: sessions_current_project_id).find(params[:id]) render '/observations/api/show.json.jbuilder' end |
#create ⇒ Object
POST /observations POST /observations.json
53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'app/controllers/observations_controller.rb', line 53 def create @observation = Observation.new(observation_params) respond_to do |format| if @observation.save format.html { redirect_to observation_path(@observation.), notice: 'Observation was successfully created.' } format.json { render :show, status: :created, location: @observation. } else format.html { render :new } format.json { render json: @observation..errors, status: :unprocessable_entity } end end end |
#destroy ⇒ Object
DELETE /observations/1 DELETE /observations/1.json
85 86 87 88 89 90 91 |
# File 'app/controllers/observations_controller.rb', line 85 def destroy @observation.destroy! respond_to do |format| format.html { redirect_to observations_url, notice: 'Observation was successfully destroyed.' } format.json { head :no_content } end end |
#destroy_row ⇒ Object
DELETE /observations/destroy_row.json?observation_matrix_row_id=123
94 95 96 97 98 99 100 101 |
# File 'app/controllers/observations_controller.rb', line 94 def destroy_row @observation_matrix_row = ObservationMatrixRow.where(project_id: sessions_current_project_id).find(params.require(:observation_matrix_row_id)) if Observation.destroy_row(@observation_matrix_row.id) render json: {success: true} else render json: {success: false} end end |
#edit ⇒ Object
GET /observations/1/edit
44 45 |
# File 'app/controllers/observations_controller.rb', line 44 def edit end |
#filter_params ⇒ Object (private)
139 140 141 |
# File 'app/controllers/observations_controller.rb', line 139 def filter_params params.permit(:otu_id, :descriptor_id, :collection_object_id, :observation_object_global_id, :token, :project_token, :format, :authenticate_user_or_project) end |
#index ⇒ Object
GET /observations GET /observations.json
10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'app/controllers/observations_controller.rb', line 10 def index respond_to do |format| format.html do @recent_objects = Observation.recent_from_project_id(sessions_current_project_id) .order(updated_at: :desc).limit(10) render '/shared/data/all/index' end format.json { @observations = Queries::Observation::Filter.new(filter_params).all.with_project_id(sessions_current_project_id) } end end |
#list ⇒ Object
47 48 49 |
# File 'app/controllers/observations_controller.rb', line 47 def list @observations = Observation.with_project_id(sessions_current_project_id).page(params[:page]) end |
#new ⇒ Object
GET /observations/new
39 40 41 |
# File 'app/controllers/observations_controller.rb', line 39 def new @observation = Observation.new end |
#observation_params ⇒ Object (private)
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'app/controllers/observations_controller.rb', line 115 def observation_params params.require(:observation).permit( :observation_object_global_id, :descriptor_id, :otu_id, :collection_object_id, :character_state_id, :frequency, :continuous_value, :continuous_unit, :sample_n, :sample_min, :sample_max, :sample_median, :sample_mean, :sample_units, :sample_standard_deviation, :sample_standard_error, :presence, :description, :type, images_attributes: [:id, :_destroy, :image_file, :rotate], depictions_attributes: [ :id, :_destroy, :depiction_object_id, :depiction_object_type, :annotated_global_entity, :caption, :is_metadata_depiction, :image_id, :figure_label, image_attributes: [:image_file] ] ) end |
#set_observation ⇒ Object (private)
111 112 113 |
# File 'app/controllers/observations_controller.rb', line 111 def set_observation @observation = Observation.where(project_id: sessions_current_project_id).find(params[:id]) end |
#show ⇒ Object
GET /observations/1 GET /observations/1.json
35 36 |
# File 'app/controllers/observations_controller.rb', line 35 def show end |
#update ⇒ Object
PATCH/PUT /observations/1 PATCH/PUT /observations/1.json
70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'app/controllers/observations_controller.rb', line 70 def update respond_to do |format| if @observation.update(observation_params) format.html { redirect_to url_for(@observation.), notice: 'Observation was successfully updated.' } format.json { render :show, status: :ok, location: @observation. } else format.html { render :edit } format.json { render json: @observation..errors, status: :unprocessable_entity } end end end |