Class: CollectionObjectObservationsController

Inherits:
ApplicationController show all
Includes:
DataControllerConfiguration::ProjectDataControllerConfiguration
Defined in:
app/controllers/collection_object_observations_controller.rb

Instance Attribute Summary

Attributes inherited from ApplicationController

#is_data_controller, #is_task_controller, #meta_data, #meta_description, #meta_keywords, #meta_title, #page_title, #site_name

Instance Method Summary (collapse)

Methods inherited from ApplicationController

#clear_project_and_user_variables, #digest_cookie, #digested_cookie_exists?, #disable_turbolinks, #intercept_api, #invalid_object, #is_data_controller?, #is_task_controller?, #log_user_recent_route, #notice_user, #project_matches, #record_not_found, #set_project_and_user_variables, #set_project_from_params, #token_authenticate

Methods included from ProjectsHelper

#project_link, #project_tag, #projects_list, #projects_search_form

Instance Method Details

- (Object) autocomplete



73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'app/controllers/collection_object_observations_controller.rb', line 73

def autocomplete
  @collection_object_observations = CollectionObjectObservation.find_for_autocomplete(params.merge(project_id: sessions_current_project_id))

  data = @collection_object_observations.collect do |t|
    {id: t.id,
     label: t.data,
     response_values: {
       params[:method] => t.id
     },
     label_html: t.data 
    }
  end
  render :json => data
end

- (Object) collection_object_observation_params (private)

Never trust parameters from the scary internet, only allow the white list through.



108
109
110
# File 'app/controllers/collection_object_observations_controller.rb', line 108

def collection_object_observation_params
  params.require(:collection_object_observation).permit(:data)
end

- (Object) create

POST /collection_object_observations POST /collection_object_observations.json



31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'app/controllers/collection_object_observations_controller.rb', line 31

def create
  @collection_object_observation = CollectionObjectObservation.new(collection_object_observation_params)

  respond_to do |format|
    if @collection_object_observation.save
      format.html { redirect_to @collection_object_observation, notice: 'Collection object observation was successfully created.' }
      format.json { render :show, status: :created, location: @collection_object_observation }
    else
      format.html { render :new }
      format.json { render json: @collection_object_observation.errors, status: :unprocessable_entity }
    end
  end
end

- (Object) destroy

DELETE /collection_object_observations/1 DELETE /collection_object_observations/1.json



61
62
63
64
65
66
67
# File 'app/controllers/collection_object_observations_controller.rb', line 61

def destroy
  @collection_object_observation.destroy
  respond_to do |format|
    format.html { redirect_to collection_object_observations_url, notice: 'Collection object observation was successfully destroyed.' }
    format.json { head :no_content }
  end
end

- (Object) download

GET /collection_object_observations/download



97
98
99
# File 'app/controllers/collection_object_observations_controller.rb', line 97

def download
  send_data CollectionObjectObservation.generate_download( CollectionObjectObservation.where(project_id: $project_id) ), type: 'text', filename: "collection_object_observations_#{DateTime.now.to_s}.csv"
end

- (Object) edit

GET /collection_object_observations/1/edit



26
27
# File 'app/controllers/collection_object_observations_controller.rb', line 26

def edit
end

- (Object) index

GET /collection_object_observations GET /collection_object_observations.json



8
9
10
11
# File 'app/controllers/collection_object_observations_controller.rb', line 8

def index
  @recent_objects = CollectionObjectObservation.recent_from_project_id($project_id).order(updated_at: :desc).limit(10)
  render '/shared/data/all/index' 
end

- (Object) list



69
70
71
# File 'app/controllers/collection_object_observations_controller.rb', line 69

def list
  @collection_object_observations = CollectionObjectObservation.with_project_id($project_id).order(:id).page(params[:page]) #.per(10) 
end

- (Object) new

GET /collection_object_observations/new



19
20
21
# File 'app/controllers/collection_object_observations_controller.rb', line 19

def new
  @collection_object_observation = CollectionObjectObservation.new
end

- (Object) search



88
89
90
91
92
93
94
# File 'app/controllers/collection_object_observations_controller.rb', line 88

def search
  if params[:id].blank?
    redirect_to collection_object_observations_path, notice: 'You must select an item from the list with a click or tab press before clicking show.'
  else
    redirect_to collection_object_observation_path(params[:id])
  end
end

- (Object) set_collection_object_observation (private)

Use callbacks to share common setup or constraints between actions.



103
104
105
# File 'app/controllers/collection_object_observations_controller.rb', line 103

def set_collection_object_observation
  @collection_object_observation = CollectionObjectObservation.find(params[:id])
end

- (Object) show

GET /collection_object_observations/1 GET /collection_object_observations/1.json



15
16
# File 'app/controllers/collection_object_observations_controller.rb', line 15

def show
end

- (Object) update

PATCH/PUT /collection_object_observations/1 PATCH/PUT /collection_object_observations/1.json



47
48
49
50
51
52
53
54
55
56
57
# File 'app/controllers/collection_object_observations_controller.rb', line 47

def update
  respond_to do |format|
    if @collection_object_observation.update(collection_object_observation_params)
      format.html { redirect_to @collection_object_observation, notice: 'Collection object observation was successfully updated.' }
      format.json { render :show, status: :ok, location: @collection_object_observation }
    else
      format.html { render :edit }
      format.json { render json: @collection_object_observation.errors, status: :unprocessable_entity }
    end
  end
end