Browse Source

Fix set baseline

pull/1/head
Wahyu Ramadhan 1 year ago
parent
commit
c16bdba85d
  1. 5
      edit-mode/function/function.js
  2. 154
      edit-mode/function/ganttSettings.js
  3. 35
      edit-mode/function/restActivityLink.js

5
edit-mode/function/function.js

@ -383,6 +383,11 @@ function getGanttOpen() {
} }
$(document).ready(function () { $(document).ready(function () {
$("#gantt_here").on("scroll", function () {
var container = $(this);
var scrollPositionX = container.scrollLeft();
});
$("#critalPathBox").on("change", function () { $("#critalPathBox").on("change", function () {
let checked = $(this).is(":checked"); let checked = $(this).is(":checked");
if (checked) { if (checked) {

154
edit-mode/function/ganttSettings.js

@ -39,11 +39,11 @@ var daysObj = [
value: "6" value: "6"
} }
]; ];
var days = [0,1,2,3,4,5,6]; // Sunday -> Saturday var days = [0, 1, 2, 3, 4, 5, 6]; // Sunday -> Saturday
var selectDayOffChoices = null; var selectDayOffChoices = null;
$(document).ready(function() { $(document).ready(function () {
// init select multiple workdays // init select multiple workdays
selectDayOffChoices = new Choices('#select_dayoff', { selectDayOffChoices = new Choices('#select_dayoff', {
removeItemButton: true, removeItemButton: true,
@ -53,13 +53,13 @@ $(document).ready(function() {
// renderChoiceLimit: 5 // renderChoiceLimit: 5
}); });
$('#gantt_setting_btn').on('click', async function() { $('#gantt_setting_btn').on('click', async function () {
const result = await axiosInstance const result = await axiosInstance
.get(VERSION_GANTT_EDIT_URL, HEADER) .get(VERSION_GANTT_EDIT_URL, HEADER)
.then(res => res) .then(res => res)
.catch((error) => error.response); .catch((error) => error.response);
if(result && result.status==200){ if (result && result.status == 200) {
if (result.data && result.data.data) { if (result.data && result.data.data) {
var config_dayoff = null; var config_dayoff = null;
if (result.data.data.config_dayoff !== null) { if (result.data.data.config_dayoff !== null) {
@ -67,20 +67,20 @@ $(document).ready(function() {
if (config_dayoff && config_dayoff.length > 0) { if (config_dayoff && config_dayoff.length > 0) {
var config_dayoff_arr = config_dayoff.split(','); var config_dayoff_arr = config_dayoff.split(',');
for (var i=0; i < config_dayoff_arr.length; i++) { for (var i = 0; i < config_dayoff_arr.length; i++) {
var day = daysObj.find(o => parseInt(o.value) === parseInt(config_dayoff_arr[i])); var day = daysObj.find(o => parseInt(o.value) === parseInt(config_dayoff_arr[i]));
selectDayOffChoices.setChoiceByValue(day.value); selectDayOffChoices.setChoiceByValue(day.value);
} }
} }
} }
} }
}else{ } else {
gantt.alert({type: "error", text: "Failed to get settings. Please check your internet connection."}); gantt.alert({ type: "error", text: "Failed to get settings. Please check your internet connection." });
} }
$('#modal_gantt_setting').modal('show'); $('#modal_gantt_setting').modal('show');
}); });
$('#btn_save_setting').on('click', async function() { $('#btn_save_setting').on('click', async function () {
var holidays = []; var holidays = [];
var dayoff = $('#select_dayoff').val(); var dayoff = $('#select_dayoff').val();
var costToComplete = $("#costToCompleteBox").val(); var costToComplete = $("#costToCompleteBox").val();
@ -90,13 +90,13 @@ $(document).ready(function() {
var workdays = _.difference(days, dayoff); var workdays = _.difference(days, dayoff);
// reset the dayoff first // reset the dayoff first
for (var i=0; i < days.length; i++) { for (var i = 0; i < days.length; i++) {
gantt.unsetWorkTime({day: days[i], hours: false}); gantt.unsetWorkTime({ day: days[i], hours: false });
} }
if (dayoff.length > 0) { if (dayoff.length > 0) {
for (var i=0; i < dayoff.length; i++) { for (var i = 0; i < dayoff.length; i++) {
gantt.setWorkTime({ day:dayoff[i], hours:false }); gantt.setWorkTime({ day: dayoff[i], hours: false });
} }
} }
@ -116,30 +116,30 @@ $(document).ready(function() {
refresData(); refresData();
} }
else { else {
gantt.alert({type: "error", text: "Failed to update setting"}); gantt.alert({ type: "error", text: "Failed to update setting" });
} }
gantt.render(); gantt.render();
}); });
$("#gantt_toggle_task_btn").on('click', function(event) { $("#gantt_toggle_task_btn").on('click', function (event) {
toggleCollapseTasks(); toggleCollapseTasks();
}); });
$("#dashboard-project").on('click', function(event) { $("#dashboard-project").on('click', function (event) {
window.location.href = `https://adw.ospro.id/#/dashboard-project/${projectId}/${ganttId}`; window.location.href = `https://adw.ospro.id/#/dashboard-project/${projectId}/${ganttId}`;
}); });
$("#gantt-baseline").on('click', function(event) { $("#gantt-baseline").on('click', function (event) {
setBaseline(); setBaseline();
}); });
$("#save-activity").on('click', function(event) { $("#save-activity").on('click', function (event) {
resetActivity(); resetActivity();
}); });
$("#gantt-synchronize").on('click', function(event) { $("#gantt-synchronize").on('click', function (event) {
setSynchronize(); setSynchronize();
}); });
@ -147,7 +147,7 @@ $(document).ready(function() {
initGanttSettings(); initGanttSettings();
}); });
async function initHolidays(){ async function initHolidays() {
let payload = { let payload = {
"columns": [ "columns": [
{ "name": "version_gantt_id", "logic_operator": "=", "value": ganttId }, { "name": "version_gantt_id", "logic_operator": "=", "value": ganttId },
@ -190,39 +190,39 @@ async function initGanttSettings() {
.then(res => res) .then(res => res)
.catch((error) => error.response); .catch((error) => error.response);
if (result && result.status==200){ if (result && result.status == 200) {
var config_dayoff = result.data.data.config_dayoff; var config_dayoff = result.data.data.config_dayoff;
var type_gantt = result.data.data.calculation_type; var type_gantt = result.data.data.calculation_type;
reRenderColumns(type_gantt); reRenderColumns(type_gantt);
var dayoff = []; var dayoff = [];
if(config_dayoff && config_dayoff.length > 0){ if (config_dayoff && config_dayoff.length > 0) {
dayoff = config_dayoff.split(','); dayoff = config_dayoff.split(',');
} }
// reset the dayoff first // reset the dayoff first
for (var i=0; i < days.length; i++) { for (var i = 0; i < days.length; i++) {
gantt.unsetWorkTime({day: days[i], hours: false}); gantt.unsetWorkTime({ day: days[i], hours: false });
} }
if (dayoff.length > 0) { if (dayoff.length > 0) {
for (var i=0; i < dayoff.length; i++) { for (var i = 0; i < dayoff.length; i++) {
gantt.setWorkTime({ day:dayoff[i], hours:false }); gantt.setWorkTime({ day: dayoff[i], hours: false });
} }
} }
for (let index = 1; index <= 7; index++) { for (let index = 1; index <= 7; index++) {
const dateToCheck = new Date(2023, 4, index); // Note: Month is 0-based, so 5 represents June const dateToCheck = new Date(2023, 4, index); // Note: Month is 0-based, so 5 represents June
if (gantt.isWorkTime({ date: dateToCheck, hours: false })) { if (gantt.isWorkTime({ date: dateToCheck, hours: false })) {
console.log(dateToCheck.toString() + ' is work time.'); console.log(dateToCheck.toString() + ' is work time.');
} else { } else {
console.log(dateToCheck.toString() + ' is not work time.'); console.log(dateToCheck.toString() + ' is not work time.');
} }
} }
} }
} }
function expandTask(){ function expandTask() {
console.log("check expandTask") console.log("check expandTask")
gantt.eachTask(function(task){ gantt.eachTask(function (task) {
task.$open = true; task.$open = true;
}); });
// updateProperty({task_open:true}) // updateProperty({task_open:true})
@ -236,11 +236,11 @@ function expandTask(){
function toggleCollapseTasks() { function toggleCollapseTasks() {
// collapse task / activity // collapse task / activity
console.log('toggleCollapseTasks'); console.log('toggleCollapseTasks');
gantt.eachTask(function(task){ gantt.eachTask(function (task) {
task.$open = toggleTasks == "Expand"; task.$open = toggleTasks == "Expand";
}); });
if (toggleTasks == "Expand") { if (toggleTasks == "Expand") {
updateProperty({task_open:true}) updateProperty({ task_open: true })
// console.log('to collapse'); // console.log('to collapse');
toggleTasks = "Collapse"; toggleTasks = "Collapse";
$("#gantt_toggle_task_btn").prop('title', 'Collapse Activities'); $("#gantt_toggle_task_btn").prop('title', 'Collapse Activities');
@ -248,7 +248,7 @@ function toggleCollapseTasks() {
$("#gantt_toggle_task_btn").children().addClass('fa-compress-alt'); // change icon to collapse $("#gantt_toggle_task_btn").children().addClass('fa-compress-alt'); // change icon to collapse
} else { } else {
// console.log('to expand'); // console.log('to expand');
updateProperty({task_open:false}) updateProperty({ task_open: false })
toggleTasks = "Expand"; toggleTasks = "Expand";
$("#gantt_toggle_task_btn").prop('title', 'Expand Activities'); $("#gantt_toggle_task_btn").prop('title', 'Expand Activities');
$("#gantt_toggle_task_btn").children().removeClass('fa-compress-alt'); $("#gantt_toggle_task_btn").children().removeClass('fa-compress-alt');
@ -260,42 +260,42 @@ function toggleCollapseTasks() {
// Function Show / Hide Columns // Function Show / Hide Columns
function getColumnsSelection(node){ function getColumnsSelection(node) {
var selectedColumns = node.querySelectorAll(":checked"); var selectedColumns = node.querySelectorAll(":checked");
var unselectedColumn = node.querySelectorAll('input[type="checkbox"]:not(:checked)'); var unselectedColumn = node.querySelectorAll('input[type="checkbox"]:not(:checked)');
// var allSelected = node.querySelector("#check-all").prop('checked'); // var allSelected = node.querySelector("#check-all").prop('checked');
// console.log("unselectedColumn", unselectedColumn) // console.log("unselectedColumn", unselectedColumn)
var checkedColumns = {}; var checkedColumns = {};
selectedColumns.forEach(function(node){ selectedColumns.forEach(function (node) {
checkedColumns[node.name] = true; checkedColumns[node.name] = true;
}); });
unselectedColumn.forEach(function(node){ unselectedColumn.forEach(function (node) {
checkedColumns[node.name] = false; checkedColumns[node.name] = false;
}); });
return checkedColumns; return checkedColumns;
} }
function populateColumnsDropdown(node){ function populateColumnsDropdown(node) {
var visibleColumns = {}; var visibleColumns = {};
// var preventHide = ['action']; // var preventHide = ['action'];
gantt.config.columns.forEach(function(col){ gantt.config.columns.forEach(function (col) {
visibleColumns[col.name] = true; visibleColumns[col.name] = true;
}); });
var lines = []; var lines = [];
allColumns.forEach(function(col){ allColumns.forEach(function (col) {
var checked = visibleColumns[col.name] ? "checked" : ""; var checked = visibleColumns[col.name] ? "checked" : "";
// skip action to be pushed // skip action to be pushed
lines.push(`<label class="${col.name === 'action' ? 'elm-hide2': ''} dropdown-item"><input type="checkbox" name="${col.name}" ${checked}> ${col.label}</label>`); lines.push(`<label class="${col.name === 'action' ? 'elm-hide2' : ''} dropdown-item"><input type="checkbox" name="${col.name}" ${checked}> ${col.label}</label>`);
}); });
node.innerHTML = '<span class="dropdown-title">Show / Hide Columns</span><br>' + lines.join("<br>"); node.innerHTML = '<span class="dropdown-title">Show / Hide Columns</span><br>' + lines.join("<br>");
} }
function getDropdownNode(){ function getDropdownNode() {
return document.querySelector("#gantt_dropdown"); return document.querySelector("#gantt_dropdown");
} }
gantt.$showDropdown = function(node){ gantt.$showDropdown = function (node) {
var position = node.getBoundingClientRect(); var position = node.getBoundingClientRect();
var dropDown = getDropdownNode(); var dropDown = getDropdownNode();
dropDown.style.top = position.bottom + "px"; dropDown.style.top = position.bottom + "px";
@ -303,9 +303,9 @@ gantt.$showDropdown = function(node){
dropDown.style.display = "block"; dropDown.style.display = "block";
populateColumnsDropdown(dropDown); populateColumnsDropdown(dropDown);
dropDown.onchange = function(){ dropDown.onchange = function () {
var selection = getColumnsSelection(dropDown); var selection = getColumnsSelection(dropDown);
if(readOnly && parseInt(readOnly)==0){ if (readOnly && parseInt(readOnly) == 0) {
updateShowHideColumn(selection) updateShowHideColumn(selection)
} }
gantt.config.columns = createColumnsConfig(selection); gantt.config.columns = createColumnsConfig(selection);
@ -313,18 +313,18 @@ gantt.$showDropdown = function(node){
} }
dropDown.keep = true; dropDown.keep = true;
setTimeout(function(){ setTimeout(function () {
dropDown.keep = false; dropDown.keep = false;
}) })
} }
gantt.$hideDropdown = function(){ gantt.$hideDropdown = function () {
var dropDown = getDropdownNode(); var dropDown = getDropdownNode();
dropDown.style.display = "none"; dropDown.style.display = "none";
} }
window.addEventListener("click", function(event){ window.addEventListener("click", function (event) {
if(!event.target.closest("#gantt_dropdown") && !getDropdownNode().keep){ if (!event.target.closest("#gantt_dropdown") && !getDropdownNode().keep) {
gantt.$hideDropdown(); gantt.$hideDropdown();
} }
}); });
@ -336,14 +336,14 @@ window.addEventListener("click", function(event){
function setBaseline() { function setBaseline() {
var box = gantt.confirm({ var box = gantt.confirm({
text: "Set Baseline?", text: "Set Baseline?",
ok:"Yes", ok: "Yes",
cancel:"No", cancel: "No",
callback: async function(result){ callback: async function (result) {
if(result){ if (result) {
// gantt.message("Yes!"); // gantt.message("Yes!");
// send to API // send to API
await setBaselineAPI(); await setBaselineAPI();
}else{ } else {
// gantt.message("No..."); // gantt.message("No...");
} }
} }
@ -351,6 +351,36 @@ function setBaseline() {
} }
async function setBaselineAPI() { async function setBaselineAPI() {
expandTask();
var allTasks = [];
var taskCount = gantt.getTaskCount();
for (var i = 0; i < taskCount; i++) {
var task = gantt.getTaskByIndex(i);
allTasks.push(task);
}
$("body").addClass("loading");
const response = await gantt.ajax.post({
headers: {
"Content-Type": "application/json",
"Authorization": `Bearer ${token}`
},
url: `${base_url}activity/import-update`,
dataType: "json",
data: JSON.stringify(allTasks)
}).then(function (response) {
$("body").removeClass("loading");
let res = response.responseText
res = JSON.parse(res)
}).catch(function (error) {
$("body").removeClass("loading");
gantt.alert({
title: "Peringatan",
type: "alert-error",
text: "Update import gagal"
});
});
const res = await axiosInstance const res = await axiosInstance
.get(ACTIVITY_SET_BASELINE_URL, HEADER) .get(ACTIVITY_SET_BASELINE_URL, HEADER)
.then(res => res) .then(res => res)
@ -364,7 +394,7 @@ async function setBaselineAPI() {
window.location.reload(); window.location.reload();
} }
else { else {
gantt.alert({type: "error", text: "Failed to set baseline"}); gantt.alert({ type: "error", text: "Failed to set baseline" });
} }
gantt.render(); gantt.render();
} }
@ -378,9 +408,9 @@ function setSynchronize() {
// }); // });
gantt.confirm({ gantt.confirm({
text: "Plase set baseline before continue.", text: "Plase set baseline before continue.",
ok:"Set Baseline", ok: "Set Baseline",
cancel:"Cancel", cancel: "Cancel",
callback: async function(result) { callback: async function (result) {
if (result) { if (result) {
await setBaselineAPI(); await setBaselineAPI();
} }
@ -391,14 +421,14 @@ function setSynchronize() {
var box = gantt.confirm({ var box = gantt.confirm({
text: "Synchronize to Report Activity?", text: "Synchronize to Report Activity?",
ok:"Yes", ok: "Yes",
cancel:"No", cancel: "No",
callback: async function(result){ callback: async function (result) {
if(result){ if (result) {
// gantt.message("Yes!"); // gantt.message("Yes!");
// send to API // send to API
await setSynchronizeAPI() await setSynchronizeAPI()
}else{ } else {
// gantt.message("No..."); // gantt.message("No...");
} }
} }
@ -420,7 +450,7 @@ async function setSynchronizeAPI() {
window.location.reload(); window.location.reload();
} }
else { else {
gantt.alert({type: "error", text: "Failed to Synchronize to Report"}); gantt.alert({ type: "error", text: "Failed to Synchronize to Report" });
} }
gantt.render(); gantt.render();
} }

35
edit-mode/function/restActivityLink.js

@ -34,41 +34,6 @@ gantt.ajax.get({
getGanttOpen(); getGanttOpen();
gantt.parse(data); gantt.parse(data);
}); });
if (Date.now() < timestamp) {
expandTask();
var allTasks = [];
var taskCount = gantt.getTaskCount();
for (var i = 0; i < taskCount; i++) {
var task = gantt.getTaskByIndex(i);
allTasks.push(task);
}
$("body").addClass("loading");
gantt.ajax.post({
headers: {
"Content-Type": "application/json",
"Authorization": `Bearer ${token}`
},
url: `${base_url}activity/import-update`,
dataType: "json",
data: JSON.stringify(allTasks)
}).then(function (response) {
$("body").removeClass("loading");
let res = response.responseText
res = JSON.parse(res)
if (res) {
refresData();
}
}).catch(function (error) {
$("body").removeClass("loading");
gantt.alert({
title: "Peringatan",
type: "alert-error",
text: "Update import gagal"
});
});
}
}).catch(function (error) { }).catch(function (error) {
$("body").removeClass("loading"); $("body").removeClass("loading");
gantt.alert({ gantt.alert({

Loading…
Cancel
Save