Browse Source

Merge pull request 'staging' (#2) from staging into master

Reviewed-on: ordo/adw-gantt#2
pull/1/head
ibnu 1 year ago
parent
commit
b45d40b332
  1. 68
      edit-mode/function/function.js
  2. 7
      edit-mode/function/ganttConfig.js
  3. 4
      edit-mode/function/ganttEvent.js
  4. 2
      edit-mode/function/ganttSettings.js
  5. 39
      edit-mode/function/reportActivity.js
  6. 106
      edit-mode/function/restActivityLink.js
  7. 4
      edit-mode/index.html
  8. 21
      view-mode/function/overlaySCurve.js

68
edit-mode/function/function.js

@ -633,7 +633,67 @@ function expandTask() {
gantt.render(); gantt.render();
} }
function resetActivity() { // Function to get the earliest planned start date among all tasks
localStorage.setItem('batchEntity', ''); function getEarliestTaskDate() {
gantt.alert("Actiivity Saved"); var earliestDate = null;
} gantt.eachTask(function (task) {
var taskStartDate = task.planned_start || task.start_date;
if (!earliestDate || task.planned_start < earliestDate) {
earliestDate = taskStartDate;
if (task.start_date < earliestDate) {
earliestDate = task.start_date;
}
}
});
return earliestDate;
}
// Function to get the latest planned end date among all tasks
function getLatestTaskDate() {
var latestDate = null;
gantt.eachTask(function (task) {
var taskEndDate = task.planned_end || task.end_date;
if (!latestDate || task.planned_end > latestDate) {
latestDate = taskEndDate;
if (task.end_date > latestDate) {
latestDate = task.end_date;
}
}
});
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")
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 }, '*');

7
edit-mode/function/ganttConfig.js

@ -22,7 +22,12 @@ const axiosInstance = axios.create({
"Content-type": "application/json" "Content-type": "application/json"
} }
}); });
const axiosInstanceMultipart = axios.create({
headers: {
"Content-Type": "multipart/form-data",
"Authorization": `Bearer ${token}`,
}
});
axiosInstance.interceptors.request.use(async (config) => { axiosInstance.interceptors.request.use(async (config) => {
try { try {
$("body").addClass("loading"); $("body").addClass("loading");

4
edit-mode/function/ganttEvent.js

@ -168,11 +168,11 @@ gantt.attachEvent("onGanttScroll", function (left, top){
var max_allowed_date = gantt.date.add(gantt.config.end_date, -1, "day"); var max_allowed_date = gantt.date.add(gantt.config.end_date, -1, "day");
var repaint = false; var repaint = false;
if (+left_date <= +min_allowed_date){ if (earliest && +left_date <= +min_allowed_date && +left_date >= +earliest){
gantt.config.start_date = gantt.date.add(gantt.config.start_date, -1, "day"); gantt.config.start_date = gantt.date.add(gantt.config.start_date, -1, "day");
repaint = true; repaint = true;
} }
if (+right_date >= +max_allowed_date){ if (latest && +right_date >= +max_allowed_date && +right_date <= +latest){
gantt.config.end_date = gantt.date.add(gantt.config.end_date, 1, "day"); gantt.config.end_date = gantt.date.add(gantt.config.end_date, 1, "day");
repaint = true; repaint = true;
} }

2
edit-mode/function/ganttSettings.js

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

39
edit-mode/function/reportActivity.js

@ -418,23 +418,32 @@ $(document).ready(function () {
} }
async function submitRaMaterial(formData, id) { async function submitRaMaterial(formData, id) {
let qty_actual = $("#volume_pekerjaan_material").val(); try {
formData.set('qty', qty_actual); const qty_actual = $("#volume_pekerjaan_material").val();
const result = await axiosInstance formData.set('qty', qty_actual);
.post(`${base_url}report-activity-material/add`, formData) const result = await axiosInstance
.then(res => res) .post(`${base_url}report-activity-material/add`, formData);
.catch((error) => error.response);
const reportId = result.data.data.report_id;
// console.log("cek result", result); const image = formData.get("files");
const imageFormData = new FormData();
if (result && result.status == 200) { imageFormData.append("ref_id", reportId);
gantt.alert("Add report activity material Success!"); imageFormData.append("category", "report_activity");
resetFormAddRaMaterial(); imageFormData.append("files", image, image.name);
tableRaMaterialActual.draw();
} else { const resultImage = await axiosInstanceMultipart.post(`${base_url}image/upload`, imageFormData);
if (result.status === 200 && resultImage.status === 200) {
gantt.alert("Add report activity material Success!");
resetFormAddRaMaterial();
tableRaMaterialActual.draw();
} else {
throw new Error("Add report activity material failed.");
}
} catch (error) {
resetFormAddRaMaterial(); resetFormAddRaMaterial();
$("body").removeClass("loading"); $("body").removeClass("loading");
gantt.alert("Add report activity material failed, try again later!"); gantt.alert("Add report activity material failed.");
} }
} }

106
edit-mode/function/restActivityLink.js

@ -1,4 +1,6 @@
let geom = []; let geom = [];
let latest;
let earliest;
$("body").addClass("loading"); $("body").addClass("loading");
gantt.ajax.get({ gantt.ajax.get({
url: `${base_url}activity/${ganttId}/${proyekId}/get`, url: `${base_url}activity/${ganttId}/${proyekId}/get`,
@ -33,6 +35,8 @@ gantt.ajax.get({
gantt.parse(data); gantt.parse(data);
getGanttOpen(); getGanttOpen();
gantt.parse(data); gantt.parse(data);
earliest = getEarliestTaskDate();
latest = getLatestTaskDate();
}); });
}).catch(function (error) { }).catch(function (error) {
$("body").removeClass("loading"); $("body").removeClass("loading");
@ -77,6 +81,8 @@ function refresData(id) {
gantt.parse(data); gantt.parse(data);
getGanttOpen(); getGanttOpen();
gantt.parse(data); gantt.parse(data);
earliest = getEarliestTaskDate();
latest = getLatestTaskDate();
}); });
if (id) { if (id) {
if (gantt.isTaskExists(id)) { if (gantt.isTaskExists(id)) {
@ -176,56 +182,56 @@ var dp = gantt.createDataProcessor(function (entity, action, data, id) {
}); });
} }
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'); let existingEntity = localStorage.getItem('batchEntity');
// if (existingEntity) { if (existingEntity) {
// existingEntity = JSON.parse(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 // Now batchEntity is an object containing your data, and you can access its properties like batchEntity.entity and batchEntity.data
// } }
// let batchEntity = { let batchEntity = {
// entity: entity, entity: entity,
// data: data data: data
// }; };
// let toBeSet = [] let toBeSet = []
// if (existingEntity) { if (existingEntity) {
// toBeSet = [...existingEntity, batchEntity] toBeSet = [...existingEntity, batchEntity]
// } else { } else {
// toBeSet = [batchEntity] toBeSet = [batchEntity]
// } }
// localStorage.setItem('batchEntity', JSON.stringify(toBeSet)); localStorage.setItem('batchEntity', JSON.stringify(toBeSet));
$("body").addClass("loading"); // $("body").addClass("loading");
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) {
$("body").removeClass("loading"); // $("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)
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);
} // }
} else if (parent && parent > 0) { // } else if (parent && parent > 0) {
updateActivity(parent); // updateActivity(parent);
} // }
if (!parent) { // if (!parent) {
refresData(); // refresData();
} // }
} // }
}).catch(function (error) { // }).catch(function (error) {
$("body").removeClass("loading"); // $("body").removeClass("loading");
gantt.alert({ // gantt.alert({
title: "Peringatan", // title: "Peringatan",
type: "alert-error", // type: "alert-error",
text: "Update activity gagal" // text: "Update activity gagal"
}); // });
}); // });
break; break;
case "delete": 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 <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 <button title="Save" class="btn btn-sm btn-icon-toolbar" id="save-activity"><i
class="fa fa-save icon-toolbar"></i></button> 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 <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>

21
view-mode/function/overlaySCurve.js

@ -145,19 +145,22 @@ var lineOverlay = overlayControl.addOverlay(function(container) {
var values = getProgressLine(); var values = getProgressLine();
var scaleLabels = []; var scaleLabels = [];
if(parts[2] && parts[2] == '1'){ // if(parts[2] && parts[2] == '1'){
// values.dates.forEach(function(date){
// var dateScale = new Date(date);
// scaleLabels.push(dateToStr(dateScale));
// })
// } else {
// var chartScale = getChartScaleRange();
// chartScale.forEach(function(date){
// scaleLabels.push(dateToStr(date));
// });
// }
values.dates.forEach(function(date){ values.dates.forEach(function(date){
var dateScale = new Date(date); var dateScale = new Date(date);
scaleLabels.push(dateToStr(dateScale)); scaleLabels.push(dateToStr(dateScale));
}) })
} else {
var chartScale = getChartScaleRange();
chartScale.forEach(function(date){
scaleLabels.push(dateToStr(date));
});
}
var canvas = document.createElement("canvas"); var canvas = document.createElement("canvas");
container.appendChild(canvas); container.appendChild(canvas);
canvas.style.height = container.offsetHeight + "px"; canvas.style.height = container.offsetHeight + "px";

Loading…
Cancel
Save