From 61d0a8c4edf62db8cd5934b3ae4ec50d8b897b39 Mon Sep 17 00:00:00 2001 From: sabarinathan155 Date: Wed, 2 Apr 2025 16:47:02 +0530 Subject: [PATCH] template ,float,3dWidget socket events creation --- .../visualization/3dWidget-Service.ts | 81 +++---- .../visualization/floatWidget-Service.ts | 127 +++++++++-- .../visualization/templateServices.ts | 215 ++++++++++++++++-- .../services/visualization/widget-Services.ts | 5 +- src/socket-server/socket/events.ts | 9 +- src/socket-server/socket/socketManager.ts | 145 ++++++------ 6 files changed, 433 insertions(+), 149 deletions(-) diff --git a/src/socket-server/services/visualization/3dWidget-Service.ts b/src/socket-server/services/visualization/3dWidget-Service.ts index 343718e..1eec0ba 100644 --- a/src/socket-server/services/visualization/3dWidget-Service.ts +++ b/src/socket-server/services/visualization/3dWidget-Service.ts @@ -1,50 +1,55 @@ import zoneSchema from "../../../shared/model/builder/lines/zone-Model.ts"; import widget3dModel from "../../../shared/model/vizualization/3dwidget.ts"; export const add3Dwidget = async (data: any) => { - const { organization, widget, zoneId } = data + const { organization, widget, zoneId } = data - console.log('data: ', data) - try { - const existingZone = await zoneSchema(organization).findOne({ + try { + const existingZone = await zoneSchema(organization).findOne({ + zoneId: zoneId, + isArchive: false, + }); + if (!existingZone) + return { success: false, message: "Zone not found for the zoneId", organization: organization } + const existing3Dwidget = await widget3dModel(organization).findOne({ + widgetID: widget.id, + isArchive: false, + }); + if (existing3Dwidget) { + const update3dwidget = await widget3dModel( + organization + ).findOneAndUpdate( + { + widgetID: widget.id, zoneId: zoneId, isArchive: false, - }); - if (!existingZone) - return { success: false, message: "Zone not found for the zoneId", organization: organization } - const existing3Dwidget = await widget3dModel(organization).findOne({ - widgetID: widget.id, - isArchive: false, - }); - if (existing3Dwidget) { - const update3dwidget = await widget3dModel( - organization - ).findOneAndUpdate( - { - widgetID: widget.id, - zoneId: zoneId, - isArchive: false, - }, - { position: widget.position }, - { upsert: true, new: true } - ); - if (update3dwidget) - return { success: true, message:"widget update successfully", organization: organization } + }, + { position: widget.position }, + { upsert: true, new: true } + ); + if (update3dwidget) + return { success: true, message: "widget update successfully", organization: organization } - - else return{ success: false, message: "Widget not updated", organization: organization } - } - const newWidget3d = await widget3dModel(organization).create({ - widgetName: widget.type, - widgetID: widget.id, - position: widget.position, - zoneId, - }); - if (newWidget3d) - return { success: false, message: "Widget created successfully",data:newWidget3d, organization: organization } - } catch (error: any) { - return { success: false, message: error?.message || "Error occurred while 3Dwidget", error, organization: organization } + else return { success: false, message: "Widget not updated", organization: organization } + } + const newWidget3d = await widget3dModel(organization).create({ + widgetName: widget.type, + widgetID: widget.id, + position: widget.position, + zoneId, + }); + if (newWidget3d) { + + const widgemodel3D_Datas = { + widget: { id: newWidget3d.widgetID, type: newWidget3d.widgetName, position: newWidget3d.position, }, + Data: newWidget3d.Data, zoneId: zoneId, } + return { success: true, message: "Widget created successfully", data: widgemodel3D_Datas, organization: organization } + } + + } catch (error: any) { + return { success: false, message: error?.message || "Error occurred while 3Dwidget", error, organization: organization } + } } diff --git a/src/socket-server/services/visualization/floatWidget-Service.ts b/src/socket-server/services/visualization/floatWidget-Service.ts index 4b39be5..9fa8eb1 100644 --- a/src/socket-server/services/visualization/floatWidget-Service.ts +++ b/src/socket-server/services/visualization/floatWidget-Service.ts @@ -1,9 +1,8 @@ -import floatWidgetModel from "../../../shared/model/vizualization/3dwidget.ts"; +import floatWidgetModel from "../../../shared/model/vizualization/floatWidget.ts"; import zoneSchema from "../../../shared/model/builder/lines/zone-Model.ts"; export const addfloat = async (data: any) => { - const { organization, widget, zoneId } = data; - console.log('data: ', data); + const { organization, widget, zoneId, index } = data; try { const existingZone = await zoneSchema(organization).findOne({ zoneId: zoneId, @@ -29,9 +28,9 @@ export const addfloat = async (data: any) => { Data: { measurements: widget?.Data.measurements, duration: widget?.Data.duration, - }, - header: widget?.header, - position: widget?.position, + }, + header: widget?.header, + position: widget?.position, }, }, { @@ -39,7 +38,12 @@ export const addfloat = async (data: any) => { new: true, } ); - return { success: true, message: "Widget updated successfully", data: updateFloatWidget, organization: organization } + const floatUpdateDatas = { + position: updateFloatWidget.position, + index: index, + zoneId: zoneId, zoneName: existingZone.zoneName + } + return { success: true, message: "Widget updated successfully", data: floatUpdateDatas, organization: organization } } const newFloadWidget = await floatWidgetModel(organization).create({ @@ -52,7 +56,83 @@ export const addfloat = async (data: any) => { zoneId: zoneId, }); if (newFloadWidget) { - return { success: true, message: "FloatWidget created successfully", data: newFloadWidget, organization: organization } + const floatDatas = { + widget: { + position: newFloadWidget.position, header: newFloadWidget.header, value: newFloadWidget.value + , per: newFloadWidget.per, className: newFloadWidget.className, id: newFloadWidget.floatWidgetID + }, + zoneId: zoneId, zoneName: existingZone.zoneName + } + return { success: true, message: "FloatWidget created successfully", data: floatDatas, organization: organization } + } + } catch (error: any) { + return { success: false, message: error?.message || "Error occurred while float", error, organization: organization } + } + +} +export const duplicatefloat = async (data: any) => { + const { organization, widget, zoneId, index } = data; + try { + const existingZone = await zoneSchema(organization).findOne({ + zoneId: zoneId, + isArchive: false, + }); + if (!existingZone) + return { success: false, message: "Zone not found for the zoneId", organization: organization } + + const existingFloatWidget = await floatWidgetModel(organization).findOne({ + floatWidgetID: widget.id, + isArchive: false, + zoneId: zoneId, + + }); + if (existingFloatWidget) { + const updateFloatWidget = await floatWidgetModel(organization).findOneAndUpdate( + { + floatWidgetID: widget.id, + isArchive: false, + }, + { + $set: { + Data: { + measurements: widget?.Data.measurements, + duration: widget?.Data.duration, + }, + header: widget?.header, + position: widget?.position, + }, + }, + { + upsert: true, + new: true, + } + ); + const floatUpdateDatas = { + position: updateFloatWidget.position, + index: index, + zoneId: zoneId, zoneName: existingZone.zoneName + } + return { success: true, message: "Widget updated successfully", data: floatUpdateDatas, organization: organization } + } + + const newFloadWidget = await floatWidgetModel(organization).create({ + className: widget.className, + header: widget.header, + floatWidgetID: widget.id, + position: widget.position, + per: widget.per, + value: widget.value, + zoneId: zoneId, + }); + if (newFloadWidget) { + const floatDatas = { + widget: { + position: newFloadWidget.position, header: newFloadWidget.header, value: newFloadWidget.value + , per: newFloadWidget.per, className: newFloadWidget.className, id: newFloadWidget.floatWidgetID + }, + zoneId: zoneId, zoneName: existingZone.zoneName,index:index + } + return { success: true, message: "duplicate FloatWidget created successfully", data: floatDatas, organization: organization } } } catch (error: any) { return { success: false, message: error?.message || "Error occurred while float", error, organization: organization } @@ -60,25 +140,36 @@ export const addfloat = async (data: any) => { } export const deletefloat = async (data: any) => { - const { floatWidgetID, organization } = data; - - console.log('data: ', data); + const { floatWidgetID, zoneId, organization } = data; try { + const existingZone = await zoneSchema(organization).findOne({ + zoneId: zoneId, + isArchive: false, + }); + if (!existingZone) + return { success: false, message: "Zone not found for the zoneId", organization: organization } + const findfloatWidget = await floatWidgetModel(organization).findOne({ - floatWidgetID: floatWidgetID, - isArchive: false, + floatWidgetID: floatWidgetID, + isArchive: false, }); if (!findfloatWidget) return { success: false, message: "Zone not found for the zoneId", organization: organization } const widgetData = await floatWidgetModel(organization).updateOne( - { _id: findfloatWidget._id, isArchive: false }, - { $set: { isArchive: true } } + { _id: findfloatWidget._id, isArchive: false }, + { $set: { isArchive: true } } ); - return { success: true, message: "FloatingWidget deleted successfully", data: widgetData, organization: organization } + const floatDeleteData = { + floatWidgetID: findfloatWidget.floatWidgetID, + zoneId: findfloatWidget.zoneId, + zoneName: existingZone.zoneName - } catch (error: any) { + } + return { success: true, message: "FloatingWidget deleted successfully", data: floatDeleteData, organization: organization } + + } catch (error: any) { return { success: false, message: error?.message || "Error occurred while float", error, organization: organization } - } + } } diff --git a/src/socket-server/services/visualization/templateServices.ts b/src/socket-server/services/visualization/templateServices.ts index 51326f1..8eeab77 100644 --- a/src/socket-server/services/visualization/templateServices.ts +++ b/src/socket-server/services/visualization/templateServices.ts @@ -1,26 +1,203 @@ import templateModel from "../../../shared/model/vizualization/templatemodel.ts"; +import zoneSchema from "../../../shared/model/builder/lines/zone-Model.ts"; +import panelSchema from "../../../shared/model/vizualization/panelmodel.ts"; +import widgetSchema from "../../../shared/model/vizualization/widgemodel.ts"; +import floatWidgetModel from "../../../shared/model/vizualization/floatWidget.ts"; export const addTemplate = async (data: any) => { - const { organization, templateID, name, panelOrder, widgets, snapshot } =data; - console.log('data: ', data); - try { - - const existingTemplate = await templateModel(organization).findOne({ - templateID: templateID, + const { organization, template, name, panelOrder, widgets, snapshot } = data; + console.log('data: ', data); + try { + // console.log("req.body: ", req.body); + const existingTemplate = await templateModel(organization).findOne({ + templateID: template.id, + isArchive: false, + }); + + if (existingTemplate) + return { success: false, message: "TemplateID alreay exists", organization: organization } + const newTemplate = await templateModel(organization).create({ + templateID: template.id, + templateName: template.name, + panelOrder: template.panelOrder, + widgets: template.widgets, + snapshot: template.snapshot, + floatWidgets: template.floatingWidget, + Widgets3D: template.Widgets3D, + }); + if (newTemplate) { + const allTemplateDatas = await templateModel(organization) + .find({ isArchive: false }) + .select("-_id -__v -isArchive -createdAt -updatedAt"); + + const formattedTemplates = allTemplateDatas.map((data) => ({ + id: data.templateID, + name: data.templateName, + panelOrder: data.panelOrder, + widgets: data.widgets, + floatingWidget: data.floatWidgets, + widgets3D: data.Widgets3D, + snapshot: data.snapshot, + })); + + return { + success: true, + message: "Template saved successfully", + data: formattedTemplates, + organization: organization, + }; + } + + } catch (error: any) { + return { success: false, message: error?.message || "Error occurred while template", error, organization: organization } + + } + + +} + +export const addTemplateZone = async (data: any) => { + const { zoneId, templateID, organization } = data; + try { + const existingZone = await zoneSchema(organization).findOne({ + zoneId: zoneId, + isArchive: false, + }); + if (!existingZone) + return { success: false, message: "Zone not found ", organization: organization } + + const existingTemplate = await templateModel(organization).findOne({ + templateID: templateID, + isArchive: false, + }); + if (!existingTemplate) + return { success: false, message: "TemplateID not found", organization: organization } + + if (existingZone.panelOrder.length > 0) { + existingZone.panelOrder = existingTemplate.panelOrder; + await existingZone.save(); + // Clear existing data before adding new data + const archivePanelDatas = await panelSchema(organization).find({ + zoneId, + isArchive: false, + }); + for (const panelData of archivePanelDatas) { + await widgetSchema(organization).deleteMany({ + panelID: panelData._id, isArchive: false, }); - if (existingTemplate) - return { success: false, message: "TemplateID alreay exists", organization: organization } - const newTemplate = await templateModel(organization).create({ - templateID, - name, - panelOrder, - widgets, - snapshot, - }); - if (newTemplate) - return { success: false, message: "Template saved successfully", data: newTemplate, organization: organization } - } catch (error: any) { - return { success: false, message: error?.message || "Error occurred while template", error, organization: organization } + } + await panelSchema(organization).deleteMany({ + zoneId, + isArchive: false, + }); + await floatWidgetModel(organization).deleteMany({ + zoneId, + isArchive: false, + }); + } + existingZone.panelOrder = existingTemplate.panelOrder; + await existingZone.save(); + const existingPanels = await panelSchema(organization).find({ + zoneId, + isArchive: false, + }); + const existingPanelNames = existingPanels.map( + (panel: any) => panel.panelName + ); + + const missingPanels = existingTemplate.panelOrder.filter( + (panelName: string) => !existingPanelNames.includes(panelName) + ); + const createdPanels = await Promise.all( + missingPanels.map((panelName: any) => + panelSchema(organization).create({ + zoneId, + panelName, + widgets: [], + isArchive: false, + }) + ) + ); + + for (const widgetData of existingTemplate.widgets) { + const addedExistingPanel = await panelSchema(organization).findOne({ + panelName: widgetData.panel, + zoneId, + isArchive: false, + }); + if (!addedExistingPanel) continue; + + const existingWidget = await widgetSchema(organization).findOne({ + panelID: addedExistingPanel._id, + widgetID: widgetData.id, + isArchive: false, + }); + if (existingWidget) continue; + + const newWidget = await widgetSchema(organization).create({ + widgetID: widgetData.id, + elementType: widgetData.type, + widgetName: widgetData.widgetName || "Widget", + panelID: addedExistingPanel._id, + widgetside: widgetData.panel, + }); + addedExistingPanel.widgets.push(newWidget._id); + await addedExistingPanel.save(); + } + + for (const floatData of existingTemplate.floatWidgets) { + const existingFloatWidget = await floatWidgetModel( + organization + ).findOne({ floatWidgetID: floatData.id, isArchive: false, zoneId }); + if (existingFloatWidget) continue; + + await floatWidgetModel(organization).create({ + className: floatData.className, + header: floatData.header, + floatWidgetID: floatData.id, + position: floatData.position, + per: floatData.per, + value: floatData.value, + zoneId, + }); + } + const templateZoneDatas = { + template: { id: existingTemplate.templateID, name: existingTemplate.templateName, panelOrder: existingTemplate.panelOrder, widgets: existingTemplate.widgets, snapshot: existingTemplate.snapshot, floatingWidget: existingTemplate.floatWidgets }, + zoneId: existingZone.zoneId, zoneName: existingZone.zoneName + } + + + return { success: true, message: "Template placed in Zone", data: templateZoneDatas, organization: organization } + + } catch (error: any) { + return { success: false, message: error?.message || "Error occurred while template", error, organization: organization } + } + + +} +export const TemplateZoneDelete = async (data: any) => { + const { zoneId, templateID, organization } = data; + try { + const existingTemplate = await templateModel(organization).findOne({ + templateID: templateID, + isArchive: false, + }); + if (existingTemplate) { + const newTemplate = await templateModel(organization).updateOne( + { templateID: templateID, isArchive: false }, + { $set: { isArchive: true } } + ); + if (newTemplate) { + + const TemplateDeleteData = existingTemplate.templateID + return { success: true, message: "Template deleted successfully", data: TemplateDeleteData, organization: organization } } + + } + } catch (error: any) { + return { success: false, message: error?.message || "Error occurred while template", error, organization: organization } + } + + } \ No newline at end of file diff --git a/src/socket-server/services/visualization/widget-Services.ts b/src/socket-server/services/visualization/widget-Services.ts index f87281c..9f8317a 100644 --- a/src/socket-server/services/visualization/widget-Services.ts +++ b/src/socket-server/services/visualization/widget-Services.ts @@ -1,4 +1,3 @@ -import { title } from "process"; import panelSchema from "../../../shared/model/vizualization/panelmodel.ts"; import widgetSchema from "../../../shared/model/vizualization/widgemodel.ts"; import zoneSchema from "../../../shared/model/builder/lines/zone-Model.ts"; @@ -77,7 +76,6 @@ export const addWidget = async (data: any) => { title: newWidget.widgetName, } const finaldata = { widgetData: widgetData, zoneId: existingZone.zoneId, zoneName: existingZone.zoneName } - // console.log('existingPanel: ', widgetData); return { success: true, message: "Widget created successfully", data: finaldata, organization: organization } } } @@ -89,7 +87,6 @@ export const addWidget = async (data: any) => { } export const Widgetdelete = async (data: any) => { const { widgetID, zoneId, organization } = data - console.log('data: ', data); try { const existingZone = await zoneSchema(organization).findOne({ zoneId: zoneId, @@ -114,7 +111,7 @@ export const Widgetdelete = async (data: any) => { panelID: findWidget.panelID, isArchive: false, }); - console.log('widgets: ', widgets); + // console.log('widgets: ', widgets); // .sort({ widgetOrder: 1 }); // Reassign widgetOrder values diff --git a/src/socket-server/socket/events.ts b/src/socket-server/socket/events.ts index 15f75b1..d5e4153 100644 --- a/src/socket-server/socket/events.ts +++ b/src/socket-server/socket/events.ts @@ -65,10 +65,17 @@ export const EVENTS = { floatUpdateRespones: "viz-float:response:updates", deleteFloat: "v2:viz-float:delete", floatDeleteRespones: "viz-float:response:delete", + duplicatefloat:"v2:viz-float:addDuplicate", + duplicatefloatUpdateRespones:"viz-float:response:addDuplicate", //template addTemplate:"v2:viz-template:add", - templateUpdateRespones:"viz-template:response:updates", + templateUpdateRespones:"viz-template:response:add", + addTemplateZone:"v2:viz-template:addToZone", + addTemplateZoneResponse:"viz-template:response:addTemplateZone", + deleteTemplate:"v2:viz-template:deleteTemplate", + TemplateDeleteResponse:"viz-template:response:delete", + //model-asset setAssetModel: "v2:model-asset:add", diff --git a/src/socket-server/socket/socketManager.ts b/src/socket-server/socket/socketManager.ts index b5a40fd..03e99dd 100644 --- a/src/socket-server/socket/socketManager.ts +++ b/src/socket-server/socket/socketManager.ts @@ -9,8 +9,8 @@ import { activeUserOffline, activeUsers, } from '../services/users/user-controll import { deleteZone, setZone } from '../services/lines/zone-controller.ts'; import { addPanel, panelDelete } from '../services/visualization/panel-Services.ts'; import { addWidget, Widgetdelete } from '../services/visualization/widget-Services.ts'; -import { addfloat, deletefloat } from '../services/visualization/floatWidget-Service.ts'; -import { addTemplate } from '../services/visualization/templateServices.ts'; +import { addfloat, deletefloat, duplicatefloat } from '../services/visualization/floatWidget-Service.ts'; +import { addTemplate, addTemplateZone, TemplateZoneDelete } from '../services/visualization/templateServices.ts'; import { deleteAssetModel, setAssetModel } from '../services/assets/asset-Controller.ts'; import { add3Dwidget } from '../services/visualization/3dWidget-Service.ts'; @@ -355,10 +355,7 @@ const lineHandleEvent =async (event: string, socket: Socket, data: any,io:any) = const responseEvent = EVENTS.deletePointResponse // console.log('responseEvent: ', responseEvent); const organization = result?.organization - // console.log('organization: ', organization); - // const emitTarget = notifySender ? socket.in(organization) : socket.to(organization); - // console.log(`👀 Active sockets in room:`, namespace.adapter.rooms.get(organization)); - // console.log('emitTarget: ', emitTarget); + if (organization) { socket.to(organization).emit(responseEvent, { success: result.success, @@ -419,10 +416,6 @@ const userStatus =async (event: string, socket: Socket, data: any,io:any) => { const responseEvent = EVENTS.userDisConnect // console.log('responseEvent: ', responseEvent); const organization = result?.organization - // console.log('organization: ', organization); - // const emitTarget = notifySender ? socket.in(organization) : socket.to(organization); - // console.log(`👀 Active sockets in room:`, namespace.adapter.rooms.get(organization)); - // console.log('emitTarget: ', emitTarget); if (organization) { socket.to(organization).emit(responseEvent, { success: result.success, @@ -482,11 +475,7 @@ const zoneHandleEvent = async (event: string, socket: Socket, data: any, io: any const responseEvent = EVENTS.ZoneDeleteRespones // console.log('responseEvent: ', responseEvent); const organization = result?.organization - // console.log('organization: ', organization); - // const emitTarget = notifySender ? socket.in(organization) : socket.to(organization); - // console.log(`👀 Active sockets in room:`, namespace.adapter.rooms.get(organization)); - // console.log('emitTarget: ', emitTarget); - if (organization) { + if (organization) { socket.to(organization).emit(responseEvent, { success: result.success, message: result.message, @@ -542,10 +531,6 @@ const panelHandleEvent = async (event: string, socket: Socket, data: any, namesp const responseEvent = EVENTS.PanelDeleteRespones // console.log('responseEvent: ', responseEvent); const organization = result?.organization - // console.log('organization: ', organization); - // const emitTarget = notifySender ? socket.in(organization) : socket.to(organization); - // console.log(`👀 Active sockets in room:`, namespace.adapter.rooms.get(organization)); - // console.log('emitTarget: ', emitTarget); if (organization) { socket.to(organization).emit(responseEvent, { success: result.success, @@ -587,11 +572,7 @@ const widgetHandleEvent = async (event: string, socket: Socket, data: any, names const responseEvent = EVENTS.widgetUpdateRespones // console.log('responseEvent: ', responseEvent); const organization = result?.organization - // console.log('organization: ', organization); - // const emitTarget = notifySender ? socket.in(organization) : socket.to(organization); - // console.log(`👀 Active sockets in room:`, namespace.adapter.rooms.get(organization)); - // console.log('emitTarget: ', emitTarget); - if (organization) { + if (organization) { socket.to(organization).emit(responseEvent, { success: result.success, message: result.message, @@ -613,10 +594,7 @@ const widgetHandleEvent = async (event: string, socket: Socket, data: any, names const responseEvent = EVENTS.widgetDeleteRespones // console.log('responseEvent: ', responseEvent); const organization = result?.organization - // console.log('organization: ', organization); - // const emitTarget = notifySender ? socket.in(organization) : socket.to(organization); - // console.log(`👀 Active sockets in room:`, namespace.adapter.rooms.get(organization)); - // console.log('emitTarget: ', emitTarget); + if (organization) { socket.to(organization).emit(responseEvent, { success: result.success, @@ -656,12 +634,8 @@ const floatHandleEvent = async (event: string, socket: Socket, data: any, namesp const responseEvent = EVENTS.floatUpdateRespones // console.log('responseEvent: ', responseEvent); const organization = result?.organization - // console.log('organization: ', organization); - // const emitTarget = notifySender ? socket.in(organization) : socket.to(organization); - // console.log(`👀 Active sockets in room:`, namespace.adapter.rooms.get(organization)); - // console.log('emitTarget: ', emitTarget); if (organization) { - socket.emit(responseEvent, { + socket.to(organization).emit(responseEvent, { success: result.success, message: result.message, data: result.data, @@ -682,10 +656,6 @@ const floatHandleEvent = async (event: string, socket: Socket, data: any, namesp const responseEvent = EVENTS.floatDeleteRespones // console.log('responseEvent: ', responseEvent); const organization = result?.organization - // console.log('organization: ', organization); - // const emitTarget = notifySender ? socket.in(organization) : socket.to(organization); - // console.log(`👀 Active sockets in room:`, namespace.adapter.rooms.get(organization)); - // console.log('emitTarget: ', emitTarget); if (organization) { socket.to(organization).emit(responseEvent, { success: result.success, @@ -739,32 +709,72 @@ const templateHandleEvent = async (event: string, socket: Socket, data: any, nam } break } - // case EVENTS.deleteWidget: { - // const result = await Widgetdelete(data) - // if (result) { - // // console.log('result?.success: ', result.organization); - // const responseEvent = EVENTS.widgetDeleteRespones - // // console.log('responseEvent: ', responseEvent); - // const organization = result?.organization - // // console.log('organization: ', organization); - // // const emitTarget = notifySender ? socket.in(organization) : socket.to(organization); - // // console.log(`👀 Active sockets in room:`, namespace.adapter.rooms.get(organization)); - // // console.log('emitTarget: ', emitTarget); - // if (organization) { - // socket.emit(responseEvent, { - // success: result.success, - // message: result.message, - // data: result.data, - // error: result.error || null, - // socketId: socket.id, - // organization, - // }); - // } else { - // console.warn(`Organization missing in response for event: ${event}`); - // } - // } - // break - // } + case EVENTS.addTemplateZone: { + const result = await addTemplateZone(data) + if (result) { + // console.log('result?.success: ', result.organization); + const responseEvent = EVENTS.addTemplateZoneResponse + // console.log('responseEvent: ', responseEvent + const organization = result?.organization + if (organization) { + socket.to(organization).emit(responseEvent, { + success: result.success, + message: result.message, + data: result.data, + error: result.error || null, + socketId: socket.id, + organization, + }); + } else { + console.warn(`Organization missing in response for event: ${event}`); + } + } + break + } + case EVENTS.deleteTemplate: { + const result = await TemplateZoneDelete(data) + if (result) { + // console.log('result?.success: ', result.organization); + const responseEvent = EVENTS.TemplateDeleteResponse + // console.log('responseEvent: ', responseEvent); + const organization = result?.organization + if (organization) { + socket.to(organization).emit(responseEvent, { + success: result.success, + message: result.message, + data: result.data, + error: result.error || null, + socketId: socket.id, + organization, + }); + } else { + console.warn(`Organization missing in response for event: ${event}`); + } + } + break + } + case EVENTS.duplicatefloat: { + const result = await duplicatefloat(data) + if (result) { + // console.log('result?.success: ', result.organization); + const responseEvent = EVENTS.duplicatefloatUpdateRespones + // console.log('responseEvent: ', responseEvent); + const organization = result?.organization + if (organization) { + socket.to(organization).emit(responseEvent, { + success: result.success, + message: result.message, + data: result.data, + error: result.error || null, + socketId: socket.id, + organization, + }); + } else { + console.warn(`Organization missing in response for event: ${event}`); + } + } + break + } default: return; @@ -803,7 +813,8 @@ const Widget3DHandleEvent = async (event: string, socket: Socket, data: any, nam } break } - // case EVENTS.deleteWidget: { + + // case EVENTS.deleteWidget: { // const result = await Widgetdelete(data) // if (result) { // // console.log('result?.success: ', result.organization); @@ -874,10 +885,6 @@ const modelAssetHandleEvent = async (event: string, socket: Socket, data: any, n const responseEvent = EVENTS.assetDeleteRespones // console.log('responseEvent: ', responseEvent); const organization = result?.organization - // console.log('organization: ', organization); - // const emitTarget = notifySender ? socket.in(organization) : socket.to(organization); - // console.log(`👀 Active sockets in room:`, namespace.adapter.rooms.get(organization)); - // console.log('emitTarget: ', emitTarget); if (organization) { socket.to(organization).emit(responseEvent, { success: result.success, @@ -1031,7 +1038,7 @@ export const initSocketServer = (httpServer: any) => { // handleNamespace("visualization", namespaces.panel, panelHandleEvent); // handleNamespace("widget", namespaces.visualization, widgetHandleEvent); handleNamespace("Builder", namespaces.Builder, userStatus,modelAssetHandleEvent, cameraHandleEvent, EnvironmentHandleEvent, wallItemsHandleEvent, lineHandleEvent,zoneHandleEvent); - handleNamespace("Visualization", namespaces.visualization, panelHandleEvent, widgetHandleEvent, floatHandleEvent, templateHandleEvent); + handleNamespace("Visualization", namespaces.visualization, panelHandleEvent, widgetHandleEvent, floatHandleEvent, templateHandleEvent,Widget3DHandleEvent); return io; };