Browse Source

Fix edit duration on holiday

pull/1/head
Wahyu Ramadhan 1 year ago
parent
commit
879a93b896
  1. 10
      edit-mode/function/ganttConfig.js
  2. 30
      edit-mode/function/ganttEvent.js

10
edit-mode/function/ganttConfig.js

@ -11,8 +11,8 @@ let activityId = 0;
let actionHappen = false; let actionHappen = false;
let activityName = ""; let activityName = "";
let token = getUrlParameter("token"); let token = getUrlParameter("token");
let editDurationTriggered = false; let forceDurationUpdateTriggered = false;
let editEndDateTriggered = false; let editEndDateDurationTriggered = false;
if (!token || token == "") { if (!token || token == "") {
token = `eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwczpcL1wvYXBpLWl1Lm9zcHJvLmlkXC9hcGlcL2xvZ2luIiwiaWF0IjoxNjQ2ODA3OTA4LCJleHAiOjE2NDY4OTQzMDgsIm5iZiI6MTY0NjgwNzkwOCwianRpIjoiNmdtcEx3cjlob1JFZ0hSNSIsInN1YiI6MSwicHJ2IjoiMjNiZDVjODk0OWY2MDBhZGIzOWU3MDFjNDAwODcyZGI3YTU5NzZmNyJ9.1xB2rvTJ6Edf7l_8jRPOmoMYnf8f59Rd8jJghJ39xps`; token = `eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwczpcL1wvYXBpLWl1Lm9zcHJvLmlkXC9hcGlcL2xvZ2luIiwiaWF0IjoxNjQ2ODA3OTA4LCJleHAiOjE2NDY4OTQzMDgsIm5iZiI6MTY0NjgwNzkwOCwianRpIjoiNmdtcEx3cjlob1JFZ0hSNSIsInN1YiI6MSwicHJ2IjoiMjNiZDVjODk0OWY2MDBhZGIzOWU3MDFjNDAwODcyZGI3YTU5NzZmNyJ9.1xB2rvTJ6Edf7l_8jRPOmoMYnf8f59Rd8jJghJ39xps`;
} }
@ -145,7 +145,7 @@ var dateEditor = gantt.config.editor_types.date;
gantt.config.editor_types.end_date = gantt.mixin({ 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; editEndDateDurationTriggered = true;
return selectedValue; return selectedValue;
}, },
}, dateEditor); }, dateEditor);
@ -154,9 +154,9 @@ 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; editEndDateDurationTriggered = true;
if (old_value.duration == modifiedValue - 1) { if (old_value.duration == modifiedValue - 1) {
editDurationTriggered = true; forceDurationUpdateTriggered = true;
return modifiedValue; return modifiedValue;
} }
return modifiedValue - 1; return modifiedValue - 1;

30
edit-mode/function/ganttEvent.js

@ -56,23 +56,45 @@ 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) { if (editEndDateDurationTriggered) {
if(link.length == 0){
new_item['start_date'].setHours(0,0,0);
}
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 (forceDurationUpdateTriggered) {
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;
} }
editEndDateTriggered = false;
const dateToCheck = new Date(new_item['end_date']);
if (gantt.isWorkTime({ date: dateToCheck, hours: false })) {
} else {
if (link.length == 0) {
let duration = gantt.calculateDuration({
start_date: new_item['start_date'],
end_date: new_item['end_date']
})
let endDate = gantt.calculateEndDate({
start_date: new_item['start_date'],
duration: duration + 1
})
endDate.setDate(endDate.getDate() - 1)
endDate.setHours(23,59,59);
new_item['end_date'] = endDate
}
}
forceDurationUpdateTriggered = false;
editEndDateDurationTriggered = false;
} }
}); });

Loading…
Cancel
Save