Zone rename, model rename, clear panel and locked panel API and socket completed

This commit is contained in:
2025-04-09 18:22:12 +05:30
parent c4d8fc14c8
commit 40eb9d8fb9
12 changed files with 450 additions and 124 deletions

View File

@@ -136,5 +136,7 @@ router.post("/panel/save", panelService.AddPanel);
* description: Server error * description: Server error
*/ */
router.patch("/panel/delete", panelService.deletePanel); router.patch("/panel/delete", panelService.deletePanel);
router.patch("/clearpanel", panelService.clearPanel);
// router.get("/zone/:sceneID", Zoneservice.allZones); // router.get("/zone/:sceneID", Zoneservice.allZones);
export default router; export default router;

View File

@@ -538,4 +538,5 @@ router.get("/A_zone/:zoneId/:organization", Zoneservice.ZoneData);
*/ */
router.patch("/zone/:zoneId", Zoneservice.deleteAZone); //delete Zone router.patch("/zone/:zoneId", Zoneservice.deleteAZone); //delete Zone
// router.get("/zone/:sceneID", Zoneservice.allZones); // router.get("/zone/:sceneID", Zoneservice.allZones);
router.patch("/zones/lockedPanels", Zoneservice.lockedPanel);
export default router; export default router;

View File

@@ -1,34 +1,56 @@
import { Request, Response } from "express"; import { Request, Response } from "express";
import floorItemsModel from "../../../shared/model/assets/flooritems-Model.ts"; import floorItemsModel from "../../../shared/model/assets/flooritems-Model.ts";
export class floorItems { export class floorItems {
static async setFloorItems(req: Request, res: Response) { static async setFloorItems(req: Request, res: Response) {
try { try {
const { modeluuid, modelname, position, modelfileID,rotation,isLocked,isVisible,organization } = req.body const {
modeluuid,
modelname,
position,
modelfileID,
rotation,
isLocked,
isVisible,
organization,
} = req.body;
const findvalue = await floorItemsModel(organization).findOne({
const findvalue = await floorItemsModel(organization).findOne({ modeluuid: modeluuid,modelname:modelname }) modeluuid: modeluuid,
modelname: modelname,
});
if (findvalue) { if (findvalue) {
const updatevalue = await floorItemsModel(
const updatevalue = await floorItemsModel(organization).findOneAndUpdate( organization
{ modeluuid: modeluuid,modelname:modelname }, { position: position, rotation: rotation,isVisible:isVisible,isLocked:isLocked }, { new: true }); ).findOneAndUpdate(
{ modeluuid: modeluuid, modelname: modelname },
{
position: position,
rotation: rotation,
isVisible: isVisible,
isLocked: isLocked,
},
{ new: true }
);
res.status(201).json(updatevalue); res.status(201).json(updatevalue);
} else { } else {
const newValue = await floorItemsModel(organization).create({
const newValue = await floorItemsModel(organization).create({ modeluuid, modelfileID,modelname, position, rotation,isLocked,isVisible, }); modeluuid,
modelfileID,
modelname,
position,
rotation,
isLocked,
isVisible,
});
res.status(201).json(newValue); res.status(201).json(newValue);
} }
// Send response with the created document // Send response with the created document
} catch (error) { } catch (error) {
console.error('Error creating flooritems:', error); console.error("Error creating flooritems:", error);
res.status(500).json({ message: "Failed to create flooritems" }); res.status(500).json({ message: "Failed to create flooritems" });
} }
} }
@@ -37,31 +59,32 @@ export class floorItems {
const { organization } = req.params; const { organization } = req.params;
// console.log('req.params: ', req.params); // console.log('req.params: ', req.params);
const findValue = await floorItemsModel(organization).find() const findValue = await floorItemsModel(organization).find();
if (!findValue) { if (!findValue) {
res.status(200).json("floorItems not found"); res.status(200).json("floorItems not found");
} else { } else {
res.status(201).json(findValue); res.status(201).json(findValue);
} }
} catch (error) { } catch (error) {
console.error('Error get flooritems:', error); console.error("Error get flooritems:", error);
res.status(500).json({ error: "Failed to get flooritems" }); res.status(500).json({ error: "Failed to get flooritems" });
} }
} }
static async deleteFloorItems(req: Request, res: Response) { static async deleteFloorItems(req: Request, res: Response) {
try { try {
const { modeluuid,modelname,organization } = req.body; const { modeluuid, modelname, organization } = req.body;
const findValue = await floorItemsModel(organization).findOneAndDelete({modeluuid:modeluuid,modelname:modelname}) const findValue = await floorItemsModel(organization).findOneAndDelete({
modeluuid: modeluuid,
modelname: modelname,
});
if (!findValue) { if (!findValue) {
res.status(200).json("user not found"); res.status(200).json("user not found");
} else { } else {
res.status(201).json(findValue); res.status(201).json(findValue);
} }
} catch (error) { } catch (error) {
console.error('Error get flooritems:', error); console.error("Error get flooritems:", error);
res.status(500).json({ error: "Failed to get flooritems" }); res.status(500).json({ error: "Failed to get flooritems" });
} }
} }

View File

@@ -30,6 +30,7 @@ interface IPointConveyor extends IPointBase {
} }
interface IPointVehicle extends IPointBase { interface IPointVehicle extends IPointBase {
rotation: number[];
actions: { actions: {
uuid: string; uuid: string;
name: string; name: string;
@@ -51,33 +52,34 @@ interface IPointArmbot extends IPointBase {
uuid: string; uuid: string;
name: string; name: string;
speed: number; speed: number;
processes: { triggerId: string; startPoint: string; endPoint: string }[] processes: { triggerId: string; startPoint: string; endPoint: string }[];
}; };
triggers: { uuid: string; name: string; type: string }; triggers: { uuid: string; name: string; type: string };
connections: { connections: {
source: { modelUUID: string; pointUUID: string }; source: { modelUUID: string; pointUUID: string };
targets: { modelUUID: string; pointUUID: string }[] targets: { modelUUID: string; pointUUID: string }[];
}; };
} }
interface IPointStaticMachine extends IPointBase{ interface IPointStaticMachine extends IPointBase {
rotation: number[]; rotation: number[];
actions: { actions: {
uuid: string; uuid: string;
name: string; name: string;
buffer: number | string; buffer: number | string;
material: string; material: string;
}, };
triggers: { uuid: string; name: string; type: string }; triggers: { uuid: string; name: string; type: string };
connections: { connections: {
source: { modelUUID: string; pointUUID: string }; source: { modelUUID: string; pointUUID: string };
targets: { modelUUID: string; pointUUID: string }[] }; targets: { modelUUID: string; pointUUID: string }[];
};
} }
export class pointService { export class pointService {
static async addPoints(req: Request, res: Response): Promise<any> { static async addPoints(req: Request, res: Response): Promise<any> {
const { type, modelfileID, organization } = req.body; const { type, modelfileID, organization } = req.body;
// Validate type // Validate type
if (!["Conveyor", "Vehicle","ArmBot","StaticMachine"].includes(type)) { if (!["Conveyor", "Vehicle", "ArmBot", "StaticMachine"].includes(type)) {
return res.status(400).json({ message: "Invalid type requested" }); return res.status(400).json({ message: "Invalid type requested" });
} }
@@ -189,8 +191,7 @@ export class pointService {
...baseData, ...baseData,
points: conveyorPoints, points: conveyorPoints,
}); });
} } else if (type === "Vehicle") {
if (type === "Vehicle") {
console.log("vehcile data"); console.log("vehcile data");
const baseData = { const baseData = {
modelfileID: "67e3da19c2e8f37134526e6a", modelfileID: "67e3da19c2e8f37134526e6a",
@@ -198,6 +199,7 @@ export class pointService {
}; };
const vehiclePoint: IPointVehicle = { const vehiclePoint: IPointVehicle = {
uuid: "point1UUID", uuid: "point1UUID",
rotation: [0, 0, 0],
position: [0, 1.3, 0], position: [0, 1.3, 0],
actions: { actions: {
uuid: "randomUUID", uuid: "randomUUID",
@@ -214,11 +216,6 @@ export class pointService {
}, },
speed: 2, speed: 2,
}; };
if ("rotation" in vehiclePoint) {
return res
.status(400)
.json({ error: "Rotation not allowed for Vehicle points" });
}
if ("triggers" in vehiclePoint) { if ("triggers" in vehiclePoint) {
return res return res
.status(400) .status(400)
@@ -229,8 +226,7 @@ export class pointService {
...baseData, ...baseData,
points: vehiclePoint, points: vehiclePoint,
}); });
} } else if (type === "ArmBot") {
if (type === "ArmBot") {
console.log("ArmBot data"); console.log("ArmBot data");
const baseData = { const baseData = {
modelfileID: "67eb7904c2e8f37134527eae", modelfileID: "67eb7904c2e8f37134527eae",
@@ -239,27 +235,35 @@ export class pointService {
const ArmBotPoint: IPointArmbot = { const ArmBotPoint: IPointArmbot = {
uuid: "point1UUID", uuid: "point1UUID",
position: [0, 2.75, -0.5], position: [0, 2.75, -0.5],
rotation:[0,0,0], rotation: [0, 0, 0],
actions: { actions: {
uuid: "randomUUID", uuid: "randomUUID",
name: "Action 1", name: "Action 1",
speed:1, speed: 1,
processes:[{triggerId:"triggerId",startPoint:"startPoint",endPoint:"endPoint"}] processes: [
{
triggerId: "triggerId",
startPoint: "startPoint",
endPoint: "endPoint",
},
],
},
triggers: {
uuid: "randomUUID",
name: "trigger 1",
type: "OnComplete",
}, },
triggers: { uuid: "randomUUID", name: "trigger 1", type: "OnComplete" },
connections: { connections: {
source: { modelUUID: "modelUUID", pointUUID: "point1UUID" }, source: { modelUUID: "modelUUID", pointUUID: "point1UUID" },
targets: [{ modelUUID: "modelUUID", pointUUID: "point1UUID" }], targets: [{ modelUUID: "modelUUID", pointUUID: "point1UUID" }],
}, },
}; };
await pointModel(organization).create({ await pointModel(organization).create({
...baseData, ...baseData,
points: ArmBotPoint, points: ArmBotPoint,
}); });
} } else if (type === "StaticMachine") {
if (type === "StaticMachine") {
console.log("StaticMachine data"); console.log("StaticMachine data");
const baseData = { const baseData = {
modelfileID: "67e3db5ac2e8f37134526f40", modelfileID: "67e3db5ac2e8f37134526f40",
@@ -268,26 +272,31 @@ export class pointService {
const StaticMachinePoint: IPointStaticMachine = { const StaticMachinePoint: IPointStaticMachine = {
uuid: "point1UUID", uuid: "point1UUID",
position: [0, 1.5, -0.5], position: [0, 1.5, -0.5],
rotation:[0,0,0], rotation: [0, 0, 0],
actions: { actions: {
uuid: "randomUUID", uuid: "randomUUID",
name: "Action 1", name: "Action 1",
buffer: 0, material: "Inherit", buffer: 0,
material: "Inherit",
},
triggers: {
uuid: "randomUUID",
name: "trigger 1",
type: "OnComplete",
}, },
triggers: { uuid: "randomUUID", name: "trigger 1", type: "OnComplete" },
connections: { connections: {
source: { modelUUID: "modelUUID", pointUUID: "point1UUID" }, source: { modelUUID: "modelUUID", pointUUID: "point1UUID" },
targets: [{ modelUUID: "modelUUID", pointUUID: "point1UUID" }], targets: [{ modelUUID: "modelUUID", pointUUID: "point1UUID" }],
}, },
}; };
await pointModel(organization).create({ await pointModel(organization).create({
...baseData, ...baseData,
points: StaticMachinePoint, points: StaticMachinePoint,
}); });
} else {
return res.json({ message: "Requested type mismatch" });
} }
return res.status(201).json({ message: "Points created successfully" }); return res.status(201).json({ message: "Points created successfully" });
} catch (error) { } catch (error) {
return res.status(500).json({ return res.status(500).json({

View File

@@ -4,7 +4,6 @@ import panelSchema from "../../../shared/model/vizualization/panelmodel.ts";
import widgetSchema from "../../../shared/model/vizualization/widgemodel.ts"; import widgetSchema from "../../../shared/model/vizualization/widgemodel.ts";
export class Zoneservice { export class Zoneservice {
static async addandUpdateZone(req: Request, res: Response): Promise<any> { static async addandUpdateZone(req: Request, res: Response): Promise<any> {
// console.log("req.body: ", req.body);
try { try {
const organization = req.body.organization; const organization = req.body.organization;
const zoneDatas = req.body.zonesdata; const zoneDatas = req.body.zonesdata;
@@ -14,7 +13,7 @@ export class Zoneservice {
}); });
if (!existingZone) { if (!existingZone) {
const newZone = await zoneSchema(organization).create({ const newZone = await zoneSchema(organization).create({
zoneName: zoneDatas.zonename, zoneName: zoneDatas.zoneName,
zoneId: zoneDatas.zoneId, zoneId: zoneDatas.zoneId,
zonePoints: zoneDatas.points, zonePoints: zoneDatas.points,
viewPortposition: zoneDatas.viewportPosition, viewPortposition: zoneDatas.viewportPosition,
@@ -34,16 +33,23 @@ export class Zoneservice {
}, },
}); });
} else { } else {
// const existingZoneName = await zoneSchema(organization).find({
// zoneName: zoneDatas.zoneName,
// isArchive: false,
// });
// if (existingZoneName.length > 0) {
// return res.json({ message: "Zone name already exists" });
// }
const replaceZone = await zoneSchema(organization).findOneAndUpdate( const replaceZone = await zoneSchema(organization).findOneAndUpdate(
{ zoneId: zoneDatas.zoneId, isArchive: false }, { zoneId: zoneDatas.zoneId, isArchive: false },
{ {
zoneName: zoneDatas.zoneName,
zonePoints: zoneDatas.points, zonePoints: zoneDatas.points,
viewPortposition: zoneDatas.viewPortposition, viewPortposition: zoneDatas.viewPortposition,
viewPortCenter: zoneDatas.viewPortCenter, viewPortCenter: zoneDatas.viewPortCenter,
}, },
{ new: true } { new: true }
); );
console.log("replaceZone: ", replaceZone);
if (!replaceZone) if (!replaceZone)
return res.status(404).json({ message: "Zone not updated" }); return res.status(404).json({ message: "Zone not updated" });
else else
@@ -245,6 +251,40 @@ export class Zoneservice {
} }
} }
static async lockedPanel(req: Request, res: Response): Promise<any> {
console.log(req.body);
const organization = req.body.organization;
const zoneId = req.body.zoneId;
const lockedPanel = req.body.lockedPanel;
try {
const existingZone = await zoneSchema(organization).findOne({
zoneId: zoneId,
isArchive: false,
});
if (!existingZone) {
return res.status(404).json({ message: "Zone not found for the UUID" });
} else {
const updateLockedPanel = await zoneSchema(
organization
).findOneAndUpdate(
{ zoneId: zoneId, isArchive: false },
{
lockedPanel: lockedPanel,
},
{ new: true }
);
if (updateLockedPanel) {
return res
.status(200)
.json({ message: "locked panel updated successfully" });
}
}
} catch (error: any) {
return res.status(500).send(error.message);
}
}
// static async zoneIdgenerate(req: Request, res: Response): Promise<any> { // static async zoneIdgenerate(req: Request, res: Response): Promise<any> {
// const organization = req.query.organization; // const organization = req.query.organization;
// const sceneID = req.params.sceneID; // const sceneID = req.params.sceneID;

View File

@@ -18,10 +18,11 @@ export class assetsFloorservice {
organization, organization,
eventData, eventData,
} = req.body; } = req.body;
console.log("req.body: ", req.body);
const findvalue = await assetModel(organization).findOne({ const findvalue = await assetModel(organization).findOne({
modeluuid, modeluuid,
modelname, // modelname,
isArchive: false, isArchive: false,
}); });
const checkpointType = await pointModel(organization).findOne({ const checkpointType = await pointModel(organization).findOne({
@@ -31,8 +32,9 @@ export class assetsFloorservice {
if (findvalue) { if (findvalue) {
const updatevalue = await assetModel(organization).findOneAndUpdate( const updatevalue = await assetModel(organization).findOneAndUpdate(
{ modeluuid, modelname, isArchive: false }, { modeluuid, isArchive: false },
{ {
modelname: modelname,
position, position,
rotation, rotation,
isVisible, isVisible,
@@ -63,11 +65,11 @@ export class assetsFloorservice {
.status(400) .status(400)
.json({ message: "Vehicle points must be a single object" }); .json({ message: "Vehicle points must be a single object" });
} }
if (eventData.points.rotation) { // if (eventData.points.rotation) {
return res.status(400).json({ // return res.status(400).json({
message: "Rotation is not allowed for Vehicle points", // message: "Rotation is not allowed for Vehicle points",
}); // });
} // }
if (eventData.points.triggers) { if (eventData.points.triggers) {
return res.status(400).json({ return res.status(400).json({

View File

@@ -109,4 +109,47 @@ export class panelService {
return res.status(500).send(error.message); return res.status(500).send(error.message);
} }
} }
static async clearPanel(req: Request, res: Response): Promise<any> {
try {
console.log("req.body;: ", req.body);
const { organization, panelName, zoneId } = req.body;
const existingZone = await zoneSchema(organization).findOne({
zoneId: zoneId,
panelOrder: { $in: [panelName] },
isArchive: false,
});
if (!existingZone) return res.json({ message: "Zone not found" });
const existingPanel = await panelSchema(organization).findOne({
zoneId: zoneId,
panelName: panelName,
isArchive: false,
});
if (!existingPanel)
return res.json({ message: "Requested Panel not found" });
const existingWidgets = await widgetSchema(organization).find({
panelID: existingPanel._id,
isArchive: false,
});
if (existingWidgets.length === 0)
return res.json({ message: "No widgets to clear" });
const clearWidgetsofPanel = await widgetSchema(organization).updateMany(
{ panelID: existingPanel._id, isArchive: false },
{ isArchive: true }
);
const removeWidgetsInPanel = await panelSchema(
organization
).findOneAndUpdate(
{ _id: existingPanel._id, isArchive: false },
{ $set: { widgets: [] } },
{ new: true }
);
if (!clearWidgetsofPanel && !removeWidgetsInPanel)
return res.json({ message: "Failed to clear widgets in panel" });
return res
.status(200)
.json({ message: "PanelWidgets cleared successfully" });
} catch (error: any) {
return res.status(500).send(error.message);
}
}
} }

View File

@@ -56,6 +56,7 @@ interface IPointConveyor extends IPointBase {
} }
interface IPointVehicle extends IPointBase { interface IPointVehicle extends IPointBase {
rotation: number[];
actions: { actions: {
uuid: string; uuid: string;
name: string; name: string;
@@ -78,44 +79,48 @@ interface IPointArmbot extends IPointBase {
uuid: string; uuid: string;
name: string; name: string;
speed: number; speed: number;
processes: { triggerId: string; startPoint: string; endPoint: string }[] processes: { triggerId: string; startPoint: string; endPoint: string }[];
}; };
triggers: { uuid: string; name: string; type: string }; triggers: { uuid: string; name: string; type: string };
connections: { connections: {
source: { modelUUID: string; pointUUID: string }; source: { modelUUID: string; pointUUID: string };
targets: { modelUUID: string; pointUUID: string }[] targets: { modelUUID: string; pointUUID: string }[];
}; };
} }
interface IPointStaticMachine extends IPointBase{ interface IPointStaticMachine extends IPointBase {
rotation: number[]; rotation: number[];
actions: { actions: {
uuid: string; uuid: string;
name: string; name: string;
buffer: number ; buffer: number;
material: string; material: string;
}, isUsed: boolean;
};
triggers: { uuid: string; name: string; type: string }; triggers: { uuid: string; name: string; type: string };
connections: { connections: {
source: { modelUUID: string; pointUUID: string }; source: { modelUUID: string; pointUUID: string };
targets: { modelUUID: string; pointUUID: string }[] }; targets: { modelUUID: string; pointUUID: string }[];
};
} }
// Main Document Interface
interface IPointModel extends Document { interface IPointModel extends Document {
modelfileID: string; modelfileID: string;
type: "Conveyor" | "Vehicle" |"ArmBot" |"StaticMachine", type: "Conveyor" | "Vehicle" | "ArmBot" | "StaticMachine";
points: IPointConveyor[] | IPointVehicle |IPointArmbot |IPointStaticMachine; points: IPointConveyor[] | IPointVehicle | IPointArmbot | IPointStaticMachine;
isArchive: boolean; isArchive: boolean;
} }
// Single Schema for both types
const PointSchema = new Schema<IPointModel>( const PointSchema = new Schema<IPointModel>(
{ {
modelfileID: { type: String }, modelfileID: { type: String },
type: { type: String, enum: ["Conveyor", "Vehicle","ArmBot","StaticMachine"], required: true }, type: {
type: String,
enum: ["Conveyor", "Vehicle", "ArmBot", "StaticMachine"],
required: true,
},
isArchive: { type: Boolean, default: false }, isArchive: { type: Boolean, default: false },
points: { points: {
type: Schema.Types.Mixed, // Flexible structure based on type type: Schema.Types.Mixed,
required: true, required: true,
}, },
}, },
@@ -124,7 +129,7 @@ const PointSchema = new Schema<IPointModel>(
// Model Creation // Model Creation
const pointModel = (db: string) => { const pointModel = (db: string) => {
return MainModel(db, "Points", PointSchema, "Points"); // Single collection return MainModel(db, "Points", PointSchema, "Points");
}; };
export default pointModel; export default pointModel;

View File

@@ -2,8 +2,6 @@ import assetModel from "../../../shared/model/builder/assets/asset-Model.ts";
import actionModel from "../../../shared/model/simulation/actionmodel.ts"; import actionModel from "../../../shared/model/simulation/actionmodel.ts";
import triggerModel from "../../../shared/model/simulation/triggersmodel.ts"; import triggerModel from "../../../shared/model/simulation/triggersmodel.ts";
export const setAssetModel = async (data: any) => { export const setAssetModel = async (data: any) => {
const { const {
modeluuid, modeluuid,
@@ -19,14 +17,15 @@ export const setAssetModel = async (data: any) => {
try { try {
const findvalue = await assetModel(organization).findOne({ const findvalue = await assetModel(organization).findOne({
modeluuid: modeluuid, modeluuid: modeluuid,
modelname: modelname, // modelname: modelname,
isArchive: false, isArchive: false,
}); });
if (findvalue) { if (findvalue) {
const updatevalue = await assetModel(organization).findOneAndUpdate( const updatevalue = await assetModel(organization).findOneAndUpdate(
{ modeluuid: modeluuid, modelname: modelname, isArchive: false }, { modeluuid: modeluuid, isArchive: false },
{ {
modelname: modelname,
position: position, position: position,
rotation: rotation, rotation: rotation,
isVisible: isVisible, isVisible: isVisible,
@@ -63,13 +62,13 @@ export const setAssetModel = async (data: any) => {
organization: organization, organization: organization,
}; };
} }
if (eventData.points.rotation) { // if (eventData.points.rotation) {
return { // return {
success: false, // success: false,
message: "Rotation is not allowed for Vehicle points", // message: "Rotation is not allowed for Vehicle points",
organization: organization, // organization: organization,
}; // };
} // }
if (eventData.points.triggers) { if (eventData.points.triggers) {
return { return {
success: false, success: false,
@@ -99,8 +98,7 @@ export const setAssetModel = async (data: any) => {
speed: assetDoc.speed, speed: assetDoc.speed,
}, },
}; };
} } else if (assetDoc.type === "Vehicle") {
if (assetDoc.type === "Vehicle") {
assetDatas = { assetDatas = {
modeluuid: assetDoc.modeluuid, modeluuid: assetDoc.modeluuid,
modelname: assetDoc.modelname, modelname: assetDoc.modelname,
@@ -114,6 +112,44 @@ export const setAssetModel = async (data: any) => {
type: assetDoc.type, type: assetDoc.type,
}, },
}; };
} else if (assetDoc.type === "ArmBot") {
assetDatas = {
modeluuid: assetDoc.modeluuid,
modelname: assetDoc.modelname,
modelfileID: assetDoc.modelfileID,
position: assetDoc.position,
rotation: assetDoc.rotation,
isLocked: assetDoc.isLocked,
isVisible: assetDoc.isVisible,
eventData: {
points: assetDoc.points,
type: assetDoc.type,
},
};
} else if (assetDoc.type === "StaticMachine") {
assetDatas = {
modeluuid: assetDoc.modeluuid,
modelname: assetDoc.modelname,
modelfileID: assetDoc.modelfileID,
position: assetDoc.position,
rotation: assetDoc.rotation,
isLocked: assetDoc.isLocked,
isVisible: assetDoc.isVisible,
eventData: {
points: assetDoc.points,
type: assetDoc.type,
},
};
} else {
assetDatas = {
modeluuid: assetDoc.modeluuid,
modelname: assetDoc.modelname,
modelfileID: assetDoc.modelfileID,
position: assetDoc.position,
rotation: assetDoc.rotation,
isLocked: assetDoc.isLocked,
isVisible: assetDoc.isVisible,
};
} }
return { return {
success: true, success: true,

View File

@@ -144,7 +144,124 @@ export const panelDelete = async (data: any) => {
}; };
} }
}; };
export const panelClear = async (data: any) => {
const { organization, panelName, zoneId } = data;
console.log("data: ", data);
try {
const existingZone = await zoneSchema(organization).findOne({
zoneId: zoneId,
panelOrder: { $in: [panelName] },
isArchive: false,
});
if (!existingZone)
return {
success: false,
message: "Zone not found",
organization: organization,
};
const existingPanel = await panelSchema(organization).findOne({
zoneId: zoneId,
panelName: panelName,
isArchive: false,
});
if (!existingPanel)
return {
success: false,
message: "Requested Panel not found",
organization: organization,
};
const existingWidgets = await widgetSchema(organization).find({
panelID: existingPanel._id,
isArchive: false,
});
if (existingWidgets.length === 0)
return {
success: false,
message: "No widgets to clear",
organization: organization,
};
const clearWidgetsofPanel = await widgetSchema(organization).updateMany(
{ panelID: existingPanel._id, isArchive: false },
{ isArchive: true }
);
const removeWidgetsInPanel = await panelSchema(
organization
).findOneAndUpdate(
{ _id: existingPanel._id, isArchive: false },
{ $set: { widgets: [] } },
{ new: true }
);
if (!clearWidgetsofPanel && !removeWidgetsInPanel)
return {
success: false,
message: "Failed to clear widgets in panel",
organization: organization,
};
const zoneAndPanelData = await getZoneAndPanelData(organization, zoneId);
if (!zoneAndPanelData) {
return zoneAndPanelData; // If the zone and panel data retrieval fails, return the error.
}
return {
success: true,
data: zoneAndPanelData,
message: "PanelWidgets cleared successfully",
organization: organization,
};
} catch (error: any) {
return {
success: false,
message: error?.message || "Error occurred while panel",
error,
organization: organization,
};
}
};
export const panelLocked = async (data: any) => {
const { organization, lockedPanel, zoneId } = data;
console.log("data: ", data);
try {
const existingZone = await zoneSchema(organization).findOne({
zoneId: zoneId,
isArchive: false,
});
if (!existingZone) {
return {
success: false,
message: "Zone not found",
organization: organization,
};
} else {
const updateLockedPanel = await zoneSchema(organization).findOneAndUpdate(
{ zoneId: zoneId, isArchive: false },
{
lockedPanel: lockedPanel,
},
{ new: true }
);
const zoneAndPanelData = await getZoneAndPanelData(organization, zoneId);
if (!zoneAndPanelData) {
return zoneAndPanelData; // If the zone and panel data retrieval fails, return the error.
}
if (updateLockedPanel) {
return {
success: true,
message: "locked panel updated successfully",
data: zoneAndPanelData,
organization: organization,
};
}
}
} catch (error: any) {
return {
success: false,
message: error?.message || "Error occurred while panel",
error,
organization: organization,
};
}
};
const getZoneAndPanelData = async (organization: string, zoneId: string) => { const getZoneAndPanelData = async (organization: string, zoneId: string) => {
// const { organization, zoneId, } = data // const { organization, zoneId, } = data
// console.log('data: ', data); // console.log('data: ', data);

View File

@@ -49,10 +49,15 @@ export const EVENTS = {
ZoneDeleteResponse:"zone:response:delete", ZoneDeleteResponse:"zone:response:delete",
//visualization //visualization
//panel
addPanel:"v2:viz-panel:add", addPanel:"v2:viz-panel:add",
panelUpdateResponse:"viz-panel:response:updates", panelUpdateResponse:"viz-panel:response:updates",
deletePanel:"v2:viz-panel:delete", deletePanel:"v2:viz-panel:delete",
PanelDeleteResponse:"viz-panel:response:delete", PanelDeleteResponse:"viz-panel:response:delete",
clearPanel:"v2:viz-panel:clear",
PanelClearResponse:"viz-panel:response:clear",
lockedPanel:"v2:viz-panel:locked",
PanelLockedResponse:"viz-panel:response:locked",
//widget //widget
addWidget:"v2:viz-widget:add", addWidget:"v2:viz-widget:add",

View File

@@ -7,7 +7,7 @@ import { deleteWallItems, setWallItems } from '../services/assets/wallitem-Contr
import { deleteLineItems, deleteLinPoiteItems, updateLineItems, createLineItems, deleteLayer } from '../services/lines/line-Controller.ts'; import { deleteLineItems, deleteLinPoiteItems, updateLineItems, createLineItems, deleteLayer } from '../services/lines/line-Controller.ts';
import { activeUserOffline, activeUsers, } from '../services/users/user-controller.ts'; import { activeUserOffline, activeUsers, } from '../services/users/user-controller.ts';
import { deleteZone, setZone } from '../services/lines/zone-controller.ts'; import { deleteZone, setZone } from '../services/lines/zone-controller.ts';
import { addPanel, panelDelete } from '../services/visualization/panel-Services.ts'; import { addPanel, panelClear, panelDelete, panelLocked } from '../services/visualization/panel-Services.ts';
import { addWidget, Widgetdelete } from '../services/visualization/widget-Services.ts'; import { addWidget, Widgetdelete } from '../services/visualization/widget-Services.ts';
import { addfloat, deletefloat, duplicatefloat } from '../services/visualization/floatWidget-Service.ts'; import { addfloat, deletefloat, duplicatefloat } from '../services/visualization/floatWidget-Service.ts';
import { addTemplate, addTemplateZone, TemplateZoneDelete } from '../services/visualization/templateServices.ts'; import { addTemplate, addTemplateZone, TemplateZoneDelete } from '../services/visualization/templateServices.ts';
@@ -547,7 +547,50 @@ const panelHandleEvent = async (event: string, socket: Socket, data: any, namesp
} }
break break
} }
case EVENTS.clearPanel: {
const result = await panelClear(data)
if (result) {
// console.log('result?.success: ', result.organization);
const responseEvent = EVENTS.PanelClearResponse
// console.log('responseEvent: ', responseEvent);
const organization = result?.organization
if (organization) {
socket.to(organization).emit(responseEvent, {
success: result.success,
message: result.message,
data: result.data,
error: result.error || null,
socketId: socket.id,
organization,
});
} else {
console.warn(`Organization missing in response for event: ${event}`);
}
}
break
}
case EVENTS.lockedPanel: {
const result = await panelLocked(data)
if (result) {
// console.log('result?.success: ', result.organization);
const responseEvent = EVENTS.PanelLockedResponse
// console.log('responseEvent: ', responseEvent);
const organization = result?.organization
if (organization) {
socket.to(organization).emit(responseEvent, {
success: result.success,
message: result.message,
data: result.data,
error: result.error || null,
socketId: socket.id,
organization,
});
} else {
console.warn(`Organization missing in response for event: ${event}`);
}
}
break
}
default: default:
return; return;