Browse Source

Gantt update optimization

pull/1/head
Wahyu Ramadhan 1 year ago
parent
commit
b7ec2cac2d
  1. 5
      edit-mode/function/function.js
  2. 9
      edit-mode/function/ganttEvent.js
  3. 5
      edit-mode/function/ganttSettings.js
  4. 44
      edit-mode/function/restActivityLink.js
  5. 3
      edit-mode/index.html

5
edit-mode/function/function.js

@ -631,3 +631,8 @@ function expandTask() {
$("#gantt_toggle_task_btn").children().addClass('fa-compress-alt'); $("#gantt_toggle_task_btn").children().addClass('fa-compress-alt');
gantt.render(); gantt.render();
} }
function resetActivity() {
localStorage.setItem('batchEntity', '');
gantt.alert("Actiivity Saved");
}

9
edit-mode/function/ganttEvent.js

@ -92,7 +92,14 @@ gantt.attachEvent("onBeforeTaskUpdate", function (id, new_item) {
new_item['end_date'] = endDate new_item['end_date'] = endDate
} }
} }
let newStart = new Date(new_item['start_date']);
let newEnd = new Date(new_item['end_date']);
if (new_item['start_date'] && new_item['end_date']) {
new_item['duration'] = gantt.calculateDuration({
start_date: newStart,
end_date: newEnd
});
}
forceDurationUpdateTriggered = false; forceDurationUpdateTriggered = false;
editEndDateDurationTriggered = false; editEndDateDurationTriggered = false;
} }

5
edit-mode/function/ganttSettings.js

@ -135,6 +135,10 @@ $(document).ready(function() {
setBaseline(); setBaseline();
}); });
$("#save-activity").on('click', function(event) {
resetActivity();
});
$("#gantt-synchronize").on('click', function(event) { $("#gantt-synchronize").on('click', function(event) {
setSynchronize(); setSynchronize();
}); });
@ -251,6 +255,7 @@ function toggleCollapseTasks() {
$("#gantt_toggle_task_btn").children().addClass('fa-expand-alt'); // change icon to expand $("#gantt_toggle_task_btn").children().addClass('fa-expand-alt'); // change icon to expand
} }
gantt.render(); gantt.render();
setGanttOpen();
} }

44
edit-mode/function/restActivityLink.js

@ -58,7 +58,7 @@ function refresData(id) {
x: gantt.getScrollState().x, x: gantt.getScrollState().x,
y: gantt.getScrollState().y y: gantt.getScrollState().y
}; };
$("body").addClass("loading");
gantt.ajax.get({ gantt.ajax.get({
url: `${base_url}activity/${ganttId}/${proyekId}/get`, url: `${base_url}activity/${ganttId}/${proyekId}/get`,
headers: { headers: {
@ -66,6 +66,7 @@ function refresData(id) {
"Authorization": `Bearer ${token}` "Authorization": `Bearer ${token}`
} }
}).then(function (xhr) { }).then(function (xhr) {
$("body").removeClass("loading");
gantt.clearAll(); gantt.clearAll();
let data = {}; let data = {};
let response = xhr.responseText; let response = xhr.responseText;
@ -92,6 +93,13 @@ function refresData(id) {
// Restore the scroll position // Restore the scroll position
gantt.scrollTo(scrollState.x, scrollState.y); gantt.scrollTo(scrollState.x, scrollState.y);
}).catch(function (error) {
$("body").removeClass("loading");
gantt.alert({
title: "Peringatan",
type: "alert-error",
text: "Update activity gagal"
});
}); });
} }
@ -164,15 +172,24 @@ var dp = gantt.createDataProcessor(function (entity, action, data, id) {
} }
}); });
} }
let newStart = new Date(data['start_date']);
let newEnd = new Date(data['end_date']);
if (data['start_date'] && data['end_date']) {
data['duration'] = gantt.calculateDuration({
start_date: newStart,
end_date: newEnd
});
}
data['geom'] = geom.find(obj => obj.activity_id == id)?.geom; 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({ return gantt.ajax.put({
headers: { headers: {
"Content-Type": "application/json", "Content-Type": "application/json",
@ -181,6 +198,7 @@ var dp = gantt.createDataProcessor(function (entity, action, data, id) {
url: base_url + entity + "/" + id, url: base_url + entity + "/" + id,
data: JSON.stringify(data) data: JSON.stringify(data)
}).then(function (response) { }).then(function (response) {
$("body").removeClass("loading");
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)
@ -190,11 +208,17 @@ var dp = gantt.createDataProcessor(function (entity, action, data, id) {
if (parent && parent > 0) { if (parent && parent > 0) {
updateActivity(parent); updateActivity(parent);
} }
refresData(id);
} else if (parent && parent > 0) { } else if (parent && parent > 0) {
updateActivity(parent); updateActivity(parent);
} }
} }
}).catch(function (error) {
$("body").removeClass("loading");
gantt.alert({
title: "Peringatan",
type: "alert-error",
text: "Update activity gagal"
});
}); });
break; break;

3
edit-mode/index.html

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

Loading…
Cancel
Save