Class: CollectionObjectObservationsController

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

Constant Summary

Constants included from ProjectsHelper

ProjectsHelper::CLASSIFIER, ProjectsHelper::CLASSIFIER_ANNOTATION

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

#cumulative_gb_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, #taxonworks_classification, #week_in_review_graphs

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

#autocompleteObject



76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'app/controllers/collection_object_observations_controller.rb', line 76

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

#collection_object_observation_paramsObject (private)

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



114
115
116
# File 'app/controllers/collection_object_observations_controller.rb', line 114

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

#createObject

POST /collection_object_observations POST /collection_object_observations.json



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

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

#destroyObject

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



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

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

#downloadObject

GET /collection_object_observations/download



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

def download
  send_data(Export::CSV.generate_csv(CollectionObjectObservation.where(project_id: sessions_current_project_id)),
            type: 'text',
            filename: "collection_object_observations_#{DateTime.now}.tsv")
end

#editObject

GET /collection_object_observations/1/edit



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

def edit
end

#indexObject

GET /collection_object_observations GET /collection_object_observations.json



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

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

#listObject



71
72
73
74
# File 'app/controllers/collection_object_observations_controller.rb', line 71

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

#newObject

GET /collection_object_observations/new



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

def new
  @collection_object_observation = CollectionObjectObservation.new
end

#searchObject



91
92
93
94
95
96
97
98
# File 'app/controllers/collection_object_observations_controller.rb', line 91

def search
  if params[:id].blank?
    redirect_to collection_object_observations_path,
                alert: '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

#set_collection_object_observationObject (private)

Use callbacks to share common setup or constraints between actions.



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

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

#showObject

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



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

def show
end

#updateObject

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



47
48
49
50
51
52
53
54
55
56
57
58
# 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