From 8386a7043cfb9f205c513e220b7ddc08ce74ffbc Mon Sep 17 00:00:00 2001 From: Wahyu Ramadhan Date: Sun, 2 Jul 2023 13:54:08 +0700 Subject: [PATCH] Initial linear curve --- view-mode/function/overlaySCurve.js | 62 ++++++++++++++++++++--------- 1 file changed, 44 insertions(+), 18 deletions(-) diff --git a/view-mode/function/overlaySCurve.js b/view-mode/function/overlaySCurve.js index 487b8d0..e4bf48f 100644 --- a/view-mode/function/overlaySCurve.js +++ b/view-mode/function/overlaySCurve.js @@ -13,18 +13,49 @@ function callback(response) { } function getSCurveData(){ - $.ajax({ - headers: { - "Content-Type": "application/json", - "Authorization": `Bearer ${token}` - }, - url: `${base_url}project/get-s-curve`, - type: "POST", - data:JSON.stringify(sCurvePayload), - success: function (data) { - callback(data) - } - }); + + // Send a message to the parent window requesting the URL + window.parent.postMessage({ action: 'getUrl' }, '*'); + + // Listen for messages from the parent window + window.addEventListener('message', function(event) { + if (event.data && event.data.action === 'sendUrl') { + const parentUrl = event.data.url; + + // Remove the base URL and hash + const path = parentUrl.replace("http://localhost:3000/#/dashboard-project/", ""); + + // Split the remaining path by "/" + const parts = path.split("/"); + if (parts[2] && parts[2] == "1") { + $.ajax({ + headers: { + "Content-Type": "application/json", + "Authorization": `Bearer ${token}` + }, + url: `${base_url}project/get-linear-s-curve`, + type: "POST", + data:JSON.stringify(sCurvePayload), + success: function (data) { + callback(data) + } + }); + } else { + $.ajax({ + headers: { + "Content-Type": "application/json", + "Authorization": `Bearer ${token}` + }, + url: `${base_url}project/get-s-curve`, + type: "POST", + data:JSON.stringify(sCurvePayload), + success: function (data) { + callback(data) + } + }); + } + } + }); }; function toggleOverlay() { @@ -189,12 +220,7 @@ var lineOverlay = overlayControl.addOverlay(function(container) { ticks: { display: true, min: 0, - max: 100, - stepSize: 10, - callback: function(current) { - if (current > 100) {return "";} - return current + "%"; - } + stepSize: 100, } }, ]