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 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

Instance Method Details

#annotationsObject

GET /annotations



94
95
96
97
# File 'app/controllers/observations_controller.rb', line 94

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

#createObject

POST /observations POST /observations.json



43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'app/controllers/observations_controller.rb', line 43

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



75
76
77
78
79
80
81
# File 'app/controllers/observations_controller.rb', line 75

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_rowObject

DELETE /observations/destroy_row.json?observation_matrix_row_id=123



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

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



34
35
# File 'app/controllers/observations_controller.rb', line 34

def edit
end

#filter_paramsObject (private)



129
130
131
# File 'app/controllers/observations_controller.rb', line 129

def filter_params
  params.permit(:otu_id, :descriptor_id, :collection_object_id, :observation_object_global_id)
end

#indexObject

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

#listObject



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

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

#newObject

GET /observations/new



29
30
31
# File 'app/controllers/observations_controller.rb', line 29

def new
  @observation = Observation.new
end

#observation_paramsObject (private)



105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'app/controllers/observations_controller.rb', line 105

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_observationObject (private)



101
102
103
# File 'app/controllers/observations_controller.rb', line 101

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

#showObject

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



25
26
# File 'app/controllers/observations_controller.rb', line 25

def show
end

#updateObject

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



60
61
62
63
64
65
66
67
68
69
70
71
# File 'app/controllers/observations_controller.rb', line 60

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