Class: CollectionProfilesController

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



84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'app/controllers/collection_profiles_controller.rb', line 84

def autocomplete
  @collection_profiles = CollectionProfile.find_for_autocomplete(params.merge(project_id: sessions_current_project_id)).include(:taxon_names)
  data = @collection_profile.collect do |t|
    {id: t.id,
     label: ApplicationController.helpers.collection_profile_tag(t),
     response_values: {
         params[:method] => t.id
     },
     label_html: ApplicationController.helpers.collection_profile_tag(t)
    }
  end

  render :json => data
end

- (Object) collection_profile_params (private)

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



111
112
113
114
115
116
117
# File 'app/controllers/collection_profiles_controller.rb', line 111

def collection_profile_params
  params.require(:collection_profile).permit(:container_id, :otu_id, :conservation_status, :processing_state,
                                             :container_condition, :condition_of_labels, :identification_level,
                                             :arrangement_level, :data_quality, :computerization_level,
                                             :number_of_collection_objects, :number_of_containers, :collection_type, :force_update
  )
end

- (Object) create

POST /collection_profiles POST /collection_profiles.json



33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'app/controllers/collection_profiles_controller.rb', line 33

def create
  @collection_profile = CollectionProfile.new(collection_profile_params)

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

- (Object) destroy

DELETE /collection_profiles/1 DELETE /collection_profiles/1.json



68
69
70
71
72
73
74
# File 'app/controllers/collection_profiles_controller.rb', line 68

def destroy
  @collection_profile.destroy
  respond_to do |format|
    format.html { redirect_to collection_profiles_url }
    format.json { head :no_content }
  end
end

- (Object) edit

GET /collection_profiles/1/edit



24
25
# File 'app/controllers/collection_profiles_controller.rb', line 24

def edit
end

- (Object) index

GET /collection_profiles GET /collection_profiles.json



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

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

- (Object) list



99
100
101
# File 'app/controllers/collection_profiles_controller.rb', line 99

def list
  @collection_profiles = CollectionProfile.order(:id).page(params[:page]) #.per(10) #.per(3)
end

- (Object) new

GET /collection_profiles/new



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

def new
  @collection_profile = CollectionProfile.new(collection_type: :dry)
end

- (Object) search



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

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

- (Object) set_collection_profile (private)

Use callbacks to share common setup or constraints between actions.



105
106
107
108
# File 'app/controllers/collection_profiles_controller.rb', line 105

def set_collection_profile
  @collection_profile = CollectionProfile.with_project_id(sessions_current_project_id).find(params[:id])
  @recent_object = @collection_profile
end

- (Object) show

GET /collection_profiles/1 GET /collection_profiles/1.json



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

def show
end

- (Object) swap_form_attribute_types



27
28
29
# File 'app/controllers/collection_profiles_controller.rb', line 27

def swap_form_attribute_types
  render partial: 'collection_profile_collection_type_attributes_form', locals: { collection_profile: CollectionProfile.new(params.permit(:collection_type)) }
end

- (Object) update

PATCH/PUT /collection_profiles/1 PATCH/PUT /collection_profiles/1.json



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'app/controllers/collection_profiles_controller.rb', line 49

def update
  respond_to do |format|
    if collection_profile_params['force_update'] == '0'
      flash['notice'] = 'Collection profile are not updatable unless forced, consider cloning this record or click force.'
      render :edit and return
    end

    if @collection_profile.update(collection_profile_params)
      format.html { redirect_to @collection_profile, notice: 'Collection profile was successfully updated.' }
      format.json { render :show, status: :ok, location: @collection_profile }
    else
      format.html { render :edit }
      format.json { render json: @collection_profile.errors, status: :unprocessable_entity }
    end
  end
end