Browse Source

Add formatting

pull/1/head
Wahyu Ramadhan 1 year ago
parent
commit
5edb3cdf61
  1. 263
      edit-mode/function/function.js
  2. 66
      edit-mode/function/ganttEvent.js
  3. 184
      edit-mode/function/restActivityLink.js

263
edit-mode/function/function.js

@ -15,23 +15,22 @@ function getUrlParameter(sParam) {
}; };
const formatNumber = (angka) => { const formatNumber = (angka) => {
var number_string = angka.replace(/[^,\d]/g, '').toString(), var number_string = angka.replace(/[^,\d]/g, '').toString(),
split = number_string.split(','), split = number_string.split(','),
sisa = split[0].length % 3, sisa = split[0].length % 3,
rupiah = split[0].substr(0, sisa), rupiah = split[0].substr(0, sisa),
ribuan = split[0].substr(sisa).match(/\d{3}/gi); ribuan = split[0].substr(sisa).match(/\d{3}/gi);
var separator = ""; var separator = "";
if(ribuan){ if (ribuan) {
separator = sisa ? '.' : ''; separator = sisa ? '.' : '';
rupiah += separator + ribuan.join('.'); rupiah += separator + ribuan.join('.');
} }
rupiah = split[1] != undefined ? rupiah + ',' + split[1] : rupiah; rupiah = split[1] != undefined ? rupiah + ',' + split[1] : rupiah;
return rupiah return rupiah
} }
function getCodeLinkByType(type) function getCodeLinkByType(type) {
{
type = parseInt(type); type = parseInt(type);
switch (type) { switch (type) {
case 1: case 1:
@ -49,7 +48,7 @@ function getCodeLinkByType(type)
} }
} }
var getInput = function(node){ var getInput = function (node) {
return node.querySelector("input"); return node.querySelector("input");
}; };
@ -103,7 +102,7 @@ gantt.config.editor_types.progressCustom = {
hide: function () { hide: function () {
}, },
set_value: function (value, id, column, node) { set_value: function (value, id, column, node) {
value = value*100 value = value * 100
getInput(node).value = value; getInput(node).value = value;
}, },
get_value: function (id, column, node) { get_value: function (id, column, node) {
@ -131,12 +130,12 @@ gantt.config.editor_types.progressCustom = {
} }
}; };
function initializationProject(){ function initializationProject() {
let projectId = getUrlParameter("proyek_id"); let projectId = getUrlParameter("proyek_id");
if(projectId && projectId > 0){ if (projectId && projectId > 0) {
$.ajax({ $.ajax({
url: `${base_url}project/edit/${projectId}`, url: `${base_url}project/edit/${projectId}`,
type:"GET", type: "GET",
success: function (result) { success: function (result) {
let data = result.data; let data = result.data;
let projectName = data.nama; let projectName = data.nama;
@ -148,18 +147,18 @@ function initializationProject(){
} }
} }
function getSatuan(){ function getSatuan() {
$.ajax({ $.ajax({
url: `${base_url}satuan/list`, url: `${base_url}satuan/list`,
type:"GET", type: "GET",
success: function (result) { success: function (result) {
let satuanList = []; let satuanList = [];
let resSatuan = result.data || [] let resSatuan = result.data || []
resSatuan.map((val, index) => { resSatuan.map((val, index) => {
let satuan = { let satuan = {
key:val.id, key: val.id,
label:val.name, label: val.name,
text:val.name text: val.name
} }
satuanList.push(satuan) satuanList.push(satuan)
}); });
@ -192,7 +191,7 @@ function getSatuan(){
allowClear: true allowClear: true
}); });
if(satuanList.length > 0){ if (satuanList.length > 0) {
gantt.updateCollection("satuan", satuanList); gantt.updateCollection("satuan", satuanList);
gantt.refreshData(); gantt.refreshData();
gantt.render(); gantt.render();
@ -204,11 +203,10 @@ function getSatuan(){
}); });
} }
function updateActivity(id) function updateActivity(id) {
{
$.ajax({ $.ajax({
url: `${base_url}task/get-update/${id}`, url: `${base_url}task/get-update/${id}`,
type:"GET", type: "GET",
success: function (result) { success: function (result) {
let data = result.data; let data = result.data;
gantt.getTask(id).assign_hr = data.assign_hr; gantt.getTask(id).assign_hr = data.assign_hr;
@ -230,18 +228,17 @@ function updateActivity(id)
/* Fungsi format ribuan label*/ /* Fungsi format ribuan label*/
function formatRupiah(n) { function formatRupiah(n) {
var parts=n.toString().split("."); var parts = n.toString().split(".");
return parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ".") + (parts[1] ? "," + parts[1] : ""); return parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ".") + (parts[1] ? "," + parts[1] : "");
} }
/* Fungsi format ribuan inputan*/ /* Fungsi format ribuan inputan*/
function formatRibuanInput(angka, prefix) function formatRibuanInput(angka, prefix) {
{
var number_string = angka.replace(/[^,\d]/g, '').toString(), var number_string = angka.replace(/[^,\d]/g, '').toString(),
split = number_string.split(','), split = number_string.split(','),
sisa = split[0].length % 3, sisa = split[0].length % 3,
rupiah = split[0].substr(0, sisa), rupiah = split[0].substr(0, sisa),
ribuan = split[0].substr(sisa).match(/\d{3}/gi); ribuan = split[0].substr(sisa).match(/\d{3}/gi);
if (ribuan) { if (ribuan) {
separator = sisa ? '.' : ''; separator = sisa ? '.' : '';
@ -253,13 +250,13 @@ function formatRibuanInput(angka, prefix)
} }
/* Fungsi replace titik, untuk save ke DB*/ /* Fungsi replace titik, untuk save ke DB*/
function formatReplaceTitikRibuan(param){ function formatReplaceTitikRibuan(param) {
let myStr = param; let myStr = param;
let newStr = myStr.replace(/\./g, ''); let newStr = myStr.replace(/\./g, '');
return newStr; return newStr;
} }
function formatDate(params){ function formatDate(params) {
let today = new Date(params); let today = new Date(params);
let yyyy = today.getFullYear(); let yyyy = today.getFullYear();
let mm = today.getMonth() + 1; // Months start at 0! let mm = today.getMonth() + 1; // Months start at 0!
@ -273,55 +270,54 @@ function formatDate(params){
} }
function roundToTwo(num) { function roundToTwo(num) {
return +(Math.round(num + "e+2") + "e-2"); return +(Math.round(num + "e+2") + "e-2");
} }
function initialProperty() function initialProperty() {
{
$.ajax({ $.ajax({
url: `${base_url}user-to-version-gantt/get-by-gantt/${ganttId}`, url: `${base_url}user-to-version-gantt/get-by-gantt/${ganttId}`,
type:"GET", type: "GET",
success: function (result) { success: function (result) {
let data = result.data; let data = result.data;
if(data.status && data.status=="not have"){ if (data.status && data.status == "not have") {
toggleCollapseTasks(); toggleCollapseTasks();
}else{ } else {
if(data.id){ if (data.id) {
userToVersionGanttId = data.id userToVersionGanttId = data.id
} }
if(data.critical_path){ if (data.critical_path) {
gantt.config.highlight_critical_path = true; gantt.config.highlight_critical_path = true;
$("#critalPathBox").prop("checked", true); $("#critalPathBox").prop("checked", true);
} }
if(data.auto_schedule){ if (data.auto_schedule) {
gantt.config.auto_schedule = true; gantt.config.auto_schedule = true;
$("#autoSchedule").prop("checked", true); $("#autoSchedule").prop("checked", true);
} }
if(data.committed_cost){ if (data.committed_cost) {
$("#committedCostBox").val(data.committed_cost); $("#committedCostBox").val(data.committed_cost);
} }
if(data.cost_to_complete){ if (data.cost_to_complete) {
$("#costToCompleteBox").val(data.cost_to_complete); $("#costToCompleteBox").val(data.cost_to_complete);
} }
if(data.zoom){ if (data.zoom) {
gantt.ext.zoom.setLevel(data.zoom); gantt.ext.zoom.setLevel(data.zoom);
$('input[value="'+data.zoom+'"]').prop("checked", true); $('input[value="' + data.zoom + '"]').prop("checked", true);
} }
if(data.task_open){ if (data.task_open) {
gantt.eachTask(function(task){ gantt.eachTask(function (task) {
task.$open = true; task.$open = true;
}); });
toggleTasks = "Collapse"; toggleTasks = "Collapse";
$("#gantt_toggle_task_btn").prop('title', 'Collapse Activities'); $("#gantt_toggle_task_btn").prop('title', 'Collapse Activities');
$("#gantt_toggle_task_btn").children().removeClass('fa-expand-alt'); $("#gantt_toggle_task_btn").children().removeClass('fa-expand-alt');
$("#gantt_toggle_task_btn").children().addClass('fa-compress-alt'); $("#gantt_toggle_task_btn").children().addClass('fa-compress-alt');
}else{ } else {
toggleCollapseTasks(); toggleCollapseTasks();
} }
@ -334,18 +330,17 @@ function initialProperty()
}); });
} }
function initializationColumn() function initializationColumn() {
{
$.ajax({ $.ajax({
url: `${base_url}gantt-show-hide/get-by-gantt/${ganttId}`, url: `${base_url}gantt-show-hide/get-by-gantt/${ganttId}`,
type:"GET", type: "GET",
success: function (result) { success: function (result) {
let data = result.data; let data = result.data;
if(data.status=="not yet have"){ if (data.status == "not yet have") {
addShowHideColumn(); addShowHideColumn();
}else if(data.status=="not have access"){ } else if (data.status == "not have access") {
}else{ } else {
setUpForShowHideColumn(data); setUpForShowHideColumn(data);
} }
}, },
@ -355,8 +350,8 @@ function initializationColumn()
}); });
} }
function setGanttOpen(){ function setGanttOpen() {
let ganttOpen = []; let ganttOpen = [];
gantt.eachTask(function (task) { gantt.eachTask(function (task) {
const existingIndex = ganttOpen.findIndex(item => item.id === task.id); const existingIndex = ganttOpen.findIndex(item => item.id === task.id);
if (existingIndex !== -1) { if (existingIndex !== -1) {
@ -371,73 +366,73 @@ function setGanttOpen(){
localStorage.setItem('ganttOpen', JSON.stringify(ganttOpen)); localStorage.setItem('ganttOpen', JSON.stringify(ganttOpen));
} }
function getGanttOpen(){ function getGanttOpen() {
let ganttOpen = localStorage.getItem('ganttOpen'); let ganttOpen = localStorage.getItem('ganttOpen');
if (ganttOpen) { if (ganttOpen) {
// Parse the stored data into a JavaScript object // Parse the stored data into a JavaScript object
ganttOpen = JSON.parse(ganttOpen); ganttOpen = JSON.parse(ganttOpen);
gantt.eachTask(function (task) { gantt.eachTask(function (task) {
const index = ganttOpen.findIndex(item => item.id == task.id); const index = ganttOpen.findIndex(item => item.id == task.id);
if (index !== -1) { if (index !== -1) {
task.$open = ganttOpen[index].open; task.$open = ganttOpen[index].open;
} else { } else {
task.$open = false; task.$open = false;
} }
}); });
} }
} }
$(document).ready(function () { $(document).ready(function () {
$("#critalPathBox").on("change", function (){ $("#critalPathBox").on("change", function () {
let checked = $(this).is(":checked"); let checked = $(this).is(":checked");
if(checked){ if (checked) {
gantt.config.highlight_critical_path = true; gantt.config.highlight_critical_path = true;
updateProperty({critical_path:true}) updateProperty({ critical_path: true })
}else{ } else {
gantt.config.highlight_critical_path = false; gantt.config.highlight_critical_path = false;
updateProperty({critical_path:false}) updateProperty({ critical_path: false })
} }
gantt.render(); gantt.render();
}); });
$("#autoSchedule").on("change", function (){ $("#autoSchedule").on("change", function () {
let checked = $(this).is(":checked"); let checked = $(this).is(":checked");
if(checked){ if (checked) {
gantt.config.auto_schedule = true; gantt.config.auto_schedule = true;
updateProperty({auto_schedule:true}) updateProperty({ auto_schedule: true })
}else{ } else {
gantt.config.auto_schedule = false; gantt.config.auto_schedule = false;
updateProperty({auto_schedule:false}) updateProperty({ auto_schedule: false })
} }
gantt.render(); gantt.render();
}); });
}); });
function linkLagEditor(){ function linkLagEditor() {
function endPopup(){ function endPopup() {
modal = null; modal = null;
editLinkId = null; editLinkId = null;
} }
function cancelEditLink(){ function cancelEditLink() {
endPopup() endPopup()
} }
function deleteLink(){ function deleteLink() {
gantt.deleteLink(editLinkId); gantt.deleteLink(editLinkId);
endPopup() endPopup()
} }
function saveLink(){ function saveLink() {
var link = gantt.getLink(editLinkId); var link = gantt.getLink(editLinkId);
var lagValue = modal.querySelector(".lag-input").value; var lagValue = modal.querySelector(".lag-input").value;
if(!isNaN(parseInt(lagValue, 10))){ if (!isNaN(parseInt(lagValue, 10))) {
link.lag = parseInt(lagValue, 10); link.lag = parseInt(lagValue, 10);
} }
gantt.updateLink(link.id); gantt.updateLink(link.id);
if(gantt.autoSchedule){ if (gantt.autoSchedule) {
gantt.autoSchedule(link.source); gantt.autoSchedule(link.source);
} }
endPopup(); endPopup();
@ -447,11 +442,11 @@ function linkLagEditor(){
var modal; var modal;
var editLinkId; var editLinkId;
gantt.attachEvent("onLinkDblClick", function(id,e){ gantt.attachEvent("onLinkDblClick", function (id, e) {
editLinkId = id; editLinkId = id;
var link = gantt.getLink(id); var link = gantt.getLink(id);
var linkTitle; var linkTitle;
switch(link.type){ switch (link.type) {
case gantt.config.links.finish_to_start: case gantt.config.links.finish_to_start:
linkTitle = "FS"; linkTitle = "FS";
break; break;
@ -471,17 +466,17 @@ function linkLagEditor(){
modal = gantt.modalbox({ modal = gantt.modalbox({
title: linkTitle, title: linkTitle,
text: "<div>" + text: "<div>" +
"<label>Lag <input type='number' class='lag-input' /></label>" + "<label>Lag <input type='number' class='lag-input' /></label>" +
"</div>", "</div>",
buttons: [ buttons: [
{label:"Save", css:"link-save-btn", value:"save"}, { label: "Save", css: "link-save-btn", value: "save" },
{label:"Cancel", css:"link-cancel-btn", value:"cancel"}, { label: "Cancel", css: "link-cancel-btn", value: "cancel" },
{label:"Delete", css:"link-delete-btn", value:"delete"} { label: "Delete", css: "link-delete-btn", value: "delete" }
], ],
width: "500px", width: "500px",
type: "popup-css-class-here", type: "popup-css-class-here",
callback: function(result){ callback: function (result) {
switch(result){ switch (result) {
case "save": case "save":
saveLink(); saveLink();
break; break;
@ -504,24 +499,22 @@ function linkLagEditor(){
} }
function addShowHideColumn() function addShowHideColumn() {
{
let allColumn = []; let allColumn = [];
allColumns.forEach(function(column){ allColumns.forEach(function (column) {
allColumn.push(column.name); allColumn.push(column.name);
}); });
submitShowHideColumn(allColumn); submitShowHideColumn(allColumn);
} }
function submitShowHideColumn(allColumn) function submitShowHideColumn(allColumn) {
{
let payload = { let payload = {
version_gantt_id:ganttId, version_gantt_id: ganttId,
columns:allColumn columns: allColumn
} }
$.ajax({ $.ajax({
data: JSON.stringify(payload), data: JSON.stringify(payload),
url: `${base_url}gantt-show-hide/add`, url: `${base_url}gantt-show-hide/add`,
type: "POST", type: "POST",
processData: false, processData: false,
@ -535,8 +528,7 @@ function submitShowHideColumn(allColumn)
}); });
} }
function setUpForShowHideColumn(data) function setUpForShowHideColumn(data) {
{
let columns = data || [] let columns = data || []
let configColumn = {} let configColumn = {}
@ -550,14 +542,13 @@ function setUpForShowHideColumn(data)
gantt.render(); gantt.render();
} }
function updateShowHideColumn(data) function updateShowHideColumn(data) {
{
let payload = { let payload = {
columns:data columns: data
} }
$.ajax({ $.ajax({
data: JSON.stringify(payload), data: JSON.stringify(payload),
url: `${base_url}gantt-show-hide/update/${ganttId}`, url: `${base_url}gantt-show-hide/update/${ganttId}`,
type: "POST", type: "POST",
processData: false, processData: false,
@ -582,7 +573,7 @@ function colAjaxReq(type) {
isFound = ganttColumnsByType.find(obj => { isFound = ganttColumnsByType.find(obj => {
return obj.column_name == val.name; return obj.column_name == val.name;
}); });
if(isFound) if (isFound)
return val; return val;
}); });
gantt.config.columns = x.filter(item => item); gantt.config.columns = x.filter(item => item);
@ -592,14 +583,14 @@ function colAjaxReq(type) {
}); });
} }
async function reRenderColumns(type){ async function reRenderColumns(type) {
await colAjaxReq(type); await colAjaxReq(type);
} }
function updateProperty(payload){ function updateProperty(payload) {
if(userToVersionGanttId > 0 && readOnly && parseInt(readOnly)==0){ if (userToVersionGanttId > 0 && readOnly && parseInt(readOnly) == 0) {
$.ajax({ $.ajax({
data: JSON.stringify(payload), data: JSON.stringify(payload),
url: `${base_url}user-to-version-gantt/update/${userToVersionGanttId}`, url: `${base_url}user-to-version-gantt/update/${userToVersionGanttId}`,
type: "PUT", type: "PUT",
processData: false, processData: false,
@ -612,7 +603,7 @@ function updateProperty(payload){
} }
} }
function costPlanningChange(e){ function costPlanningChange(e) {
let value = e.value; let value = e.value;
value = replaceAll(value, ".", "") value = replaceAll(value, ".", "")
value = replaceAll(value, ",", ".") value = replaceAll(value, ",", ".")
@ -625,18 +616,18 @@ function escapeRegExp(string) {
} }
function replaceAll(str, find, replace) { function replaceAll(str, find, replace) {
if(str){ if (str) {
return str.replace(new RegExp(escapeRegExp(find), 'g'), replace); return str.replace(new RegExp(escapeRegExp(find), 'g'), replace);
} }
return str return str
} }
function expandTask(){ function expandTask() {
gantt.eachTask(function(task){ gantt.eachTask(function (task) {
task.$open = true; task.$open = true;
}); });
toggleTasks = "Collapse"; toggleTasks = "Collapse";
$("#gantt_toggle_task_btn").prop('title', 'Collapse Activities'); $("#gantt_toggle_task_btn").prop('title', 'Collapse Activities');
$("#gantt_toggle_task_btn").children().removeClass('fa-expand-alt'); $("#gantt_toggle_task_btn").children().removeClass('fa-expand-alt');
$("#gantt_toggle_task_btn").children().addClass('fa-compress-alt'); $("#gantt_toggle_task_btn").children().addClass('fa-compress-alt');
gantt.render(); gantt.render();
} }

66
edit-mode/function/ganttEvent.js

@ -1,57 +1,57 @@
gantt.attachEvent("onTaskDblClick", function(id,e){ gantt.attachEvent("onTaskDblClick", function (id, e) {
return false; return false;
}); });
gantt.attachEvent("onAfterTaskAdd", function(id,item){ gantt.attachEvent("onAfterTaskAdd", function (id, item) {
if(item.parent && gantt.hasChild()) { if (item.parent && gantt.hasChild()) {
let parentId = item.parent; let parentId = item.parent;
if(gantt.getTask(parentId).parent_id != null){ if (gantt.getTask(parentId).parent_id != null) {
gantt.getTask(parentId).type = "project"; gantt.getTask(parentId).type = "project";
gantt.updateTask(parentId); gantt.updateTask(parentId);
} }
} }
}); });
gantt.attachEvent("onTaskRowClick", function(id,row){ gantt.attachEvent("onTaskRowClick", function (id, row) {
activityId = id; activityId = id;
var activity = gantt.getTaskBy("id", id); var activity = gantt.getTaskBy("id", id);
activityName = activity[0]?.name; activityName = activity[0]?.name;
}); });
gantt.ext.inlineEditors.attachEvent("onBeforeEditStart", function(state){ gantt.ext.inlineEditors.attachEvent("onBeforeEditStart", function (state) {
let id = parseInt(state.id) let id = parseInt(state.id)
let ganttData = gantt.getTask(id); let ganttData = gantt.getTask(id);
if(ganttData?.type_activity=="header"){ if (ganttData?.type_activity == "header") {
return false return false
} }
let column = state.columnName let column = state.columnName
if(column=="progress" || column=="rencana_biaya"){ if (column == "progress" || column == "rencana_biaya") {
let hasChild = gantt.hasChild(id); let hasChild = gantt.hasChild(id);
if(hasChild){ if (hasChild) {
return false return false
} }
} }
if(column=="cost_actual"){ if (column == "cost_actual") {
let progress = ganttData.progress ? ganttData.progress : 0 let progress = ganttData.progress ? ganttData.progress : 0
if(progress <= 0){ if (progress <= 0) {
return false return false
} }
} }
return true return true
}); });
gantt.attachEvent("onBeforeTaskUpdate", function(id,new_item){ gantt.attachEvent("onBeforeTaskUpdate", function (id, new_item) {
// format progress // format progress
let progress = new_item.progress; let progress = new_item.progress;
if(progress > 100){ if (progress > 100) {
progress = 100; progress = 100;
}else if(progress <= 0){ } else if (progress <= 0) {
progress = 0; progress = 0;
}else if(progress <= 1 && progress > 0){ } else if (progress <= 1 && progress > 0) {
progress = progress*100 progress = progress * 100
} }
progress = progress/100; progress = progress / 100;
let task = gantt.getTask(id); let task = gantt.getTask(id);
let link = task.$target; let link = task.$target;
// link.length > 0 -> successor // link.length > 0 -> successor
@ -76,44 +76,44 @@ gantt.attachEvent("onBeforeTaskUpdate", function(id,new_item){
} }
}); });
gantt.attachEvent("onAfterTaskDrag", function(id, mode, e){ gantt.attachEvent("onAfterTaskDrag", function (id, mode, e) {
var task = gantt.getTask(id); var task = gantt.getTask(id);
task.end_date = gantt.calculateEndDate(task); task.end_date = gantt.calculateEndDate(task);
gantt.updateTask(id); gantt.updateTask(id);
}); });
gantt.attachEvent("onBeforeLinkAdd", function(id,link){ gantt.attachEvent("onBeforeLinkAdd", function (id, link) {
//any custom logic here //any custom logic here
let source = link.source; let source = link.source;
let target = link.target; let target = link.target;
let parents = gantt.getParent(source); let parents = gantt.getParent(source);
let parentt = gantt.getParent(target); let parentt = gantt.getParent(target);
let childt = gantt.hasChild(target); let childt = gantt.hasChild(target);
if(childt){ if (childt) {
return false; return false;
} }
if(parents==target){ if (parents == target) {
return false; return false;
} }
if(parentt==source){ if (parentt == source) {
return false return false
} }
return true; return true;
}); });
gantt.attachEvent("onGanttReady", function(){ gantt.attachEvent("onGanttReady", function () {
}); });
gantt.attachEvent("onGanttRender", function(){ gantt.attachEvent("onGanttRender", function () {
if(readOnly && parseInt(readOnly)==1){ if (readOnly && parseInt(readOnly) == 1) {
gantt.config.readonly = true; gantt.config.readonly = true;
}else if(readOnly && parseInt(readOnly)==0){ } else if (readOnly && parseInt(readOnly) == 0) {
gantt.config.readonly = false; gantt.config.readonly = false;
}else{ } else {
gantt.config.readonly = true; gantt.config.readonly = true;
} }
}); });

184
edit-mode/function/restActivityLink.js

@ -7,7 +7,7 @@ gantt.ajax.get({
} }
}).then(function (xhr) { }).then(function (xhr) {
let data = {}; let data = {};
let response = xhr.responseText; let response = xhr.responseText;
let obj = JSON.parse(response); let obj = JSON.parse(response);
data['data'] = obj.data.data; data['data'] = obj.data.data;
data['links'] = obj.data.links; data['links'] = obj.data.links;
@ -20,38 +20,38 @@ gantt.ajax.get({
isBaselineSet = false; isBaselineSet = false;
} }
} }
geom = []; geom = [];
data.data.forEach(element => { data.data.forEach(element => {
geom.push({ geom.push({
"activity_id": element.id, "activity_id": element.id,
"geom": element.geom "geom": element.geom
}) })
}); });
gantt.silent(function () { gantt.silent(function () {
gantt.parse(data); gantt.parse(data);
getGanttOpen(); getGanttOpen();
}); });
if (Date.now() < timestamp) { if (Date.now() < timestamp) {
gantt.ajax.post({ gantt.ajax.post({
headers: { headers: {
"Content-Type": "application/json", "Content-Type": "application/json",
"Authorization": `Bearer ${token}` "Authorization": `Bearer ${token}`
}, },
url: `${base_url}activity/import-update`, url: `${base_url}activity/import-update`,
dataType: "json", dataType: "json",
data: JSON.stringify(allTasks) data: JSON.stringify(allTasks)
}).then(function(response){ }).then(function (response) {
let res = response.responseText let res = response.responseText
res = JSON.parse(res) res = JSON.parse(res)
if (res) { if (res) {
refresData(); refresData();
} }
}); });
} }
}); });
function refresData(id){ function refresData(id) {
console.log("refres triggered!!"); console.log("refres triggered!!");
// Store the current scroll position // Store the current scroll position
var scrollState = { var scrollState = {
@ -68,30 +68,30 @@ function refresData(id){
}).then(function (xhr) { }).then(function (xhr) {
gantt.clearAll(); gantt.clearAll();
let data = {}; let data = {};
let response = xhr.responseText; let response = xhr.responseText;
let obj = JSON.parse(response); let obj = JSON.parse(response);
data['data'] = obj.data.data; data['data'] = obj.data.data;
data['links'] = obj.data.links; data['links'] = obj.data.links;
geom = []; geom = [];
data.data.forEach(element => { data.data.forEach(element => {
geom.push({ geom.push({
"activity_id": element.id, "activity_id": element.id,
"geom": element.geom "geom": element.geom
}) })
}); });
gantt.silent(function () { gantt.silent(function () {
gantt.parse(data); gantt.parse(data);
getGanttOpen(); getGanttOpen();
}); });
if(id){ if (id) {
if(gantt.isTaskExists(id)){ if (gantt.isTaskExists(id)) {
expandTask(); expandTask();
} }
} }
// Restore the scroll position // Restore the scroll position
gantt.scrollTo(scrollState.x, scrollState.y); gantt.scrollTo(scrollState.x, scrollState.y);
}); });
} }
@ -99,68 +99,68 @@ function refresData(id){
// action - "create"|"update"|"delete" // action - "create"|"update"|"delete"
// data - an object with task or link data // data - an object with task or link data
// id – the id of a processed object (task or link) // id – the id of a processed object (task or link)
var dp = gantt.createDataProcessor(function(entity, action, data, id) { var dp = gantt.createDataProcessor(function (entity, action, data, id) {
switch(action) { switch (action) {
case "create": case "create":
if(entity=="task"){ if (entity == "task") {
data['proyek_id'] = proyekId; data['proyek_id'] = proyekId;
//TODO : Possible end date bug //TODO : Possible end date bug
data['start_date'] = `${data.start_date}+07`; data['start_date'] = `${data.start_date}+07`;
let endDate = moment(data.end_date, "YYYY-MM-DD"); let endDate = moment(data.end_date, "YYYY-MM-DD");
data['end_date'] = endDate.format("YYYY-MM-DD")+" 23:59:59+07"; data['end_date'] = endDate.format("YYYY-MM-DD") + " 23:59:59+07";
let newDuration = gantt.calculateDuration({ let newDuration = gantt.calculateDuration({
start_date: new Date(data['start_date']), start_date: new Date(data['start_date']),
end_date: new Date(data['end_date']) end_date: new Date(data['end_date'])
}) })
data['duration'] = newDuration; data['duration'] = newDuration;
if(data && data.parent){ if (data && data.parent) {
data['parent_id'] = data.parent; data['parent_id'] = data.parent;
} }
} }
data['version_gantt_id'] = ganttId; data['version_gantt_id'] = ganttId;
return gantt.ajax.post({ return gantt.ajax.post({
headers: { headers: {
"Content-Type": "application/json", "Content-Type": "application/json",
"Authorization": `Bearer ${token}` "Authorization": `Bearer ${token}`
}, },
url: base_url + entity, url: base_url + entity,
data:JSON.stringify(data) data: JSON.stringify(data)
}).then(function(response){ }).then(function (response) {
let res = response.responseText let res = response.responseText
res = JSON.parse(res) res = JSON.parse(res)
if(entity=="link"){ if (entity == "link") {
gantt.changeLinkId(id, res.tid); gantt.changeLinkId(id, res.tid);
}else if(entity=="task"){ } else if (entity == "task") {
gantt.changeTaskId(id, res.tid); gantt.changeTaskId(id, res.tid);
} }
}); });
break; break;
case "update": case "update":
if(entity=="task"){ if (entity == "task") {
// let startDate = moment(data.start_date, "YYYY-MM-DD").subtract(1, "days"); // let startDate = moment(data.start_date, "YYYY-MM-DD").subtract(1, "days");
let startDate = moment(data.start_date, "YYYY-MM-DD"); let startDate = moment(data.start_date, "YYYY-MM-DD");
// data['start_date'] = startDate.format("YYYY-MM-DD")+" 00:00:00+07"; // data['start_date'] = startDate.format("YYYY-MM-DD")+" 00:00:00+07";
let endDate = moment(data.end_date, "YYYY-MM-DD"); let endDate = moment(data.end_date, "YYYY-MM-DD");
if(startDate > endDate){ if (startDate > endDate) {
gantt.alert({ gantt.alert({
title:"Peringatan", title: "Peringatan",
type:"alert-error", type: "alert-error",
text:"Tanggal selesai tidak bisa sebelum tanggal mulai!" text: "Tanggal selesai tidak bisa sebelum tanggal mulai!"
}); });
data['end_date'] = data['start_date']; data['end_date'] = data['start_date'];
refresData(id); refresData(id);
return; return;
} }
if(data && data.parent){ if (data && data.parent) {
data['parent_id'] = data.parent; data['parent_id'] = data.parent;
} }
Object.keys(data).forEach(function(key) { Object.keys(data).forEach(function (key) {
if(data[key]==""){ if (data[key] == "") {
data[key]=null; data[key] = null;
} }
}); });
} }
@ -170,50 +170,50 @@ var dp = gantt.createDataProcessor(function(entity, action, data, id) {
data['duration'] = gantt.calculateDuration({ data['duration'] = gantt.calculateDuration({
start_date: newStart, start_date: newStart,
end_date: newEnd end_date: newEnd
}); });
} }
data['geom'] = geom.find(obj => obj.activity_id == id)?.geom; data['geom'] = geom.find(obj => obj.activity_id == id)?.geom;
return gantt.ajax.put({ return gantt.ajax.put({
headers: { headers: {
"Content-Type": "application/json", "Content-Type": "application/json",
"Authorization": `Bearer ${token}` "Authorization": `Bearer ${token}`
}, },
url: base_url + entity + "/" + id, url: base_url + entity + "/" + id,
data:JSON.stringify(data) data: JSON.stringify(data)
}).then(function(response){ }).then(function (response) {
if(entity=="task"){ if (entity == "task") {
let parent = data.parent; let parent = data.parent;
let responseText = JSON.parse(response.responseText) let responseText = JSON.parse(response.responseText)
let resData = responseText let resData = responseText
let updateBobot = resData.update_bobot || false let updateBobot = resData.update_bobot || false
if (updateBobot) { if (updateBobot) {
if (parent && parent > 0) { if (parent && parent > 0) {
updateActivity(parent); updateActivity(parent);
} }
refresData(id); refresData(id);
} else if (parent && parent > 0) { } else if (parent && parent > 0) {
updateActivity(parent); updateActivity(parent);
} }
} }
}); });
break; break;
case "delete": case "delete":
return gantt.ajax.del({ return gantt.ajax.del({
headers: { headers: {
"Authorization": `Bearer ${token}` "Authorization": `Bearer ${token}`
}, },
url: base_url + entity + "/" + id url: base_url + entity + "/" + id
}).then(function(response){ }).then(function (response) {
if(entity=="task"){ if (entity == "task") {
let parent = data.parent; let parent = data.parent;
if(parent && parent > 0){ if (parent && parent > 0) {
let children = gantt.getChildren(parent); let children = gantt.getChildren(parent);
updateActivity(parent); updateActivity(parent);
if(children && children.length > 0){ if (children && children.length > 0) {
}else{ } else {
if(gantt.isTaskExists(parent)){ if (gantt.isTaskExists(parent)) {
gantt.getTask(parent).type = "task"; gantt.getTask(parent).type = "task";
gantt.updateTask(parent); gantt.updateTask(parent);
} }
@ -221,6 +221,6 @@ var dp = gantt.createDataProcessor(function(entity, action, data, id) {
} }
} }
}); });
break; break;
} }
}); });

Loading…
Cancel
Save