Visualization Part 2d and floating API Completed. Template Save and Get API completed
This commit is contained in:
2
.env
2
.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
|
||||
|
||||
9
src/api-server/Routes/floadWidgetRoute.ts
Normal file
9
src/api-server/Routes/floadWidgetRoute.ts
Normal file
@@ -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;
|
||||
6
src/api-server/Routes/templateRoutes.ts
Normal file
6
src/api-server/Routes/templateRoutes.ts
Normal file
@@ -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;
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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") {
|
||||
|
||||
@@ -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<any> {
|
||||
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<any> {
|
||||
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,
|
||||
|
||||
@@ -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");
|
||||
|
||||
201
src/api-server/controller/visualization/floatWidgetService.ts
Normal file
201
src/api-server/controller/visualization/floatWidgetService.ts
Normal file
@@ -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<any> {
|
||||
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<any> {
|
||||
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<any> {
|
||||
// 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<any> {
|
||||
// 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<any> {
|
||||
// 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);
|
||||
// }
|
||||
// }
|
||||
}
|
||||
@@ -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) {
|
||||
|
||||
43
src/api-server/controller/visualization/templateService.ts
Normal file
43
src/api-server/controller/visualization/templateService.ts
Normal file
@@ -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<any> {
|
||||
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<any> {
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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<any> {
|
||||
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 });
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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<IPoint>({
|
||||
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<IBaseModel>(
|
||||
@@ -66,7 +94,6 @@ const BaseSchema = new Schema<IBaseModel>(
|
||||
type: Schema.Types.Mixed,
|
||||
required: true,
|
||||
},
|
||||
speed: { type: Number },
|
||||
},
|
||||
{ discriminatorKey: "type", timestamps: true }
|
||||
);
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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 }
|
||||
);
|
||||
|
||||
44
src/shared/model/vizualization/3dwidget.ts
Normal file
44
src/shared/model/vizualization/3dwidget.ts
Normal file
@@ -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;
|
||||
@@ -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 }
|
||||
|
||||
@@ -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 },
|
||||
|
||||
Reference in New Issue
Block a user