From 778bb9f6d739cf3f6a3e1ea60361bab6cbd4e90f Mon Sep 17 00:00:00 2001 From: Wahyu Ramadhan Date: Tue, 18 Jul 2023 11:14:28 +0700 Subject: [PATCH] Fix duration --- edit-mode/function/ganttConfig.js | 3 +++ edit-mode/function/ganttEvent.js | 31 ++++++++++++++------------ edit-mode/function/restActivityLink.js | 4 ++++ 3 files changed, 24 insertions(+), 14 deletions(-) diff --git a/edit-mode/function/ganttConfig.js b/edit-mode/function/ganttConfig.js index ce7f1d4..97a5cf5 100644 --- a/edit-mode/function/ganttConfig.js +++ b/edit-mode/function/ganttConfig.js @@ -12,6 +12,7 @@ let actionHappen = false; let activityName = ""; let token = getUrlParameter("token"); let editDurationTriggered = false; +let editEndDateTriggered = false; if (!token || token == "") { token = `eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwczpcL1wvYXBpLWl1Lm9zcHJvLmlkXC9hcGlcL2xvZ2luIiwiaWF0IjoxNjQ2ODA3OTA4LCJleHAiOjE2NDY4OTQzMDgsIm5iZiI6MTY0NjgwNzkwOCwianRpIjoiNmdtcEx3cjlob1JFZ0hSNSIsInN1YiI6MSwicHJ2IjoiMjNiZDVjODk0OWY2MDBhZGIzOWU3MDFjNDAwODcyZGI3YTU5NzZmNyJ9.1xB2rvTJ6Edf7l_8jRPOmoMYnf8f59Rd8jJghJ39xps`; } @@ -150,6 +151,7 @@ gantt.config.editor_types.end_date = gantt.mixin({ }, get_value: function(id, column, node) { var selectedValue = dateEditor.get_value.apply(this, [id, column, node]); + editEndDateTriggered = true; return gantt.date.add(selectedValue, 1, "day"); }, }, dateEditor); @@ -158,6 +160,7 @@ gantt.config.editor_types.duration = gantt.mixin({ get_value: function(id, column, node) { var old_value = gantt.getTask(id); var modifiedValue = durationEditor.get_value.apply(this, [id, column, node]); + editEndDateTriggered = true; if(old_value.duration == modifiedValue - 1){ editDurationTriggered = true; return modifiedValue; diff --git a/edit-mode/function/ganttEvent.js b/edit-mode/function/ganttEvent.js index 48d9e9d..4a19431 100644 --- a/edit-mode/function/ganttEvent.js +++ b/edit-mode/function/ganttEvent.js @@ -56,20 +56,23 @@ gantt.attachEvent("onBeforeTaskUpdate", function(id,new_item){ let link = task.$target; // link.length > 0 -> successor new_item['progress'] = progress; - new_item['duration'] = new_item['duration'] + (link.length == 0 ? 0 : 1); - new_item['end_date'] = gantt.calculateEndDate({ - start_date: new_item['start_date'], - duration: new_item['duration'] - }) - new_item['end_date'].setHours(23,59,59); - if (editDurationTriggered) { - let tempDuration = new_item['duration'] - 1; - new_item['end_date'] = gantt.calculateEndDate({ - start_date: new_item['start_date'], - duration: tempDuration - }) - new_item['end_date'].setHours(23,59,59); - editDurationTriggered = false; + if (editEndDateTriggered) { + new_item['duration'] = new_item['duration'] + (link.length == 0 ? 0 : 1); + new_item['end_date'] = gantt.calculateEndDate({ + start_date: new_item['start_date'], + duration: new_item['duration'] + }) + new_item['end_date'].setHours(23, 59, 59); + if (editDurationTriggered) { + let tempDuration = new_item['duration'] - 1; + new_item['end_date'] = gantt.calculateEndDate({ + start_date: new_item['start_date'], + duration: tempDuration + }) + new_item['end_date'].setHours(23, 59, 59); + editDurationTriggered = false; + } + editEndDateTriggered = false; } }); diff --git a/edit-mode/function/restActivityLink.js b/edit-mode/function/restActivityLink.js index 15abacc..eddfb0c 100644 --- a/edit-mode/function/restActivityLink.js +++ b/edit-mode/function/restActivityLink.js @@ -162,6 +162,10 @@ var dp = gantt.createDataProcessor(function(entity, action, data, id) { } }); } + data['duration'] = gantt.calculateDuration({ + start_date: new Date(data['start_date']), + end_date: new Date(data['end_date']) + }); data['geom'] = geom.find(obj => obj.activity_id == id)?.geom; return gantt.ajax.put({ headers: {