Class: Tasks::Containers::CollectionLayoutController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- Tasks::Containers::CollectionLayoutController
- Includes:
- TaskControllerConfiguration
- Defined in:
- app/controllers/tasks/containers/collection_layout_controller.rb
Instance Method Summary collapse
-
#children ⇒ Object
GET /tasks/containers/collection_layout/children.json?container_id=123 Returns the direct children of a container with their placement (disposition_x/y/z) and whether each child itself has children (for drill-down eligibility).
-
#collection_tree ⇒ Object
GET /tasks/containers/collection_layout/collection_tree.json?building_id=123 Returns hierarchical treemap data for a given building Container id.
-
#index ⇒ Object
GET /tasks/containers/collection_layout.
-
#scaffold ⇒ Object
POST /tasks/containers/collection_layout/scaffold.json Params: building_id, cabinet_type, rooms, cabinets, drawers.
- #scaffold_params ⇒ Object private
Methods included from TaskControllerConfiguration
Instance Method Details
#children ⇒ Object
GET /tasks/containers/collection_layout/children.json?container_id=123 Returns the direct children of a container with their placement (disposition_x/y/z) and whether each child itself has children (for drill-down eligibility).
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'app/controllers/tasks/containers/collection_layout_controller.rb', line 11 def children id = params[:container_id] || params[:building_id] container = Container.with_project_id(sessions_current_project_id).find(id) ci = ContainerItem.find_by(contained_object: container) items = ci ? ci.children.map { |child_ci| obj = child_ci.contained_object { container_item_id: child_ci.id, id: obj.id, name: obj.name.presence || obj.type.demodulize, type: obj.type, disposition_x: child_ci.disposition_x, disposition_y: child_ci.disposition_y, disposition_z: child_ci.disposition_z, has_children: child_ci.children.exists? } } : [] render json: items rescue ActiveRecord::RecordNotFound render json: { error: 'Container not found' }, status: :not_found end |
#collection_tree ⇒ Object
GET /tasks/containers/collection_layout/collection_tree.json?building_id=123 Returns hierarchical treemap data for a given building Container id
37 38 39 40 41 42 43 |
# File 'app/controllers/tasks/containers/collection_layout_controller.rb', line 37 def collection_tree building_id = params.require(:building_id) building = Container.with_project_id(sessions_current_project_id).find(building_id) render json: CollectionLayout::TreeData.new(building).to_json_tree rescue ActiveRecord::RecordNotFound render json: { error: 'Building not found' }, status: :not_found end |
#index ⇒ Object
GET /tasks/containers/collection_layout
5 6 |
# File 'app/controllers/tasks/containers/collection_layout_controller.rb', line 5 def index end |
#scaffold ⇒ Object
POST /tasks/containers/collection_layout/scaffold.json Params: building_id, cabinet_type, rooms, cabinets, drawers
47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'app/controllers/tasks/containers/collection_layout_controller.rb', line 47 def scaffold building = Container.with_project_id(sessions_current_project_id).find(params.require(:building_id)) result = Container.scaffold(scaffold_params.merge(building_id: building.id)) if result render json: { created_rooms: result.length }, status: :created else render json: { error: 'Failed to scaffold containers. Check params.' }, status: :unprocessable_entity end rescue ActiveRecord::RecordNotFound render json: { error: 'Building not found' }, status: :not_found end |
#scaffold_params ⇒ Object (private)
62 63 64 65 66 |
# File 'app/controllers/tasks/containers/collection_layout_controller.rb', line 62 def scaffold_params params.permit(:building_id, :drawer_type, :rooms, :cabinets, :drawers, :cabinet_size_x, :cabinet_size_y, :cabinet_size_z, :asserted_percent_empty, :asserted_percent_earmarked) end |