From 7661232569327ab57607c26aee4d9c7b78c7e9c5 Mon Sep 17 00:00:00 2001 From: Wahyu Ramadhan Date: Wed, 2 Aug 2023 15:20:47 +0700 Subject: [PATCH 1/6] Fix horizontal scroll --- edit-mode/function/function.js | 29 ++++++++++++++++++++++++++ edit-mode/function/ganttEvent.js | 4 ++-- edit-mode/function/restActivityLink.js | 6 ++++++ 3 files changed, 37 insertions(+), 2 deletions(-) diff --git a/edit-mode/function/function.js b/edit-mode/function/function.js index 2e7aa28..7ce02f1 100644 --- a/edit-mode/function/function.js +++ b/edit-mode/function/function.js @@ -636,4 +636,33 @@ function expandTask() { function resetActivity() { localStorage.setItem('batchEntity', ''); gantt.alert("Actiivity Saved"); +} +// Function to get the earliest planned start date among all tasks +function getEarliestTaskDate() { + var earliestDate = null; + gantt.eachTask(function (task) { + var taskStartDate = task.planned_start || task.start_date; + if (!earliestDate || task.planned_start < earliestDate) { + earliestDate = taskStartDate; + if (task.start_date < earliestDate) { + earliestDate = task.start_date; + } + } + }); + return earliestDate; +} + +// Function to get the latest planned end date among all tasks +function getLatestTaskDate() { + var latestDate = null; + gantt.eachTask(function (task) { + var taskEndDate = task.planned_end || task.end_date; + if (!latestDate || task.planned_end > latestDate) { + latestDate = taskEndDate; + if (task.end_date > latestDate) { + latestDate = task.end_date; + } + } + }); + return latestDate; } \ No newline at end of file diff --git a/edit-mode/function/ganttEvent.js b/edit-mode/function/ganttEvent.js index b58d96a..3aa4710 100644 --- a/edit-mode/function/ganttEvent.js +++ b/edit-mode/function/ganttEvent.js @@ -168,11 +168,11 @@ gantt.attachEvent("onGanttScroll", function (left, top){ var max_allowed_date = gantt.date.add(gantt.config.end_date, -1, "day"); var repaint = false; - if (+left_date <= +min_allowed_date){ + if (earliest && +left_date <= +min_allowed_date && +left_date >= +earliest){ gantt.config.start_date = gantt.date.add(gantt.config.start_date, -1, "day"); repaint = true; } - if (+right_date >= +max_allowed_date){ + if (latest && +right_date >= +max_allowed_date && +right_date <= +latest){ gantt.config.end_date = gantt.date.add(gantt.config.end_date, 1, "day"); repaint = true; } diff --git a/edit-mode/function/restActivityLink.js b/edit-mode/function/restActivityLink.js index bf23dc5..84d2f05 100644 --- a/edit-mode/function/restActivityLink.js +++ b/edit-mode/function/restActivityLink.js @@ -1,4 +1,6 @@ let geom = []; +let latest; +let earliest; $("body").addClass("loading"); gantt.ajax.get({ url: `${base_url}activity/${ganttId}/${proyekId}/get`, @@ -33,6 +35,8 @@ gantt.ajax.get({ gantt.parse(data); getGanttOpen(); gantt.parse(data); + earliest = getEarliestTaskDate(); + latest = getLatestTaskDate(); }); }).catch(function (error) { $("body").removeClass("loading"); @@ -77,6 +81,8 @@ function refresData(id) { gantt.parse(data); getGanttOpen(); gantt.parse(data); + earliest = getEarliestTaskDate(); + latest = getLatestTaskDate(); }); if (id) { if (gantt.isTaskExists(id)) { From aaaa231a59440b758f402c453002e9bccd6931f2 Mon Sep 17 00:00:00 2001 From: Wahyu Ramadhan Date: Thu, 3 Aug 2023 09:01:28 +0700 Subject: [PATCH 2/6] Fix date label range --- view-mode/function/overlaySCurve.js | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/view-mode/function/overlaySCurve.js b/view-mode/function/overlaySCurve.js index 364d90e..fb56d20 100644 --- a/view-mode/function/overlaySCurve.js +++ b/view-mode/function/overlaySCurve.js @@ -145,19 +145,22 @@ var lineOverlay = overlayControl.addOverlay(function(container) { var values = getProgressLine(); var scaleLabels = []; - if(parts[2] && parts[2] == '1'){ +// if(parts[2] && parts[2] == '1'){ +// values.dates.forEach(function(date){ +// var dateScale = new Date(date); +// scaleLabels.push(dateToStr(dateScale)); +// }) +// } else { +// var chartScale = getChartScaleRange(); + +// chartScale.forEach(function(date){ +// scaleLabels.push(dateToStr(date)); +// }); +// } values.dates.forEach(function(date){ var dateScale = new Date(date); scaleLabels.push(dateToStr(dateScale)); }) - } else { - var chartScale = getChartScaleRange(); - - chartScale.forEach(function(date){ - scaleLabels.push(dateToStr(date)); - }); - } - var canvas = document.createElement("canvas"); container.appendChild(canvas); canvas.style.height = container.offsetHeight + "px"; From e2a88321215d9c2fa481a84232db8c29ebe82f3b Mon Sep 17 00:00:00 2001 From: Wahyu Ramadhan Date: Thu, 3 Aug 2023 10:36:28 +0700 Subject: [PATCH 3/6] Fix report image --- edit-mode/function/ganttConfig.js | 7 ++++++- edit-mode/function/reportActivity.js | 13 ++++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/edit-mode/function/ganttConfig.js b/edit-mode/function/ganttConfig.js index a22ca2d..4370aa7 100644 --- a/edit-mode/function/ganttConfig.js +++ b/edit-mode/function/ganttConfig.js @@ -22,7 +22,12 @@ const axiosInstance = axios.create({ "Content-type": "application/json" } }); - +const axiosInstanceMultipart = axios.create({ + headers: { + "Content-Type": "multipart/form-data", + "Authorization": `Bearer ${token}`, + } +}); axiosInstance.interceptors.request.use(async (config) => { try { $("body").addClass("loading"); diff --git a/edit-mode/function/reportActivity.js b/edit-mode/function/reportActivity.js index 7c6d232..97baba6 100644 --- a/edit-mode/function/reportActivity.js +++ b/edit-mode/function/reportActivity.js @@ -426,8 +426,19 @@ $(document).ready(function () { .catch((error) => error.response); // console.log("cek result", result); + let reportId = result.data.data.report_id; + let imageFormData = new FormData(); + let image = formData.get("files"); + imageFormData.append("ref_id",reportId); + imageFormData.append("category", "report_activity"); + imageFormData.append("files", image, image.name); + + const resultImage = await axiosInstanceMultipart + .post(`${base_url}image/upload`, imageFormData) + .then(res => res) + .catch((error) => error.response); - if (result && result.status == 200) { + if (result && result.status == 200 && resultImage && resultImage.status == 200) { gantt.alert("Add report activity material Success!"); resetFormAddRaMaterial(); tableRaMaterialActual.draw(); From 302e428b2b1724173c5b6fa2ee03b4aea831c7d5 Mon Sep 17 00:00:00 2001 From: Wahyu Ramadhan Date: Thu, 3 Aug 2023 10:56:17 +0700 Subject: [PATCH 4/6] Improve error handling --- edit-mode/function/reportActivity.js | 50 +++++++++++++--------------- 1 file changed, 24 insertions(+), 26 deletions(-) diff --git a/edit-mode/function/reportActivity.js b/edit-mode/function/reportActivity.js index 97baba6..1d0ae69 100644 --- a/edit-mode/function/reportActivity.js +++ b/edit-mode/function/reportActivity.js @@ -418,34 +418,32 @@ $(document).ready(function () { } async function submitRaMaterial(formData, id) { - let qty_actual = $("#volume_pekerjaan_material").val(); - formData.set('qty', qty_actual); - const result = await axiosInstance - .post(`${base_url}report-activity-material/add`, formData) - .then(res => res) - .catch((error) => error.response); - - // console.log("cek result", result); - let reportId = result.data.data.report_id; - let imageFormData = new FormData(); - let image = formData.get("files"); - imageFormData.append("ref_id",reportId); - imageFormData.append("category", "report_activity"); - imageFormData.append("files", image, image.name); - - const resultImage = await axiosInstanceMultipart - .post(`${base_url}image/upload`, imageFormData) - .then(res => res) - .catch((error) => error.response); - - if (result && result.status == 200 && resultImage && resultImage.status == 200) { - gantt.alert("Add report activity material Success!"); - resetFormAddRaMaterial(); - tableRaMaterialActual.draw(); - } else { + try { + const qty_actual = $("#volume_pekerjaan_material").val(); + formData.set('qty', qty_actual); + const result = await axiosInstance + .post(`${base_url}report-activity-material/add`, formData); + + const reportId = result.data.data.report_id; + const image = formData.get("files"); + const imageFormData = new FormData(); + imageFormData.append("ref_id", reportId); + imageFormData.append("category", "report_activity"); + imageFormData.append("files", image, image.name); + + const resultImage = await axiosInstanceMultipart.post(`${base_url}image/upload`, imageFormData); + + if (result.status === 200 && resultImage.status === 200) { + gantt.alert("Add report activity material Success!"); + resetFormAddRaMaterial(); + tableRaMaterialActual.draw(); + } else { + throw new Error("Add report activity material failed."); + } + } catch (error) { resetFormAddRaMaterial(); $("body").removeClass("loading"); - gantt.alert("Add report activity material failed, try again later!"); + gantt.alert("Add report activity material failed."); } } From c97629ec56e21dac0289e438db58495723dfadb0 Mon Sep 17 00:00:00 2001 From: Wahyu Ramadhan Date: Fri, 4 Aug 2023 13:29:07 +0700 Subject: [PATCH 5/6] Update gantt update local storage --- edit-mode/function/function.js | 42 +++++++++-- edit-mode/function/ganttSettings.js | 2 +- edit-mode/function/restActivityLink.js | 100 ++++++++++++------------- edit-mode/index.html | 4 +- 4 files changed, 90 insertions(+), 58 deletions(-) diff --git a/edit-mode/function/function.js b/edit-mode/function/function.js index 7ce02f1..9aee472 100644 --- a/edit-mode/function/function.js +++ b/edit-mode/function/function.js @@ -633,10 +633,6 @@ function expandTask() { gantt.render(); } -function resetActivity() { - localStorage.setItem('batchEntity', ''); - gantt.alert("Actiivity Saved"); -} // Function to get the earliest planned start date among all tasks function getEarliestTaskDate() { var earliestDate = null; @@ -665,4 +661,40 @@ function getLatestTaskDate() { } }); return latestDate; -} \ No newline at end of file +} + +function batchUpdate(){ + let data = localStorage.getItem('batchEntity'); + $("body").addClass("loading"); + return gantt.ajax.post({ + headers: { + "Content-Type": "application/json", + "Authorization": `Bearer ${token}` + }, + url: base_url + "activity/batch-update/" + ganttId, + data: data + }).then(function (response) { + $("body").removeClass("loading"); + localStorage.setItem('batchEntity', ''); + }).catch(function (error) { + $("body").removeClass("loading") + localStorage.setItem('batchEntity', ''); + + gantt.alert({ + title: "Peringatan", + type: "alert-error", + text: "Update activity gagal" + }); + }); +} + +$(window).on('beforeunload', function(event) { + let batchEntity = localStorage.getItem('batchEntity'); + if (batchEntity && batchEntity != '') { + event.preventDefault() + return event.returnValue = 'You have unsaved changes. Are you sure you want to leave this page?'; + } +}); + +const batchEntityData = localStorage.getItem('batchEntity'); +window.parent.postMessage({ batchEntity: batchEntityData }, '*'); \ No newline at end of file diff --git a/edit-mode/function/ganttSettings.js b/edit-mode/function/ganttSettings.js index 061bbc4..77db70c 100644 --- a/edit-mode/function/ganttSettings.js +++ b/edit-mode/function/ganttSettings.js @@ -136,7 +136,7 @@ $(document).ready(function () { }); $("#save-activity").on('click', function (event) { - resetActivity(); + batchUpdate(); }); $("#gantt-synchronize").on('click', function (event) { diff --git a/edit-mode/function/restActivityLink.js b/edit-mode/function/restActivityLink.js index 84d2f05..5fdaff1 100644 --- a/edit-mode/function/restActivityLink.js +++ b/edit-mode/function/restActivityLink.js @@ -182,56 +182,56 @@ var dp = gantt.createDataProcessor(function (entity, action, data, id) { }); } data['geom'] = geom.find(obj => obj.activity_id == id)?.geom; - // let existingEntity = localStorage.getItem('batchEntity'); - // if (existingEntity) { - // existingEntity = JSON.parse(existingEntity); - // // Now batchEntity is an object containing your data, and you can access its properties like batchEntity.entity and batchEntity.data - // } - // let batchEntity = { - // entity: entity, - // data: data - // }; - // let toBeSet = [] - // if (existingEntity) { - // toBeSet = [...existingEntity, batchEntity] - // } else { - // toBeSet = [batchEntity] - // } - // localStorage.setItem('batchEntity', JSON.stringify(toBeSet)); - $("body").addClass("loading"); - return gantt.ajax.put({ - headers: { - "Content-Type": "application/json", - "Authorization": `Bearer ${token}` - }, - url: base_url + entity + "/" + id, - data: JSON.stringify(data) - }).then(function (response) { - $("body").removeClass("loading"); - if (entity == "task") { - let parent = data.parent; - let responseText = JSON.parse(response.responseText) - let resData = responseText - let updateBobot = resData.update_bobot || false - if (updateBobot) { - if (parent && parent > 0) { - updateActivity(parent); - } - } else if (parent && parent > 0) { - updateActivity(parent); - } - if (!parent) { - refresData(); - } - } - }).catch(function (error) { - $("body").removeClass("loading"); - gantt.alert({ - title: "Peringatan", - type: "alert-error", - text: "Update activity gagal" - }); - }); + let existingEntity = localStorage.getItem('batchEntity'); + if (existingEntity) { + existingEntity = JSON.parse(existingEntity); + // Now batchEntity is an object containing your data, and you can access its properties like batchEntity.entity and batchEntity.data + } + let batchEntity = { + entity: entity, + data: data + }; + let toBeSet = [] + if (existingEntity) { + toBeSet = [...existingEntity, batchEntity] + } else { + toBeSet = [batchEntity] + } + localStorage.setItem('batchEntity', JSON.stringify(toBeSet)); + // $("body").addClass("loading"); + // return gantt.ajax.put({ + // headers: { + // "Content-Type": "application/json", + // "Authorization": `Bearer ${token}` + // }, + // url: base_url + entity + "/" + id, + // data: JSON.stringify(data) + // }).then(function (response) { + // $("body").removeClass("loading"); + // if (entity == "task") { + // let parent = data.parent; + // let responseText = JSON.parse(response.responseText) + // let resData = responseText + // let updateBobot = resData.update_bobot || false + // if (updateBobot) { + // if (parent && parent > 0) { + // updateActivity(parent); + // } + // } else if (parent && parent > 0) { + // updateActivity(parent); + // } + // if (!parent) { + // refresData(); + // } + // } + // }).catch(function (error) { + // $("body").removeClass("loading"); + // gantt.alert({ + // title: "Peringatan", + // type: "alert-error", + // text: "Update activity gagal" + // }); + // }); break; case "delete": diff --git a/edit-mode/index.html b/edit-mode/index.html index 5a188e1..dd17be9 100644 --- a/edit-mode/index.html +++ b/edit-mode/index.html @@ -87,9 +87,9 @@ | - + | | From 1cdfcfa2707fa6621e2f0b6015d71fd7db8ff95a Mon Sep 17 00:00:00 2001 From: Wahyu Ramadhan Date: Mon, 7 Aug 2023 11:09:26 +0700 Subject: [PATCH 6/6] Batch update quick fix --- edit-mode/function/function.js | 1 - 1 file changed, 1 deletion(-) diff --git a/edit-mode/function/function.js b/edit-mode/function/function.js index 9aee472..e60d975 100644 --- a/edit-mode/function/function.js +++ b/edit-mode/function/function.js @@ -678,7 +678,6 @@ function batchUpdate(){ localStorage.setItem('batchEntity', ''); }).catch(function (error) { $("body").removeClass("loading") - localStorage.setItem('batchEntity', ''); gantt.alert({ title: "Peringatan",