let geom = []; let latest; let earliest; $("body").addClass("loading"); 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 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; } } geom = []; data.data.forEach(element => { geom.push({ "activity_id": element.id, "geom": element.geom }) }); gantt.silent(function () { 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" }); }); function refresData(id) { console.log("refres triggered!!"); // Store the current scroll position var scrollState = { x: gantt.getScrollState().x, y: gantt.getScrollState().y }; $("body").addClass("loading"); gantt.ajax.get({ url: `${base_url}activity/${ganttId}/${proyekId}/get`, headers: { "Content-Type": "application/json", "Authorization": `Bearer ${token}` } }).then(function (xhr) { $("body").removeClass("loading"); gantt.clearAll(); let data = {}; let response = xhr.responseText; let obj = JSON.parse(response); data['data'] = obj.data.data; data['links'] = obj.data.links; geom = []; data.data.forEach(element => { geom.push({ "activity_id": element.id, "geom": element.geom }) }); gantt.silent(function () { gantt.parse(data); getGanttOpen(); gantt.parse(data); earliest = getEarliestTaskDate(); latest = getLatestTaskDate(); }); if (id) { if (gantt.isTaskExists(id)) { expandTask(); } } // Restore the scroll position gantt.scrollTo(scrollState.x, scrollState.y); }).catch(function (error) { $("body").removeClass("loading"); gantt.alert({ title: "Peringatan", type: "alert-error", text: "Update activity gagal" }); }); } // 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) { switch (action) { case "create": if (entity == "task") { data['proyek_id'] = proyekId; //TODO : Possible end date bug 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"; let newDuration = gantt.calculateDuration({ start_date: new Date(data['start_date']), end_date: new Date(data['end_date']) }) data['duration'] = newDuration; if (data && data.parent) { data['parent_id'] = data.parent; } } data['version_gantt_id'] = ganttId; $("body").addClass("loading"); return gantt.ajax.post({ headers: { "Content-Type": "application/json", "Authorization": `Bearer ${token}` }, url: base_url + entity, data: JSON.stringify(data) }).then(function (response) { $("body").removeClass("loading"); 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); } }).catch(function (error) { $("body").removeClass("loading"); gantt.alert({ title: "Peringatan", type: "alert-error", text: "Add activity gagal" }); }); break; case "update": 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"); 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; } if (data && data.parent) { data['parent_id'] = data.parent; } Object.keys(data).forEach(function (key) { if (data[key] == "") { data[key] = null; } }); } 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)); $("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" }); }); break; case "delete": $("body").addClass("loading"); return gantt.ajax.del({ headers: { "Authorization": `Bearer ${token}` }, url: base_url + entity + "/" + id }).then(function (response) { $("body").removeClass("loading"); 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); } } } } }).catch(function (error) { $("body").removeClass("loading"); gantt.alert({ title: "Peringatan", type: "alert-error", text: "Update activity gagal" }); }); break; } });