Class: ContainerItemsController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- ContainerItemsController
- Defined in:
- app/controllers/container_items_controller.rb
Constant Summary
Constants included from ProjectsHelper
ProjectsHelper::CLASSIFIER, ProjectsHelper::CLASSIFIER_ANNOTATION
Instance Method Summary collapse
- #autocomplete ⇒ Object
-
#batch_add ⇒ Object
POST container_items/batch_add.
- #container_item_params ⇒ Object private
-
#create ⇒ Object
POST /container_items POST /container_items.json.
-
#destroy ⇒ Object
DELETE /container_items/1 DELETE /container_items/1.json.
-
#index ⇒ Object
GET /container_items GET /container_items.json.
- #list ⇒ Object
- #search ⇒ Object
- #set_container_item ⇒ Object private
-
#show ⇒ Object
GET /container_items/1 GET /container_items/1.json.
-
#update ⇒ Object
PATCH/PUT /container_items/1 PATCH/PUT /container_items/1.json.
Methods included from DataControllerConfiguration::ProjectDataControllerConfiguration
Methods included from RedirectHelper
Methods included from RequestType
Methods included from LogRecent
Methods included from Cookies
#digest_cookie, #digested_cookie_exists?
Methods included from Whitelist
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
Methods included from TokenAuthentication
#intercept_project, #intercept_user, #intercept_user_or_project, #project_token_authenticate, #token_authenticate
Instance Method Details
#autocomplete ⇒ Object
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 |
#batch_add ⇒ Object
POST container_items/batch_add
88 89 90 91 92 93 94 95 96 97 |
# File 'app/controllers/container_items_controller.rb', line 88 def batch_add if r = ContainerItem.batch_add(params) # preview: params[:preview], # collecting_event: collecting_event_params.merge(by: sessions_current_user_id), # collecting_event_query: params[:collecting_event_query]) render json: r.to_json, status: :ok else render json: {}, status: :unprocessable_entity end end |
#container_item_params ⇒ Object (private)
104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'app/controllers/container_items_controller.rb', line 104 def container_item_params params.require(:container_item).permit( :global_entity, :contained_object_id, :contained_object_type, :container_id, :position, :parent_id, :disposition, :disposition_x, :disposition_y, :disposition_z) end |
#create ⇒ Object
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 |
#destroy ⇒ Object
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 |
#index ⇒ Object
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 |
#list ⇒ Object
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 |
#search ⇒ Object
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_item ⇒ Object (private)
100 101 102 |
# File 'app/controllers/container_items_controller.rb', line 100 def set_container_item @container_item = ContainerItem.with_project_id(sessions_current_project_id).find(params[:id]) end |
#show ⇒ Object
GET /container_items/1 GET /container_items/1.json
15 16 |
# File 'app/controllers/container_items_controller.rb', line 15 def show end |
#update ⇒ Object
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 |