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
- #autocomplete ⇒ 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
- #navigation ⇒ Object
-
#new ⇒ Object
GET /observations/new.
- #observation_params ⇒ Object private
- #select_options ⇒ Object
- #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, #cumulative_projects_created_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, #sound_cumulative_gb_per_year, #sound_gb_per_year, #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
134 135 136 137 |
# File 'app/controllers/observations_controller.rb', line 134 def annotations @object = @observation render '/shared/data/all/annotations' end |
#api_index ⇒ Object
27 28 29 30 31 32 33 34 |
# File 'app/controllers/observations_controller.rb', line 27 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
36 37 38 39 |
# File 'app/controllers/observations_controller.rb', line 36 def api_show @observation = Observation.where(project_id: sessions_current_project_id).find(params[:id]) render '/observations/api/v1/show' end |
#autocomplete ⇒ Object
139 140 141 142 143 144 |
# File 'app/controllers/observations_controller.rb', line 139 def autocomplete @observations = Queries::Observation::Autocomplete.new( params[:term], project_id: sessions_current_project_id, polymorphic_types: params[:polymorphic_types_allowed] ).autocomplete end |
#code_column ⇒ Object
POST /observations/code_column.json?observation_matrix_column_id=123&observation_matrix_id=456&<observation params>
127 128 129 130 131 |
# File 'app/controllers/observations_controller.rb', line 127 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
61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'app/controllers/observations_controller.rb', line 61 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
93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'app/controllers/observations_controller.rb', line 93 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
117 118 119 120 121 122 123 124 |
# File 'app/controllers/observations_controller.rb', line 117 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
107 108 109 110 111 112 113 114 |
# File 'app/controllers/observations_controller.rb', line 107 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
52 53 |
# File 'app/controllers/observations_controller.rb', line 52 def edit end |
#index ⇒ Object
GET /observations GET /observations.json
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# 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(params) .all .where(project_id: sessions_current_project_id) .page(params[:page]) .per(params[:per]) } end end |
#list ⇒ Object
55 56 57 |
# File 'app/controllers/observations_controller.rb', line 55 def list @observations = Observation.with_project_id(sessions_current_project_id).page(params[:page]) end |
#navigation ⇒ Object
146 147 |
# File 'app/controllers/observations_controller.rb', line 146 def end |
#new ⇒ Object
GET /observations/new
47 48 49 |
# File 'app/controllers/observations_controller.rb', line 47 def new @observation = Observation.new end |
#observation_params ⇒ Object (private)
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 |
# File 'app/controllers/observations_controller.rb', line 159 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 |
#select_options ⇒ Object
149 150 151 |
# File 'app/controllers/observations_controller.rb', line 149 def @observations = Observation.select_optimized(sessions_current_user_id, sessions_current_project_id, params.require(:target)) end |
#set_observation ⇒ Object (private)
155 156 157 |
# File 'app/controllers/observations_controller.rb', line 155 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
43 44 |
# File 'app/controllers/observations_controller.rb', line 43 def show end |
#update ⇒ Object
PATCH/PUT /observations/1 PATCH/PUT /observations/1.json
78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'app/controllers/observations_controller.rb', line 78 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 |