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.

300 lines
11 KiB

let geom = [];
let latest;
let earliest;
let ganttTask;
$("body").addClass("loading");
3 years ago
gantt.ajax.get({
url: `${base_url}activity/${ganttId}/${proyekId}/get`,
headers: {
"Content-Type": "application/json",
"Authorization": `Bearer ${token}`
}
}).then(function (xhr) {
$("body").removeClass("loading");
let batchEntity = localStorage.getItem('batchEntity');
if (!batchEntity || batchEntity == '') {
$("#save-activity").hide();
$("#save-separator").hide();
} else {
$("#save-activity").show();
$("#save-separator").show();
}
3 years ago
let data = {};
1 year ago
let response = xhr.responseText;
3 years ago
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;
}
}
1 year ago
geom = [];
data.data.forEach(element => {
geom.push({
"activity_id": element.id,
"geom": element.geom
})
});
gantt.silent(function () {
// updateLinksLag(data);
ganttTask = data;
gantt.parse(data);
getGanttOpen();
gantt.parse(data);
earliest = getEarliestTaskDate();
latest = getLatestTaskDate();
});
}).catch(function (error) {
$("body").removeClass("loading");
gantt.alert({
title: "Peringatan",
type: "alert-error",
text: "Get activity gagal"
});
3 years ago
});
1 year ago
function refresData(id) {
2 years ago
// Store the current scroll position
var scrollState = {
x: gantt.getScrollState().x,
y: gantt.getScrollState().y
};
$("body").addClass("loading");
3 years ago
gantt.ajax.get({
url: `${base_url}activity/${ganttId}/${proyekId}/get`,
headers: {
"Content-Type": "application/json",
"Authorization": `Bearer ${token}`
}
}).then(function (xhr) {
$("body").removeClass("loading");
let batchEntity = localStorage.getItem('batchEntity');
if (!batchEntity || batchEntity == '') {
$("#save-activity").hide();
$("#save-separator").hide();
} else {
$("#save-activity").show();
$("#save-separator").show();
}
gantt.clearAll();
3 years ago
let data = {};
1 year ago
let response = xhr.responseText;
3 years ago
let obj = JSON.parse(response);
data['data'] = obj.data.data;
data['links'] = obj.data.links;
1 year ago
geom = [];
data.data.forEach(element => {
geom.push({
"activity_id": element.id,
"geom": element.geom
})
});
gantt.silent(function () {
// updateLinksLag(data);
ganttTask = data;
gantt.parse(data);
getGanttOpen();
gantt.parse(data);
earliest = getEarliestTaskDate();
latest = getLatestTaskDate();
});
1 year ago
if (id) {
if (gantt.isTaskExists(id)) {
3 years ago
expandTask();
}
3 years ago
}
2 years ago
// Restore the scroll position
gantt.scrollTo(scrollState.x, scrollState.y);
1 year ago
}).catch(function (error) {
$("body").removeClass("loading");
gantt.alert({
title: "Peringatan",
type: "alert-error",
text: "Update activity gagal"
});
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)
1 year ago
var dp = gantt.createDataProcessor(function (entity, action, data, id) {
switch (action) {
3 years ago
case "create":
1 year ago
if (entity == "task") {
3 years ago
data['proyek_id'] = proyekId;
//TODO : Possible end date bug
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");
1 year ago
data['end_date'] = endDate.format("YYYY-MM-DD") + " 23:59:59+07";
2 years ago
let newDuration = gantt.calculateDuration({
1 year ago
start_date: new Date(data['start_date']),
end_date: new Date(data['end_date'])
2 years ago
})
data['duration'] = newDuration;
3 years ago
1 year ago
if (data && data.parent) {
3 years ago
data['parent_id'] = data.parent;
}
}
data['version_gantt_id'] = ganttId;
$("body").addClass("loading");
3 years ago
return gantt.ajax.post({
headers: {
1 year ago
"Content-Type": "application/json",
"Authorization": `Bearer ${token}`
3 years ago
},
url: base_url + entity,
1 year ago
data: JSON.stringify(data)
}).then(function (response) {
$("body").removeClass("loading");
3 years ago
let res = response.responseText
res = JSON.parse(res)
1 year ago
if (entity == "link") {
3 years ago
gantt.changeLinkId(id, res.tid);
1 year ago
} else if (entity == "task") {
3 years ago
gantt.changeTaskId(id, res.tid);
}
}).catch(function (error) {
$("body").removeClass("loading");
gantt.alert({
title: "Peringatan",
type: "alert-error",
text: "Add activity gagal"
});
3 years ago
});
1 year ago
break;
3 years ago
case "update":
1 year ago
if (entity == "task") {
// 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");
let configStart = moment(gantt.config.start_date);
let configEnd = moment(gantt.config.end_date);
if (startDate >= configEnd || startDate <= configStart || endDate >= configEnd || endDate <= configStart) {
// location.reload();
}
1 year ago
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;
}
1 year ago
if (data && data.parent) {
3 years ago
data['parent_id'] = data.parent;
}
1 year ago
Object.keys(data).forEach(function (key) {
if (data[key] == "") {
data[key] = null;
3 years ago
}
});
}
data['geom'] = geom.find(obj => obj.activity_id == id)?.geom;
let existingEntity = localStorage.getItem('batchEntity');
if (existingEntity) {
existingEntity = JSON.parse(existingEntity);
// Now batchEntity is an object containing your data, and you can access its properties like batchEntity.entity and batchEntity.data
}
let batchEntity = {
entity: entity,
data: data
};
let toBeSet = []
if (existingEntity) {
toBeSet = [...existingEntity, batchEntity]
} else {
toBeSet = [batchEntity]
}
localStorage.setItem('batchEntity', JSON.stringify(toBeSet));
$("#save-activity").show();
$("#save-separator").show();
sendStorage();
// $("body").addClass("loading");
// return gantt.ajax.put({
// headers: {
// "Content-Type": "application/json",
// "Authorization": `Bearer ${token}`
// },
// url: base_url + entity + "/" + id,
// data: JSON.stringify(data)
// }).then(function (response) {
// $("body").removeClass("loading");
// if (entity == "task") {
// let parent = data.parent;
// let responseText = JSON.parse(response.responseText)
// let resData = responseText
// let updateBobot = resData.update_bobot || false
// if (updateBobot) {
// if (parent && parent > 0) {
// updateActivity(parent);
// }
// } else if (parent && parent > 0) {
// updateActivity(parent);
// }
// if (!parent) {
// refresData();
// }
// }
// }).catch(function (error) {
// $("body").removeClass("loading");
// gantt.alert({
// title: "Peringatan",
// type: "alert-error",
// text: "Update activity gagal"
// });
// });
3 years ago
1 year ago
break;
3 years ago
case "delete":
$("body").addClass("loading");
3 years ago
return gantt.ajax.del({
headers: {
1 year ago
"Authorization": `Bearer ${token}`
3 years ago
},
url: base_url + entity + "/" + id
1 year ago
}).then(function (response) {
$("body").removeClass("loading");
1 year ago
if (entity == "task") {
3 years ago
let parent = data.parent;
1 year ago
if (parent && parent > 0) {
3 years ago
let children = gantt.getChildren(parent);
updateActivity(parent);
1 year ago
if (children && children.length > 0) {
3 years ago
1 year ago
} else {
if (gantt.isTaskExists(parent)) {
3 years ago
gantt.getTask(parent).type = "task";
gantt.updateTask(parent);
}
}
}
}
}).catch(function (error) {
$("body").removeClass("loading");
gantt.alert({
title: "Peringatan",
type: "alert-error",
text: "Update activity gagal"
});
3 years ago
});
1 year ago
break;
}
});