Compare commits

...

4 Commits

4 changed files with 289 additions and 246 deletions

View File

@@ -1,32 +1,38 @@
import { useEffect, useState } from 'react' import { useEffect, useState } from 'react'
import { ClockThreeIcon, LocationPinIcon, TargetIcon } from '../../../../icons/ExportCommonIcons' import { ClockThreeIcon, LocationPinIcon, TargetIcon } from '../../../../icons/ExportCommonIcons'
import { useSceneContext } from '../../../../../modules/scene/sceneContext'; import { useSceneContext } from '../../../../../modules/scene/sceneContext';
import { useProductContext } from '../../../../../modules/simulation/products/productContext';
import RenameInput from '../../../../ui/inputs/RenameInput'; import RenameInput from '../../../../ui/inputs/RenameInput';
import { useResourceManagementId } from '../../../../../store/builder/store'; import { useResourceManagementId } from '../../../../../store/builder/store';
import { set } from 'immer/dist/internal'; import { getAssetThumbnail } from '../../../../../services/factoryBuilder/asset/assets/getAssetThumbnail';
// import NavigateCatagory from '../NavigateCatagory' // import NavigateCatagory from '../NavigateCatagory'
const Hrm = () => { const Hrm = () => {
const [selectedCard, setSelectedCard] = useState(0); const [selectedCard, setSelectedCard] = useState(0);
const [workers, setWorkers] = useState<any[]>([]); const [workers, setWorkers] = useState<any[]>([]);
const { productStore } = useSceneContext();
const { products, getProductById } = productStore();
const { selectedProductStore } = useProductContext();
const { selectedProduct } = selectedProductStore();
const { setResourceManagementId } = useResourceManagementId(); const { setResourceManagementId } = useResourceManagementId();
const { assetStore } = useSceneContext();
const { assets: allAssets } = assetStore();
async function getAsset(assetId: string) {
let thumbnail = await getAssetThumbnail(assetId)
if (thumbnail.thumbnail) {
let assetImage = thumbnail.thumbnail
return assetImage;
}
}
useEffect(() => { useEffect(() => {
if (selectedProduct) { if (allAssets.length > 0) {
const productDetails = getProductById(selectedProduct.productUuid); const fetchWorkers = async () => {
const workerDetails = productDetails?.eventDatas || []; const humans = allAssets.filter((worker: any) => worker.eventData.type === "Human");
const formattedWorkers = workerDetails const formattedWorkers = await Promise.all(
.filter((worker: any) => worker.type === "human") humans.map(async (worker: any, index: number) => {
.map((worker: any, index: number) => ({ const assetImage = await getAsset(worker.assetId);
return {
employee: { employee: {
image: "", image: assetImage,
name: worker.modelName, name: worker.modelName,
modelId: worker.modelUuid, modelId: worker.modelUuid,
employee_id: `HR-${204 + index}`, employee_id: `HR-${204 + index}`,
@@ -34,134 +40,129 @@ const Hrm = () => {
}, },
task: { task: {
status: "Ongoing", status: "Ongoing",
title: worker.taskTitle || "No Task Assigned", title: worker.taskTitle ?? "No Task Assigned",
location: { location: {
floor: worker.floor || 0, floor: worker.floor ?? 0,
zone: worker.zone || "N/A" zone: worker.zone ?? "N/A",
}, },
planned_time_hours: worker.plannedTime || 0, planned_time_hours: worker.plannedTime ?? 0,
time_spent_hours: worker.timeSpent || 0, time_spent_hours: worker.timeSpent ?? 0,
total_tasks: worker.totalTasks || 0, total_tasks: worker.totalTasks ?? 0,
completed_tasks: worker.completedTasks || 0 completed_tasks: worker.completedTasks ?? 0,
}, },
actions: [ actions: ["Assign Task", "Reassign Task", "Pause", "Emergency Stop"],
"Assign Task", location: `Floor ${worker.floor || "-"} . Zone ${worker.zone || "-"}`,
"Reassign Task", };
"Pause", })
"Emergency Stop" );
],
location: `Floor ${worker.floor || "-"} . Zone ${worker.zone || "-"}`
}));
setWorkers(formattedWorkers); setWorkers(formattedWorkers);
};
fetchWorkers();
} }
}, [selectedProduct, getProductById]); }, [allAssets]);
useEffect(() => {
//
}, [workers]);
// const employee_details = [
// {
// "employee": {
// image: "",
// "name": "John Doe",
// "employee_id": "HR-204",
// "status": "Active",
// const employee_details = [ // },
// { // "task": {
// "employee": { // "status": "Ongoing",
// image: "", // "title": "Inspecting Machine X",
// "name": "John Doe", // "location": {
// "employee_id": "HR-204", // "floor": 4,
// "status": "Active", // "zone": "B"
// },
// "planned_time_hours": 6,
// "time_spent_hours": 2,
// "total_tasks": 12,
// "completed_tasks": 3
// },
// "actions": [
// "Assign Task",
// "Reassign Task",
// "Pause",
// "Emergency Stop"
// ],
// "location": "Floor 4 . Zone B"
// },
// {
// "employee": {
// image: "",
// "name": "Alice Smith",
// "employee_id": "HR-205",
// "status": "Active",
// }, // },
// "task": { // "task": {
// "status": "Ongoing", // "status": "Ongoing",
// "title": "Inspecting Machine X", // "title": "Calibrating Sensor Y",
// "location": { // "location": {
// "floor": 4, // "floor": 2,
// "zone": "B" // "zone": "A"
// }, // },
// "planned_time_hours": 6, // "planned_time_hours": 4,
// "time_spent_hours": 2, // "time_spent_hours": 1.5,
// "total_tasks": 12, // "total_tasks": 10,
// "completed_tasks": 3 // "completed_tasks": 2
// }, // },
// "actions": [ // "actions": [
// "Assign Task", // "Assign Task",
// "Reassign Task", // "Reassign Task",
// "Pause", // "Pause",
// "Emergency Stop" // "Emergency Stop"
// ], // ],
// "location": "Floor 4 . Zone B" // "location": "Floor 4 . Zone B"
// }, // },
// { // {
// "employee": { // "employee": {
// image: "", // image: "",
// "name": "Alice Smith", // "name": "Michael Lee",
// "employee_id": "HR-205", // "employee_id": "HR-206",
// "status": "Active", // "status": "Active",
// }, // },
// "task": { // "task": {
// "status": "Ongoing", // "status": "Ongoing",
// "title": "Calibrating Sensor Y", // "title": "Testing Conveyor Belt Z",
// "location": { // "location": {
// "floor": 2, // "floor": 5,
// "zone": "A" // "zone": "C"
// }, // },
// "planned_time_hours": 4, // "planned_time_hours": 5,
// "time_spent_hours": 1.5, // "time_spent_hours": 3,
// "total_tasks": 10, // "total_tasks": 8,
// "completed_tasks": 2 // "completed_tasks": 5
// }, // },
// "actions": [ // "actions": [
// "Assign Task", // "Assign Task",
// "Reassign Task", // "Reassign Task",
// "Pause", // "Pause",
// "Emergency Stop" // "Emergency Stop"
// ], // ],
// "location": "Floor 4 . Zone B" // "location": "Floor 4 . Zone B"
// }, // },
// { // ]
// "employee": { function handleRenameWorker(newName: string) {
// image: "",
// "name": "Michael Lee",
// "employee_id": "HR-206",
// "status": "Active",
// },
// "task": {
// "status": "Ongoing",
// "title": "Testing Conveyor Belt Z",
// "location": {
// "floor": 5,
// "zone": "C"
// },
// "planned_time_hours": 5,
// "time_spent_hours": 3,
// "total_tasks": 8,
// "completed_tasks": 5
// },
// "actions": [
// "Assign Task",
// "Reassign Task",
// "Pause",
// "Emergency Stop"
// ],
// "location": "Floor 4 . Zone B"
// },
// ]
function handleRenameWorker(newName: string) {
//
} }
function handleHumanClick(employee: any) { function handleHumanClick(employee: any) {
if (employee.modelId) { if (employee.modelId) {
setResourceManagementId(employee.modelId); setResourceManagementId(employee.modelId);
} }
} }
return ( return (
<> <>
{/* <NavigateCatagory {/* <NavigateCatagory
category={["All People", "Technician", "Operator", "Supervisor", "Safety Officer"]} category={["All People", "Technician", "Operator", "Supervisor", "Safety Officer"]}
@@ -274,7 +275,7 @@ const Hrm = () => {
))} ))}
</div> </div>
</> </>
) )
} }
export default Hrm export default Hrm

View File

@@ -3,60 +3,65 @@ import { useEffect, useState } from 'react'
import { EyeIcon, ForkLiftIcon, KebabIcon, LocationPinIcon, RightHalfFillCircleIcon } from '../../../../../icons/ExportCommonIcons'; import { EyeIcon, ForkLiftIcon, KebabIcon, LocationPinIcon, RightHalfFillCircleIcon } from '../../../../../icons/ExportCommonIcons';
import assetImage from "../../../../../../assets/image/asset-image.png" import assetImage from "../../../../../../assets/image/asset-image.png"
import { useSceneContext } from '../../../../../../modules/scene/sceneContext'; import { useSceneContext } from '../../../../../../modules/scene/sceneContext';
import { useProductContext } from '../../../../../../modules/simulation/products/productContext';
import RenameInput from '../../../../../ui/inputs/RenameInput'; import RenameInput from '../../../../../ui/inputs/RenameInput';
import { useResourceManagementId } from '../../../../../../store/builder/store'; import { useResourceManagementId } from '../../../../../../store/builder/store';
import { getAssetThumbnail } from '../../../../../../services/factoryBuilder/asset/assets/getAssetThumbnail';
const AssetManagement = () => { const AssetManagement = () => {
// const [selectedCategory, setSelectedCategory] = useState("All Assets"); // const [selectedCategory, setSelectedCategory] = useState("All Assets");
const [expandedAssetId, setExpandedAssetId] = useState<string | null>(null); const [expandedAssetId, setExpandedAssetId] = useState<string | null>(null);
const [assets, setAssets] = useState<any[]>([]); const [assets, setAssets] = useState<any[]>([]);
const { productStore } = useSceneContext();
const { products, getProductById } = productStore();
const { selectedProductStore } = useProductContext();
const { selectedProduct } = selectedProductStore();
const { setResourceManagementId } = useResourceManagementId(); const { setResourceManagementId } = useResourceManagementId();
const { assetStore } = useSceneContext();
const { assets: allAssets } = assetStore();
async function getAsset(assetId: string) {
let thumbnail = await getAssetThumbnail(assetId)
if (thumbnail.thumbnail) {
let assetImage = thumbnail.thumbnail
return assetImage;
}
}
useEffect(() => { useEffect(() => {
if (selectedProduct) { if (allAssets.length > 0) {
const productDetails = getProductById(selectedProduct.productUuid); const fetchAssets = async () => {
const productAssets = productDetails?.eventDatas || [];
const grouped: Record<string, any> = {}; const grouped: Record<string, any> = {};
productAssets.forEach((asset: any) => {
if (asset.type === "storageUnit" || asset.type === "human") return; // Use Promise.all to handle all async operations
if (!grouped[asset.modelName]) { await Promise.all(allAssets.map(async (asset: any) => {
grouped[asset.modelName] = {
if (asset.eventData.type === "Storage" || asset.eventData.type === "Human") return;
const assetImage = await getAsset(asset.assetId);
if (!grouped[asset.assetId]) {
grouped[asset.assetId] = {
id: asset.modelUuid, id: asset.modelUuid,
assetId: asset.assetId,
name: asset.modelName, name: asset.modelName,
model: asset.modelCode || "N/A", model: asset.modelCode ?? "N/A",
status: asset.status || "Online", status: asset.status ?? "Online",
usageRate: asset.usageRate || 15, usageRate: asset.usageRate ?? 15,
level: asset.level || "Level 1", level: asset.level ?? "Level 1",
image: assetImage, image: assetImage,
description: asset.description || "No description", description: asset.description ?? "No description",
cost: asset.cost || 0, cost: asset.cost ?? 0,
count: 1, count: 1,
}; };
} else { } else {
grouped[asset.modelName].count += 1; grouped[asset.assetId].count += 1;
} }
}); }));
setAssets(Object.values(grouped)); setAssets(Object.values(grouped));
} }
}, [selectedProduct]); fetchAssets();
}
}, [allAssets]);
function handleRenameAsset(newName: string) { function handleRenameAsset(newName: string) {
//
// if (expandedAssetId) {
// setAssets(prevAssets =>
// prevAssets.map(asset =>
// asset.id === expandedAssetId ? { ...asset, name: newName } : asset
// )
// );
// }
} }
useEffect(() => { useEffect(() => {
@@ -65,8 +70,6 @@ const AssetManagement = () => {
}, [assets]); }, [assets]);
function handleAssetClick(id: string) { function handleAssetClick(id: string) {
setResourceManagementId(id); setResourceManagementId(id);
} }
@@ -170,9 +173,9 @@ const AssetManagement = () => {
</div> </div>
</div> </div>
<div className="asset-estimate__view-button"> <div className="asset-estimate__view-button" onClick={() => handleAssetClick(asset.id)}>
<EyeIcon isClosed={false} /> <EyeIcon isClosed={false} />
<div className="asset-estimate__view-text" onClick={() => handleAssetClick(asset.id)}>View in Scene</div> <div className="asset-estimate__view-text">View in Scene</div>
</div> </div>
</div> </div>

View File

@@ -0,0 +1,33 @@
let url_Backend_dwinzo = `http://${process.env.REACT_APP_SERVER_MARKETPLACE_URL}`;
export const getAssetThumbnail = async (assetId: String) => {
try {
const response = await fetch(
`${url_Backend_dwinzo}/api/v2/getAssetThumbnail/${assetId}`,
{
method: "GET",
headers: {
Authorization: "Bearer <access_token>",
"Content-Type": "application/json",
token: localStorage.getItem("token") || "",
refresh_token: localStorage.getItem("refreshToken") || "",
},
}
);
const newAccessToken = response.headers.get("x-access-token");
if (newAccessToken) {
localStorage.setItem("token", newAccessToken);
}
if (!response.ok) {
throw new Error("Failed to fetch assets");
}
//
return await response.json();
} catch (error: any) {
echo.error("Failed to get asset image");
}
};

View File

@@ -117,6 +117,12 @@
border-radius: 50%; border-radius: 50%;
background-color: #fff; background-color: #fff;
position: relative; position: relative;
overflow: hidden;
.user-image{
height: 300%;
width: 300%;
transform: translate(-26px, -12px);
}
.status { .status {
border-radius: 50%; border-radius: 50%;