From 7c0e59edadb77462c8b46d99c42b80fdd2af00ae Mon Sep 17 00:00:00 2001 From: Nivetharamesh99 Date: Sat, 29 Mar 2025 17:31:08 +0530 Subject: [PATCH] Visualization Part 2d and floating API Completed. Template Save and Get API completed --- .env | 2 + src/api-server/Routes/floadWidgetRoute.ts | 9 + src/api-server/Routes/templateRoutes.ts | 6 + src/api-server/Routes/widgetRoute.ts | 2 +- src/api-server/Routes/zone-Routes.ts | 2 +- src/api-server/Routes/zoneRoutes.ts | 2 +- src/api-server/app.ts | 7 +- .../controller/assets/pointService.ts | 41 +++- .../controller/lines/zoneService.ts | 10 +- .../simulation/assetsFloorservice.ts | 121 ++++------- .../visualization/floatWidgetService.ts | 201 ++++++++++++++++++ .../controller/visualization/panelService.ts | 8 +- .../visualization/templateService.ts | 43 ++++ .../controller/visualization/widgetService.ts | 70 ++++-- .../model/builder/assets/asset-Model.ts | 89 ++++---- .../model/builder/assets/assetPoint-Model.ts | 75 ++++--- src/shared/model/simulation/actionmodel.ts | 52 +++-- src/shared/model/simulation/triggersmodel.ts | 34 ++- src/shared/model/vizualization/3dwidget.ts | 44 ++++ .../model/vizualization/templatemodel.ts | 8 + src/shared/model/vizualization/widgemodel.ts | 6 +- 21 files changed, 604 insertions(+), 228 deletions(-) create mode 100644 src/api-server/Routes/floadWidgetRoute.ts create mode 100644 src/api-server/Routes/templateRoutes.ts create mode 100644 src/api-server/controller/visualization/floatWidgetService.ts create mode 100644 src/api-server/controller/visualization/templateService.ts create mode 100644 src/shared/model/vizualization/3dwidget.ts diff --git a/.env b/.env index c8ef4e5..e45e670 100644 --- a/.env +++ b/.env @@ -2,6 +2,8 @@ # MONGO_USER=mydata # MONGO_PASSWORD=mongodb@hexr2002 # MONGO_AUTH_DB=admin + + MONGO_USER=admin MONGO_PASSWORD=admin321 MONGO_AUTH_DB=admin diff --git a/src/api-server/Routes/floadWidgetRoute.ts b/src/api-server/Routes/floadWidgetRoute.ts new file mode 100644 index 0000000..733b6a0 --- /dev/null +++ b/src/api-server/Routes/floadWidgetRoute.ts @@ -0,0 +1,9 @@ +import * as express from "express"; +import { floatWidgetService } from "../controller/visualization/floatWidgetService.ts"; +const router = express.Router(); +router.post("/floatwidget/save", floatWidgetService.addfloatWidget); +router.get( + "/floadData/:zoneId/:organization", + floatWidgetService.getfloatWidget +); +export default router; \ No newline at end of file diff --git a/src/api-server/Routes/templateRoutes.ts b/src/api-server/Routes/templateRoutes.ts new file mode 100644 index 0000000..efb2c96 --- /dev/null +++ b/src/api-server/Routes/templateRoutes.ts @@ -0,0 +1,6 @@ +import * as express from "express"; +import { templateService } from "../controller/visualization/templateService.ts"; +const router = express.Router(); +router.post("/template/save", templateService.AddTemplate); +router.get("/templateData/:organization", templateService.GetTemplate); +export default router; diff --git a/src/api-server/Routes/widgetRoute.ts b/src/api-server/Routes/widgetRoute.ts index 0731940..df5f7c3 100644 --- a/src/api-server/Routes/widgetRoute.ts +++ b/src/api-server/Routes/widgetRoute.ts @@ -136,7 +136,7 @@ const router = express.Router(); */ router.post("/widget/save", widgetService.addWidget); router.patch("/widget/:widgetID", widgetService.updatewidget); -router.patch("/widget/delete", widgetService.deleteWidget); +router.patch("/delete/widget", widgetService.deleteWidget); router.get( "/WidgetData/:widgetID/:organization", widgetService.getDatafromWidget diff --git a/src/api-server/Routes/zone-Routes.ts b/src/api-server/Routes/zone-Routes.ts index e26fdda..4293328 100644 --- a/src/api-server/Routes/zone-Routes.ts +++ b/src/api-server/Routes/zone-Routes.ts @@ -7,7 +7,7 @@ const router = express.Router(); router.post('/setZone',zone.setZone) router.delete('/deleteZone',zone.deleteZone) router.get('/findZones/:organization',zone.getZones) -router.get('/A_zone/:zoneId/:organization',zone.ZoneData) +// router.get('/A_zone/:zoneId/:organization',zone.ZoneData) diff --git a/src/api-server/Routes/zoneRoutes.ts b/src/api-server/Routes/zoneRoutes.ts index e1dd2af..9f45e47 100644 --- a/src/api-server/Routes/zoneRoutes.ts +++ b/src/api-server/Routes/zoneRoutes.ts @@ -483,7 +483,7 @@ router.get("/ZoneVisualization/:zoneId", Zoneservice.singleZonePanelDatas); * value: * message: "Zone not found" */ -router.get("/A_zone/:zoneId", Zoneservice.ZoneData); +router.get("/A_zone/:zoneId/:organization", Zoneservice.ZoneData); /** * @swagger diff --git a/src/api-server/app.ts b/src/api-server/app.ts index c2e62f8..92fe6bb 100644 --- a/src/api-server/app.ts +++ b/src/api-server/app.ts @@ -15,7 +15,8 @@ import panelRouter from "./Routes/panelRoutes.ts"; import widgetRouter from "./Routes/widgetRoute.ts"; import assetpointRouter from "./Routes/assetpointRoutes.ts"; import assetfloorRoutes from "./Routes/assetfloorRoutes.ts"; - +import floadWidgetRoutes from "./Routes/floadWidgetRoute.ts"; +import templateRoutes from "./Routes/templateRoutes.ts"; const app = express(); app.use(cors()); app.use(express.json()); @@ -34,11 +35,13 @@ app.use("/api/v1", flooritemRoutes); app.use("/api/v1", WallitemRoutes); app.use("/api/v1", userRoutes); app.use("/api/v1", shareRoutes); -app.use('/api/v2', zoneRoutes); +app.use("/api/v2", zoneRoutes); //update app.use("/api/v2", zoneRoutes2); //updates app.use("/api/v2", panelRouter); app.use("/api/v2", widgetRouter); app.use("/api/v2", assetpointRouter); app.use("/api/v2", assetfloorRoutes); +app.use("/api/v2", floadWidgetRoutes); +app.use("/api/v2", templateRoutes); export default app; diff --git a/src/api-server/controller/assets/pointService.ts b/src/api-server/controller/assets/pointService.ts index a26beca..e3cd816 100644 --- a/src/api-server/controller/assets/pointService.ts +++ b/src/api-server/controller/assets/pointService.ts @@ -35,14 +35,24 @@ export class pointService { isUsed: false, }, ], - triggers: [], + triggers: [ + { + uuid: "randomUUID", + name: "trigger 1", + type: "Inherit", + bufferTime: 0, + // delay: "Inherit", + // spawnInterval: "Inherit", + isUsed: false, + }, + ], // connections: { // source: { pathUUID: "modelUUID", pointUUID: "point1UUID" }, // targets: [], // }, }, { - uuid: "point1UUID", + uuid: "point2UUID", position: [0, 0.85, 0], rotation: [0, 0, 0], actions: [ @@ -56,14 +66,24 @@ export class pointService { isUsed: false, }, ], - triggers: [], + triggers: [ + { + uuid: "randomUUID", + name: "trigger 1", + type: "Inherit", + bufferTime: 0, + // delay: "Inherit", + // spawnInterval: "Inherit", + isUsed: false, + }, + ], // connections: { // source: { pathUUID: "modelUUID", pointUUID: "point1UUID" }, // targets: [], // }, }, { - uuid: "point1UUID", + uuid: "point3UUID", position: [0, 0.85, -2.2], rotation: [0, 0, 0], actions: [ @@ -77,14 +97,23 @@ export class pointService { isUsed: false, }, ], - triggers: [], + triggers: [ + { + uuid: "randomUUID", + name: "trigger 1", + type: "Inherit", + bufferTime: 0, + // delay: "Inherit", + // spawnInterval: "Inherit", + isUsed: false, + }, + ], // connections: { // source: { pathUUID: "modelUUID", pointUUID: "point1UUID" }, // targets: [], // }, }, ], - speed: 1, }); } // else if (type === "Vehicle") { diff --git a/src/api-server/controller/lines/zoneService.ts b/src/api-server/controller/lines/zoneService.ts index 61ba019..973be85 100644 --- a/src/api-server/controller/lines/zoneService.ts +++ b/src/api-server/controller/lines/zoneService.ts @@ -4,10 +4,10 @@ import panelSchema from "../../../shared/model/vizualization/panelmodel.ts"; import widgetSchema from "../../../shared/model/vizualization/widgemodel.ts"; export class Zoneservice { static async addandUpdateZone(req: Request, res: Response): Promise { - const organization = req.body.organization; - const zoneDatas = req.body.zonesdata; - + console.log("req.body: ", req.body); try { + const organization = req.body.organization; + const zoneDatas = req.body.zonesdata; const existingZone = await zoneSchema(organization).findOne({ zoneId: zoneDatas.zoneId, isArchive: false, @@ -43,6 +43,7 @@ export class Zoneservice { }, { new: true } ); + console.log("replaceZone: ", replaceZone); if (!replaceZone) return res.status(404).json({ message: "Zone not updated" }); else @@ -231,7 +232,8 @@ export class Zoneservice { static async ZoneData(req: Request, res: Response): Promise { try { - const organization = req.query.organization; + console.log("req.params: ", req.params); + const organization = req.params.organization; const zoneId = req.params.zoneId; const findZone = await zoneSchema(organization).findOne({ zoneId: zoneId, diff --git a/src/api-server/controller/simulation/assetsFloorservice.ts b/src/api-server/controller/simulation/assetsFloorservice.ts index 5cfbbad..b0e785a 100644 --- a/src/api-server/controller/simulation/assetsFloorservice.ts +++ b/src/api-server/controller/simulation/assetsFloorservice.ts @@ -10,9 +10,10 @@ export class assetsFloorservice { const { modeluuid, modelname, - position, + speed, + assetPosition, modelfileID, - rotation, + assetRotation, isLocked, isVisible, organization, @@ -28,8 +29,8 @@ export class assetsFloorservice { const updatevalue = await assetModel(organization).findOneAndUpdate( { modeluuid: modeluuid, modelname: modelname }, { - position: position, - rotation: rotation, + assetPosition: assetPosition, + assetRotation: assetRotation, isVisible: isVisible, isLocked: isLocked, }, @@ -37,95 +38,46 @@ export class assetsFloorservice { ); res.status(201).json(updatevalue); } else { - // const newValue = await assetModel(organization).create({ - // modeluuid, - // modelfileID, - // modelname, - // position, - // rotation, - // isLocked, - // isVisible, - // points, - // }); - - // for (const point of points) { - // // Create actions if they exist - // for (const action of point.actions || []) { - // const actionData = await actionModel(organization).create({ - // pointsUUID: point.uuid, - // actionUUID: action.uuid, - // eventData: { - // uuid: action.uuid, - // type: action.type, - // material: action.material, - // delay: action.delay, - // spawn_Interval: action.spawnInterval, - // }, - // }); - - // // Push action ID to point - // newValue.points - // .find((p: any) => p.uuid === point.uuid) - // ?.actions.push(actionData._id); - // } - - // // Create triggers if they exist - // for (const trigger of point.triggers || []) { - // const triggerData = await triggerModel(organization).create({ - // pointsUUID: point.uuid, - // actionUUID: trigger.uuid, - // triggerData: { - // type: trigger.type, - // }, - // }); - - // // Push trigger ID to point - // newValue.points - // .find((p: any) => p.uuid === point.uuid) - // ?.triggers.push(triggerData._id); - // } - // } - - // // Save the updated document - // await newValue.save(); - - // res.status(201).json(newValue); - let pointRefs = []; for (const point of points) { let actionRefs = []; let triggerRefs = []; - // Store Actions (Events) if (point.actions && point.actions.length > 0) { for (const action of point.actions) { const actionDoc = await actionModel(organization).create({ pointsUUID: point.uuid, - actionUUID: action.uuid, isArchive: false, - eventData: [action], // Store the action data + uuid: action.uuid, + name: action.name, + type: action.type, + material: action.material, + delay: action.delay, + spawn_Interval: action.spawn_Interval, + // eventData: [action], }); await actionDoc.save(); - actionRefs.push(actionDoc._id); // Store reference + actionRefs.push(actionDoc._id); } } - // Store Triggers if (point.triggers && point.triggers.length > 0) { for (const trigger of point.triggers) { const triggerDoc = await triggerModel(organization).create({ pointsUUID: point.uuid, - actionUUID: trigger.uuid, isArchive: false, - triggerData: [trigger], // Store trigger data + uuid: trigger.uuid, + name: trigger.name, + type: trigger.type, + bufferTime: trigger.bufferTime, + // triggerData: [trigger], }); await triggerDoc.save(); - triggerRefs.push(triggerDoc._id); // Store reference + triggerRefs.push(triggerDoc._id); } } - // Store the Point document pointRefs.push({ uuid: point.uuid, position: point.position, @@ -135,13 +87,13 @@ export class assetsFloorservice { }); } - // Store the main asset document const assetDoc = await assetModel(organization).create({ modeluuid, + speed, modelname, - position, + assetPosition, modelfileID, - rotation, + assetRotation, isLocked, isVisible, points: pointRefs, @@ -163,22 +115,29 @@ export class assetsFloorservice { const { organization } = req.params; const findValue = await assetModel(organization) .find() - .select("-_id -__v") + .select("-_id") + .populate({ + path: "points", + // model: assetModel(organization), + select: "-_id", + }) .populate({ path: "points.actions", - select: "-_id", - populate: { - path: "eventData", - select: "uuid type -_id", - }, + model: actionModel(organization), + // select: "-_id", + // populate: { + // path: "eventData", + select: "-__v -_id -isArchive -pointsUUID -createdAt -updatedAt", + // }, }) .populate({ path: "points.triggers", - select: "-_id", - populate: { - path: "triggerData", - select: "uuid type -_id", - }, + model: triggerModel(organization), + // select: "-_id", + // populate: { + // path: "triggerData", + select: "-__v -_id -isArchive -pointsUUID -createdAt -updatedAt", + // }, }); if (!findValue) { res.status(200).json("floorItems not found"); diff --git a/src/api-server/controller/visualization/floatWidgetService.ts b/src/api-server/controller/visualization/floatWidgetService.ts new file mode 100644 index 0000000..bb37c8f --- /dev/null +++ b/src/api-server/controller/visualization/floatWidgetService.ts @@ -0,0 +1,201 @@ +import { Request, Response } from "express"; +import floatWidgetModel from "../../../shared/model/vizualization/3dwidget.ts"; +import zoneSchema from "../../../shared/model/builder/lines/zone-Model.ts"; +export class floatWidgetService { + static async addfloatWidget(req: Request, res: Response): Promise { + try { + const { organization, widget, zoneId } = req.body; + const existingZone = await zoneSchema(organization).findOne({ + zoneId: zoneId, + isArchive: false, + }); + if (!existingZone) + return res + .status(404) + .json({ message: "Zone not found for the zoneId" }); + const existingFloatWidget = await floatWidgetModel(organization).findOne({ + floatWidgetID: widget.id, + isArchive: false, + }); + if (existingFloatWidget) { + const updateFloatWidget = await floatWidgetModel( + organization + ).findOneAndUpdate( + { + floatWidgetID: widget.id, + isArchive: false, + }, + { + $set: { + // Data: { + // // measurements: widget.Data.measurements || {}, + // duration: widget.Data.duration || "1h", + // }, + position: widget.position, + }, + }, + { + upsert: true, + new: true, + } + ); + + return res.status(200).json({ message: "Widget updated successfully" }); + } + + 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) { + return res + .status(201) + .json({ message: "FloatWidget created successfully" }); + } + } catch (error: any) { + return res.status(500).send(error.message); + } + } + static async getfloatWidget(req: Request, res: Response): Promise { + const { organization, zoneId } = req.params; + const existingZone = await zoneSchema(organization).findOne({ + zoneId: zoneId, + isArchive: false, + }); + if (!existingZone) + return res.status(404).json({ message: "Zone not found" }); + const widgetData = await floatWidgetModel(organization) + .find({ + zoneId: zoneId, + isArchive: false, + }) + .select("-_id -zoneId -createdAt -updatedAt -__v"); + if (!widgetData || widgetData.length === 0) { + return res.send([]); + } + + const formattedWidgets = widgetData.map((widget) => ({ + Data: { + measurements: widget.Data?.measurements || {}, + duration: widget.Data?.duration || "1h", + }, + className: widget.className, + header: widget.header, + id: widget.floatWidgetID, + position: widget.position, + per: widget.per, + value: widget.value, + })); + return res.status(200).json(formattedWidgets); + } + + // static async deleteWidget(req: Request, res: Response): Promise { + // try { + // const { widgetID, organization } = req.body; + // const findWidget = await widgetSchema(organization).findOne({ + // widgetID: widgetID, + // isArchive: false, + // }); + // if (!findWidget) + // return res.status(409).json({ message: "Widget not found" }); + // const widgetData = await widgetSchema(organization).updateOne( + // { _id: findWidget._id, isArchive: false }, + // { $set: { isArchive: true } } + // ); + + // if (widgetData) { + // // Find all widgets in the same panel and sort them by widgetOrder + // const widgets = await widgetSchema(organization).find({ + // panelID: findWidget.panelID, + // isArchive: false, + // }); + // // .sort({ widgetOrder: 1 }); + + // // Reassign widgetOrder values + // // for (let i = 0; i < widgets.length; i++) { + // // widgets[i].widgetOrder = (i + 1).toString(); // Convert to string + // // await widgets[i].save(); + // // } + // const panelData = await panelSchema(organization).findOne({ + // _id: findWidget.panelID, + // isArchive: false, + // }); + // if (panelData.widgets.includes(findWidget._id)) { + // const index1 = panelData.widgets.indexOf(findWidget._id); + // panelData.widgets.splice(index1, 1); + // } + // await panelData.save(); + // } + // return res.status(200).json({ message: "Widget deleted successfully" }); + // } catch (error: any) { + // return res.status(500).send(error.message); + // } + // } + + // static async updatewidget(req: Request, res: Response): Promise { + // try { + // const { organization, widgetID, values } = req.body; + // const findwidget = await widgetSchema(organization).findOne({ + // widgetID: widgetID, + // isArchive: false, + // }); + // if (!findwidget) + // return res.status(404).send({ message: "Data not found" }); + // const updateData = { + // widgetName: values.widgetName, + // widgetSide: values.widgetSide, // Fixed typo from widgetside to widgetSide + // elementType: values.type, + // Data: { + // measurement: values.Data.measurement, + // duration: values.Data.duration, + // }, + // elementColor: values.color, + // fontFamily: values.fontFamily, + // fontStyle: values.fontStyle, + // fontWeight: values.fontWeight, + // isArchive: false, + // }; + + // const changedWidget = await widgetSchema(organization).findOneAndUpdate( + // { widgetID: widgetID, isArchive: false }, + // updateData, + // { + // new: true, + // upsert: true, + // setDefaultsOnInsert: true, + // } + // ); + + // return res.status(200).json({ + // message: "Widget updated successfully", + // }); + // } catch (error: any) { + // return res.status(500).send(error.message); + // } + // } + + // static async getDatafromWidget(req: Request, res: Response): Promise { + // const { organization, widgetID } = req.params; + // try { + // const existingWidget = await widgetSchema(organization) + // .findOne({ + // widgetID: widgetID, + // isArchive: false, + // }) + // .select("Data -_id"); + // const Datastructure = { + // measurements: existingWidget.Data.measurements || {}, + // duration: existingWidget.Data.duration || "1h", + // }; + + // if (existingWidget) return res.status(200).json({ Data: Datastructure }); + // } catch (error: any) { + // return res.status(500).send(error.message); + // } + // } +} diff --git a/src/api-server/controller/visualization/panelService.ts b/src/api-server/controller/visualization/panelService.ts index 3e41a91..e95cedd 100644 --- a/src/api-server/controller/visualization/panelService.ts +++ b/src/api-server/controller/visualization/panelService.ts @@ -95,12 +95,10 @@ export class panelService { } if (existingZone.panelOrder.includes(existingPanel.panelName)) { - existingZone.panelOrder = existingZone.panelOrder.filter( - (panel: any) => panel !== existingPanel.panelName - ); - - await existingZone.save(); + const index1 = existingZone.panelOrder.indexOf(existingPanel.panelName); + existingZone.panelOrder.splice(index1, 1); } + await existingZone.save(); return res.status(200).json({ message: "Panel deleted successfully" }); } catch (error: any) { diff --git a/src/api-server/controller/visualization/templateService.ts b/src/api-server/controller/visualization/templateService.ts new file mode 100644 index 0000000..dee8b10 --- /dev/null +++ b/src/api-server/controller/visualization/templateService.ts @@ -0,0 +1,43 @@ +import { Request, Response } from "express"; +import templateModel from "../../../shared/model/vizualization/templatemodel.ts"; + +export class templateService { + static async AddTemplate(req: Request, res: Response): Promise { + try { + console.log("req.body: ", req.body); + const { organization, templateID, name, panelOrder, widgets, snapshot } = + req.body; + const existingTemplate = await templateModel(organization).findOne({ + templateID: templateID, + isArchive: false, + }); + if (existingTemplate) + return res.status(409).json({ message: "TemplateID alreay exists" }); + const newTemplate = await templateModel(organization).create({ + templateID, + name, + panelOrder, + widgets, + snapshot, + }); + if (newTemplate) + return res.status(200).json({ message: "Template saved successfully" }); + } catch (error: any) { + return res.status(500).send(error.message); + } + } + static async GetTemplate(req: Request, res: Response): Promise { + try { + const { organization } = req.params; + const existingTemplate = await templateModel(organization) + .find({ + isArchive: false, + }) + .select("-_id -__v -isArchive -createdAt -updatedAt"); + if (!existingTemplate) return res.status(409).send([]); + return res.status(200).json(existingTemplate); + } catch (error: any) { + return res.status(500).send(error.message); + } + } +} diff --git a/src/api-server/controller/visualization/widgetService.ts b/src/api-server/controller/visualization/widgetService.ts index 6cd9734..bce1b0a 100644 --- a/src/api-server/controller/visualization/widgetService.ts +++ b/src/api-server/controller/visualization/widgetService.ts @@ -1,15 +1,23 @@ import { Request, Response } from "express"; import panelSchema from "../../../shared/model/vizualization/panelmodel.ts"; +import zoneSchema from "../../../shared/model/builder/lines/zone-Model.ts"; import widgetSchema from "../../../shared/model/vizualization/widgemodel.ts"; export class widgetService { static async addWidget(req: Request, res: Response): Promise { try { + console.log("req.body: ", req.body); const { organization, // panel, zoneId, widget, } = req.body; + const existingZone = await zoneSchema(organization).findOne({ + zoneId: zoneId, + isArchive: false, + }); + if (!existingZone) + return res.status(404).json({ message: "Zone not found" }); const existingPanel = await panelSchema(organization).findOne({ panelName: widget.panel, zoneId: zoneId, @@ -25,10 +33,35 @@ export class widgetService { isArchive: false, // widgetOrder: widget.widgetOrder, }); + // console.log('existingWidget: ', widget.data.measurements); if (existingWidget) { + const updateWidget = await widgetSchema( + organization + ).findOneAndUpdate( + { + panelID: existingPanel._id, + widgetID: widget.id, + isArchive: false, + }, + { + $set: { + // panelID: existingPanel._id, + // widgetID: widget.id, + Data: { + measurements: widget.Data.measurements, + duration: widget.Data.duration, + }, + // isArchive: false, + }, + }, + { upsert: true, new: true } // Upsert: create if not exists, new: return updated document + ); return res - .status(409) - .json({ message: "Widget already exist for the widgetID" }); + .status(200) + .json({ message: "Widget updated successfully" }); + // return res + // .status(409) + // .json({ message: "Widget already exist for the widgetID" }); } const newWidget = await widgetSchema(organization).create({ widgetID: widget.id, @@ -39,7 +72,7 @@ export class widgetService { widgetside: widget.panel, // Data: { // measurements: widget.Data.measurements || {}, - // duration: widget.Data.duration || "1hr", + // duration: widget.Data.duration || "1h", // }, }); if (newWidget) { @@ -65,7 +98,7 @@ export class widgetService { isArchive: false, }); if (!findWidget) - return res.status(409).json({ message: "Widget already deleted" }); + return res.status(409).json({ message: "Widget not found" }); const widgetData = await widgetSchema(organization).updateOne( { _id: findWidget._id, isArchive: false }, { $set: { isArchive: true } } @@ -73,27 +106,24 @@ export class widgetService { if (widgetData) { // Find all widgets in the same panel and sort them by widgetOrder - const widgets = await widgetSchema(organization) - .find({ - panelID: findWidget.panelID, - isArchive: false, - }) - .sort({ widgetOrder: 1 }); + const widgets = await widgetSchema(organization).find({ + panelID: findWidget.panelID, + isArchive: false, + }); + // .sort({ widgetOrder: 1 }); // Reassign widgetOrder values - for (let i = 0; i < widgets.length; i++) { - widgets[i].widgetOrder = (i + 1).toString(); // Convert to string - await widgets[i].save(); - } + // for (let i = 0; i < widgets.length; i++) { + // widgets[i].widgetOrder = (i + 1).toString(); // Convert to string + // await widgets[i].save(); + // } const panelData = await panelSchema(organization).findOne({ _id: findWidget.panelID, isArchive: false, }); - if (panelData.widgets.includes(findWidget._id)) { - panelData.widgets = panelData.widgets.filter( - (widget: any) => widget !== findWidget._id - ); + const index1 = panelData.widgets.indexOf(findWidget._id); + panelData.widgets.splice(index1, 1); } await panelData.save(); } @@ -150,13 +180,13 @@ export class widgetService { try { const existingWidget = await widgetSchema(organization) .findOne({ - _id: widgetID, + widgetID: widgetID, isArchive: false, }) .select("Data -_id"); const Datastructure = { measurements: existingWidget.Data.measurements || {}, - duration: existingWidget.Data.duration || "1hr", + duration: existingWidget.Data.duration || "1h", }; if (existingWidget) return res.status(200).json({ Data: Datastructure }); diff --git a/src/shared/model/builder/assets/asset-Model.ts b/src/shared/model/builder/assets/asset-Model.ts index 400ea70..2ed9aae 100644 --- a/src/shared/model/builder/assets/asset-Model.ts +++ b/src/shared/model/builder/assets/asset-Model.ts @@ -1,44 +1,41 @@ import mongoose, { Document, Schema } from "mongoose"; import MainModel from "../../../connect/mongoose.ts"; -interface IAction { - uuid: string; - name: string; - type: string; - material: string; - delay: string; - spawnInterval: string; - isUsed: boolean; -} - -// Interface for TypeScript with PascalCase export interface assetData extends Document { modeluuid: string; modelfileID: string; modelname: string; isLocked: boolean; + type: string; isVisible: boolean; - position: []; - rotation: { - x: number; - y: number; - z: number; - }; - points: [ - { - uuid: string; - position: []; - rotation: []; - actions: [mongoose.Types.ObjectId]; - triggers: [mongoose.Types.ObjectId]; - // connections:{ - // source:{ - // pathuuid:string,pointuuid:string - // }, - // target:[] - // } - } - ]; + // position: []; + // rotation: { + // x: number; + // y: number; + // z: number; + // }; + points: { + uuid: string; + position: []; + rotation: []; + actions: [mongoose.Types.ObjectId]; + triggers: [mongoose.Types.ObjectId]; + connections: { + source: { + pathUUID: string; + pointUUID: string; + }; + targets: [ + { + pathUUID: string; + pointUUID: string; + } + ]; + }[]; + }[]; + assetPosition: number[]; + assetRotation: number[]; + speed: number; } // Define the Mongoose Schema @@ -46,7 +43,8 @@ const assetDataSchema: Schema = new Schema({ modeluuid: { type: String }, modelfileID: { type: String }, modelname: { type: String }, - position: { type: Array }, + type: { type: String }, + // assetPosition: { type: Array }, points: [ { uuid: { type: String }, @@ -54,15 +52,30 @@ const assetDataSchema: Schema = new Schema({ rotation: { type: Array }, actions: [{ type: mongoose.Schema.Types.ObjectId, ref: "Actions" }], triggers: [{ type: mongoose.Schema.Types.ObjectId, ref: "Triggers" }], + connections: { + source: { + pathUUID: { type: String }, + pointUUID: { type: String }, + }, + targets: [ + { + pathUUID: { type: String }, + pointUUID: { type: String }, + }, + ], + }, }, ], + assetPosition: { type: [Number] }, + assetRotation: { type: [Number] }, + speed: { type: Number }, isLocked: { type: Boolean }, isVisible: { type: Boolean }, - rotation: { - x: { type: Number }, - y: { type: Number }, - z: { type: Number }, - }, + // rotation: { + // x: { type: Number }, + // y: { type: Number }, + // z: { type: Number }, + // }, }); // export default floorItemsModel; diff --git a/src/shared/model/builder/assets/assetPoint-Model.ts b/src/shared/model/builder/assets/assetPoint-Model.ts index 5197e01..9fb4767 100644 --- a/src/shared/model/builder/assets/assetPoint-Model.ts +++ b/src/shared/model/builder/assets/assetPoint-Model.ts @@ -9,53 +9,81 @@ interface IAction { delay: string; spawnInterval: string; isUsed: boolean; + hitCount: number; + start: string; + end: string; + buffer: number; } -// interface IConnection { -// source: { pathUUID: string; pointUUID: string }; -// targets: string[]; -// } +interface ITriggers { + uuid: string; + name: string; + type: string; + isUsed: boolean; + bufferTime: number; +} + +interface IConnection { + source: { pathUUID: string; pointUUID: string }; + targets: { pathUUID: string; pointUUID: string }[]; +} interface IPoint { uuid: string; position: number[]; rotation: number[]; actions: IAction[]; - triggers: string[]; - // connections: IConnection; + triggers: ITriggers[]; + connections: IConnection; } interface IBaseModel extends Document { modelfileID: string; type: "Conveyor" | "Vehicle"; points: IPoint[] | IPoint; - speed: number; } // Base Schema const PointSchema = new Schema({ uuid: { type: String, required: true }, - position: { type: [Number], required: true }, - rotation: { type: [Number], required: true }, + position: { type: [Number] }, + rotation: { type: [Number] }, actions: [ { uuid: { type: String, default: "" }, - name: { type: String, required: true }, - type: { type: String, required: true }, - material: { type: String, required: true }, - delay: { type: String, required: true }, - spawnInterval: { type: String, required: true }, - isUsed: { type: Boolean, required: true }, + name: { type: String }, + type: { type: String }, + material: { type: String }, + delay: { type: String }, + spawnInterval: { type: String }, + isUsed: { type: Boolean }, + hitCount: { type: String }, + start: { type: String }, + end: { type: String }, + buffer: { type: String }, }, ], - triggers: { type: [String], default: [] }, - // connections: { - // source: { - // pathUUID: { type: String, required: true }, - // pointUUID: { type: String, required: true }, - // }, - // targets: { type: [String], default: [] }, - // }, + triggers: [ + { + uuid: { type: String, default: "" }, + name: { type: String }, + type: { type: String }, + bufferTime: { type: Number }, + isUsed: { type: Boolean }, + }, + ], + connections: { + source: { + pathUUID: { type: String }, + pointUUID: { type: String }, + }, + targets: [ + { + pathUUID: { type: String }, + pointUUID: { type: String }, + }, + ], + }, }); const BaseSchema = new Schema( @@ -66,7 +94,6 @@ const BaseSchema = new Schema( type: Schema.Types.Mixed, required: true, }, - speed: { type: Number }, }, { discriminatorKey: "type", timestamps: true } ); diff --git a/src/shared/model/simulation/actionmodel.ts b/src/shared/model/simulation/actionmodel.ts index 7b77ff5..f376c06 100644 --- a/src/shared/model/simulation/actionmodel.ts +++ b/src/shared/model/simulation/actionmodel.ts @@ -1,38 +1,46 @@ import mongoose, { Schema, Document, model } from "mongoose"; import MainModel from "../../connect/mongoose.ts"; -export interface Event extends Document { +export interface Action extends Document { pointsUUID: string; - actionUUID: string; + // actionUUID: string; isArchive: string; - sceneID: string; - eventData: { - uuid: string; - type: string; - material: string; - delay: number; - spawn_Interval: number; - }; + // sceneID: string; + // eventData: { + uuid: string; + name: string; + type: string; + material: string; + delay: string; + spawnInterval: string; + isUsed: boolean; + hitCount: number; + start: string; + end: string; + buffer: number; + // }; } -const eventSchema: Schema = new Schema( +const actionSchema: Schema = new Schema( { pointsUUID: { type: String }, isArchive: { type: Boolean, default: false }, - actionUUID: { type: String }, - eventData: [ - { - uuid: { type: String }, - type: { type: String }, - material: { type: String }, - delay: { type: Number }, - spawn_Interval: { type: Number }, - }, - ], + // actionUUID: { type: String }, + uuid: { type: String, default: "" }, + name: { type: String }, + type: { type: String }, + material: { type: String }, + delay: { type: String }, + spawnInterval: { type: String }, + isUsed: { type: Boolean }, + hitCount: { type: String }, + start: { type: String }, + end: { type: String }, + buffer: { type: String }, }, { timestamps: true } ); const actionModel = (db: any) => { - return MainModel(db, "Actions", eventSchema, "Actions"); + return MainModel(db, "Actions", actionSchema, "Actions"); }; export default actionModel; diff --git a/src/shared/model/simulation/triggersmodel.ts b/src/shared/model/simulation/triggersmodel.ts index b9a6b9e..83a0b7c 100644 --- a/src/shared/model/simulation/triggersmodel.ts +++ b/src/shared/model/simulation/triggersmodel.ts @@ -3,32 +3,26 @@ import MainModel from "../../connect/mongoose.ts"; export interface Trigger extends Document { pointsUUID: string; - actionUUID: string; + // triggerUUID: string; isArchive: string; - sceneID: string; - triggerData: { - uuid: string; - type: string; - // material: string; - // delay: number; - // spawn_Interval: number; - }; + // sceneID: string; + uuid: string; + name: string; + type: string; + isUsed: boolean; + bufferTime: number; } const triggerSchema: Schema = new Schema( { pointsUUID: { type: String }, isArchive: { type: Boolean, default: false }, - actionUUID: { type: String }, - sceneID: { type: String }, - triggerData: [ - { - uuid: { type: String }, - type: { type: String }, - // material: { type: String }, - // delay: { type: Number }, - // spawn_Interval: { type: Number }, - }, - ], + // triggerUUID: { type: String }, + uuid: { type: String, default: "" }, + name: { type: String }, + type: { type: String }, + material: { type: String }, + delay: { type: String }, + isUsed: { type: Boolean }, }, { timestamps: true } ); diff --git a/src/shared/model/vizualization/3dwidget.ts b/src/shared/model/vizualization/3dwidget.ts new file mode 100644 index 0000000..2222d40 --- /dev/null +++ b/src/shared/model/vizualization/3dwidget.ts @@ -0,0 +1,44 @@ +import mongoose, { Schema, Document, model } from "mongoose"; +import MainModel from "../../connect/mongoose.ts"; + +export interface floatingWidget extends Document { + className: string; + header: string; + floatWidgetID: string; + position: {}; + per: string; + value: string; + isArchive: boolean; + zoneId: string; + Data: { + measurements: {}; + duration: string; + }; +} +const floatingWidgetSchema: Schema = new Schema( + { + className: { type: String }, + header: { type: String }, + floatWidgetID: { type: String }, + position: { type: Object }, + per: { type: String }, + value: { type: String }, + zoneId: { type: String }, + Data: { + measurements: { type: Object, default: {} }, + duration: { type: String, default: "1h" }, + }, + isArchive: { type: Boolean, default: false }, + }, + { timestamps: true } +); + +const floatWidgetModel = (db: any) => { + return MainModel( + db, + "FloatingWidget", + floatingWidgetSchema, + "FloatingWidget" + ); +}; +export default floatWidgetModel; diff --git a/src/shared/model/vizualization/templatemodel.ts b/src/shared/model/vizualization/templatemodel.ts index e1917bc..0d5f163 100644 --- a/src/shared/model/vizualization/templatemodel.ts +++ b/src/shared/model/vizualization/templatemodel.ts @@ -3,11 +3,19 @@ import MainModel from "../../connect/mongoose.ts"; export interface Template extends Document { templateName: string; + templateID: string; + snapshot: string; + panelOrder: []; + widgets: []; isArchive: boolean; } const templateSchema: Schema = new Schema( { templateName: { type: String }, + templateID: { type: String }, + snapshot: { type: String }, + panelOrder: { type: Array }, + widgets: { type: Array }, isArchive: { type: Boolean, default: false }, }, { timestamps: true } diff --git a/src/shared/model/vizualization/widgemodel.ts b/src/shared/model/vizualization/widgemodel.ts index ec4bf70..4e0ee3d 100644 --- a/src/shared/model/vizualization/widgemodel.ts +++ b/src/shared/model/vizualization/widgemodel.ts @@ -14,7 +14,7 @@ export interface widget extends Document { isArchive: boolean; panelID: mongoose.Types.ObjectId; Data: { - measurement: [any]; + measurements: {}; duration: string; }; } @@ -29,8 +29,8 @@ const widgetSchema: Schema = new Schema( fontFamily: { type: String }, fontStyle: { type: String }, Data: { - measurements: { type: Array, default: [] }, - duration: { type: String, default: "1hr" }, + measurements: { type: Object, default: {} }, + duration: { type: String, default: "1h" }, }, fontWeight: { type: String }, isArchive: { type: Boolean, default: false },