Full Visualization Page API completed
This commit is contained in:
15
.env
15
.env
@@ -3,24 +3,9 @@
|
||||
# MONGO_PASSWORD=mongodb@hexr2002
|
||||
# MONGO_AUTH_DB=admin
|
||||
|
||||
|
||||
MONGO_USER=admin
|
||||
MONGO_PASSWORD=admin321
|
||||
MONGO_AUTH_DB=admin
|
||||
# MONGO_USER=admin
|
||||
# MONGO_PASSWORD=admin321
|
||||
# MONGO_AUTH_DB=admin
|
||||
MONGO_URI=mongodb://mongo/
|
||||
API_PORT=5000
|
||||
=======
|
||||
MONGO_URI=mongodb://192.168.0.111/
|
||||
MONGO_USER=mydata
|
||||
MONGO_PASSWORD=mongodb@hexr2002
|
||||
MONGO_AUTH_DB=admin
|
||||
# MONGO_USER=admin
|
||||
# MONGO_PASSWORD=admin321
|
||||
# MONGO_AUTH_DB=admin
|
||||
# MONGO_URI=mongodb://mongo/
|
||||
API_PORT=5000
|
||||
>>>>>>> Stashed changes
|
||||
SOCKET_PORT=8000
|
||||
@@ -2,8 +2,10 @@ import * as express from "express";
|
||||
import { floatWidgetService } from "../controller/visualization/floatWidgetService.ts";
|
||||
const router = express.Router();
|
||||
router.post("/floatwidget/save", floatWidgetService.addfloatWidget);
|
||||
router.patch("/floatwidget/delete", floatWidgetService.deletefloatWidget);
|
||||
router.get(
|
||||
"/floadData/:zoneId/:organization",
|
||||
floatWidgetService.getfloatWidget
|
||||
);
|
||||
router.get("/A_floatWidget/:floatWidgetID/:organization",floatWidgetService.getsinglefloatWidget)
|
||||
export default router;
|
||||
@@ -2,5 +2,11 @@ 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);
|
||||
router.get("/templateData/:organization", templateService.GetAllTemplates);
|
||||
router.post("/TemplatetoZone", templateService.AddToZone);
|
||||
router.patch(
|
||||
"/TemplateDelete/:templateID/:organization",
|
||||
templateService.Deletezone
|
||||
); //delete zone
|
||||
|
||||
export default router;
|
||||
|
||||
6
src/api-server/Routes/widget3dRoutes.ts
Normal file
6
src/api-server/Routes/widget3dRoutes.ts
Normal file
@@ -0,0 +1,6 @@
|
||||
import * as express from "express";
|
||||
import { widget3dService } from "../controller/visualization/3dWidgetService.ts";
|
||||
const router = express.Router();
|
||||
router.post("/3dwidget/save", widget3dService.add3Dwidget);
|
||||
router.get("/3dwidgetData/:zoneId/:organization", widget3dService.get3Dwiget);
|
||||
export default router;
|
||||
@@ -17,6 +17,8 @@ import assetpointRouter from "./Routes/assetpointRoutes.ts";
|
||||
import assetfloorRoutes from "./Routes/assetfloorRoutes.ts";
|
||||
import floadWidgetRoutes from "./Routes/floadWidgetRoute.ts";
|
||||
import templateRoutes from "./Routes/templateRoutes.ts";
|
||||
import widget3dRoutes from "./Routes/widget3dRoutes.ts";
|
||||
|
||||
const app = express();
|
||||
app.use(cors());
|
||||
app.use(express.json());
|
||||
@@ -44,4 +46,5 @@ app.use("/api/v2", assetpointRouter);
|
||||
app.use("/api/v2", assetfloorRoutes);
|
||||
app.use("/api/v2", floadWidgetRoutes);
|
||||
app.use("/api/v2", templateRoutes);
|
||||
app.use("/api/v2", widget3dRoutes);
|
||||
export default app;
|
||||
|
||||
@@ -158,7 +158,21 @@ export class pointService {
|
||||
modelfileID: modelfileID,
|
||||
})
|
||||
.select("-_id -__v -createdAt -updatedAt");
|
||||
res.send(getData);
|
||||
if (!getData) {
|
||||
return res.json({ message: "Data not found" });
|
||||
}
|
||||
|
||||
const formattedData = {
|
||||
modelfileID: getData?.modelfileID,
|
||||
type: getData?.type,
|
||||
points: Array.isArray(getData?.points)
|
||||
? getData.points.map((point: any) => ({
|
||||
position: point.position,
|
||||
rotation: point.rotation,
|
||||
}))
|
||||
: [],
|
||||
};
|
||||
return res.status(200).json(formattedData);
|
||||
} catch (error) {
|
||||
res.status(500).json({ message: "Server error", error });
|
||||
}
|
||||
|
||||
@@ -2,49 +2,71 @@ import { Request, Response } from "express";
|
||||
import environmentModel from "../../../shared/model/environments/environments-Model.ts";
|
||||
|
||||
export class environment {
|
||||
static async setEnvironment(req: Request, res: Response) {
|
||||
try {
|
||||
const { userId,roofVisibility,wallVisibility,shadowVisibility, organization } = req.body
|
||||
|
||||
static async setEnvironment(req: Request, res: Response) {
|
||||
try {
|
||||
const {
|
||||
userId,
|
||||
roofVisibility,
|
||||
wallVisibility,
|
||||
shadowVisibility,
|
||||
organization,
|
||||
renderDistance,
|
||||
limitDistance,
|
||||
} = req.body;
|
||||
|
||||
const findvalue = await environmentModel(organization).findOne({ userId: userId })
|
||||
|
||||
if (findvalue) {
|
||||
|
||||
const updatevalue = await environmentModel(organization).findOneAndUpdate(
|
||||
{ userId: userId }, { roofVisibility:roofVisibility,wallVisibility:wallVisibility,shadowVisibility:shadowVisibility}, { new: true });
|
||||
res.status(201).json(updatevalue);
|
||||
|
||||
const findvalue = await environmentModel(organization).findOne({
|
||||
userId: userId,
|
||||
});
|
||||
|
||||
} else {
|
||||
const newValue = await environmentModel(organization).create({ userId, roofVisibility, wallVisibility, });
|
||||
|
||||
|
||||
res.status(201).json(newValue);
|
||||
if (findvalue) {
|
||||
const updatevalue = await environmentModel(
|
||||
organization
|
||||
).findOneAndUpdate(
|
||||
{ userId: userId },
|
||||
{
|
||||
roofVisibility: roofVisibility,
|
||||
renderDistance: renderDistance,
|
||||
wallVisibility: wallVisibility,
|
||||
shadowVisibility: shadowVisibility,
|
||||
limitDistance: limitDistance,
|
||||
},
|
||||
{ new: true }
|
||||
);
|
||||
res.status(201).json(updatevalue);
|
||||
} else {
|
||||
const newValue = await environmentModel(organization).create({
|
||||
userId,
|
||||
roofVisibility,
|
||||
wallVisibility,
|
||||
renderDistance,
|
||||
shadowVisibility,
|
||||
limitDistance,
|
||||
});
|
||||
|
||||
}
|
||||
res.status(201).json(newValue);
|
||||
}
|
||||
|
||||
// Send response with the created document
|
||||
} catch (error) {
|
||||
console.error('Error creating environments:', error);
|
||||
res.status(500).json({message:"Failed to create environments"});
|
||||
}
|
||||
// Send response with the created document
|
||||
} catch (error) {
|
||||
console.error("Error creating environments:", error);
|
||||
res.status(500).json({ message: "Failed to create environments" });
|
||||
}
|
||||
static async getEnvironment(req: Request, res: Response) {
|
||||
try {
|
||||
const { userId, organization } = req.params;
|
||||
|
||||
}
|
||||
static async getEnvironment(req: Request, res: Response) {
|
||||
try {
|
||||
const { userId, organization } = req.params;
|
||||
|
||||
const findValue = await environmentModel(organization).findOne({ userId: userId })
|
||||
if (!findValue) {
|
||||
res.status(200).json("user not found");
|
||||
} else {
|
||||
|
||||
res.status(201).json(findValue);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error get environments:', error);
|
||||
res.status(500).json({ error: "Failed to get environments" });
|
||||
}
|
||||
const findValue = await environmentModel(organization).findOne({
|
||||
userId: userId,
|
||||
});
|
||||
if (!findValue) {
|
||||
res.status(200).json("user not found");
|
||||
} else {
|
||||
res.status(201).json(findValue);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Error get environments:", error);
|
||||
res.status(500).json({ error: "Failed to get environments" });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,102 +5,108 @@ import actionModel from "../../../shared/model/simulation/actionmodel.ts";
|
||||
import triggerModel from "../../../shared/model/simulation/triggersmodel.ts";
|
||||
|
||||
export class assetsFloorservice {
|
||||
static async setFloorassets(req: Request, res: Response) {
|
||||
static async setFloorassets(req: Request, res: Response): Promise<any> {
|
||||
try {
|
||||
console.log("req.body: ", req.body);
|
||||
const {
|
||||
modeluuid,
|
||||
modelname,
|
||||
speed,
|
||||
assetPosition,
|
||||
modelfileID,
|
||||
assetRotation,
|
||||
isLocked,
|
||||
isVisible,
|
||||
organization,
|
||||
points,
|
||||
eventData, // Optional
|
||||
} = req.body;
|
||||
|
||||
const findvalue = await assetModel(organization).findOne({
|
||||
modeluuid: modeluuid,
|
||||
modelname: modelname,
|
||||
modeluuid,
|
||||
modelname,
|
||||
});
|
||||
|
||||
if (findvalue) {
|
||||
const updatevalue = await assetModel(organization).findOneAndUpdate(
|
||||
{ modeluuid: modeluuid, modelname: modelname },
|
||||
{ modeluuid, modelname },
|
||||
{
|
||||
assetPosition: assetPosition,
|
||||
assetRotation: assetRotation,
|
||||
isVisible: isVisible,
|
||||
isLocked: isLocked,
|
||||
assetPosition,
|
||||
assetRotation,
|
||||
isVisible,
|
||||
isLocked,
|
||||
},
|
||||
{ new: true }
|
||||
);
|
||||
res.status(201).json(updatevalue);
|
||||
return res.status(201).json(updatevalue);
|
||||
} else {
|
||||
let pointRefs = [];
|
||||
|
||||
for (const point of points) {
|
||||
let actionRefs = [];
|
||||
let triggerRefs = [];
|
||||
|
||||
if (point.actions && point.actions.length > 0) {
|
||||
for (const action of point.actions) {
|
||||
const actionDoc = await actionModel(organization).create({
|
||||
pointsUUID: point.uuid,
|
||||
isArchive: false,
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
if (point.triggers && point.triggers.length > 0) {
|
||||
for (const trigger of point.triggers) {
|
||||
const triggerDoc = await triggerModel(organization).create({
|
||||
pointsUUID: point.uuid,
|
||||
isArchive: false,
|
||||
uuid: trigger.uuid,
|
||||
name: trigger.name,
|
||||
type: trigger.type,
|
||||
bufferTime: trigger.bufferTime,
|
||||
// triggerData: [trigger],
|
||||
});
|
||||
await triggerDoc.save();
|
||||
triggerRefs.push(triggerDoc._id);
|
||||
}
|
||||
}
|
||||
|
||||
pointRefs.push({
|
||||
uuid: point.uuid,
|
||||
position: point.position,
|
||||
rotation: point.rotation,
|
||||
actions: actionRefs,
|
||||
triggers: triggerRefs,
|
||||
});
|
||||
}
|
||||
|
||||
const assetDoc = await assetModel(organization).create({
|
||||
let assetData: any = {
|
||||
modeluuid,
|
||||
speed,
|
||||
modelname,
|
||||
assetPosition,
|
||||
modelfileID,
|
||||
assetRotation,
|
||||
isLocked,
|
||||
isVisible,
|
||||
points: pointRefs,
|
||||
});
|
||||
};
|
||||
|
||||
if (eventData) {
|
||||
let pointRefs: any[] = [];
|
||||
|
||||
if (Array.isArray(eventData.points)) {
|
||||
for (const point of eventData.points) {
|
||||
let actionRefs: any[] = [];
|
||||
let triggerRefs: any[] = [];
|
||||
|
||||
if (Array.isArray(point.actions)) {
|
||||
for (const action of point.actions) {
|
||||
const actionDoc = await actionModel(organization).create({
|
||||
pointsUUID: point.uuid,
|
||||
isArchive: false,
|
||||
uuid: action.uuid,
|
||||
name: action.name,
|
||||
type: action.type,
|
||||
material: action.material,
|
||||
delay: action.delay,
|
||||
spawn_Interval: action.spawn_Interval,
|
||||
});
|
||||
await actionDoc.save();
|
||||
actionRefs.push(actionDoc._id);
|
||||
}
|
||||
}
|
||||
|
||||
if (Array.isArray(point.triggers)) {
|
||||
for (const trigger of point.triggers) {
|
||||
const triggerDoc = await triggerModel(organization).create({
|
||||
pointsUUID: point.uuid,
|
||||
isArchive: false,
|
||||
uuid: trigger.uuid,
|
||||
name: trigger.name,
|
||||
type: trigger.type,
|
||||
bufferTime: trigger.bufferTime,
|
||||
});
|
||||
await triggerDoc.save();
|
||||
triggerRefs.push(triggerDoc._id);
|
||||
}
|
||||
}
|
||||
|
||||
pointRefs.push({
|
||||
uuid: point.uuid,
|
||||
position: point.position || [],
|
||||
rotation: point.rotation || [],
|
||||
actions: actionRefs,
|
||||
triggers: triggerRefs,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
assetData.speed = eventData.speed;
|
||||
assetData.type = eventData.type;
|
||||
assetData.points = pointRefs;
|
||||
}
|
||||
|
||||
const assetDoc = await assetModel(organization).create(assetData);
|
||||
await assetDoc.save();
|
||||
res.status(201).json({
|
||||
|
||||
return res.status(201).json({
|
||||
message: "Model stored successfully",
|
||||
modelId: assetDoc._id,
|
||||
});
|
||||
@@ -110,39 +116,52 @@ export class assetsFloorservice {
|
||||
res.status(500).json({ message: "Failed to create flooritems" });
|
||||
}
|
||||
}
|
||||
static async getFloorItems(req: Request, res: Response) {
|
||||
static async getFloorItems(req: Request, res: Response): Promise<any> {
|
||||
try {
|
||||
const { organization } = req.params;
|
||||
const findValue = await assetModel(organization)
|
||||
const findValues = await assetModel(organization)
|
||||
.find()
|
||||
.select("-_id")
|
||||
.populate({
|
||||
path: "points",
|
||||
// model: assetModel(organization),
|
||||
select: "-_id",
|
||||
})
|
||||
.populate({
|
||||
path: "points.actions",
|
||||
model: actionModel(organization),
|
||||
// select: "-_id",
|
||||
// populate: {
|
||||
// path: "eventData",
|
||||
select: "-__v -_id -isArchive -pointsUUID -createdAt -updatedAt",
|
||||
// },
|
||||
})
|
||||
.populate({
|
||||
path: "points.triggers",
|
||||
model: triggerModel(organization),
|
||||
// select: "-_id",
|
||||
// populate: {
|
||||
// path: "triggerData",
|
||||
select: "-__v -_id -isArchive -pointsUUID -createdAt -updatedAt",
|
||||
// },
|
||||
});
|
||||
if (!findValue) {
|
||||
if (!findValues) {
|
||||
res.status(200).json("floorItems not found");
|
||||
} else {
|
||||
res.status(201).json(findValue);
|
||||
return res.status(200).json(
|
||||
findValues.map((item) => {
|
||||
let responseItem: any = {
|
||||
modeluuid: item.modeluuid,
|
||||
modelname: item.modelname,
|
||||
assetPosition: item.assetPosition,
|
||||
modelfileID: item.modelfileID,
|
||||
assetRotation: item.assetRotation,
|
||||
isLocked: item.isLocked,
|
||||
isVisible: item.isVisible,
|
||||
};
|
||||
|
||||
if (item.points.length > 1) {
|
||||
responseItem.eventData = {
|
||||
speed: item.speed,
|
||||
points: item.points,
|
||||
type: item.type,
|
||||
};
|
||||
}
|
||||
|
||||
return responseItem;
|
||||
})
|
||||
);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Error get flooritems:", error);
|
||||
@@ -167,4 +186,6 @@ export class assetsFloorservice {
|
||||
res.status(500).json({ error: "Failed to get flooritems" });
|
||||
}
|
||||
}
|
||||
|
||||
static async updateActionsDatas(req: Request, res: Response) {}
|
||||
}
|
||||
|
||||
106
src/api-server/controller/visualization/3dWidgetService.ts
Normal file
106
src/api-server/controller/visualization/3dWidgetService.ts
Normal file
@@ -0,0 +1,106 @@
|
||||
import { Request, Response } from "express";
|
||||
import zoneSchema from "../../../shared/model/builder/lines/zone-Model.ts";
|
||||
import widget3dModel from "../../../shared/model/vizualization/3dwidget.ts";
|
||||
export class widget3dService {
|
||||
static async add3Dwidget(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" });
|
||||
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 res
|
||||
.status(200)
|
||||
.json({ message: "widget update successfully" });
|
||||
else return res.send("Widget not updated");
|
||||
}
|
||||
const newWidget3d = await widget3dModel(organization).create({
|
||||
widgetName: widget.type,
|
||||
widgetID: widget.id,
|
||||
position: widget.position,
|
||||
zoneId,
|
||||
});
|
||||
if (newWidget3d)
|
||||
return res.status(201).json({ message: "Widget created successfully" });
|
||||
} catch (error: any) {
|
||||
return res.status(500).send(error.message);
|
||||
}
|
||||
}
|
||||
static async get3Dwiget(req: Request, res: Response): Promise<any> {
|
||||
try {
|
||||
const { organization, zoneId } = req.params;
|
||||
const existingZone = await zoneSchema(organization).findOne({
|
||||
zoneId: zoneId,
|
||||
isArchive: false,
|
||||
});
|
||||
if (!existingZone) return res.send("Zone not found");
|
||||
const widgetData = await widget3dModel(organization).find({
|
||||
zoneId: zoneId,
|
||||
isArchive: false,
|
||||
});
|
||||
if (!widgetData || widgetData.length === 0) {
|
||||
return res.json([]);
|
||||
}
|
||||
|
||||
const zonebasedWidget = widgetData.map((widget) => ({
|
||||
Data: {
|
||||
measurements: widget.Data?.measurements || {},
|
||||
duration: widget.Data?.duration || "1h",
|
||||
},
|
||||
type: widget.widgetName,
|
||||
id: widget.widgetID,
|
||||
position: widget.position,
|
||||
}));
|
||||
return res.status(200).json(zonebasedWidget);
|
||||
} catch (error: any) {
|
||||
return res.status(500).send(error.message);
|
||||
}
|
||||
}
|
||||
// static async update3Dposition(req: Request, res: Response): Promise<any> {
|
||||
// try {
|
||||
// const { organization, id, position, zoneId } = req.body;
|
||||
// const existing3Dwidget = await widget3dModel(organization).findOne({
|
||||
// widgetID: id,
|
||||
// isArchive: false,
|
||||
// });
|
||||
// if (existing3Dwidget) {
|
||||
// const update3dwidget = await widget3dModel(
|
||||
// organization
|
||||
// ).findOneAndUpdate(
|
||||
// {
|
||||
// widgetID: id,
|
||||
// zoneId: zoneId,
|
||||
// isArchive: false,
|
||||
// },
|
||||
// { position: position },
|
||||
// { upsert: true, new: true }
|
||||
// );
|
||||
// if (update3dwidget)
|
||||
// return res.status(200).send("widget update successfully");
|
||||
// } else {
|
||||
// return res.status(404).send("widget not found");
|
||||
// }
|
||||
// } catch (error: any) {
|
||||
// return res.status(500).send(error.message);
|
||||
// }
|
||||
// }
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
import { Request, Response } from "express";
|
||||
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 class floatWidgetService {
|
||||
static async addfloatWidget(req: Request, res: Response): Promise<any> {
|
||||
@@ -16,6 +16,7 @@ export class floatWidgetService {
|
||||
const existingFloatWidget = await floatWidgetModel(organization).findOne({
|
||||
floatWidgetID: widget.id,
|
||||
isArchive: false,
|
||||
zoneId: zoneId,
|
||||
});
|
||||
if (existingFloatWidget) {
|
||||
const updateFloatWidget = await floatWidgetModel(
|
||||
@@ -27,11 +28,12 @@ export class floatWidgetService {
|
||||
},
|
||||
{
|
||||
$set: {
|
||||
// Data: {
|
||||
// // measurements: widget.Data.measurements || {},
|
||||
// duration: widget.Data.duration || "1h",
|
||||
// },
|
||||
position: widget.position,
|
||||
Data: {
|
||||
measurements: widget?.Data.measurements,
|
||||
duration: widget?.Data.duration,
|
||||
},
|
||||
header: widget?.header,
|
||||
position: widget?.position,
|
||||
},
|
||||
},
|
||||
{
|
||||
@@ -94,49 +96,48 @@ export class floatWidgetService {
|
||||
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 deletefloatWidget(req: Request, res: Response): Promise<any> {
|
||||
try {
|
||||
const { floatWidgetID, organization } = req.body;
|
||||
const findfloatWidget = await floatWidgetModel(organization).findOne({
|
||||
floatWidgetID: floatWidgetID,
|
||||
isArchive: false,
|
||||
});
|
||||
if (!findfloatWidget)
|
||||
return res.status(409).json({ message: "Widget not found" });
|
||||
const widgetData = await floatWidgetModel(organization).updateOne(
|
||||
{ _id: findfloatWidget._id, isArchive: false },
|
||||
{ $set: { isArchive: true } }
|
||||
);
|
||||
return res
|
||||
.status(200)
|
||||
.json({ message: "FloatingWidget deleted successfully" });
|
||||
} catch (error: any) {
|
||||
return res.status(500).send(error.message);
|
||||
}
|
||||
}
|
||||
static async getsinglefloatWidget(req: Request, res: Response): Promise<any> {
|
||||
try {
|
||||
const { organization, floatWidgetID } = req.params;
|
||||
const widgetData = await floatWidgetModel(organization)
|
||||
.findOne({
|
||||
floatWidgetID: floatWidgetID,
|
||||
isArchive: false,
|
||||
})
|
||||
.select("-_id -zoneId -createdAt -updatedAt -__v");
|
||||
if (!widgetData || widgetData.length === 0) {
|
||||
return res.send([]);
|
||||
}
|
||||
const Datastructure = {
|
||||
measurements: widgetData?.Data.measurements || {},
|
||||
duration: widgetData?.Data.duration || "1h",
|
||||
};
|
||||
const header = widgetData?.header;
|
||||
return res.status(200).json({ Data: Datastructure, header });
|
||||
} 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;
|
||||
|
||||
@@ -1,24 +1,38 @@
|
||||
import { Request, Response } from "express";
|
||||
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 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 {
|
||||
organization,
|
||||
template,
|
||||
// id,
|
||||
// name,
|
||||
// panelOrder,
|
||||
// widgets,
|
||||
// snapshot,
|
||||
// floatWidgets,
|
||||
} = req.body;
|
||||
// console.log("req.body: ", req.body);
|
||||
const existingTemplate = await templateModel(organization).findOne({
|
||||
templateID: templateID,
|
||||
templateID: template.id,
|
||||
isArchive: false,
|
||||
});
|
||||
if (existingTemplate)
|
||||
return res.status(409).json({ message: "TemplateID alreay exists" });
|
||||
return res.json({ message: "TemplateID alreay exists" });
|
||||
const newTemplate = await templateModel(organization).create({
|
||||
templateID,
|
||||
name,
|
||||
panelOrder,
|
||||
widgets,
|
||||
snapshot,
|
||||
templateID: template.id,
|
||||
templateName: template.name,
|
||||
panelOrder: template.panelOrder,
|
||||
widgets: template.widgets,
|
||||
snapshot: template.snapshot,
|
||||
floatWidgets: template.floatingWidget,
|
||||
Widgets3D: template.Widgets3D,
|
||||
});
|
||||
if (newTemplate)
|
||||
return res.status(200).json({ message: "Template saved successfully" });
|
||||
@@ -26,16 +40,162 @@ export class templateService {
|
||||
return res.status(500).send(error.message);
|
||||
}
|
||||
}
|
||||
static async GetTemplate(req: Request, res: Response): Promise<any> {
|
||||
static async GetAllTemplates(req: Request, res: Response): Promise<any> {
|
||||
try {
|
||||
const { organization } = req.params;
|
||||
const existingTemplate = await templateModel(organization)
|
||||
const templateDatas = 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);
|
||||
if (!templateDatas) return res.status(200).send([]);
|
||||
|
||||
const formattedTemplates = templateDatas.map((data) => ({
|
||||
id: data.templateID,
|
||||
name: data.templateName,
|
||||
panelOrder: data.panelOrder,
|
||||
widgets: data.widgets,
|
||||
floatingWidget: data.floatWidgets,
|
||||
widgets3D: data.Widgets3D,
|
||||
snapshot: data.snapshot,
|
||||
}));
|
||||
|
||||
return res.status(200).json(formattedTemplates);
|
||||
} catch (error: any) {
|
||||
return res.status(500).send(error.message);
|
||||
}
|
||||
}
|
||||
static async AddToZone(req: Request, res: Response): Promise<any> {
|
||||
const { zoneId, templateID, organization } = req.body;
|
||||
try {
|
||||
const existingZone = await zoneSchema(organization).findOne({
|
||||
zoneId: zoneId,
|
||||
isArchive: false,
|
||||
});
|
||||
if (!existingZone)
|
||||
return res.status(404).json({ message: "Zone not found" });
|
||||
|
||||
const existingTemplate = await templateModel(organization).findOne({
|
||||
templateID: templateID,
|
||||
isArchive: false,
|
||||
});
|
||||
if (!existingTemplate)
|
||||
return res.status(409).json({ message: "TemplateID not found" });
|
||||
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,
|
||||
});
|
||||
}
|
||||
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,
|
||||
});
|
||||
}
|
||||
|
||||
return res
|
||||
.status(201)
|
||||
.json({ message: "Template placed in Zone", createdPanels });
|
||||
} catch (error: any) {
|
||||
return res.status(500).send(error.message);
|
||||
}
|
||||
}
|
||||
static async Deletezone(req: Request, res: Response): Promise<any> {
|
||||
try {
|
||||
console.log("req.params: ", req.params);
|
||||
const { organization, templateID } = req.params;
|
||||
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)
|
||||
return res
|
||||
.status(200)
|
||||
.json({ message: "Template deleted successfully" });
|
||||
}
|
||||
} catch (error: any) {
|
||||
return res.status(500).send(error.message);
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ 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);
|
||||
// console.log("req.body: ", req.body);
|
||||
const {
|
||||
organization,
|
||||
// panel,
|
||||
@@ -47,15 +47,17 @@ export class widgetService {
|
||||
$set: {
|
||||
// panelID: existingPanel._id,
|
||||
// widgetID: widget.id,
|
||||
widgetName: widget.widgetName,
|
||||
Data: {
|
||||
measurements: widget.Data.measurements,
|
||||
duration: widget.Data.duration,
|
||||
measurements: widget.Data?.measurements || {},
|
||||
duration: widget.Data?.duration || "1h",
|
||||
},
|
||||
// isArchive: false,
|
||||
},
|
||||
},
|
||||
{ upsert: true, new: true } // Upsert: create if not exists, new: return updated document
|
||||
);
|
||||
console.log("updateWidget: ", updateWidget);
|
||||
return res
|
||||
.status(200)
|
||||
.json({ message: "Widget updated successfully" });
|
||||
@@ -183,13 +185,16 @@ export class widgetService {
|
||||
widgetID: widgetID,
|
||||
isArchive: false,
|
||||
})
|
||||
.select("Data -_id");
|
||||
.select("Data widgetName -_id");
|
||||
if (!existingWidget)
|
||||
return res.json({ message: "Widget not found for the widgetID" });
|
||||
const Datastructure = {
|
||||
measurements: existingWidget.Data.measurements || {},
|
||||
duration: existingWidget.Data.duration || "1h",
|
||||
};
|
||||
|
||||
if (existingWidget) return res.status(200).json({ Data: Datastructure });
|
||||
const widgetName = existingWidget.widgetName || "Widget";
|
||||
if (existingWidget)
|
||||
return res.status(200).json({ Data: Datastructure, widgetName });
|
||||
} catch (error: any) {
|
||||
return res.status(500).send(error.message);
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ export interface assetData extends Document {
|
||||
}[];
|
||||
assetPosition: number[];
|
||||
assetRotation: number[];
|
||||
speed: number;
|
||||
speed: number | string;
|
||||
}
|
||||
|
||||
// Define the Mongoose Schema
|
||||
@@ -68,7 +68,7 @@ const assetDataSchema: Schema = new Schema({
|
||||
],
|
||||
assetPosition: { type: [Number] },
|
||||
assetRotation: { type: [Number] },
|
||||
speed: { type: Number },
|
||||
speed: { type: Schema.Types.Mixed },
|
||||
isLocked: { type: Boolean },
|
||||
isVisible: { type: Boolean },
|
||||
// rotation: {
|
||||
|
||||
@@ -1,18 +1,23 @@
|
||||
import mongoose, { Document, Schema } from 'mongoose';
|
||||
import MainModel from '../../connect/mongoose.ts';
|
||||
import mongoose, { Document, Schema } from "mongoose";
|
||||
import MainModel from "../../connect/mongoose.ts";
|
||||
// Interface for TypeScript with PascalCase
|
||||
export interface environment extends Document {
|
||||
userId: string;
|
||||
roofVisibility:boolean
|
||||
wallVisibility:boolean
|
||||
roofVisibility: boolean;
|
||||
wallVisibility: boolean;
|
||||
renderDistance: number;
|
||||
shadowVisibility: boolean;
|
||||
limitDistance: boolean;
|
||||
}
|
||||
|
||||
// Define the Mongoose Schema
|
||||
const environmentSchema: Schema = new Schema({
|
||||
userId: { type: String, unique: true },
|
||||
roofVisibility: { type: Boolean ,default:false},
|
||||
wallVisibility: { type: Boolean ,default:false},
|
||||
shadowVisibility: { type: Boolean ,default:false},
|
||||
roofVisibility: { type: Boolean, default: false },
|
||||
wallVisibility: { type: Boolean, default: false },
|
||||
shadowVisibility: { type: Boolean, default: false },
|
||||
renderDistance: { type: Number, default: false },
|
||||
limitDistance: { type: Boolean, default: true },
|
||||
});
|
||||
|
||||
// Model for MongoDB collection
|
||||
@@ -33,7 +38,7 @@ const environmentSchema: Schema = new Schema({
|
||||
// }
|
||||
|
||||
// export default environmentModel;
|
||||
const environmentModel = (db:string) => {
|
||||
return MainModel(db, "environments", environmentSchema, "environments")
|
||||
const environmentModel = (db: string) => {
|
||||
return MainModel(db, "environments", environmentSchema, "environments");
|
||||
};
|
||||
export default environmentModel;
|
||||
export default environmentModel;
|
||||
|
||||
@@ -1,13 +1,10 @@
|
||||
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;
|
||||
export interface Widget3d extends Document {
|
||||
widgetName: string;
|
||||
widgetID: string;
|
||||
position: [];
|
||||
isArchive: boolean;
|
||||
zoneId: string;
|
||||
Data: {
|
||||
@@ -15,14 +12,11 @@ export interface floatingWidget extends Document {
|
||||
duration: string;
|
||||
};
|
||||
}
|
||||
const floatingWidgetSchema: Schema = new Schema(
|
||||
const Widget3dSchema: Schema = new Schema(
|
||||
{
|
||||
className: { type: String },
|
||||
header: { type: String },
|
||||
floatWidgetID: { type: String },
|
||||
position: { type: Object },
|
||||
per: { type: String },
|
||||
value: { type: String },
|
||||
widgetName: { type: String },
|
||||
widgetID: { type: String },
|
||||
position: { type: Array },
|
||||
zoneId: { type: String },
|
||||
Data: {
|
||||
measurements: { type: Object, default: {} },
|
||||
@@ -33,12 +27,7 @@ const floatingWidgetSchema: Schema = new Schema(
|
||||
{ timestamps: true }
|
||||
);
|
||||
|
||||
const floatWidgetModel = (db: any) => {
|
||||
return MainModel(
|
||||
db,
|
||||
"FloatingWidget",
|
||||
floatingWidgetSchema,
|
||||
"FloatingWidget"
|
||||
);
|
||||
const widget3dModel = (db: any) => {
|
||||
return MainModel(db, "3dWidget", Widget3dSchema, "3dWidget");
|
||||
};
|
||||
export default floatWidgetModel;
|
||||
export default widget3dModel;
|
||||
|
||||
44
src/shared/model/vizualization/floatWidget.ts
Normal file
44
src/shared/model/vizualization/floatWidget.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;
|
||||
@@ -7,6 +7,8 @@ export interface Template extends Document {
|
||||
snapshot: string;
|
||||
panelOrder: [];
|
||||
widgets: [];
|
||||
floatWidgets: [];
|
||||
Widgets3D: [];
|
||||
isArchive: boolean;
|
||||
}
|
||||
const templateSchema: Schema = new Schema(
|
||||
@@ -16,6 +18,8 @@ const templateSchema: Schema = new Schema(
|
||||
snapshot: { type: String },
|
||||
panelOrder: { type: Array },
|
||||
widgets: { type: Array },
|
||||
floatWidgets: { type: Array },
|
||||
Widgets3D: { type: Array },
|
||||
isArchive: { type: Boolean, default: false },
|
||||
},
|
||||
{ timestamps: true }
|
||||
|
||||
@@ -20,7 +20,7 @@ export interface widget extends Document {
|
||||
}
|
||||
const widgetSchema: Schema = new Schema(
|
||||
{
|
||||
widgetName: { type: String },
|
||||
widgetName: { type: String, default: "Widget" },
|
||||
widgetside: { type: String },
|
||||
widgetID: { type: String },
|
||||
widgetOrder: { type: String },
|
||||
|
||||
Reference in New Issue
Block a user