You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

169 lines
5.6 KiB

2 years ago
gantt.ajax.get({
url: `${base_url}activity/${ganttId}/${proyekId}/get`,
headers: {
"Content-Type": "application/json",
"Authorization": `Bearer ${token}`
}
}).then(function (xhr) {
let data = {};
let response = xhr.responseText;
let obj = JSON.parse(response);
data['data'] = obj.data.data;
data['links'] = obj.data.links;
// check if baseline has been set
if (data.data && data.data.length > 0) {
if (data.data[0].planned_start !== null && data.data[0].planned_end !== null) {
isBaselineSet = true;
}
else {
isBaselineSet = false;
}
}
gantt.silent(function () {
gantt.parse(data);
});
2 years ago
});
function refresData(id){
2 years ago
console.log("refres triggered!!");
2 years ago
gantt.ajax.get({
url: `${base_url}activity/${ganttId}/${proyekId}/get`,
headers: {
"Content-Type": "application/json",
"Authorization": `Bearer ${token}`
}
}).then(function (xhr) {
gantt.clearAll();
2 years ago
let data = {};
let response = xhr.responseText;
let obj = JSON.parse(response);
data['data'] = obj.data.data;
data['links'] = obj.data.links;
gantt.silent(function () {
gantt.parse(data);
});
2 years ago
if(id){
if(gantt.isTaskExists(id)){
expandTask();
}
2 years ago
}
});
}
// entity - "task"|"link"
// action - "create"|"update"|"delete"
// data - an object with task or link data
// id – the id of a processed object (task or link)
var dp = gantt.createDataProcessor(function(entity, action, data, id) {
2 years ago
switch(action) {
case "create":
if(entity=="task"){
data['proyek_id'] = proyekId;
//TODO : Possible end date bug
2 years ago
data['start_date'] = `${data.start_date}+07`;
let endDate = moment(data.end_date, "YYYY-MM-DD");
data['end_date'] = endDate.format("YYYY-MM-DD")+" 23:59:59+07";
2 years ago
if(data && data.parent){
data['parent_id'] = data.parent;
}
}
data['version_gantt_id'] = ganttId;
2 years ago
data['duration'] += 1;
2 years ago
return gantt.ajax.post({
headers: {
2 years ago
"Content-Type": "application/json",
"Authorization": `Bearer ${token}`
},
url: base_url + entity,
data:JSON.stringify(data)
}).then(function(response){
let res = response.responseText
res = JSON.parse(res)
if(entity=="link"){
gantt.changeLinkId(id, res.tid);
}else if(entity=="task"){
gantt.changeTaskId(id, res.tid);
}
});
break;
case "update":
if(entity=="task"){
2 years ago
// let startDate = moment(data.start_date, "YYYY-MM-DD").subtract(1, "days");
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";
if(startDate > endDate){
gantt.alert({
title:"Peringatan",
type:"alert-error",
text:"Tanggal selesai tidak bisa sebelum tanggal mulai!"
});
data['end_date'] = data['start_date'];
refresData(id);
return;
}
2 years ago
if(data && data.parent){
data['parent_id'] = data.parent;
}
Object.keys(data).forEach(function(key) {
if(data[key]==""){
data[key]=null;
}
});
}
2 years ago
return gantt.ajax.put({
headers: {
2 years ago
"Content-Type": "application/json",
"Authorization": `Bearer ${token}`
},
url: base_url + entity + "/" + id,
data:JSON.stringify(data)
}).then(function(response){
if(entity=="task"){
let parent = data.parent;
let responseText = JSON.parse(response.responseText)
let resData = responseText
let updateBobot = resData.update_bobot || false
if(parent && parent > 0){
updateActivity(parent);
}
2 years ago
if(updateBobot){
refresData(id);
}
}
});
break;
case "delete":
return gantt.ajax.del({
headers: {
2 years ago
"Authorization": `Bearer ${token}`
},
url: base_url + entity + "/" + id
}).then(function(response){
if(entity=="task"){
let parent = data.parent;
if(parent && parent > 0){
let children = gantt.getChildren(parent);
updateActivity(parent);
if(children && children.length > 0){
}else{
if(gantt.isTaskExists(parent)){
gantt.getTask(parent).type = "task";
gantt.updateTask(parent);
}
}
}
}
});
break;
}
});