RT-Vis 2d and floating widget API collaboration completed, template Save and get API completed. SOCKET 2d panel and widgets events completed
This commit is contained in:
11
.env
11
.env
@@ -12,4 +12,15 @@ MONGO_AUTH_DB=admin
|
|||||||
# MONGO_AUTH_DB=admin
|
# MONGO_AUTH_DB=admin
|
||||||
MONGO_URI=mongodb://mongo/
|
MONGO_URI=mongodb://mongo/
|
||||||
API_PORT=5000
|
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
|
SOCKET_PORT=8000
|
||||||
@@ -1,119 +1,119 @@
|
|||||||
import panelSchema from "../../../shared/model/vizualization/panelmodel.ts";
|
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 const addWidget = async (data: any) => {
|
export const addWidget = async (data: any) => {
|
||||||
const { organization,panel,zoneId,widget,} = data
|
const { organization,panel,zoneId,widget,} = data
|
||||||
console.log('data: ', data);
|
console.log('data: ', data);
|
||||||
try {
|
try {
|
||||||
const existingPanel = await panelSchema(organization).findOne({
|
const existingPanel = await panelSchema(organization).findOne({
|
||||||
panelName: widget.panel,
|
panelName: widget.panel,
|
||||||
zoneId: zoneId,
|
zoneId: zoneId,
|
||||||
isArchive: false,
|
isArchive: false,
|
||||||
});
|
});
|
||||||
if (!existingPanel)
|
if (!existingPanel)
|
||||||
|
|
||||||
return { success: false, message: "panelName not found",organization: organization}
|
return { success: false, message: "panelName not found",organization: organization}
|
||||||
|
|
||||||
|
|
||||||
if (existingPanel.panelName === widget.panel) {
|
if (existingPanel.panelName === widget.panel) {
|
||||||
const existingWidget = await widgetSchema(organization).findOne({
|
const existingWidget = await widgetSchema(organization).findOne({
|
||||||
panelID: existingPanel._id,
|
panelID: existingPanel._id,
|
||||||
widgetID: widget.id,
|
widgetID: widget.id,
|
||||||
isArchive: false,
|
isArchive: false,
|
||||||
// widgetOrder: widget.widgetOrder,
|
// widgetOrder: widget.widgetOrder,
|
||||||
});
|
});
|
||||||
if (existingWidget) {
|
if (existingWidget) {
|
||||||
const updateWidget = await widgetSchema(
|
const updateWidget = await widgetSchema(
|
||||||
organization
|
organization
|
||||||
).findOneAndUpdate(
|
).findOneAndUpdate(
|
||||||
{
|
{
|
||||||
panelID: existingPanel._id,
|
panelID: existingPanel._id,
|
||||||
widgetID: widget.id,
|
widgetID: widget.id,
|
||||||
isArchive: false,
|
isArchive: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
$set: {
|
$set: {
|
||||||
panelID: existingPanel._id,
|
panelID: existingPanel._id,
|
||||||
widgetID: widget.id,
|
widgetID: widget.id,
|
||||||
Data: {
|
Data: {
|
||||||
measurements: widget.Data.measurements,
|
measurements: widget.Data.measurements,
|
||||||
duration: widget.Data.duration,
|
duration: widget.Data.duration,
|
||||||
},
|
},
|
||||||
isArchive: false,
|
isArchive: false,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{ upsert: true, new: true } // Upsert: create if not exists, new: return updated document
|
{ upsert: true, new: true } // Upsert: create if not exists, new: return updated document
|
||||||
);
|
);
|
||||||
|
|
||||||
return { success: false, message: "Widget updated successfully",data:updateWidget,organization: organization}
|
return { success: false, message: "Widget updated successfully",data:updateWidget,organization: organization}
|
||||||
|
|
||||||
}
|
}
|
||||||
const newWidget = await widgetSchema(organization).create({
|
const newWidget = await widgetSchema(organization).create({
|
||||||
widgetID: widget.id,
|
widgetID: widget.id,
|
||||||
elementType: widget.type,
|
elementType: widget.type,
|
||||||
// widgetOrder: widgetOrder,
|
// widgetOrder: widgetOrder,
|
||||||
widgetName: widget.widgetName,
|
widgetName: widget.widgetName,
|
||||||
panelID: existingPanel._id,
|
panelID: existingPanel._id,
|
||||||
widgetside: widget.panel,
|
widgetside: widget.panel,
|
||||||
// Data: {
|
// Data: {
|
||||||
// measurements: widget.Data.measurements || {},
|
// measurements: widget.Data.measurements || {},
|
||||||
// duration: widget.Data.duration || "1hr",
|
// duration: widget.Data.duration || "1hr",
|
||||||
// },
|
// },
|
||||||
});
|
});
|
||||||
if (newWidget) {
|
if (newWidget) {
|
||||||
existingPanel.widgets.push(newWidget._id);
|
existingPanel.widgets.push(newWidget._id);
|
||||||
await existingPanel.save();
|
await existingPanel.save();
|
||||||
return { success: true, message: "Widget already exist for the widgetID",data:existingPanel,organization: organization}
|
return { success: true, message: "Widget already exist for the widgetID",data:existingPanel,organization: organization}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return { success: false, message: "Type mismatch",organization: organization}
|
return { success: false, message: "Type mismatch",organization: organization}
|
||||||
|
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
return { success: false, message: 'widge not found', error,organization: organization }
|
return { success: false, message: 'widge not found', error,organization: organization }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
export const Widgetdelete = async (data: any) => {
|
export const Widgetdelete = async (data: any) => {
|
||||||
const { widgetID, organization } = data
|
const { widgetID, organization } = data
|
||||||
console.log('data: ', data);
|
console.log('data: ', data);
|
||||||
try {
|
try {
|
||||||
const findWidget = await widgetSchema(organization).findOne({
|
const findWidget = await widgetSchema(organization).findOne({
|
||||||
widgetID: widgetID,
|
widgetID: widgetID,
|
||||||
isArchive: false,
|
isArchive: false,
|
||||||
});
|
});
|
||||||
if (!findWidget)
|
if (!findWidget)
|
||||||
return { success: false, message: "Widget not found",organization: organization}
|
return { success: false, message: "Widget not found",organization: organization}
|
||||||
const widgetData = await widgetSchema(organization).updateOne(
|
const widgetData = await widgetSchema(organization).updateOne(
|
||||||
{ _id: findWidget._id, isArchive: false },
|
{ _id: findWidget._id, isArchive: false },
|
||||||
{ $set: { isArchive: true } }
|
{ $set: { isArchive: true } }
|
||||||
);
|
);
|
||||||
|
|
||||||
if (widgetData) {
|
if (widgetData) {
|
||||||
// Find all widgets in the same panel and sort them by widgetOrder
|
// Find all widgets in the same panel and sort them by widgetOrder
|
||||||
const widgets = await widgetSchema(organization).find({
|
const widgets = await widgetSchema(organization).find({
|
||||||
panelID: findWidget.panelID,
|
panelID: findWidget.panelID,
|
||||||
isArchive: false,
|
isArchive: false,
|
||||||
});
|
});
|
||||||
// .sort({ widgetOrder: 1 });
|
// .sort({ widgetOrder: 1 });
|
||||||
|
|
||||||
// Reassign widgetOrder values
|
// Reassign widgetOrder values
|
||||||
// for (let i = 0; i < widgets.length; i++) {
|
// for (let i = 0; i < widgets.length; i++) {
|
||||||
// widgets[i].widgetOrder = (i + 1).toString(); // Convert to string
|
// widgets[i].widgetOrder = (i + 1).toString(); // Convert to string
|
||||||
// await widgets[i].save();
|
// await widgets[i].save();
|
||||||
// }
|
// }
|
||||||
const panelData = await panelSchema(organization).findOne({
|
const panelData = await panelSchema(organization).findOne({
|
||||||
_id: findWidget.panelID,
|
_id: findWidget.panelID,
|
||||||
isArchive: false,
|
isArchive: false,
|
||||||
});
|
});
|
||||||
if (panelData.widgets.includes(findWidget._id)) {
|
if (panelData.widgets.includes(findWidget._id)) {
|
||||||
const index1 = panelData.widgets.indexOf(findWidget._id);
|
const index1 = panelData.widgets.indexOf(findWidget._id);
|
||||||
panelData.widgets.splice(index1, 1);
|
panelData.widgets.splice(index1, 1);
|
||||||
}
|
}
|
||||||
const panelDeletedata = await panelData.save();
|
const panelDeletedata = await panelData.save();
|
||||||
console.log('Widget deleted successfully: ');
|
console.log('Widget deleted successfully: ');
|
||||||
return { success: false, message: "Widget deleted successfully",data:panelDeletedata,organization: organization}
|
return { success: false, message: "Widget deleted successfully",data:panelDeletedata,organization: organization}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
return { success: false, message: error?.message || "An unknown error occurred.", error ,organization: organization}
|
return { success: false, message: error?.message || "An unknown error occurred.", error ,organization: organization}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user