Class: ObservationsController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- ObservationsController
- Defined in:
- app/controllers/observations_controller.rb
Constant Summary
Constants included from ProjectsHelper
ProjectsHelper::CLASSIFIER, ProjectsHelper::CLASSIFIER_ANNOTATION
Instance Method Summary collapse
-
#annotations ⇒ Object
GET /annotations.
- #api_index ⇒ Object
- #api_show ⇒ Object
-
#code_column ⇒ Object
POST /observations/code_column.json?observation_matrix_column_id=123&observation_matrix_id=456&<observation params>.
-
#create ⇒ Object
POST /observations POST /observations.json.
-
#destroy ⇒ Object
DELETE /observations/1 DELETE /observations/1.json.
-
#destroy_column ⇒ Object
DELETE /observations/destroy_column.json?observation_matrix_column_id=123.
-
#destroy_row ⇒ Object
DELETE /observations/destroy_row.json?observation_matrix_row_id=123.
-
#edit ⇒ Object
GET /observations/1/edit.
-
#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 RedirectHelper
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
#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
Methods included from TokenAuthentication
#intercept_project, #intercept_user, #intercept_user_or_project, #project_token_authenticate, #token_authenticate
Instance Method Details
#annotations ⇒ Object
GET /annotations
133 134 135 136 |
# File 'app/controllers/observations_controller.rb', line 133 def annotations @object = @observation render '/shared/data/all/annotations' end |
#api_index ⇒ Object
26 27 28 29 30 31 32 33 |
# File 'app/controllers/observations_controller.rb', line 26 def api_index @observations = Queries::Observation::Filter.new(params.merge!(api: true)).all .with_project_id(sessions_current_project_id) .page(params[:page]) .per(params[:per]) render '/observations/api/v1/index' end |
#api_show ⇒ Object
35 36 37 38 |
# File 'app/controllers/observations_controller.rb', line 35 def api_show @observation = Observation.where(project_id: sessions_current_project_id).find(params[:id]) render '/observations/api/v1/show' end |
#code_column ⇒ Object
POST /observations/code_column.json?observation_matrix_column_id=123&observation_matrix_id=456&<observation params>
126 127 128 129 130 |
# File 'app/controllers/observations_controller.rb', line 126 def code_column if o = ObservationMatrixColumn.where(project_id: sessions_current_project_id).find(params[:observation_matrix_column_id]) render json: Observation.code_column(params[:observation_matrix_column_id], observation_params ) end end |
#create ⇒ Object
POST /observations POST /observations.json
60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'app/controllers/observations_controller.rb', line 60 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
92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'app/controllers/observations_controller.rb', line 92 def destroy @observation.destroy respond_to do |format| if @observation.destroyed? format.html { destroy_redirect @observation, notice: 'Observation was successfully destroyed.' } format.json { head :no_content} else format.html { destroy_redirect @observation, notice: 'Observation was not destroyed, ' + @observation.errors..join('; ') } format.json { render json: @observation.errors, status: :unprocessable_entity } end end end |
#destroy_column ⇒ Object
DELETE /observations/destroy_column.json?observation_matrix_column_id=123
116 117 118 119 120 121 122 123 |
# File 'app/controllers/observations_controller.rb', line 116 def destroy_column @observation_matrix_column = ObservationMatrixColumn.where(project_id: sessions_current_project_id).find(params.require(:observation_matrix_column_id)) if Observation.destroy_column(@observation_matrix_column.id) render json: {success: true} else render json: {success: false} end end |
#destroy_row ⇒ Object
DELETE /observations/destroy_row.json?observation_matrix_row_id=123
106 107 108 109 110 111 112 113 |
# File 'app/controllers/observations_controller.rb', line 106 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
51 52 |
# File 'app/controllers/observations_controller.rb', line 51 def edit end |
#index ⇒ Object
GET /observations GET /observations.json
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'app/controllers/observations_controller.rb', line 9 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(params) .all .where(project_id: sessions_current_project_id) .page(params[:page]) .per(params[:per]) } end end |
#list ⇒ Object
54 55 56 |
# File 'app/controllers/observations_controller.rb', line 54 def list @observations = Observation.with_project_id(sessions_current_project_id).page(params[:page]) end |
#new ⇒ Object
GET /observations/new
46 47 48 |
# File 'app/controllers/observations_controller.rb', line 46 def new @observation = Observation.new end |
#observation_params ⇒ Object (private)
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 |
# File 'app/controllers/observations_controller.rb', line 144 def observation_params params.require(:observation).permit( :character_state_id, :frequency, :continuous_value, :continuous_unit, :day_made, :day_made, :description, :descriptor_id, :month_made, :month_made, :observation_object_global_id, :observation_object_type, :observation_object_id, :presence, :sample_n, :sample_min, :sample_max, :sample_median, :sample_mean, :sample_units, :sample_standard_deviation, :sample_standard_error, :time_made, :time_made, :type, :year_made, :year_made, 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)
140 141 142 |
# File 'app/controllers/observations_controller.rb', line 140 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
42 43 |
# File 'app/controllers/observations_controller.rb', line 42 def show end |
#update ⇒ Object
PATCH/PUT /observations/1 PATCH/PUT /observations/1.json
77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'app/controllers/observations_controller.rb', line 77 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 |