diff --git a/src/routes.js b/src/routes.js index f192be0..85e3523 100644 --- a/src/routes.js +++ b/src/routes.js @@ -54,6 +54,7 @@ const routes = [ // { path: '/dashboard', name: 'Dashboard', component: Dashboard}, { path: '/dashboard', name: 'DashboardBOD', component: DashboardBOD }, { path: '/dashboard-customer/:PROJECT_ID/:GANTT_ID', name: 'DashboardCustomer', component: DashboardCustomer }, + { path: '/dashboard-customer/:PROJECT_ID/:GANTT_ID/:SCURVE', name: 'DashboardCustomer', component: DashboardCustomer }, { path: '/dashboard-project/:PROJECT_ID/:GANTT_ID', exact: true, name: 'Dashboard Project', component: DashboardProject }, { path: '/dashboard-project/:PROJECT_ID/:GANTT_ID/:SCURVE', exact: true, name: 'Dashboard Project', component: DashboardProject }, { path: '/projects', exact: true, name: 'Projects', component: CreatedProyek }, diff --git a/src/views/Dashboard/DashboardCustomer.js b/src/views/Dashboard/DashboardCustomer.js index 613bf44..eef2fd6 100644 --- a/src/views/Dashboard/DashboardCustomer.js +++ b/src/views/Dashboard/DashboardCustomer.js @@ -33,7 +33,7 @@ const DashboardCustomer = () => { Authorization: `Bearer ${token}` } } - const { PROJECT_ID, GANTT_ID } = useParams(); + const { PROJECT_ID, GANTT_ID, SCURVE } = useParams(); const URL_GANTT = `https://adw-gantt.ospro.id/view-mode/index.html?base_url=${BASE_OSPRO}/api&gantt_id=${GANTT_ID}&proyek_id=${PROJECT_ID}&token=${token}&ro=1`; const mapRef = useRef() const [projectName, setProjectName] = useState(""); @@ -61,6 +61,7 @@ const DashboardCustomer = () => { const [healthBySchedule, setHealthBySchedule] = useState('-'); const [healthByBudget, setHealthByBudget] = useState('-'); const [reportDistribution, setReportDistribution] = useState([]); + const [calculationStatus, setCalculationStatus] = useState(false); useEffect(() => { getProjectDetail(); @@ -79,6 +80,25 @@ const DashboardCustomer = () => { } }, [activeTabIdx]); + useEffect(() => { + // Add event listener for receiving messages from the iframe + window.addEventListener('message', handleIframeMessage); + + // Clean up the event listener on component unmount + return () => { + window.removeEventListener('message', handleIframeMessage); + }; + }, []); + + const handleIframeMessage = (event) => { + if (event.data && event.data.action === 'getUrl') { + const childUrl = window.location.href; + + // Send the URL back to the iframe + event.source.postMessage({ action: 'sendUrl', url: childUrl }, event.origin); + } + }; + const getProjectDetail = async () => { setIsReadyProjectDetail(false); const URL = `${BASE_OSPRO}/api/project/detail/${PROJECT_ID}`; @@ -106,12 +126,13 @@ const DashboardCustomer = () => { setActualStart(result.data.data.header?.start_date ? result.data.data.header.start_date : null) setEstimatedFinish(result.data.data.header?.end_date ? result.data.data.header.end_date : null) setIsReadyProjectDetail(true); + setCalculationStatus(result.data.data.calculation_status ? result.data.data.calculation_status : false) } } const getSCurve = async () => { setIsReadySCurve(false); - const URL = `${BASE_OSPRO}/api/project/get-s-curve`; + URL = `${BASE_OSPRO}/api/project/calculate-s-curve`; const payload = { "project_id": PROJECT_ID.toString(), "period": "week", @@ -139,6 +160,20 @@ const DashboardCustomer = () => { let planningProgress = result.data.data[0].data?.percentagePlan[result.data.data[0].data?.percentagePlan.length-1]; setPlanningProgress(planningProgress); } + let now = new Date().toISOString().slice(0, 10); + let dates = result.data.data[0].data?.date; + let n = dates.findIndex(element => new Date(now) < new Date(element[0])); + if (n < 0) { + n = dates.length - 1; + } + if (result.data.data.length > 0 && result.data.data[0].data?.percentagePlan && result.data.data[0].data?.percentagePlan.length > 0) { + if(SCURVE && SCURVE == "1"){ + planningProgress = result.data.data[0].data?.percentagePlan[result.data.data[0].data?.percentagePlan.length - 1]; + } else { + planningProgress = result.data.data[0].data?.percentagePlan[n]; + } + setPlanningProgress(planningProgress); + } if (result.data.data.length > 0 && result.data.data[0].data?.percentageReal && result.data.data[0].data?.percentageReal.length > 0) { let actualProgress = result.data.data[0].data?.percentageReal[result.data.data[0].data?.percentageReal.length-1]; setActualProgress(actualProgress); @@ -396,7 +431,13 @@ const DashboardCustomer = () => {