Class: ContainerItemsController

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

#polymorphic_filter_params

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



70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'app/controllers/container_items_controller.rb', line 70

def autocomplete
  @container_items = ContainerItem.find_for_autocomplete(params.merge(project_id: sessions_current_project_id)).includes(:taxon_name)
  data = @container_items.collect do |t|
    {id: t.id,
     label: ApplicationController.helpers.container_item_tag(t),
     response_values: {
         params[:method] => t.id
     },
     label_html: ApplicationController.helpers.container_item_autocomplete_selected_tag(t)
    }
  end

  render :json => data
end

- (Object) container_item_params (private)

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



92
93
94
# File 'app/controllers/container_items_controller.rb', line 92

def container_item_params
  params.require(:container_item).permit(:container_id, :global_entity, :position, :parent_id, :contained_object_id, :contained_object_type, :disposition)
end

- (Object) create

POST /container_items POST /container_items.json



24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'app/controllers/container_items_controller.rb', line 24

def create
  @container_item = ContainerItem.new(container_item_params)

  respond_to do |format|
    if @container_item.save
      format.html {redirect_back(fallback_location: (request.referer || root_path), notice: 'Container item was successfully created.')}
      format.json { render json: @container_item, status: :created, location: @container_item }
    else
      format.html {redirect_back(fallback_location: (request.referer || root_path), notice: 'Container item was NOT successfully created.')}
      format.json { render json: @container_item.errors, status: :unprocessable_entity }
    end
  end
end

- (Object) destroy

DELETE /container_items/1 DELETE /container_items/1.json



54
55
56
57
58
59
60
# File 'app/controllers/container_items_controller.rb', line 54

def destroy
  @container_item.destroy
  respond_to do |format|
    format.html {redirect_back(fallback_location: (request.referer || root_path), notice: 'Container item was successfully destroyed.')}
    format.json { head :no_content }
  end
end

- (Object) index

GET /container_items GET /container_items.json



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

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

- (Object) list



18
19
20
# File 'app/controllers/container_items_controller.rb', line 18

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

- (Object) search



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

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

- (Object) set_container_item (private)

Use callbacks to share common setup or constraints between actions.



87
88
89
# File 'app/controllers/container_items_controller.rb', line 87

def set_container_item
  @container_item = ContainerItem.with_project_id($project_id).find(params[:id])
end

- (Object) show

GET /container_items/1 GET /container_items/1.json



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

def show
end

- (Object) update

PATCH/PUT /container_items/1 PATCH/PUT /container_items/1.json



40
41
42
43
44
45
46
47
48
49
50
# File 'app/controllers/container_items_controller.rb', line 40

def update
  respond_to do |format|
    if @container_item.update(container_item_params)
      format.html {redirect_back(fallback_location: (request.referer || root_path), notice: 'Container item was successfully created.')}
      format.json { render json: @container_item, status: :ok, location: @container_item }
    else
      format.html {redirect_back(fallback_location: (request.referer || root_path), notice: 'Container item was NOT successfully updated.')}
      format.json { render json: @container_item.errors, status: :unprocessable_entity }
    end
  end
end