Class: CompositionItemsController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- CompositionItemsController
- Includes:
- RenderControllerConfiguration
- Defined in:
- app/controllers/composition_items_controller.rb
Constant Summary
Constants included from ProjectsHelper
ProjectsHelper::CLASSIFIER, ProjectsHelper::CLASSIFIER_ANNOTATION
Instance Method Summary collapse
-
#composition_item_params ⇒ Object
private
type and composition_id are set only on create.
-
#create ⇒ Object
POST /composition_items.json.
-
#destroy ⇒ Object
DELETE /composition_items/1.json.
-
#index ⇒ Object
GET /compositions/:composition_id/composition_items.json All items of the Composition, unpaged: a renderer needs them all.
- #set_composition_item ⇒ Object private
-
#show ⇒ Object
GET /composition_items/1.json.
-
#update ⇒ Object
PATCH/PUT /composition_items/1.json.
Methods included from RenderControllerConfiguration
#set_hub_model, #set_hub_model_metadata, #set_is_render_controller
Methods inherited from ApplicationController
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, #cumulative_projects_created_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_initials, #project_link, #project_login_link, #project_matches, #project_tag, #projects_list, #projects_search_form, #sound_cumulative_gb_per_year, #sound_gb_per_year, #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
#composition_item_params ⇒ Object (private)
type and composition_id are set only on create
79 80 81 82 83 84 85 86 |
# File 'app/controllers/composition_items_controller.rb', line 79 def composition_item_params params.require(:composition_item).permit( :parent_id, :composition_item_object_id, :composition_item_object_type, :text, :x, :y, :z, :position, :width, :height, :zoom, :rotation_z, :svg_view_box, :svg_clip, :opacity, :is_visible, :total, :css_style ) end |
#create ⇒ Object
POST /composition_items.json
32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'app/controllers/composition_items_controller.rb', line 32 def create @composition_item = CompositionItem.new( composition_item_params.merge( type: params.dig(:composition_item, :type), composition_id: params.dig(:composition_item, :composition_id) ) ) if @composition_item.save render :show, status: :created, location: @composition_item. else render json: @composition_item.errors, status: :unprocessable_content end end |
#destroy ⇒ Object
DELETE /composition_items/1.json
58 59 60 61 62 63 64 65 |
# File 'app/controllers/composition_items_controller.rb', line 58 def destroy @composition_item.destroy if @composition_item.destroyed? head :no_content else render json: @composition_item.errors, status: :unprocessable_content end end |
#index ⇒ Object
GET /compositions/:composition_id/composition_items.json All items of the Composition, unpaged: a renderer needs them all.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'app/controllers/composition_items_controller.rb', line 9 def index @composition_items = Composition .visible_to_project(sessions_current_project_id) .find(params.require(:composition_id)) .composition_items .order( CompositionItem.arel_table[:parent_id].asc.nulls_first, :position ) # TODO: N+1 on the objects' own associations (e.g. Depiction#image) when # rendering their attributes. Consider letting each item subclass declare # a preload for its object, next to composition_item_object_permitted?. if helpers.extend_response_with('composition_item_object') @composition_items = @composition_items.includes(:composition_item_object) end end |
#set_composition_item ⇒ Object (private)
69 70 71 72 73 74 75 76 |
# File 'app/controllers/composition_items_controller.rb', line 69 def set_composition_item @composition_item = CompositionItem .where(project_id: sessions_current_project_id) .or(CompositionItem.where( composition_id: Composition.where(is_community: true).select(:id) )) .find(params[:id]) end |
#show ⇒ Object
GET /composition_items/1.json
28 29 |
# File 'app/controllers/composition_items_controller.rb', line 28 def show end |
#update ⇒ Object
PATCH/PUT /composition_items/1.json
48 49 50 51 52 53 54 55 |
# File 'app/controllers/composition_items_controller.rb', line 48 def update if @composition_item.update(composition_item_params) render :show, status: :ok, location: @composition_item. else render json: @composition_item.errors, status: :unprocessable_content end end |