Class: ContainerItemsController

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



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

def autocomplete
  Queries::ContainerItemAutocompleteQuery.new(
    params.merge(project_id: sessions_current_project_id)
  ).all.where(project_id: params[: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

#container_item_paramsObject (private)



92
93
94
95
96
97
98
99
100
101
# File 'app/controllers/container_items_controller.rb', line 92

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

#createObject

POST /container_items POST /container_items.json



24
25
26
27
28
29
30
31
32
33
34
35
# 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

#destroyObject

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



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

def destroy
  @container_item.destroy
  respond_to do |format|
    format.html { destroy_redirect @container_item, notice: 'Container item was successfully destroyed.' }
    format.json { head :no_content }
  end
end

#indexObject

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

#listObject



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

#searchObject



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

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

#set_container_itemObject (private)



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

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

#showObject

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



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

def show
end

#updateObject

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



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

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