From c41c8d98ff83037e0d1dd262c9ab64e2090cf2c5 Mon Sep 17 00:00:00 2001 From: Wahyu Ramadhan Date: Thu, 6 Jul 2023 16:42:24 +0700 Subject: [PATCH] Fix duration --- edit-mode/function/ganttConfig.js | 16 ++++++++++++++++ edit-mode/function/ganttEvent.js | 6 +----- edit-mode/function/restActivityLink.js | 25 ++++++------------------- 3 files changed, 23 insertions(+), 24 deletions(-) diff --git a/edit-mode/function/ganttConfig.js b/edit-mode/function/ganttConfig.js index 62268ef..b2a36f5 100644 --- a/edit-mode/function/ganttConfig.js +++ b/edit-mode/function/ganttConfig.js @@ -152,6 +152,13 @@ gantt.config.editor_types.end_date = gantt.mixin({ return gantt.date.add(selectedValue, 1, "day"); }, }, dateEditor); +var durationEditor = gantt.config.editor_types.duration; +gantt.config.editor_types.duration = gantt.mixin({ + get_value: function(id, column, node) { + var modifiedValue = durationEditor.get_value.apply(this, [id, column, node]); + return modifiedValue - 1; + }, +}, durationEditor); const editor = { text: { type: "text", map_to: "text" }, @@ -493,6 +500,15 @@ gantt.templates.task_end_date = function(date){ return gantt.templates.task_date(new Date(date.valueOf() - 1)); }; +var gridDateToStr = gantt.date.date_to_str("%Y-%m-%d"); +gantt.templates.grid_date_format = function(date, column){ + if(column === "end_date"){ + return gridDateToStr(new Date(date.valueOf() - 1)); + }else{ + return gridDateToStr(date); + } + +} gantt.templates.rightside_text = function (start, end, task) { if (task.planned_end) { if (end.getTime() > task.planned_end.getTime()) { diff --git a/edit-mode/function/ganttEvent.js b/edit-mode/function/ganttEvent.js index 6572b34..128f893 100644 --- a/edit-mode/function/ganttEvent.js +++ b/edit-mode/function/ganttEvent.js @@ -54,11 +54,7 @@ gantt.attachEvent("onBeforeTaskUpdate", function(id,new_item){ progress = progress/100; new_item['progress'] = progress; new_item['end_date'].setHours(23,59,59); - let newDuration = gantt.calculateDuration({ - start_date: new_item['start_date'], - end_date: new_item['end_date'] - }) - new_item['duration'] = newDuration; + new_item['duration'] += 1; }); gantt.attachEvent("onAfterTaskDrag", function(id, mode, e){ diff --git a/edit-mode/function/restActivityLink.js b/edit-mode/function/restActivityLink.js index a6a48e0..e81ca72 100644 --- a/edit-mode/function/restActivityLink.js +++ b/edit-mode/function/restActivityLink.js @@ -23,15 +23,6 @@ gantt.ajax.get({ gantt.parse(data); }); if (Date.now() < timestamp) { - expandTask(); - var allTasks = []; - var taskCount = gantt.getTaskCount(); - - for (var i = 0; i < taskCount; i++) { - var task = gantt.getTaskByIndex(i); - allTasks.push(task); - } - gantt.ajax.post({ headers: { "Content-Type": "application/json", @@ -134,12 +125,6 @@ var dp = gantt.createDataProcessor(function(entity, action, data, id) { let startDate = moment(data.start_date, "YYYY-MM-DD"); // data['start_date'] = startDate.format("YYYY-MM-DD")+" 00:00:00+07"; let endDate = moment(data.end_date, "YYYY-MM-DD"); - data['end_date'] = endDate.format("YYYY-MM-DD")+" 23:59:59+07"; - let newDuration = gantt.calculateDuration({ - start_date: new Date(data['start_date']), - end_date: new Date(data['end_date']) - }) - data['duration'] = newDuration; if(startDate > endDate){ gantt.alert({ @@ -176,11 +161,13 @@ var dp = gantt.createDataProcessor(function(entity, action, data, id) { let responseText = JSON.parse(response.responseText) let resData = responseText let updateBobot = resData.update_bobot || false - if(parent && parent > 0){ + if (updateBobot) { + if (parent && parent > 0) { updateActivity(parent); - } - if(updateBobot){ - refresData(id); + } + refresData(id); + } else if (parent && parent > 0) { + updateActivity(parent); } } });