architwin 1.14.16 → 1.15.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. package/lib/architwin.d.ts +13 -2
  2. package/lib/architwin.js +1 -1
  3. package/lib/atwinui/components/toolbar/i18n.js +71 -3
  4. package/lib/atwinui/components/toolbar/index.js +5 -1
  5. package/lib/atwinui/components/toolbar/menuBar.d.ts +1 -0
  6. package/lib/atwinui/components/toolbar/menuBar.js +12 -0
  7. package/lib/atwinui/components/toolbar/spacePartition/roomFormPane.d.ts +2 -0
  8. package/lib/atwinui/components/toolbar/spacePartition/roomFormPane.js +41 -12
  9. package/lib/atwinui/components/toolbar/spacePartition/roomTreePane.d.ts +21 -2
  10. package/lib/atwinui/components/toolbar/spacePartition/roomTreePane.js +32 -12
  11. package/lib/atwinui/components/toolbar/tagFormPane.js +2 -1
  12. package/lib/atwinui/components/toolbar/tagListPane.d.ts +7 -2
  13. package/lib/atwinui/components/toolbar/tagListPane.js +126 -38
  14. package/lib/atwinui/events.d.ts +3 -1
  15. package/lib/atwinui/events.js +629 -107
  16. package/lib/atwinui/index.js +9 -1
  17. package/lib/color.js +12 -1
  18. package/lib/loaders/polydrawerLoader.js +3 -0
  19. package/lib/types.d.ts +75 -1
  20. package/lib/types.js +17 -0
  21. package/package.json +1 -1
  22. package/static/atwinui.css +55 -7
  23. package/static/colors/SOFT_ROYAL_BLUE.png +0 -0
  24. package/static/colors/YELLOW_ORANGE.png +0 -0
  25. package/static/utility.css +156 -537
  26. package/lib/atwinui/components/toolbar/roomCreation/roomFormPane.d.ts +0 -68
  27. package/lib/atwinui/components/toolbar/roomCreation/roomFormPane.js +0 -798
  28. package/lib/atwinui/components/toolbar/roomCreation/roomLayerListPane.d.ts +0 -33
  29. package/lib/atwinui/components/toolbar/roomCreation/roomLayerListPane.js +0 -447
  30. package/lib/atwinui/components/toolbar/tagIotForm.d.ts +0 -20
  31. package/lib/atwinui/components/toolbar/tagIotForm.js +0 -391
  32. package/lib/atwinui/components/toolbar/usersPane.d.ts +0 -14
  33. package/lib/atwinui/components/toolbar/usersPane.js +0 -273
  34. package/lib/convert.d.ts +0 -13
  35. package/lib/convert.js +0 -54
@@ -1,798 +0,0 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- import i18n from '../i18n';
11
- import { SPACE_EVENTS } from "../../../../types";
12
- import { batchAddEventListenerByClassName } from "../../../events";
13
- import { startDraw, cancelDraw, disposeModel, _3DXObjects, getCurrentPolygon, dispatchSpaceEvent, getPolygonFloorOffset } from '../../../../architwin';
14
- import { generateUUID, extractUUID } from '../../../../utils';
15
- import { getCurrentEditRoomData } from './roomLayerListPane';
16
- import { toggleModal, setModalAction } from "../modal";
17
- import { Notyf } from 'notyf';
18
- import log from 'loglevel';
19
- let isDrawing = false;
20
- let roomFormMode = "ADD" /* FORM_MODE.ADD */;
21
- let isSaving = false;
22
- let currentPolygonData = null;
23
- let currentPartitionDataArray = [];
24
- let savedPartitionDataArray = [];
25
- let currentEditPartitionData = null;
26
- let currentDeletePartitionData = null;
27
- let currentEditRoomData = null;
28
- let notify = new Notyf({ position: { x: 'left', y: 'bottom' } });
29
- let newlyAddedPartition = [];
30
- let deletedSavedPartitionArray = [];
31
- export function renderRoomFormPane() {
32
- console.info("__@ renderRoomFormPane");
33
- const element = document.createElement('div');
34
- element.classList.add('at_container');
35
- element.classList.add('at_w-12');
36
- element.classList.add('at_h-full');
37
- element.setAttribute('id', 'at-room-form-pane');
38
- element.setAttribute('data-cy', 'at-room-form-pane');
39
- element.innerHTML = `
40
- <div class="at_panel_header" id="at-room-form-title">
41
- </div>
42
- <form class="at_form_container at_scrollable_container at_h-min-70" id="at-room-form" data-cy="at-room-form">
43
- <div class="at-field at_flex_row">
44
- <label for="">${i18n.t('Name')}</label>
45
- <input class="at_field_input at_w-full" type="text" name="room_name" id="at-room-name-input" data-cy="at-room-name-input" placeholder="Room 1">
46
- </div>
47
- <div class="at-field at_flex_column">
48
- <label for="">${i18n.t('Memo')}</label>
49
- <textarea name="memo" id="at-room-memo-input" data-cy="at-room-memo-input" class="at_textarea"></textarea>
50
- </div>
51
- <div class="at-field at_flex_row" id="at-room-wall-height" data-cy="at-room-wall-height">
52
- <label for="">
53
- ${i18n.t('WallHeight')}
54
- <span class="mdi mdi-help-circle-outline"></span>
55
- <div class="at_icon_tooltip" data-cy="at-tooltip-room-wall-height">Sample Explanation on the definition of wall height</div>
56
- </label>
57
- <input class="at_field_input at_w-full" type="number" name="wall_height" id="at-room-wall-height-input" data-cy="at-room-wall-height-input" value="3">
58
- </div>
59
- <div class="at-field at_flex_row" id="at-auto-level-floor" data-cy="at-auto-level-floor">
60
- <input type="checkbox" id="at-floor-offset-checkbox" data-cy="at-floor-offset-checkbox" checked/>
61
- ${i18n.t('AutoLevel')}
62
- <span class="mdi mdi-help-circle-outline"></span>
63
- </div>
64
- <div class="at-field at_flex_row" id="at-room-floor-level" data-cy="at-room-floor-level">
65
- <label for="">
66
- ${i18n.t('FloorLevel')}
67
- <span class="mdi mdi-map-marker at_icon" id="at-mark-floor-btn" data-cy="at-mark-floor-btn"></span>
68
- <span class="mdi mdi-help-circle-outline"></span>
69
- <div class="at_icon_tooltip" data-cy="at-tooltip-room-floor-level">If enabled, will add an offset to the distance between the partition and floor of the space</div>
70
- </label>
71
- <input class="at_field_input at_w-full" type="text" name="floor_level" id="at-room-floor-level-input" data-cy="at-room-floor-level-input" value="0">
72
- </div>
73
- <div class="at_button at_draw_partition_btn at_w-full" id="at-draw-partition-form-btn" data-cy="at-draw-partition-form-btn">
74
- ${i18n.t('DrawPartition')}
75
- <span class="mdi mdi-cube-outline"></span>
76
- </div>
77
- <div class="at_partition_list_container at_h-min-40" id="at-partition-list-container" data-cy="at-partition-list-container">
78
- <div class="at_face_title" id="at-face-title" style="display: none;">
79
- <span class="mdi mdi-chevron-left" id="at-back-partition"></span>
80
- <label for="">
81
- <span class="mdi mdi-vector-polygon"></span>
82
- ${i18n.t('FloorsAndWalls')}
83
- </label>
84
- <div> </div>
85
- </div>
86
-
87
- <div class="at_partition_title" id="at-partition-title">
88
- <div> </div>
89
- <label for="">
90
- <span class="mdi mdi-cube-unfolded"></span>
91
- ${i18n.t('Partitions')}
92
- </label>
93
- <div> </div>
94
- </div>
95
- <div class="at_edit_name_input" id="at-edit-partition-name">
96
- <input class="at_edit_partition_name_input" type="text" name="edit_partition_name" id="at-edit-partition-name-input" data-cy="at-edit-partition-name-input">
97
- <span class="mdi mdi-check" id="at-confirm-edit-partition-name"></span>
98
- </div>
99
-
100
- <!-- Partition Add Mode -->
101
-
102
- <div class="at_partition_item_container at_scrollable_container" id="at-partition-item-container" data-cy="at-partition-item-container">
103
-
104
- <!-- Insert Partition Items Here -->
105
-
106
- </div>
107
-
108
- <!-- Partition Edit Mode -->
109
-
110
- <div class="at_face_vertex_container at_scrollable_container" id="at-face-vertex-container" data-cy="at-face-vertex-container">
111
-
112
- <!-- Insert Face & Vertex Items Here -->
113
-
114
- </div>
115
-
116
- <!-- No Partition Display -->
117
-
118
- <div class="at_empty-display" id="at-no-partition-display" data-cy="at-no-partition-display">
119
- <label for="">
120
- ${i18n.t('NoPartitionDisplay')}
121
- </label>
122
- </div>
123
- </div>
124
- <div class="at_button at_delete_room_btn at_w-full" id="at-delete-room-btn" data-cy="at-delete-room-btn">
125
- ${i18n.t('DeleteRoom')}
126
- </div>
127
- </form>
128
- <div class="at_button_row at_justify_between">
129
- <div class="at_button at_ghost" id="at-cancel-room-form-btn" data-cy="at-cancel-room-form-btn" target-pane="at-room-tree-pane">
130
- ${i18n.t('Cancel')}
131
- <span class="mdi mdi-close-circle-outline" id="at-cancel-room-form-btn"></span>
132
- </div>
133
- <div class="at_button at_ghost" id="at-save-room-btn" data-cy="at-save-room-btn">
134
- ${i18n.t('Save')}
135
- <span class="mdi mdi-content-save" id="at-save-room-btn"></span>
136
- </div>
137
- </div>
138
- `;
139
- return element;
140
- }
141
- /**
142
- * Toggles the state of the partition drawing functionality.
143
- * If drawing is not active, it starts the drawing process.
144
- * Otherwise, it cancels the current drawing, updates partition data,
145
- * and displays the relevant UI elements for partitions.
146
- */
147
- export function toggleDrawPartitionButton() {
148
- console.log("toggleDrawPartitionButton()");
149
- if (!isDrawing) {
150
- startDrawing();
151
- }
152
- else {
153
- const partitionItem = document.getElementById('at-partition-item-container');
154
- const partitionList = document.getElementById('at-partition-list-container');
155
- const vertexList = document.getElementById('at-face-vertex-container');
156
- setPartitionData();
157
- cancelDrawing();
158
- if (currentPartitionDataArray.length !== 0) {
159
- partitionItem.style.display = 'flex';
160
- vertexList.style.display = 'none';
161
- partitionList.style.justifyContent = 'start';
162
- displayPartitions(currentPartitionDataArray);
163
- notify.success(`${i18n.t('SuccessPartitionAddSpace')}`);
164
- }
165
- currentPolygonData = undefined;
166
- }
167
- }
168
- /**
169
- * Displays the partition form based on the current form mode.
170
- * Handles different UI behaviors for edit and add modes.
171
- */
172
- export function displayPartitionFormMode() {
173
- console.log("displayPartitionFormMode()");
174
- displayFormTitle();
175
- if (roomFormMode === "EDIT" /* FORM_MODE.EDIT */) {
176
- currentEditRoomData = getCurrentEditRoomData();
177
- populatePartitionForm(currentEditRoomData);
178
- displayElement('at-delete-room-btn', 'block');
179
- }
180
- else if (roomFormMode === "ADD" /* FORM_MODE.ADD */) {
181
- const floorOffset = document.getElementById('at-room-floor-level-input');
182
- const currentOffsetValue = getPolygonFloorOffset();
183
- log.info("currentOffsetValue ", currentOffsetValue);
184
- floorOffset.value = currentOffsetValue.toString();
185
- displayElement('at-no-partition-display');
186
- displayElement('at-room-wall-height', 'block');
187
- }
188
- else {
189
- console.error("Error occurred");
190
- }
191
- }
192
- /**
193
- * Populates the partition form with the given room node data.
194
- * Updates form fields and displays partitions based on the provided data.
195
- *
196
- * @param partition - The RoomNode object containing partition data.
197
- */
198
- function populatePartitionForm(partition) {
199
- console.log("populatePartitionForm()", partition);
200
- // Populate Room Form
201
- const name = document.getElementById('at-room-name-input');
202
- name.value = partition.name;
203
- const floorLevel = document.getElementById('at-room-floor-level-input');
204
- const memo = document.getElementById('at-room-memo-input');
205
- const floorOffset = document.getElementById('at-room-floor-level-input');
206
- if (partition.polygon_json != null) {
207
- memo.value = JSON.parse(partition.polygon_json).memo;
208
- }
209
- // Display Partitions
210
- currentPartitionDataArray = partition.children;
211
- savedPartitionDataArray = partition.children;
212
- if (currentPartitionDataArray.length !== 0) {
213
- floorLevel.value = JSON.parse(partition.children[0].polygon_json).floor.floor_level;
214
- displayPartitions(currentPartitionDataArray);
215
- }
216
- }
217
- /**
218
- * Updates the form title based on the current form mode.
219
- * Displays "Add Room" or "Edit Room" accordingly.
220
- */
221
- function displayFormTitle() {
222
- const title = document.getElementById('at-room-form-title');
223
- title.innerHTML = '';
224
- const span = document.createElement('span');
225
- span.textContent = roomFormMode === 'ADD'
226
- ? i18n.t('AddRoom')
227
- : i18n.t('EditRoom');
228
- title.appendChild(span);
229
- }
230
- /**
231
- * Sets the `display` style property of a DOM element.
232
- *
233
- * @param id - The ID of the element to update.
234
- * @param value - The value to set for the `display` property (default is "flex").
235
- */
236
- function displayElement(id, value = "flex") {
237
- const element = document.getElementById(id);
238
- if (!element) {
239
- console.error(`Element with ID "${id}" not found.`);
240
- return;
241
- }
242
- element.style.display = value;
243
- }
244
- /**
245
- * Hides a DOM element by setting its `display` style property to `none`.
246
- *
247
- * @param id - The ID of the element to hide.
248
- */
249
- function hideElement(id) {
250
- const element = document.getElementById(id);
251
- if (!element) {
252
- console.error(`Element with ID "${id}" not found.`);
253
- return;
254
- }
255
- element.style.display = 'none';
256
- }
257
- /**
258
- * Displays the given partitions by updating the UI with partition rows.
259
- * Also sets up event listeners for editing partition names and confirming changes.
260
- *
261
- * @param partitions - The list of partitions to be displayed.
262
- */
263
- function displayPartitions(partitions) {
264
- console.log("displayPartitions()", partitions);
265
- if (partitions.length == 0) {
266
- displayElement('at-no-partition-display');
267
- }
268
- else {
269
- hideElement('at-no-partition-display');
270
- }
271
- const partitionContainer = document.getElementById('at-partition-item-container');
272
- partitionContainer.style.display = 'flex';
273
- partitionContainer.innerHTML = ``;
274
- // Display each partition row
275
- partitions.forEach((partition) => {
276
- const row = displayPartitionRow(partition);
277
- partitionContainer.appendChild(row);
278
- });
279
- // Set up event listener for the partition edit button
280
- batchAddEventListenerByClassName('at_edit_partition_btn', (event) => {
281
- console.log('Event', event);
282
- const partitionTitle = document.getElementById('at-partition-title');
283
- const faceTitle = document.getElementById('at-face-title');
284
- const partitionLists = document.getElementById('at-partition-item-container');
285
- const faceLists = document.getElementById('at-face-vertex-container');
286
- const editPartitionName = document.getElementById('at-edit-partition-name');
287
- const editPartitionNameInput = document.getElementById('at-edit-partition-name-input');
288
- // Toggle visibility of relevant elements
289
- partitionTitle.style.display = 'none';
290
- faceTitle.style.display = 'flex';
291
- partitionLists.style.display = 'none';
292
- faceLists.style.display = 'flex';
293
- editPartitionName.style.display = 'flex';
294
- // Get the partition ID and load the corresponding partition data
295
- const targetElement = event.target;
296
- const partitionId = extractUUID(targetElement.id);
297
- currentEditPartitionData = partitions.find(partition => partition.uuid === partitionId);
298
- if (currentEditPartitionData) {
299
- editPartitionNameInput.value = currentEditPartitionData.name;
300
- const polygonData = JSON.parse(currentEditPartitionData.polygon_json);
301
- displayFaces(polygonData);
302
- }
303
- });
304
- // Set up event listener for confirming partition name change
305
- addEventListenerById('at-confirm-edit-partition-name', () => {
306
- const editPartitionNameInput = document.getElementById('at-edit-partition-name-input');
307
- const newPartitionName = editPartitionNameInput === null || editPartitionNameInput === void 0 ? void 0 : editPartitionNameInput.value;
308
- const confirmEditPartitionName = document.getElementById('at-confirm-edit-partition-name');
309
- confirmEditPartitionName.style.display = 'none';
310
- if (newPartitionName && currentEditPartitionData) {
311
- // Update the name of the partition in the array
312
- const partitionIndex = currentPartitionDataArray.findIndex(partition => partition.uuid === currentEditPartitionData.uuid);
313
- if (partitionIndex !== -1) {
314
- currentPartitionDataArray[partitionIndex].name = newPartitionName;
315
- }
316
- }
317
- else {
318
- console.warn("Partition name is invalid or no partition is selected for editing.");
319
- }
320
- // Re-display the confirm button after 2 seconds
321
- setTimeout(() => {
322
- confirmEditPartitionName.style.display = 'flex';
323
- }, 1000);
324
- });
325
- // Set up event listener for deleting partition
326
- batchAddEventListenerByClassName('at_delete_partition_btn', (event) => __awaiter(this, void 0, void 0, function* () {
327
- console.log('Event', event);
328
- const targetElement = event.target;
329
- const partitionId = extractUUID(targetElement.id);
330
- const target = _3DXObjects.find(obj => obj.object.object_data.uuid === partitionId);
331
- if (target) {
332
- toggleModal();
333
- setModalAction({
334
- title: `${i18n.t('DeletePartition')}`,
335
- description: `${i18n.t('ConfirmDeletePartition')}`,
336
- buttonLabel: `${i18n.t('YesDelete')}`
337
- }, () => __awaiter(this, void 0, void 0, function* () {
338
- // Delete from space
339
- disposeModel(target);
340
- currentDeletePartitionData = partitions.find(partition => partition.uuid === partitionId);
341
- // Delete from display in the toolbar
342
- currentPartitionDataArray = partitions.filter(partition => partition.uuid !== partitionId);
343
- if (currentEditRoomData)
344
- currentEditRoomData.children = currentPartitionDataArray;
345
- displayPartitions(currentPartitionDataArray);
346
- // Delete from db
347
- if (!newlyAddedPartition.includes(currentDeletePartitionData)) {
348
- dispatchSpaceEvent(SPACE_EVENTS.PARTITION_DISPOSED, currentDeletePartitionData);
349
- }
350
- toggleModal(false);
351
- notify.success(`${i18n.t('SuccessPartitionDelete')}`);
352
- }));
353
- }
354
- else {
355
- notify.error("NoPartitionDeleted");
356
- }
357
- }));
358
- }
359
- /**
360
- * Creates a row element to display partition information.
361
- * Each row contains the partition name, edit button, and delete button.
362
- *
363
- * @param partition - The partition object containing the data to display.
364
- * @returns A div element representing the partition row.
365
- */
366
- function displayPartitionRow(partition) {
367
- console.log("displayPartitionRow()", partition);
368
- // Create the partition row element
369
- const element = document.createElement('div');
370
- element.classList.add('at_partition_item');
371
- // Set the inner HTML of the partition row
372
- element.innerHTML = `
373
- <div class="at_icon_left">
374
- <span class="mdi mdi-cube-outline"></span>
375
- </div>
376
- <div class="at_partition_name">
377
- <div></div>
378
- <label for="">
379
- ${i18n.t(`${partition.name}`)}
380
- </label>
381
- <span class="mdi mdi-pencil at_icon_right at_edit_partition_btn" id="at-edit-partition-${partition.uuid}"></span>
382
- </div>
383
- <div class="at_icon_right">
384
- <span class="mdi mdi-delete-outline at_delete_partition_btn" id="at-delete-partition-${partition.uuid}"></span>
385
- </div>
386
- `;
387
- return element;
388
- }
389
- /**
390
- * Displays the details of faces associated with a given polygon, including floor and wall information.
391
- * Also sets up event listeners for toggling visibility of face details and navigating back to the partition list.
392
- *
393
- * @param polygon - The polygon object containing the floor and walls data.
394
- */
395
- function displayFaces(polygon) {
396
- console.log("displayFaces()", polygon);
397
- const faceVertexContainer = document.getElementById('at-face-vertex-container');
398
- faceVertexContainer.innerHTML = '';
399
- const element = document.createElement('div');
400
- element.classList.add('at_face_vertex_item');
401
- // Display the floor details
402
- element.appendChild(displayFloor(polygon.floor));
403
- // Display each wall's details
404
- polygon.walls.forEach((wall) => {
405
- element.appendChild(displayWalls(wall));
406
- });
407
- faceVertexContainer.appendChild(element);
408
- // Back button event listener for displaying partition list
409
- addEventListenerById('at-back-partition', goBackToPartitionList);
410
- // Toggle visibility of face details when clicked
411
- batchAddEventListenerByClassName('at_face_name', (event) => {
412
- const targetElement = event.target;
413
- const faceId = extractUUID(targetElement.id);
414
- const vertexItem = document.getElementById(`at-vertex-list-${faceId}`);
415
- const isHidden = vertexItem.style.display === 'none' || vertexItem.style.display === '';
416
- vertexItem.style.display = isHidden ? 'flex' : 'none';
417
- // Toggle the chevron icon to indicate expanded or collapsed state
418
- const chevronIcon = document.getElementById(`at-expand-btn-${faceId}`).querySelector(isHidden ? '.mdi-chevron-down' : '.mdi-chevron-up');
419
- chevronIcon.classList.toggle('mdi-chevron-down');
420
- chevronIcon.classList.toggle('mdi-chevron-up');
421
- });
422
- }
423
- /**
424
- * Handles the transition back to the partition list view by updating the visibility of relevant UI elements.
425
- * Resets the edit partition data and displays the current partitions.
426
- */
427
- function goBackToPartitionList() {
428
- console.log('goBackToPartitionList()');
429
- // Show the partition title and list, hide the face title and vertex container
430
- document.getElementById('at-partition-title').style.display = 'flex';
431
- document.getElementById('at-face-title').style.display = 'none';
432
- document.getElementById('at-partition-item-container').style.display = 'flex';
433
- document.getElementById('at-face-vertex-container').style.display = 'none';
434
- document.getElementById('at-edit-partition-name').style.display = 'none';
435
- // Display the list of partitions
436
- displayPartitions(currentPartitionDataArray);
437
- // Clear the current edit partition data
438
- currentEditPartitionData = null;
439
- }
440
- /**
441
- * Displays the floor information in the UI, including the floor name, edit options, and associated vertices.
442
- * @param floor - The floor data to display.
443
- * @returns The created HTML element representing the floor and its associated data.
444
- */
445
- function displayFloor(floor) {
446
- console.log('displayFloor()', floor);
447
- const element = document.createElement('div');
448
- element.innerHTML = `
449
- <div class="at_face_item">
450
- <div class="at_icon_left">
451
- <span class="mdi mdi-perspective-less"></span>
452
- </div>
453
- <div class="at_face_name" id="at-expand-btn-${floor.uuid}" data-cy="at-expand-btn-${floor.uuid}">
454
- ${i18n.t(`${floor.name}`)}
455
- <span class="mdi mdi-chevron-down" id="at-expand-btn-${floor.uuid}" data-cy="at-expand-btn-${floor.uuid}"></span>
456
- </div>
457
- <div class="at_icon_right">
458
- <span class="mdi mdi-delete-outline"></span>
459
- </div>
460
- </div>
461
- <div class="at_edit_name" id="at-edit-name-${floor.uuid}" data-cy="at-edit-name-${floor.uuid}">
462
- <div class="at_edit_name_text" id="at-edit-name-text-${floor.uuid}" data-cy="at-edit-name-text-${floor.uuid}">
463
- ${i18n.t('ClickEditName')}
464
- <span class="mdi mdi-pencil at_icon_right" id="at-edit-name-text-${floor.uuid}"></span>
465
- </div>
466
- <div class="at_edit_name_input" id="at-edit-name-input-${floor.uuid}" data-cy="at-edit-name-input-${floor.uuid}">
467
- <input class="at_edit_face_name_input" type="text" name="edit_face_name" id="at-edit-face-name-input" data-cy="at-edit-face-name-input" placeholder="Enter name here">
468
- <span class="mdi mdi-check at_confirm_edit_name" id="at-confirm-edit-name-${floor.uuid}" data-cy="at-confirm-edit-name-${floor.uuid}"></span>
469
- </div>
470
- </div>
471
- <div class="at_vertex_list" id="at-vertex-list-${floor.uuid}" data-cy="at-vertex-list-${floor.uuid}"></div>
472
- `;
473
- // Get the at_vertex_list container for this floor
474
- const vertexListContainer = element.querySelector(`#at-vertex-list-${floor.uuid}`);
475
- // Append lines to the at_vertex_list container
476
- floor.edges.forEach((vertex, index) => {
477
- const row = displayLines(vertex, index + 1, 'floor');
478
- vertexListContainer.appendChild(row); // Append to the correct container
479
- });
480
- return element;
481
- }
482
- /**
483
- * Displays the wall information in the UI, including the wall name, edit options, and associated vertices.
484
- * @param wall - The wall data to display.
485
- * @returns The created HTML element representing the wall and its associated data.
486
- */
487
- function displayWalls(wall) {
488
- console.log('displayWalls()', wall);
489
- // Extract the wall name from the format "_wall-{number}" using regex
490
- const match = wall.name.match(/_wall-(\d+)$/);
491
- let wallName = '';
492
- if (match) {
493
- wallName = `${i18n.t('Wall')} ${match[1]}`;
494
- }
495
- const element = document.createElement('div');
496
- element.innerHTML = `
497
- <div class="at_face_item">
498
- <div class="at_icon_left">
499
- <span class="mdi mdi-perspective-less at_face_icon_rotate_270"></span>
500
- </div>
501
- <div class="at_face_name" id="at-expand-btn-${wall.uuid}" data-cy="at-expand-btn-${wall.uuid}">
502
- ${wallName}
503
- <span class="mdi mdi-chevron-down" id="at-expand-btn-${wall.uuid}" data-cy="at-expand-btn-${wall.uuid}"></span>
504
- </div>
505
- <div class="at_icon_right">
506
- <span class=""></span>
507
- </div>
508
- </div>
509
- <div class="at_edit_name" id="at-edit-name-${wall.uuid}" data-cy="at-edit-name-${wall.uuid}">
510
- <div class="at_edit_name_text" id="at-edit-name-text-${wall.uuid}" data-cy="at-edit-name-text-${wall.uuid}">
511
- ${i18n.t('ClickEditName')}
512
- <span class="mdi mdi-pencil at_icon_right" id="at-edit-name-text-${wall.uuid}"></span>
513
- </div>
514
- <div class="at_edit_name_input" id="at-edit-name-input-${wall.uuid}" data-cy="at-edit-name-input-${wall.uuid}">
515
- <input class="at_edit_face_name_input" type="text" name="edit_face_name" id="at-edit-face-name-input" data-cy="at-edit-face-name-input" placeholder="Enter name here">
516
- <span class="mdi mdi-check at_confirm_edit_name" id="at-confirm-edit-name-${wall.uuid}" data-cy="at-confirm-edit-name-${wall.uuid}"></span>
517
- </div>
518
- </div>
519
- <div class="at_vertex_list" id="at-vertex-list-${wall.uuid}" data-cy="at-vertex-list-${wall.uuid}">
520
- </div>
521
- `;
522
- // Get the at_vertex_list container for this wall
523
- const vertexListContainer = element.querySelector(`#at-vertex-list-${wall.uuid}`);
524
- // Append lines to the at_vertex_list container
525
- wall.edges.forEach((vertex, index) => {
526
- const row = displayLines(vertex, index + 1, 'wall');
527
- vertexListContainer.appendChild(row); // Append to the correct container
528
- });
529
- return element;
530
- }
531
- /**
532
- * Displays the line information for a given vertex, including its name, distance, and delete icon.
533
- * The delete icon visibility depends on whether the face type is 'floor'.
534
- * @param vertex - The vertex (edge) data to display.
535
- * @param index - The index of the line to display.
536
- * @param faceType - The type of face ('floor' or 'wall').
537
- * @returns The created HTML element representing the line and its associated data.
538
- */
539
- function displayLines(vertex, index, faceType) {
540
- console.log('displayLines()', vertex);
541
- const element = document.createElement('div');
542
- element.classList.add('at_vertex_item');
543
- // Determine whether to display the delete icon based on faceType ('floor' only)
544
- const deleteIconHtml = faceType === 'floor' ?
545
- `<div class="at_vertex_icon_right">
546
- <span class="mdi mdi-delete-outline"></span>
547
- </div>` :
548
- `<div class="at_vertex_icon_right at_invisible">
549
- <span class="mdi mdi-delete-outline"></span>
550
- </div>`;
551
- element.innerHTML = `
552
- <div class="at_vertex_icon_left">
553
- <span class="mdi mdi-vector-line"></span>
554
- </div>
555
- <div class="at_vertex_center">
556
- <div class="at_vertex_name">
557
- ${i18n.t('Line') + " " + index}
558
- </div>
559
- <div class="at_vertex_distance">
560
- ${vertex.length + " m"}
561
- </div>
562
- </div>
563
- ${deleteIconHtml}
564
- `;
565
- return element;
566
- }
567
- /**
568
- * Adds a click event listener to an element with the given ID.
569
- * @param id - The ID of the element to attach the event listener to.
570
- * @param callback - The function to be executed when the element is clicked.
571
- */
572
- function addEventListenerById(id, callback) {
573
- const element = document.getElementById(id);
574
- if (element) {
575
- element.addEventListener('click', callback);
576
- }
577
- else {
578
- console.warn(`Element with id "${id}" not found.`);
579
- }
580
- }
581
- /**
582
- * Clears the partition form by resetting UI elements and internal data.
583
- * - Navigates back to the partition list view.
584
- * - Cancels any ongoing drawing actions.
585
- * - Hides relevant UI elements like wall height, delete button, and partition container.
586
- * - Resets the form and clears data related to the current partition, room, and polygon.
587
- */
588
- export function clearPartitionForm() {
589
- console.log('clearPartitionForm()');
590
- goBackToPartitionList();
591
- cancelDrawing();
592
- const wallHeight = document.getElementById('at-room-wall-height');
593
- const deleteBtn = document.getElementById('at-delete-room-btn');
594
- const partitionContainer = document.getElementById('at-partition-item-container');
595
- wallHeight.style.display = 'none';
596
- deleteBtn.style.display = 'none';
597
- partitionContainer.style.display = 'none';
598
- document.getElementById('at-room-form').reset();
599
- currentPartitionDataArray = [];
600
- currentEditRoomData = null;
601
- currentEditPartitionData = null;
602
- currentPolygonData = null;
603
- currentDeletePartitionData = null;
604
- newlyAddedPartition = [];
605
- deletedSavedPartitionArray = [];
606
- savedPartitionDataArray = [];
607
- }
608
- /**
609
- * Cancels the drawing action for a partition.
610
- * - Calls the cancelDraw function to stop any ongoing drawing action.
611
- * - Sets the drawing state to false.
612
- * - Updates the draw room button UI to indicate the drawing is canceled (removes active class, restores button text and icon).
613
- */
614
- function cancelDrawing() {
615
- console.log('cancelDrawing()');
616
- cancelDraw();
617
- isDrawing = false;
618
- const drawRoomBtn = document.getElementById('at-draw-partition-form-btn');
619
- drawRoomBtn.classList.remove('at_draw_partition_btn_active');
620
- drawRoomBtn.classList.add('at_draw_partition_btn');
621
- drawRoomBtn.innerHTML = `
622
- ${i18n.t('DrawPartition')}
623
- <span class="mdi mdi-cube-outline"></span>
624
- `;
625
- }
626
- /**
627
- * Starts the drawing action for a partition.
628
- * - Calls the startDraw function to initiate the drawing action.
629
- * - Sets the drawing state to true.
630
- * - Updates the draw room button UI to indicate the drawing mode is active (removes inactive class, adds active class, and changes button text and icon).
631
- */
632
- function startDrawing() {
633
- console.log('startDrawing()');
634
- startDraw();
635
- isDrawing = true;
636
- const drawRoomBtn = document.getElementById('at-draw-partition-form-btn');
637
- drawRoomBtn.classList.remove('at_draw_partition_btn');
638
- drawRoomBtn.classList.add('at_draw_partition_btn_active');
639
- drawRoomBtn.innerHTML = `
640
- ${i18n.t('CompleteDrawing')}
641
- <span class="mdi mdi-check-bold"></span>
642
- `;
643
- }
644
- // ==== SETTERS AND GETTERS ==== //
645
- /**
646
- * Retrieves the form data for creating or editing a room partition.
647
- * - Collects values from form inputs (name, floor level, memo).
648
- * - Constructs a payload object containing the room data, including the space UUID and polygon data.
649
- * - Updates the polygon data for each partition in the currentPartitionDataArray to reflect the new floor level.
650
- * - If there is existing room data (currentEditRoomData), it returns that data with updated values.
651
- *
652
- * @returns {RoomNode} The room data object with partition and floor details.
653
- */
654
- export function getPartitionFormData() {
655
- var _a, _b, _c;
656
- console.log('getPartitionFormData()');
657
- const name = ((_a = document.getElementById('at-room-name-input')) === null || _a === void 0 ? void 0 : _a.value) || null;
658
- const floorLevel = ((_b = document.getElementById('at-room-floor-level-input')) === null || _b === void 0 ? void 0 : _b.value) || null;
659
- let memo = ((_c = document.getElementById('at-room-memo-input')) === null || _c === void 0 ? void 0 : _c.value) || null;
660
- const currentUrl = window.location.href;
661
- const spaceUUID = extractUUID(currentUrl);
662
- let payload = {
663
- space_uuid: spaceUUID,
664
- name: name,
665
- parent_uuid: null,
666
- polygon_json: JSON.stringify({ memo: memo }),
667
- children: currentPartitionDataArray,
668
- };
669
- if (!memo) {
670
- payload.polygon_json = null;
671
- }
672
- currentPartitionDataArray.forEach(partition => {
673
- const polygonJson = JSON.parse(partition.polygon_json);
674
- polygonJson.floor.floor_level = Number(floorLevel);
675
- partition.polygon_json = JSON.stringify(polygonJson);
676
- });
677
- if (currentEditRoomData) {
678
- payload = currentEditRoomData;
679
- payload.name = name;
680
- payload.polygon_json = JSON.stringify({ memo: memo });
681
- }
682
- return payload;
683
- }
684
- /**
685
- * Sets the saving mode for the partition form.
686
- * - If saving is enabled, `isSaving` is set to true, indicating that the form is in saving mode.
687
- * - If saving is disabled, `isSaving` is set to false.
688
- *
689
- * @param {boolean} savingEnabled - True to enable saving mode, false to disable.
690
- */
691
- export function setPartitionSavingMode(savingEnabled) {
692
- isSaving = savingEnabled;
693
- }
694
- /**
695
- * Gets the current saving mode for the partition form.
696
- *
697
- * @returns {boolean} - Returns true if saving mode is enabled, false otherwise.
698
- */
699
- export function getPartitionSavingMode() {
700
- return isSaving;
701
- }
702
- /**
703
- * Sets the form mode for the partition form.
704
- * - The form mode can be one of the predefined FORM_MODE values (e.g., CREATE, EDIT, etc.).
705
- *
706
- * @param {FORM_MODE} formType - The type of form mode to set.
707
- */
708
- export function setPartitionFormMode(formType) {
709
- roomFormMode = formType;
710
- }
711
- /**
712
- * Gets the current form mode for the partition form.
713
- *
714
- * @returns {FORM_MODE} - The current form mode.
715
- */
716
- export function getPartitionFormMode() {
717
- return roomFormMode;
718
- }
719
- /**
720
- * Sets the polygon data for the current partition, including rounding numeric values
721
- * to two decimal places and assigning UUIDs to the floor and walls.
722
- *
723
- * @param {PolygonData} payload - The polygon data to set, including floor and walls.
724
- */
725
- export function setPolygonData(payload) {
726
- console.log('setPolygonData()', payload);
727
- // Helper function to round numbers to 2 decimals
728
- function roundToTwoDecimals(value) {
729
- if (typeof value === "number") {
730
- return Math.round(value * 100) / 100; // Round to 2 decimals
731
- }
732
- else if (Array.isArray(value)) {
733
- return value.map(roundToTwoDecimals); // Recursively round each item in the array
734
- }
735
- else if (typeof value === "object" && value !== null) {
736
- return Object.keys(value).reduce((acc, key) => {
737
- acc[key] = roundToTwoDecimals(value[key]); // Recursively process each object property
738
- return acc;
739
- }, {});
740
- }
741
- return value;
742
- }
743
- // Round numbers in the polygon JSON recursively
744
- if (payload) {
745
- payload = roundToTwoDecimals(payload);
746
- }
747
- // Set floor UUID and name
748
- if (payload.floor) {
749
- payload.floor.uuid = payload.floor.uuid || generateUUID();
750
- payload.floor.name = `Floor`;
751
- }
752
- // Iterate over walls to set UUID and names
753
- if (payload.walls && payload.walls.length > 0) {
754
- payload.walls = payload.walls.map((wall, index) => {
755
- var _a, _b, _c, _d;
756
- return (Object.assign(Object.assign({}, roundToTwoDecimals(wall)), { name: `_wall-${index + 1}`, uuid: wall.uuid || generateUUID(), options: {
757
- color: (_b = (_a = wall.options) === null || _a === void 0 ? void 0 : _a.color) !== null && _b !== void 0 ? _b : 0xffffff,
758
- opacity: (_d = (_c = wall.options) === null || _c === void 0 ? void 0 : _c.opacity) !== null && _d !== void 0 ? _d : 1.0
759
- } }));
760
- });
761
- }
762
- currentPolygonData = payload;
763
- }
764
- /**
765
- * Sets the partition data, including updating the floor level and generating a new
766
- * partition with its corresponding UUID, space UUID, and polygon data.
767
- */
768
- function setPartitionData() {
769
- var _a;
770
- console.log('setPartitionData()');
771
- const floorLevel = ((_a = document.getElementById('at-room-floor-level-input')) === null || _a === void 0 ? void 0 : _a.value) || null;
772
- const currentUrl = window.location.href;
773
- const spaceUUID = extractUUID(currentUrl);
774
- const polygonObjectData = getCurrentPolygon();
775
- if (currentPolygonData) {
776
- let polygonData = currentPolygonData;
777
- polygonData.floor.floor_level = Number(floorLevel); // Set the floor level from the input
778
- // Create a new partition data payload
779
- const payload = {
780
- uuid: polygonObjectData.object.object_data.uuid,
781
- space_uuid: spaceUUID,
782
- name: `${i18n.t('Partition')} ${currentPartitionDataArray.length + 1}`,
783
- parent_uuid: null,
784
- polygon_json: JSON.stringify(polygonData)
785
- };
786
- if (currentEditRoomData) {
787
- payload.parent_uuid = currentEditRoomData.uuid; // Set the parent UUID if editing an existing room
788
- }
789
- currentPartitionDataArray.push(payload);
790
- newlyAddedPartition.push(payload);
791
- }
792
- }
793
- export function getNewlyAddedPartition() {
794
- return newlyAddedPartition;
795
- }
796
- export function getDeletedSavedPartitionArray() {
797
- return deletedSavedPartitionArray;
798
- }