From ce33001b1ee8e71ef0b5a8444b745d7d65e1f137 Mon Sep 17 00:00:00 2001 From: Leopoldadmin Date: Mon, 22 Jun 2026 21:12:07 +0000 Subject: [PATCH] Add public method placeChairsOnSelectedTables() and update ID generation to use crypto.randomUUID() --- .../tools/drawing/AutoChairPlacementTool.ts | 31 ++++++++++++++++--- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/frontend/src/tools/drawing/AutoChairPlacementTool.ts b/frontend/src/tools/drawing/AutoChairPlacementTool.ts index 80a93be..c9545cc 100644 --- a/frontend/src/tools/drawing/AutoChairPlacementTool.ts +++ b/frontend/src/tools/drawing/AutoChairPlacementTool.ts @@ -52,7 +52,7 @@ class AutoChairPlacementTool extends Tool { // Top side this.yjsDoc.createElement({ - id: Date.now().toString() + '_chair_top_' + i, + id: crypto.randomUUID() + '_chair_top_' + i, type: 'chair', layerId: 'default', x: x + positionRatio * width - chairWidth / 2, @@ -64,7 +64,7 @@ class AutoChairPlacementTool extends Tool { // Bottom side this.yjsDoc.createElement({ - id: Date.now().toString() + '_chair_bottom_' + i, + id: crypto.randomUUID() + '_chair_bottom_' + i, type: 'chair', layerId: 'default', x: x + positionRatio * width - chairWidth / 2, @@ -81,7 +81,7 @@ class AutoChairPlacementTool extends Tool { // Left side this.yjsDoc.createElement({ - id: Date.now().toString() + '_chair_left_' + i, + id: crypto.randomUUID() + '_chair_left_' + i, type: 'chair', layerId: 'default', x: x - this.chairSpacing - chairWidth, @@ -93,7 +93,7 @@ class AutoChairPlacementTool extends Tool { // Right side this.yjsDoc.createElement({ - id: Date.now().toString() + '_chair_right_' + i, + id: crypto.randomUUID() + '_chair_right_' + i, type: 'chair', layerId: 'default', x: x + width + this.chairSpacing, @@ -118,7 +118,7 @@ class AutoChairPlacementTool extends Tool { const chairY = centerY + (radius + this.chairSpacing) * Math.sin(angle) - chairHeight / 2; this.yjsDoc.createElement({ - id: Date.now().toString() + '_chair_' + i, + id: crypto.randomUUID() + '_chair_' + i, type: 'chair', layerId: 'default', x: chairX, @@ -130,6 +130,27 @@ class AutoChairPlacementTool extends Tool { } } + // Place chairs on selected tables + placeChairsOnSelectedTables(selectedTableIds: string[]): void { + // Get all elements from the document + const elements = this.yjsDoc.getElements(); + + // Filter for selected tables + const selectedTables = elements.filter(element => + selectedTableIds.includes(element.id) && + (element.type === 'rectangular_table' || element.type === 'round_table') + ); + + // Place chairs around each selected table + selectedTables.forEach(table => { + if (table.type === 'rectangular_table') { + this.placeChairsAroundRectangularTable(table); + } else if (table.type === 'round_table') { + this.placeChairsAroundRoundTable(table); + } + }); + } + // Set chair spacing setChairSpacing(spacing: number): void { this.chairSpacing = spacing;