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.
187 lines
6.9 KiB
187 lines
6.9 KiB
3 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;
|
||
|
// console.log("data parse wrong", data);
|
||
|
// check if baseline has been set
|
||
|
if (data.data && data.data.length > 0) {
|
||
|
console.log('baseline', data.data[0].planned_start);
|
||
|
if (data.data[0].planned_start !== null && data.data[0].planned_end !== null) {
|
||
|
console.log('baseline set');
|
||
|
isBaselineSet = true;
|
||
|
}
|
||
|
else {
|
||
|
console.log('baseline has not been set');
|
||
|
isBaselineSet = false;
|
||
|
}
|
||
|
}
|
||
2 years ago
|
gantt.silent(function () {
|
||
|
gantt.parse(data);
|
||
|
});
|
||
3 years ago
|
});
|
||
|
|
||
|
function refresData(id){
|
||
|
gantt.ajax.get({
|
||
|
url: `${base_url}activity/${ganttId}/${proyekId}/get`,
|
||
|
headers: {
|
||
|
"Content-Type": "application/json",
|
||
|
"Authorization": `Bearer ${token}`
|
||
|
}
|
||
|
}).then(function (xhr) {
|
||
2 years ago
|
gantt.clearAll();
|
||
3 years ago
|
let data = {};
|
||
|
let response = xhr.responseText;
|
||
|
let obj = JSON.parse(response);
|
||
|
data['data'] = obj.data.data;
|
||
|
data['links'] = obj.data.links;
|
||
|
// console.log("data parse wrong", data);
|
||
2 years ago
|
gantt.silent(function () {
|
||
|
gantt.parse(data);
|
||
|
});
|
||
3 years ago
|
if(id){
|
||
|
if(gantt.isTaskExists(id)){
|
||
|
expandTask();
|
||
2 years ago
|
}
|
||
3 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)
|
||
2 years ago
|
var dp = gantt.createDataProcessor(function(entity, action, data, id) {
|
||
3 years ago
|
switch(action) {
|
||
|
case "create":
|
||
2 years ago
|
|
||
3 years ago
|
if(entity=="task"){
|
||
|
data['proyek_id'] = proyekId;
|
||
|
data['start_date'] = `${data.start_date}+07`;
|
||
|
data['end_date'] = `${data.start_date}`;
|
||
|
// data['start_date'] = moment(data.start_date).format("DD-MM-YYYY HH:mm:ss+07");
|
||
|
// data['end_date'] = moment(data.end_date).format("DD-MM-YYYY HH:mm:ss+07");
|
||
|
|
||
|
if(data && data.parent){
|
||
|
data['parent_id'] = data.parent;
|
||
|
}
|
||
|
}
|
||
|
data['version_gantt_id'] = ganttId;
|
||
|
return gantt.ajax.post({
|
||
2 years ago
|
headers: {
|
||
3 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)
|
||
|
// console.log("cek response", res)
|
||
|
if(entity=="link"){
|
||
|
gantt.changeLinkId(id, res.tid);
|
||
|
}else if(entity=="task"){
|
||
|
gantt.changeTaskId(id, res.tid);
|
||
|
}
|
||
|
// refresData();
|
||
|
});
|
||
|
break;
|
||
|
case "update":
|
||
|
if(entity=="task"){
|
||
|
data['start_date'] = moment(data.start_date).format("YYYY-MM-DD HH:mm:ss+07");
|
||
|
data['end_date'] = moment(data.end_date).format("YYYY-MM-DD HH:mm:ss+07");
|
||
|
// data['planned_start'] = moment(data.planned_start).format("YYYY-MM-DD HH:mm:ss+07");
|
||
|
// data['planned_end'] = moment(data.planned_end).format("YYYY-MM-DD HH:mm:ss+07");
|
||
2 years ago
|
|
||
3 years ago
|
if(data && data.parent){
|
||
|
data['parent_id'] = data.parent;
|
||
|
}
|
||
|
|
||
|
Object.keys(data).forEach(function(key) {
|
||
|
if(data[key]==""){
|
||
|
data[key]=null;
|
||
|
}
|
||
|
});
|
||
|
}
|
||
|
// console.log("cek data update", data)
|
||
|
// let dataProgress = parseInt(data.progress)
|
||
|
// dataProgress = dataProgress/100
|
||
|
return gantt.ajax.put({
|
||
2 years ago
|
headers: {
|
||
3 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
|
||
|
// console.log("dataRes", resData);
|
||
|
let updateBobot = resData.update_bobot || false
|
||
|
if(updateBobot){
|
||
|
refresData(id);
|
||
|
}else{
|
||
|
if(parent && parent > 0){
|
||
|
updateActivity(parent);
|
||
|
}
|
||
|
}
|
||
|
// console.log("data", data);
|
||
|
// refresData();
|
||
|
// if(resData && resData.rencana_biaya){
|
||
|
// if(data.rencana_biaya != resData.rencana_biaya){
|
||
|
// // gantt.getTask(id).bobot_planning = resData.bobot_planning;
|
||
|
// // gantt.updateTask(id);
|
||
2 years ago
|
|
||
3 years ago
|
// }else{
|
||
|
// if(parent && parent > 0){
|
||
|
// updateActivity(parent);
|
||
|
// }
|
||
|
// }
|
||
|
// }
|
||
|
}
|
||
|
});
|
||
|
|
||
|
break;
|
||
|
case "delete":
|
||
|
// console.log("cek data", data)
|
||
|
return gantt.ajax.del({
|
||
2 years ago
|
headers: {
|
||
3 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);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
// console.log("cek data delete", data)
|
||
|
}
|
||
|
// let res = response.responseText
|
||
|
// res = JSON.parse(res)
|
||
|
// console.log("cek response", res)
|
||
2 years ago
|
|
||
3 years ago
|
// refresData();
|
||
|
});
|
||
|
break;
|
||
|
}
|
||
2 years ago
|
});
|