Browse Source

Update gantt update local storage

pull/1/head
Wahyu Ramadhan 1 year ago
parent
commit
c97629ec56
  1. 40
      edit-mode/function/function.js
  2. 2
      edit-mode/function/ganttSettings.js
  3. 100
      edit-mode/function/restActivityLink.js
  4. 4
      edit-mode/index.html

40
edit-mode/function/function.js

@ -633,10 +633,6 @@ function expandTask() {
gantt.render();
}
function resetActivity() {
localStorage.setItem('batchEntity', '');
gantt.alert("Actiivity Saved");
}
// Function to get the earliest planned start date among all tasks
function getEarliestTaskDate() {
var earliestDate = null;
@ -666,3 +662,39 @@ function getLatestTaskDate() {
});
return latestDate;
}
function batchUpdate(){
let data = localStorage.getItem('batchEntity');
$("body").addClass("loading");
return gantt.ajax.post({
headers: {
"Content-Type": "application/json",
"Authorization": `Bearer ${token}`
},
url: base_url + "activity/batch-update/" + ganttId,
data: data
}).then(function (response) {
$("body").removeClass("loading");
localStorage.setItem('batchEntity', '');
}).catch(function (error) {
$("body").removeClass("loading")
localStorage.setItem('batchEntity', '');
gantt.alert({
title: "Peringatan",
type: "alert-error",
text: "Update activity gagal"
});
});
}
$(window).on('beforeunload', function(event) {
let batchEntity = localStorage.getItem('batchEntity');
if (batchEntity && batchEntity != '') {
event.preventDefault()
return event.returnValue = 'You have unsaved changes. Are you sure you want to leave this page?';
}
});
const batchEntityData = localStorage.getItem('batchEntity');
window.parent.postMessage({ batchEntity: batchEntityData }, '*');

2
edit-mode/function/ganttSettings.js

@ -136,7 +136,7 @@ $(document).ready(function () {
});
$("#save-activity").on('click', function (event) {
resetActivity();
batchUpdate();
});
$("#gantt-synchronize").on('click', function (event) {

100
edit-mode/function/restActivityLink.js

@ -182,56 +182,56 @@ var dp = gantt.createDataProcessor(function (entity, action, data, id) {
});
}
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"
});
});
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":

4
edit-mode/index.html

@ -87,9 +87,9 @@
<button title="Dashboard Project" class="btn btn-sm btn-icon-toolbar" id="dashboard-project"><i
class="fa fa-chart-line icon-toolbar"></i></button>
<span class="icon-toolbar-separator">|</span>
<!-- <button title="Save" class="btn btn-sm btn-icon-toolbar" id="save-activity"><i
<button title="Save" class="btn btn-sm btn-icon-toolbar" id="save-activity"><i
class="fa fa-save icon-toolbar"></i></button>
<span class="icon-toolbar-separator">|</span> -->
<span class="icon-toolbar-separator">|</span>
<button title="Synchronize to Report Activity" class="btn btn-sm btn-icon-toolbar" id="gantt-synchronize"><i
class="fa fa-sync icon-toolbar"></i></button>
<span class="icon-toolbar-separator">|</span>

Loading…
Cancel
Save