Browse Source

Fix duration

pull/1/head
Wahyu Ramadhan 1 year ago
parent
commit
778bb9f6d7
  1. 3
      edit-mode/function/ganttConfig.js
  2. 7
      edit-mode/function/ganttEvent.js
  3. 4
      edit-mode/function/restActivityLink.js

3
edit-mode/function/ganttConfig.js

@ -12,6 +12,7 @@ let actionHappen = false;
let activityName = ""; let activityName = "";
let token = getUrlParameter("token"); let token = getUrlParameter("token");
let editDurationTriggered = false; let editDurationTriggered = false;
let editEndDateTriggered = false;
if (!token || token == "") { if (!token || token == "") {
token = `eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwczpcL1wvYXBpLWl1Lm9zcHJvLmlkXC9hcGlcL2xvZ2luIiwiaWF0IjoxNjQ2ODA3OTA4LCJleHAiOjE2NDY4OTQzMDgsIm5iZiI6MTY0NjgwNzkwOCwianRpIjoiNmdtcEx3cjlob1JFZ0hSNSIsInN1YiI6MSwicHJ2IjoiMjNiZDVjODk0OWY2MDBhZGIzOWU3MDFjNDAwODcyZGI3YTU5NzZmNyJ9.1xB2rvTJ6Edf7l_8jRPOmoMYnf8f59Rd8jJghJ39xps`; token = `eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwczpcL1wvYXBpLWl1Lm9zcHJvLmlkXC9hcGlcL2xvZ2luIiwiaWF0IjoxNjQ2ODA3OTA4LCJleHAiOjE2NDY4OTQzMDgsIm5iZiI6MTY0NjgwNzkwOCwianRpIjoiNmdtcEx3cjlob1JFZ0hSNSIsInN1YiI6MSwicHJ2IjoiMjNiZDVjODk0OWY2MDBhZGIzOWU3MDFjNDAwODcyZGI3YTU5NzZmNyJ9.1xB2rvTJ6Edf7l_8jRPOmoMYnf8f59Rd8jJghJ39xps`;
} }
@ -150,6 +151,7 @@ gantt.config.editor_types.end_date = gantt.mixin({
}, },
get_value: function(id, column, node) { get_value: function(id, column, node) {
var selectedValue = dateEditor.get_value.apply(this, [id, column, node]); var selectedValue = dateEditor.get_value.apply(this, [id, column, node]);
editEndDateTriggered = true;
return gantt.date.add(selectedValue, 1, "day"); return gantt.date.add(selectedValue, 1, "day");
}, },
}, dateEditor); }, dateEditor);
@ -158,6 +160,7 @@ gantt.config.editor_types.duration = gantt.mixin({
get_value: function(id, column, node) { get_value: function(id, column, node) {
var old_value = gantt.getTask(id); var old_value = gantt.getTask(id);
var modifiedValue = durationEditor.get_value.apply(this, [id, column, node]); var modifiedValue = durationEditor.get_value.apply(this, [id, column, node]);
editEndDateTriggered = true;
if(old_value.duration == modifiedValue - 1){ if(old_value.duration == modifiedValue - 1){
editDurationTriggered = true; editDurationTriggered = true;
return modifiedValue; return modifiedValue;

7
edit-mode/function/ganttEvent.js

@ -56,21 +56,24 @@ gantt.attachEvent("onBeforeTaskUpdate", function(id,new_item){
let link = task.$target; let link = task.$target;
// link.length > 0 -> successor // link.length > 0 -> successor
new_item['progress'] = progress; new_item['progress'] = progress;
if (editEndDateTriggered) {
new_item['duration'] = new_item['duration'] + (link.length == 0 ? 0 : 1); new_item['duration'] = new_item['duration'] + (link.length == 0 ? 0 : 1);
new_item['end_date'] = gantt.calculateEndDate({ new_item['end_date'] = gantt.calculateEndDate({
start_date: new_item['start_date'], start_date: new_item['start_date'],
duration: new_item['duration'] duration: new_item['duration']
}) })
new_item['end_date'].setHours(23,59,59); new_item['end_date'].setHours(23, 59, 59);
if (editDurationTriggered) { if (editDurationTriggered) {
let tempDuration = new_item['duration'] - 1; let tempDuration = new_item['duration'] - 1;
new_item['end_date'] = gantt.calculateEndDate({ new_item['end_date'] = gantt.calculateEndDate({
start_date: new_item['start_date'], start_date: new_item['start_date'],
duration: tempDuration duration: tempDuration
}) })
new_item['end_date'].setHours(23,59,59); new_item['end_date'].setHours(23, 59, 59);
editDurationTriggered = false; editDurationTriggered = false;
} }
editEndDateTriggered = false;
}
}); });
gantt.attachEvent("onAfterTaskDrag", function(id, mode, e){ gantt.attachEvent("onAfterTaskDrag", function(id, mode, e){

4
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; data['geom'] = geom.find(obj => obj.activity_id == id)?.geom;
return gantt.ajax.put({ return gantt.ajax.put({
headers: { headers: {

Loading…
Cancel
Save