Class: ObservationsController

Inherits:
ApplicationController show all
Includes:
DataControllerConfiguration::ProjectDataControllerConfiguration
Defined in:
app/controllers/observations_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

#annotationsObject

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_indexObject



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_showObject



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_columnObject

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

#createObject

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.metamorphosize),
        notice: 'Observation was successfully created.' }
      format.json { render :show, status: :created, location: @observation.metamorphosize }
    else
      format.html { render :new }
      format.json { render json: @observation.metamorphosize.errors, status: :unprocessable_entity }
    end
  end
end

#destroyObject

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.full_messages.join('; ') }
      format.json { render json: @observation.errors, status: :unprocessable_entity }
    end
  end
end

#destroy_columnObject

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_rowObject

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

#editObject

GET /observations/1/edit



51
52
# File 'app/controllers/observations_controller.rb', line 51

def edit
end

#indexObject

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

#listObject



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

#newObject

GET /observations/new



46
47
48
# File 'app/controllers/observations_controller.rb', line 46

def new
  @observation = Observation.new
end

#observation_paramsObject (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_observationObject (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

#showObject

GET /observations/1 GET /observations/1.json



42
43
# File 'app/controllers/observations_controller.rb', line 42

def show
end

#updateObject

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.metamorphosize),
                    notice: 'Observation was successfully updated.' }
      format.json { render :show, status: :ok, location: @observation.metamorphosize }
    else
      format.html { render :edit }
      format.json { render json: @observation.metamorphosize.errors, status: :unprocessable_entity }
    end
  end
end