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 ProjectsHelper

#invalid_object, #project_link, #project_matches, #project_tag, #projects_list, #projects_search_form

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



119
120
121
122
# File 'app/controllers/observations_controller.rb', line 119

def annotations
  @object = @observation
  render '/shared/data/all/annotations'
end

#api_indexObject



29
30
31
32
33
34
35
36
# File 'app/controllers/observations_controller.rb', line 29

def api_index
  @observations = Queries::Observation::Filter.new(api_params).all
    .with_project_id(sessions_current_project_id)
    .page(params[:page])
    .per(params[:per])

  render '/observations/api/v1/index'
end

#api_paramsObject (private)



176
177
178
179
180
181
182
183
184
# File 'app/controllers/observations_controller.rb', line 176

def api_params
  params.permit(
    :collection_object_id,
    :descriptor_id,
    :observation_matrix_id,
    :observation_object_global_id,
    :otu_id
  ).to_h
end

#api_showObject



38
39
40
41
# File 'app/controllers/observations_controller.rb', line 38

def api_show
  @observation = Observation.where(project_id: sessions_current_project_id).find(params[:id])
  render '/observations/api/v1/show'
end

#createObject

POST /observations POST /observations.json



63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'app/controllers/observations_controller.rb', line 63

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



95
96
97
98
99
100
101
102
103
104
105
106
# File 'app/controllers/observations_controller.rb', line 95

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_rowObject

DELETE /observations/destroy_row.json?observation_matrix_row_id=123



109
110
111
112
113
114
115
116
# File 'app/controllers/observations_controller.rb', line 109

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



54
55
# File 'app/controllers/observations_controller.rb', line 54

def edit
end

#filter_paramsObject (private)



163
164
165
166
167
168
169
170
171
172
173
174
# File 'app/controllers/observations_controller.rb', line 163

def filter_params
  params.permit(
    :collection_object_id,
    :descriptor_id,
    :format,
    :observation_object_global_id,
    :otu_id
  )
  # :authenticate_user_or_project, # WHY?
  # :project_token,
  #:token)
end

#indexObject

GET /observations GET /observations.json



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'app/controllers/observations_controller.rb', line 12

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
        .where(project_id: sessions_current_project_id)
        .page(params[:page])
        .per(params[:per])
    }
  end
end

#listObject



57
58
59
# File 'app/controllers/observations_controller.rb', line 57

def list
  @observations = Observation.with_project_id(sessions_current_project_id).page(params[:page])
end

#newObject

GET /observations/new



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

def new
  @observation = Observation.new
end

#observation_paramsObject (private)



130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
# File 'app/controllers/observations_controller.rb', line 130

def observation_params
  params.require(:observation).permit(
    :observation_object_global_id,
    :descriptor_id,
    :observation_object_type, :observation_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,
    :year_made,
    :month_made,
    :day_made,
    :time_made,
    :day_made,
    :month_made,
    :year_made,
    :time_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)



126
127
128
# File 'app/controllers/observations_controller.rb', line 126

def set_observation
  @observation = Observation.where(project_id: sessions_current_project_id).find(params[:id])
end

#showObject

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



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

def show
end

#updateObject

PATCH/PUT /observations/1 PATCH/PUT /observations/1.json



80
81
82
83
84
85
86
87
88
89
90
91
# File 'app/controllers/observations_controller.rb', line 80

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