diff --git a/app/src/components/layout/sidebarRight/visualization/IotInputCards/BarChartInput.tsx b/app/src/components/layout/sidebarRight/visualization/IotInputCards/BarChartInput.tsx index 3b7e67a..09da02b 100644 --- a/app/src/components/layout/sidebarRight/visualization/IotInputCards/BarChartInput.tsx +++ b/app/src/components/layout/sidebarRight/visualization/IotInputCards/BarChartInput.tsx @@ -91,16 +91,7 @@ const BarChartInput = (props: Props) => { duration: inputDuration, } } - // const adding3dWidget = { - // organization: organization, - // widget: newWidget, - // zoneUuid: selectedZone.zoneUuid, - // projectId, userId - // }; - // if (visualizationSocket) { - // visualizationSocket.emit("v1:viz-3D-widget:add", adding3dWidget); - - // } + let response = await addingWidgets(selectedZone.zoneUuid, organization, newWidget, projectId, selectedVersion?.versionId || ""); diff --git a/app/src/components/layout/sidebarRight/visualization/IotInputCards/LineGrapInput.tsx b/app/src/components/layout/sidebarRight/visualization/IotInputCards/LineGrapInput.tsx index 646ba88..29263fe 100644 --- a/app/src/components/layout/sidebarRight/visualization/IotInputCards/LineGrapInput.tsx +++ b/app/src/components/layout/sidebarRight/visualization/IotInputCards/LineGrapInput.tsx @@ -210,15 +210,7 @@ const LineGrapInput = (props: Props) => { } } - // const adding3dWidget = { - // organization: organization, - // widget: newWidget, - // zoneUuid: selectedZone.zoneUuid, - // projectId, userId - // }; - // if (visualizationSocket) { - // visualizationSocket.emit("v1:viz-3D-widget:add", adding3dWidget); - // } + let response = await addingWidgets(selectedZone.zoneUuid, organization, newWidget, projectId, selectedVersion?.versionId || ""); if (response.message === "Widget updated successfully") { diff --git a/app/src/components/layout/sidebarRight/visualization/IotInputCards/PieChartInput.tsx b/app/src/components/layout/sidebarRight/visualization/IotInputCards/PieChartInput.tsx index 04ac73b..26988aa 100644 --- a/app/src/components/layout/sidebarRight/visualization/IotInputCards/PieChartInput.tsx +++ b/app/src/components/layout/sidebarRight/visualization/IotInputCards/PieChartInput.tsx @@ -94,15 +94,7 @@ const PieChartInput = (props: Props) => { duration: inputDuration, }, } - // const adding3dWidget = { - // organization: organization, - // widget: newWidget, - // zoneUuid: selectedZone.zoneUuid, - // projectId, userId - // }; - // if (visualizationSocket) { - // visualizationSocket.emit("v1:viz-3D-widget:add", adding3dWidget); - // } + let response = await addingWidgets(selectedZone.zoneUuid, organization, newWidget, projectId, selectedVersion?.versionId || ""); diff --git a/app/src/components/layout/sidebarRight/visualization/IotInputCards/Progress1Input.tsx b/app/src/components/layout/sidebarRight/visualization/IotInputCards/Progress1Input.tsx index 1f573b3..6854848 100644 --- a/app/src/components/layout/sidebarRight/visualization/IotInputCards/Progress1Input.tsx +++ b/app/src/components/layout/sidebarRight/visualization/IotInputCards/Progress1Input.tsx @@ -93,15 +93,7 @@ const Progress1Input = (props: Props) => { duration: inputDuration, }, } - // const adding3dWidget = { - // organization: organization, - // widget: newWidget, - // zoneUuid: selectedZone.zoneUuid, - // projectId, userId - // }; - // if (visualizationSocket) { - // visualizationSocket.emit("v1:viz-3D-widget:add", adding3dWidget); - // } + let response = await addingWidgets(selectedZone.zoneUuid, organization, newWidget, projectId, selectedVersion?.versionId || ""); if (response.message === "Widget updated successfully") { diff --git a/app/src/components/layout/sidebarRight/visualization/IotInputCards/Progress2Input.tsx b/app/src/components/layout/sidebarRight/visualization/IotInputCards/Progress2Input.tsx index f1af380..2482346 100644 --- a/app/src/components/layout/sidebarRight/visualization/IotInputCards/Progress2Input.tsx +++ b/app/src/components/layout/sidebarRight/visualization/IotInputCards/Progress2Input.tsx @@ -94,16 +94,6 @@ const Progress2Input = (props: Props) => { } } - // const adding3dWidget = { - // organization: organization, - // widget: newWidget, - // zoneUuid: selectedZone.zoneUuid, - // projectId, userId - // }; - // if (visualizationSocket) { - // visualizationSocket.emit("v1:viz-3D-widget:add", adding3dWidget); - // } - let response = await addingWidgets(selectedZone.zoneUuid, organization, newWidget, projectId, selectedVersion?.versionId || ""); if (response.message === "Widget updated successfully") { diff --git a/app/src/components/layout/sidebarRight/visualization/IotInputCards/Widget2InputCard3D.tsx b/app/src/components/layout/sidebarRight/visualization/IotInputCards/Widget2InputCard3D.tsx index 79fd00e..0889809 100644 --- a/app/src/components/layout/sidebarRight/visualization/IotInputCards/Widget2InputCard3D.tsx +++ b/app/src/components/layout/sidebarRight/visualization/IotInputCards/Widget2InputCard3D.tsx @@ -38,15 +38,15 @@ const Widget2InputCard3D = (props: Props) => { setLoading(true); const response = await axios.get(`http://${iotApiUrl}/floatinput`); if (response.status === 200) { - // console.log("dropdown data:", response.data); + // setDropDownData(response.data); setLoading(false); } else { - // console.log("Unexpected response:", response); + // } } catch (error) { echo.error("Failed to fetch zone data"); - console.error("There was an error!", error); + } }; fetchZoneData(); @@ -55,14 +55,14 @@ const Widget2InputCard3D = (props: Props) => { useEffect(() => { const fetchSavedInputes = async () => { if (selectedChartId.id !== "") { - let response = await get3dWidgetInput(selectedChartId.id, organization) - console.log('response: ', response); + let response = await get3dWidgetInput(selectedChartId.id, organization, projectId, selectedVersion?.versionId || "") + if (response) { - setSelections(response.data.Data.measurements); - setDuration(response.data.Data.duration); - setWidgetName(response.data.widgetName); + setSelections(response.Datastructure.measurements); + setDuration(response.Datastructure.duration); + setWidgetName(response.widgetName); } - + } }; @@ -81,44 +81,61 @@ const Widget2InputCard3D = (props: Props) => { inputDuration: any, inputName: any ) => { - // let newWidget = { - // id: selectedChartId.id, - // widgetName: inputName, - // Data: { - // measurements: inputMeasurement, - // duration: inputDuration, - // }, - // } - - // let response = await adding3dWidgets(selectedZone.zoneUuid, organization, newWidget,projectId, selectedVersion?.versionId || "") - // console.log('response: ', response); - try { - const response = await axios.post( - `http://${process.env.REACT_APP_SERVER_REST_API_BASE_URL}/api/V1/widget3d/save`, - { - organization, - zoneUuid: selectedZone.zoneUuid, - widget: { - id: selectedChartId.id, - widgetName: inputName, - Data: { - measurements: inputMeasurement, - duration: inputDuration, - }, - }, - } as any - ); - if (response.status === 200) { - return true; - } else { - // console.log("Unexpected response:", response); - return false; - } - } catch (error) { - echo.error("Failed to send input"); - console.error("There was an error!", error); - return false; + let newWidget = { + id: selectedChartId.id, + widgetName: inputName, + Data: { + measurements: inputMeasurement, + duration: inputDuration, + }, } + + let response = await adding3dWidgets(selectedZone.zoneUuid, organization, newWidget, projectId, selectedVersion?.versionId || "") + + if (response.message === "widget update successfully") { + return true; + } else { + return false + } + // try { + // const response = await axios.post( + // `http://${process.env.REACT_APP_SERVER_REST_API_BASE_URL}/api/V1/widget3d/save`, + // { + // headers: { + // Authorization: "Bearer ", + // "Content-Type": "application/json", + // token: localStorage.getItem("token") || "", + // refresh_token: localStorage.getItem("refreshToken") || "", + // }, + // }, + // { + // organization, + // zoneUuid: selectedZone.zoneUuid, + // widget: { + // id: selectedChartId.id, + // widgetName: inputName, + // Data: { + // measurements: inputMeasurement, + // duration: inputDuration, + // }, + // }, + // projectId: projectId, + // versionId: selectedVersion?.versionId || "" + // } as any, + + // ); + // + // if (response.status === 200) { + // return true; + // } else { + // // + // return false; + // } + // } catch (error) { + // echo.error("Failed to send input"); + // + // return false; + // } }; const handleSelect = async ( @@ -133,7 +150,7 @@ const Widget2InputCard3D = (props: Props) => { newSelections[inputKey] = selectedData; } // setMeasurements(newSelections); // Update Zustand store - // console.log(newSelections); + // if (await sendInputes(newSelections, duration, widgetName)) { setSelections(newSelections); } @@ -150,7 +167,7 @@ const Widget2InputCard3D = (props: Props) => { }; const handleNameChange = async (name: any) => { - // console.log("name change requested", name); + // if (await sendInputes(selections, duration, name)) { setWidgetName(name); diff --git a/app/src/components/layout/sidebarRight/visualization/IotInputCards/Widget3InputCard3D.tsx b/app/src/components/layout/sidebarRight/visualization/IotInputCards/Widget3InputCard3D.tsx index 3e0ddde..a236d5a 100644 --- a/app/src/components/layout/sidebarRight/visualization/IotInputCards/Widget3InputCard3D.tsx +++ b/app/src/components/layout/sidebarRight/visualization/IotInputCards/Widget3InputCard3D.tsx @@ -36,15 +36,15 @@ const Widget3InputCard3D = () => { setLoading(true); const response = await axios.get(`http://${iotApiUrl}/getinput`); if (response.status === 200) { - // console.log("dropdown data:", response.data); + // setDropDownData(response.data); setLoading(false); } else { - // console.log("Unexpected response:", response); + // } } catch (error) { echo.error("Failed to fetch zone data"); - console.error("There was an error!", error); + } }; fetchZoneData(); @@ -53,12 +53,12 @@ const Widget3InputCard3D = () => { useEffect(() => { const fetchSavedInputes = async () => { if (selectedChartId.id !== "") { - let response = await get3dWidgetInput(selectedChartId.id, organization) - console.log('response: ', response); + let response = await get3dWidgetInput(selectedChartId.id, organization, projectId, selectedVersion?.versionId || "") + if (response) { - setSelections(response.data.Data.measurements); - setDuration(response.data.Data.duration); - setWidgetName(response.data.widgetName); + setSelections(response.Datastructure.measurements); + setDuration(response.Datastructure.duration); + setWidgetName(response.widgetName); } } @@ -79,45 +79,61 @@ const Widget3InputCard3D = () => { inputName: any ) => { - // let newWidget = { - // id: selectedChartId.id, - // widgetName: inputName, - // Data: { - // measurements: inputMeasurement, - // duration: inputDuration, - // }, - // } - - // let response = await adding3dWidgets(selectedZone.zoneUuid, organization, newWidget, projectId, selectedVersion?.versionId || "") - // console.log('response: ', response); - - try { - const response = await axios.post( - `http://${process.env.REACT_APP_SERVER_REST_API_BASE_URL}/api/V1/widget3d/save`, - { - organization, - zoneUuid: selectedZone.zoneUuid, - widget: { - id: selectedChartId.id, - widgetName: inputName, - Data: { - measurements: inputMeasurement, - duration: inputDuration, - }, - }, - } as any - ); - if (response.status === 200) { - return true; - } else { - // console.log("Unexpected response:", response); - return false; - } - } catch (error) { - echo.error("Failed to send input"); - console.error("There was an error!", error); - return false; + let newWidget = { + id: selectedChartId.id, + widgetName: inputName, + Data: { + measurements: inputMeasurement, + duration: inputDuration, + }, } + + let response = await adding3dWidgets(selectedZone.zoneUuid, organization, newWidget, projectId, selectedVersion?.versionId || "") + + if (response.message === "widget update successfully") { + return true; + } else { + return false + } + + // try { + // const response = await axios.post( + // `http://${process.env.REACT_APP_SERVER_REST_API_BASE_URL}/api/V1/widget3d/save`, + // { + // headers: { + // Authorization: "Bearer ", + // "Content-Type": "application/json", + // token: localStorage.getItem("token") || "", + // refresh_token: localStorage.getItem("refreshToken") || "", + // }, + // }, + // { + // organization, + // zoneUuid: selectedZone.zoneUuid, + // widget: { + // id: selectedChartId.id, + // widgetName: inputName, + // Data: { + // measurements: inputMeasurement, + // duration: inputDuration, + // }, + // }, + // projectId: projectId, + // versionId: selectedVersion?.versionId || "" + // } as any + // ); + // + // if (response.status === 200) { + // return true; + // } else { + // // + // return false; + // } + // } catch (error) { + // echo.error("Failed to send input"); + // + // return false; + // } }; const handleSelect = async ( @@ -132,7 +148,7 @@ const Widget3InputCard3D = () => { newSelections[inputKey] = selectedData; } // setMeasurements(newSelections); // Update Zustand store - // console.log(newSelections); + // if (await sendInputes(newSelections, duration, widgetName)) { setSelections(newSelections); } @@ -145,7 +161,7 @@ const Widget3InputCard3D = () => { }; const handleNameChange = async (name: any) => { - // console.log("name change requested", name); + // if (await sendInputes(selections, duration, name)) { setWidgetName(name); diff --git a/app/src/components/layout/sidebarRight/visualization/IotInputCards/Widget4InputCard3D.tsx b/app/src/components/layout/sidebarRight/visualization/IotInputCards/Widget4InputCard3D.tsx index 2da2e61..df09e7b 100644 --- a/app/src/components/layout/sidebarRight/visualization/IotInputCards/Widget4InputCard3D.tsx +++ b/app/src/components/layout/sidebarRight/visualization/IotInputCards/Widget4InputCard3D.tsx @@ -38,15 +38,15 @@ const Widget4InputCard3D = (props: Props) => { setLoading(true); const response = await axios.get(`http://${iotApiUrl}/floatinput`); if (response.status === 200) { - // console.log("dropdown data:", response.data); + // setDropDownData(response.data); setLoading(false); } else { - // console.log("Unexpected response:", response); + // } } catch (error) { echo.error("Failed to fetch zone data"); - console.error("There was an error!", error); + } }; fetchZoneData(); @@ -55,14 +55,17 @@ const Widget4InputCard3D = (props: Props) => { useEffect(() => { const fetchSavedInputes = async () => { if (selectedChartId.id !== "") { - let response = await get3dWidgetInput(selectedChartId.id, organization) - console.log('response: ', response); + + + + let response = await get3dWidgetInput(selectedChartId.id, organization, projectId, selectedVersion?.versionId || "") + if (response) { - setSelections(response.data.Data.measurements); - setDuration(response.data.Data.duration); - setWidgetName(response.data.widgetName); + setSelections(response.Datastructure.measurements); + setDuration(response.Datastructure.duration); + setWidgetName(response.widgetName); } - + } }; @@ -81,44 +84,61 @@ const Widget4InputCard3D = (props: Props) => { inputDuration: any, inputName: any ) => { - // let newWidget = { - // id: selectedChartId.id, - // widgetName: inputName, - // Data: { - // measurements: inputMeasurement, - // duration: inputDuration, - // }, - // } - - // let response = await adding3dWidgets(selectedZone.zoneUuid, organization, newWidget, projectId, selectedVersion?.versionId || "") - // console.log('response: ', response); - try { - const response = await axios.post( - `http://${process.env.REACT_APP_SERVER_REST_API_BASE_URL}/api/V1/widget3d/save`, - { - organization, - zoneUuid: selectedZone.zoneUuid, - widget: { - id: selectedChartId.id, - widgetName: inputName, - Data: { - measurements: inputMeasurement, - duration: inputDuration, - }, - }, - } as any - ); - if (response.status === 200) { - return true; - } else { - // console.log("Unexpected response:", response); - return false; - } - } catch (error) { - echo.error("Failed to send input"); - console.error("There was an error!", error); - return false; + let newWidget = { + id: selectedChartId.id, + widgetName: inputName, + Data: { + measurements: inputMeasurement, + duration: inputDuration, + }, } + + let response = await adding3dWidgets(selectedZone.zoneUuid, organization, newWidget, projectId, selectedVersion?.versionId || "") + + if (response.message === "widget update successfully") { + return true; + } else { + return false + } + // + // try { + // const response = await axios.post( + // `http://${process.env.REACT_APP_SERVER_REST_API_BASE_URL}/api/V1/widget3d/save`, + // { + // headers: { + // Authorization: "Bearer ", + // "Content-Type": "application/json", + // token: localStorage.getItem("token") || "", + // refresh_token: localStorage.getItem("refreshToken") || "", + // }, + // }, + // { + // organization, + // zoneUuid: selectedZone.zoneUuid, + // widget: { + // id: selectedChartId.id, + // widgetName: inputName, + // Data: { + // measurements: inputMeasurement, + // duration: inputDuration, + // }, + // }, + // projectId: projectId, + // versionId: selectedVersion?.versionId || "" + // } as any + // ); + // + // if (response.status === 200) { + // return true; + // } else { + // // + // return false; + // } + // } catch (error) { + // echo.error("Failed to send input"); + // + // return false; + // } }; const handleSelect = async ( @@ -133,7 +153,7 @@ const Widget4InputCard3D = (props: Props) => { newSelections[inputKey] = selectedData; } // setMeasurements(newSelections); // Update Zustand store - // console.log(newSelections); + // if (await sendInputes(newSelections, duration, widgetName)) { setSelections(newSelections); } @@ -150,7 +170,7 @@ const Widget4InputCard3D = (props: Props) => { }; const handleNameChange = async (name: any) => { - console.log("name change requested", name); + if (await sendInputes(selections, duration, name)) { setWidgetName(name); diff --git a/app/src/modules/builder/dfx/LoadBlueprint.tsx b/app/src/modules/builder/dfx/LoadBlueprint.tsx index 4c48d59..4e2425d 100644 --- a/app/src/modules/builder/dfx/LoadBlueprint.tsx +++ b/app/src/modules/builder/dfx/LoadBlueprint.tsx @@ -79,6 +79,7 @@ const DxfFile = ({ userId } + console.log('input: ', input); socket.emit('v1:Line:create', input); }) diff --git a/app/src/modules/builder/geomentries/floors/drawOnlyFloor.ts b/app/src/modules/builder/geomentries/floors/drawOnlyFloor.ts index ad837fe..74b06ef 100644 --- a/app/src/modules/builder/geomentries/floors/drawOnlyFloor.ts +++ b/app/src/modules/builder/geomentries/floors/drawOnlyFloor.ts @@ -158,6 +158,7 @@ async function drawOnlyFloor( userId, }; + console.log('input: ', input); socket.emit("v1:Line:create", input); setNewLines([newLines[0], newLines[1], line.current]); @@ -248,6 +249,7 @@ async function drawOnlyFloor( userId, }; + console.log('input: ', input); socket.emit("v1:Line:create", input); setNewLines([line.current]); diff --git a/app/src/modules/builder/geomentries/lines/drawWall.ts b/app/src/modules/builder/geomentries/lines/drawWall.ts index b64ed64..fb6cf10 100644 --- a/app/src/modules/builder/geomentries/lines/drawWall.ts +++ b/app/src/modules/builder/geomentries/lines/drawWall.ts @@ -141,6 +141,7 @@ async function drawWall( userId, }; + console.log('input: ', input); socket.emit("v1:Line:create", input); setNewLines([newLines[0], newLines[1], line.current]); @@ -222,6 +223,7 @@ async function drawWall( userId, }; + console.log('input: ', input); socket.emit("v1:Line:create", input); setNewLines([line.current]); diff --git a/app/src/modules/builder/geomentries/lines/splitLine.ts b/app/src/modules/builder/geomentries/lines/splitLine.ts index 2e8f9b1..31c2646 100644 --- a/app/src/modules/builder/geomentries/lines/splitLine.ts +++ b/app/src/modules/builder/geomentries/lines/splitLine.ts @@ -107,6 +107,7 @@ function splitLine( userId, }; + console.log('input1: ', input1); socket.emit("v1:Line:create", input1); //REST @@ -126,6 +127,7 @@ function splitLine( userId, }; + console.log('input2: ', input2); socket.emit("v1:Line:create", input2); lines.current.push(newLine1, newLine2); diff --git a/app/src/modules/visualization/widgets/3d/Dropped3dWidget.tsx b/app/src/modules/visualization/widgets/3d/Dropped3dWidget.tsx index a9b65ea..ad00c35 100644 --- a/app/src/modules/visualization/widgets/3d/Dropped3dWidget.tsx +++ b/app/src/modules/visualization/widgets/3d/Dropped3dWidget.tsx @@ -106,17 +106,17 @@ export default function Dropped3dWidgets() { const hasEntered = { current: false }; const handleDragEnter = (event: DragEvent) => { - console.log("dragEnter"); + event.preventDefault(); event.stopPropagation(); if (hasEntered.current || !widgetSelect.startsWith("ui")) return; - console.log('hasEntered.current : ', hasEntered.current ); + hasEntered.current = true; - const group1 = scene.getObjectByName("itemsGroup"); - console.log('group1: ', group1); - if (!group1) return; + // const group1 = scene.getObjectByName("itemsGroup"); + // + // if (!group1) return; const rect = canvasElement.getBoundingClientRect(); mouse.x = ((event.clientX - rect.left) / rect.width) * 2 - 1; @@ -139,7 +139,7 @@ export default function Dropped3dWidgets() { intersect.object.type !== "GridHelper" ); - console.log('intersects: ', intersects); + if (intersects.length > 0) { const { x, y, z } = intersects[0].point; const newWidget: WidgetData = { @@ -238,10 +238,11 @@ export default function Dropped3dWidgets() { organization, widget: newWidget, zoneUuid: selectedZone.zoneUuid, - version: selectedVersion?.versionId || '', + versionId: selectedVersion?.versionId || '', projectId, userId }; + if (visualizationSocket) { visualizationSocket.emit("v1:viz-3D-widget:add", add3dWidget); @@ -276,7 +277,7 @@ export default function Dropped3dWidgets() { const widgetToDuplicate = activeZoneWidgets.find( (w: WidgetData) => w.id === rightClickSelected ); - console.log("3d widget to duplecate", widgetToDuplicate); + if (!widgetToDuplicate) return; const newWidget: any = { @@ -301,6 +302,7 @@ export default function Dropped3dWidgets() { projectId, userId }; + if (visualizationSocket) { visualizationSocket.emit("v1:viz-3D-widget:add", adding3dWidget); } @@ -470,20 +472,20 @@ export default function Dropped3dWidgets() { } // if (rightSelect === "Vertical Move") { - // // console.log('rightSelect: ', rightSelect); + // // - // // console.log('floorPlanesVertical: ', floorPlanesVertical); - // // console.log('planeIntersect.current: ', planeIntersect.current); + // // + // // // // const intersect = raycaster.ray.intersectPlane( // // floorPlanesVertical, // // planeIntersect.current // // ); - // // console.log('intersect: ', intersect); + // // // let intersect = event.clientY // if (intersect && typeof intersectcontextmenu === "number") { - // console.log('intersect: ', intersect); + // // const diff = intersect - intersectcontextmenu; // const unclampedY = selectedWidget.position[1] + diff; // const newY = Math.max(0, unclampedY); // Prevent going below floor (y=0) @@ -495,7 +497,7 @@ export default function Dropped3dWidgets() { // newY, // selectedWidget.position[2], // ]; - // console.log('newPosition: ', newPosition); + // // updateWidgetPosition(selectedzoneUuid, rightClickSelected, newPosition); diff --git a/app/src/modules/visualization/widgets/3d/cards/ProductionCapacity.tsx b/app/src/modules/visualization/widgets/3d/cards/ProductionCapacity.tsx index f951456..2a104c3 100644 --- a/app/src/modules/visualization/widgets/3d/cards/ProductionCapacity.tsx +++ b/app/src/modules/visualization/widgets/3d/cards/ProductionCapacity.tsx @@ -18,6 +18,8 @@ import { useWidgetStore } from "../../../../../store/useWidgetStore"; import useChartStore from "../../../../../store/visualization/useChartStore"; import { getUserData } from "../../../../../functions/getUserData"; import { get3dWidgetInput } from "../../../../../services/visulization/zone/get3dWidgetInput"; +import { useVersionContext } from "../../../../builder/version/versionContext"; +import { useParams } from "react-router-dom"; // Register ChartJS components ChartJS.register( @@ -70,6 +72,9 @@ const ProductionCapacity: React.FC = ({ }); const iotApiUrl = process.env.REACT_APP_IOT_SOCKET_SERVER_URL; const { userName, userId, organization, email } = getUserData(); + const { selectedVersionStore } = useVersionContext(); + const { selectedVersion } = selectedVersionStore(); + const { projectId } = useParams() // Chart data for a week const defaultChartData = { labels: ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"], // Days of the week @@ -171,12 +176,15 @@ const ProductionCapacity: React.FC = ({ const fetchSavedInputes = async () => { if (id !== "") { - let response = await get3dWidgetInput(id, organization) - console.log('response: ', response); + let response = await get3dWidgetInput(id, organization, projectId, selectedVersion?.versionId || "") + + if (response.message === "Widget not found") { + return + } if (response) { - setmeasurements(response.data.Data.measurements); - setDuration(response.data.Data.duration); - setName(response.data.widgetName); + setmeasurements(response.Datastructure.measurements); + setDuration(response.Datastructure.duration); + setName(response.widgetName); } // try { // const response = await axios.get( @@ -215,7 +223,7 @@ const ProductionCapacity: React.FC = ({ scale={scale} rotation={rotation} // class - wrapperClass="pointer-none" + // wrapperClass="pointer-none" // other transform zIndexRange={[1, 0]} diff --git a/app/src/modules/visualization/widgets/3d/cards/ReturnOfInvestment.tsx b/app/src/modules/visualization/widgets/3d/cards/ReturnOfInvestment.tsx index 80cd269..514b278 100644 --- a/app/src/modules/visualization/widgets/3d/cards/ReturnOfInvestment.tsx +++ b/app/src/modules/visualization/widgets/3d/cards/ReturnOfInvestment.tsx @@ -19,6 +19,8 @@ import useChartStore from "../../../../../store/visualization/useChartStore"; import { WavyIcon } from "../../../../../components/icons/3dChartIcons"; import { getUserData } from "../../../../../functions/getUserData"; import { get3dWidgetInput } from "../../../../../services/visulization/zone/get3dWidgetInput"; +import { useVersionContext } from "../../../../builder/version/versionContext"; +import { useParams } from "react-router-dom"; // Register Chart.js components ChartJS.register( @@ -79,6 +81,9 @@ const ReturnOfInvestment: React.FC = ({ datasets: [], }); const iotApiUrl = process.env.REACT_APP_IOT_SOCKET_SERVER_URL; + const { selectedVersionStore } = useVersionContext(); + const { selectedVersion } = selectedVersionStore(); + const { projectId } = useParams() const { userName, userId, organization, email } = getUserData(); // Improved sample data for the smooth curve graph (single day) const graphData: ChartData<"line"> = { @@ -200,8 +205,11 @@ const ReturnOfInvestment: React.FC = ({ const fetchSavedInputes = async () => { if (id !== "") { - let response = await get3dWidgetInput(id, organization) - console.log('response: ', response); + let response = await get3dWidgetInput(id, organization, projectId, selectedVersion?.versionId || "") + + if (response.message === "Widget not found") { + return + } if (response) { setmeasurements(response.data.Data.measurements); setDuration(response.data.Data.duration); @@ -216,11 +224,11 @@ const ReturnOfInvestment: React.FC = ({ // setDuration(response.data.Data.duration); // setName(response.data.widgetName); // } else { - // // console.log("Unexpected response:", response); + // // // } // } catch (error) { // echo.error("Failed to fetch saved inputs"); - // console.error("There was an error!", error); + // // } } }; diff --git a/app/src/modules/visualization/widgets/3d/cards/StateWorking.tsx b/app/src/modules/visualization/widgets/3d/cards/StateWorking.tsx index f664661..e6e3b5f 100644 --- a/app/src/modules/visualization/widgets/3d/cards/StateWorking.tsx +++ b/app/src/modules/visualization/widgets/3d/cards/StateWorking.tsx @@ -7,6 +7,8 @@ import { useWidgetStore } from "../../../../../store/useWidgetStore"; import useChartStore from "../../../../../store/visualization/useChartStore"; import { getUserData } from "../../../../../functions/getUserData"; import { get3dWidgetInput } from "../../../../../services/visulization/zone/get3dWidgetInput"; +import { useVersionContext } from "../../../../builder/version/versionContext"; +import { useParams } from "react-router-dom"; // import image from "../../../../assets/image/temp/image.png"; interface StateWorkingProps { @@ -41,6 +43,9 @@ const StateWorking: React.FC = ({ const [datas, setDatas] = useState({}); const iotApiUrl = process.env.REACT_APP_IOT_SOCKET_SERVER_URL; const { userName, userId, organization, email } = getUserData(); + const { selectedVersionStore } = useVersionContext(); + const { selectedVersion } = selectedVersionStore(); + const { projectId } = useParams() // const datas = [ // { key: "Oil Tank:", value: "24/341" }, // { key: "Oil Refin:", value: 36.023 }, @@ -78,12 +83,15 @@ const StateWorking: React.FC = ({ const fetchSavedInputes = async () => { if (id !== "") { - let response = await get3dWidgetInput(id, organization) - console.log('response: ', response); + let response = await get3dWidgetInput(id, organization, projectId, selectedVersion?.versionId || "") + + if (response.message === "Widget not found") { + return + } if (response) { - setmeasurements(response.data.Data.measurements); - setDuration(response.data.Data.duration); - setName(response.data.widgetName); + setmeasurements(response.Datastructure.measurements); + setDuration(response.Datastructure.duration); + setName(response.widgetName); } // try { // const response = await axios.get( @@ -94,17 +102,17 @@ const StateWorking: React.FC = ({ // setDuration(response.data.Data.duration); // setName(response.data.widgetName); // } else { - // // console.log("Unexpected response:", response); + // // // } // } catch (error) { // echo.error("Failed to fetch saved inputs"); - // console.error("There was an error!", error); + // // } } }; useEffect(() => { - fetchSavedInputes(); + // fetchSavedInputes(); }, []); useEffect(() => { diff --git a/app/src/modules/visualization/widgets/3d/cards/Throughput.tsx b/app/src/modules/visualization/widgets/3d/cards/Throughput.tsx index ea87c7f..599b566 100644 --- a/app/src/modules/visualization/widgets/3d/cards/Throughput.tsx +++ b/app/src/modules/visualization/widgets/3d/cards/Throughput.tsx @@ -21,6 +21,8 @@ import useChartStore from "../../../../../store/visualization/useChartStore"; import { ThroughputIcon } from "../../../../../components/icons/3dChartIcons"; import { getUserData } from "../../../../../functions/getUserData"; import { get3dWidgetInput } from "../../../../../services/visulization/zone/get3dWidgetInput"; +import { useVersionContext } from "../../../../builder/version/versionContext"; +import { useParams } from "react-router-dom"; // Register Chart.js components ChartJS.register( @@ -83,6 +85,9 @@ const Throughput: React.FC = ({ }); const iotApiUrl = process.env.REACT_APP_IOT_SOCKET_SERVER_URL; const { userName, userId, organization, email } = getUserData(); + const { selectedVersionStore } = useVersionContext(); + const { selectedVersion } = selectedVersionStore(); + const { projectId } = useParams() @@ -180,12 +185,15 @@ const Throughput: React.FC = ({ const fetchSavedInputes = async () => { if (id !== "") { - let response = await get3dWidgetInput(id, organization) - console.log('response: ', response); + let response = await get3dWidgetInput(id, organization, projectId, selectedVersion?.versionId || "") + + if (response.message === "Widget not found") { + return + } if (response) { - setmeasurements(response.data.Data.measurements); - setDuration(response.data.Data.duration); - setName(response.data.widgetName); + setmeasurements(response.Datastructure.measurements); + setDuration(response.Datastructure.duration); + setName(response.widgetName); } // try { // const response = await axios.get( @@ -196,17 +204,17 @@ const Throughput: React.FC = ({ // setDuration(response.data.Data.duration); // setName(response.data.widgetName); // } else { - // // console.log("Unexpected response:", response); + // // // } // } catch (error) { // echo.error("Failed to fetch saved inputs"); - // console.error("There was an error!", error); + // // } } }; useEffect(() => { - fetchSavedInputes(); + // fetchSavedInputes(); }, []); useEffect(() => { diff --git a/app/src/services/visulization/zone/add3dWidget.ts b/app/src/services/visulization/zone/add3dWidget.ts index caca8d9..322c8bb 100644 --- a/app/src/services/visulization/zone/add3dWidget.ts +++ b/app/src/services/visulization/zone/add3dWidget.ts @@ -6,8 +6,10 @@ export const adding3dWidgets = async ( widget: {}, projectId?: string, versionId?: string - + ) => { + + try { const response = await fetch(`${url_Backend_dwinzo}/api/V1/widget3d/save`, { method: "POST", @@ -20,15 +22,16 @@ export const adding3dWidgets = async ( body: JSON.stringify({ organization, zoneUuid, widget, projectId, versionId }), }); + const newAccessToken = response.headers.get("x-access-token"); if (newAccessToken) { - //console.log("New token received:", newAccessToken); + // localStorage.setItem("token", newAccessToken); } if (!response.ok) { - console.error("Failed to add 3dwidget in the zone"); + } const result = await response.json(); @@ -36,9 +39,9 @@ export const adding3dWidgets = async ( } catch (error) { echo.error("Failed to add 3d widget"); if (error instanceof Error) { - console.log(error.message); + } else { - console.log("An unknown error occurred"); + } } }; diff --git a/app/src/services/visulization/zone/get3dWidgetInput.ts b/app/src/services/visulization/zone/get3dWidgetInput.ts index 71f38ef..25e817c 100644 --- a/app/src/services/visulization/zone/get3dWidgetInput.ts +++ b/app/src/services/visulization/zone/get3dWidgetInput.ts @@ -2,9 +2,13 @@ let url_Backend_dwinzo = `http://${process.env.REACT_APP_SERVER_REST_API_BASE_UR export const get3dWidgetInput = async (chartId: string, organization: string, projectId?: string, versionId?: string) => { + + + + try { const response = await fetch( - `${url_Backend_dwinzo}/api/v2/widget3D/${chartId}/${organization}`, + `${url_Backend_dwinzo}/api/V1/widget3dData/${chartId}/${projectId}/${versionId}`, { method: "GET", headers: { @@ -15,9 +19,10 @@ export const get3dWidgetInput = async (chartId: string, organization: string, pr }, } ); + const newAccessToken = response.headers.get("x-access-token"); if (newAccessToken) { - //console.log("New token received:", newAccessToken); + // localStorage.setItem("token", newAccessToken); } @@ -25,10 +30,10 @@ export const get3dWidgetInput = async (chartId: string, organization: string, pr throw new Error("Failed to fetch zoneDatas"); } const result = await response.json(); - console.log('result: ', result); + return result; } catch (error: any) { echo.error("Failed to fetch 2d widget data"); - console.log(error.message); + } };