From 285b8aa8cdc1a25ef5eeadad85d4b984fed6956c Mon Sep 17 00:00:00 2001 From: wahyun Date: Sun, 21 Jul 2024 20:15:58 +0700 Subject: [PATCH] feat: fixed bug --- edit-mode/function/expenseResource.js | 35 +- edit-mode/function/function.js | 3 +- edit-mode/function/ganttConfig.js | 16 +- edit-mode/function/ganttSettings.js | 1018 +++++++++++++------------ edit-mode/index.html | 2 +- 5 files changed, 539 insertions(+), 535 deletions(-) diff --git a/edit-mode/function/expenseResource.js b/edit-mode/function/expenseResource.js index d41965b..bf36e32 100644 --- a/edit-mode/function/expenseResource.js +++ b/edit-mode/function/expenseResource.js @@ -1,10 +1,11 @@ var expenseModal = $('#modal-expense > .modal-dialog > .modal-content'); function resetFormAssignexpense() { - $('#select-expense').val(null).trigger("change"); - $('#select-expense').find('option').remove(); - $('#select-expense').val(""); - $('#uom-req-expense').val(null).trigger('change'); + // $('#select-expense').val(null).trigger("change"); + // $('#select-expense').find('option').remove(); + // $('#select-expense').val(""); + $("#desc-expense").val(""); + $('#uom-req-expense').val("").trigger('change'); $('#form-assign-expense').trigger("reset"); $('#btn-assign-expense').html('Assign'); $('#btn-assign-expense').prop("disabled", false); @@ -88,18 +89,18 @@ $(document).ready(function () { }); $('#modal-expense').on('show.bs.modal', function (event) { - $("#desc-expense").val(activityName); + resetFormAssignexpense(); $('#modal-expense-title').html("Overhead " + activityName); $('#modal-expense-sub-title').html(`

Plan Date: ${moment(activityEarlyStart).format('DD MMMM YYYY')} - ${moment(activityEarlyFinish).format('DD MMMM YYYY')}

`); tableexpense.draw(); }); $('#modal-expense').on('hide.bs.modal', function (event) { + resetFormAssignexpense(); $("#show-form-expense").show(); if (actionHappen) { updateActivity(activityId); } - resetFormAssignexpense(); }); $('#select-expense').select2({ @@ -160,7 +161,7 @@ $(document).ready(function () { type: "expense", fom_date: required_date, required_date: required_date, - proyek_id: proyekId, + proyek_id: parseInt(proyekId), uom: uom, qty: formatReplaceTitikRibuan(qty_planning), price: formatReplaceTitikRibuan(price) @@ -175,7 +176,6 @@ $(document).ready(function () { if (data && data.code === 200) { material_id = data.data.id; resetFormAssignexpense(); - let payloadAssign = { proyek_id: proyekId, activity_id: activityId, @@ -192,35 +192,34 @@ $(document).ready(function () { contentType: false, success: function (data) { if (data && data.code === 200) { + resetFormAssignexpense(); actionHappen = true; gantt.alert("Data added!"); tableexpense.draw(); - resetFormAssignexpense(); - } - else { - gantt.alert({ type: "error", text: data.message }); + } else { $('#btn-assign-expense').html('Assign'); $('#btn-assign-expense').prop("disabled", false); + gantt.alert({ type: "error", text: data.message }); } }, error: function (data) { + $('#btn-assign-expense').html('Assign'); + $('#btn-assign-expense').prop("disabled", false); gantt.alert("Assign Failed, try again later!"); - resetFormAssignexpense(); } }); - } - else { - gantt.alert({ type: "error", text: data.message }); + } else { $('#btn-assign-expense').html('Assign'); $('#btn-assign-expense').prop("disabled", false); + gantt.alert({ type: "error", text: data.message }); } }, error: function (data) { + $('#btn-assign-expense').html('Assign'); + $('#btn-assign-expense').prop("disabled", false); gantt.alert("Overhead request Failed, try again later!"); - resetFormAssignexpense(); } }); - }); // delete from row diff --git a/edit-mode/function/function.js b/edit-mode/function/function.js index f3535f4..0ef13cd 100644 --- a/edit-mode/function/function.js +++ b/edit-mode/function/function.js @@ -196,6 +196,7 @@ function getSatuan() { ] } } + $.ajax({ data: JSON.stringify(payload), url: `${base_url}satuan/search`, @@ -223,7 +224,7 @@ function getSatuan() { let newOption = new Option(option.label, option.label); $('#uom-req-material').append(newOption); }); - + $('#uom-req-expense').append(new Option('', '', true, true)); satuanList.forEach((option) => { let newOption = new Option(option.label, option.label); $('#uom-req-expense').append(newOption); diff --git a/edit-mode/function/ganttConfig.js b/edit-mode/function/ganttConfig.js index 24e008c..0a22727 100644 --- a/edit-mode/function/ganttConfig.js +++ b/edit-mode/function/ganttConfig.js @@ -294,14 +294,14 @@ var allColumns = [ editor: editor.text, resize: true, template: function (text) { - function truncateText(text, maxLength) { - if (text.length > maxLength) { - return text.substring(0, maxLength) + '...'; - } - return text; - } - const truncatedText = truncateText(text.text, 30); - return `${truncatedText}`; + // function truncateText(text, maxLength) { + // if (text.length > maxLength) { + // return text.substring(0, maxLength) + '...'; + // } + // return text; + // } + // const truncatedText = truncateText(text.text, 30); + return `${text.text}`; } }, { diff --git a/edit-mode/function/ganttSettings.js b/edit-mode/function/ganttSettings.js index 8b57a1d..3c43dfc 100644 --- a/edit-mode/function/ganttSettings.js +++ b/edit-mode/function/ganttSettings.js @@ -1,507 +1,511 @@ -// set work days - -// gantt.setWorkTime({ day:1, hours:false }); - -const VERSION_GANTT_EDIT_URL = `${base_url}version-gantt/edit/${ganttId}`; -const VERSION_GANTT_UPDATE_URL = `${base_url}version-gantt/update/${ganttId}`; -const ACTIVITY_SET_BASELINE_URL = `${base_url}project/set-baseline/${ganttId}`; -const ACTIVITY_SET_BASELINE_ACTIVITY_URL = (id) => { - return `${base_url}project/set-baseline-activity/${id}/${ganttId}`; -} -const ACTIVITY_SYNCHRONIZE_REPORT_URL = `${base_url}project/synchronize-report/${ganttId}`; -let projectId = getUrlParameter("proyek_id"); -var toggleTasks = "Collapse"; -var isBaselineSet = false; -var daysObj = [ - { - text: "Sunday", - value: "0" - }, - { - text: "Monday", - value: "1" - }, - { - text: "Tuesday", - value: "2" - }, - { - text: "Wednesday", - value: "3" - }, - { - text: "Thursday", - value: "4" - }, - { - text: "Friday", - value: "5" - }, - { - text: "Saturday", - value: "6" - } -]; -var days = [0, 1, 2, 3, 4, 5, 6]; // Sunday -> Saturday - -var selectDayOffChoices = null; - -$(document).ready(function () { - // init select multiple workdays - selectDayOffChoices = new Choices('#select_dayoff', { - removeItemButton: true, - shouldSort: false - // maxItemCount: 5, - // searchResultLimit: 5, - // renderChoiceLimit: 5 - }); - - $('#gantt_setting_btn').on('click', async function () { - const result = await axiosInstance - .get(VERSION_GANTT_EDIT_URL, HEADER) - .then(res => res) - .catch((error) => error.response); - - if (result && result.status == 200) { - if (result.data && result.data.data) { - var config_dayoff = null; - if (result.data.data.config_dayoff !== null) { - config_dayoff = result.data.data.config_dayoff; - - if (config_dayoff && config_dayoff.length > 0) { - var config_dayoff_arr = config_dayoff.split(','); - for (var i = 0; i < config_dayoff_arr.length; i++) { - var day = daysObj.find(o => parseInt(o.value) === parseInt(config_dayoff_arr[i])); - selectDayOffChoices.setChoiceByValue(day.value); - } - } - } - } - } else { - gantt.alert({ type: "error", text: "Failed to get settings. Please check your internet connection." }); - } - $('#modal_gantt_setting').modal('show'); - }); - - $('#btn_save_setting').on('click', async function () { - var holidays = []; - var dayoff = $('#select_dayoff').val(); - var costToComplete = $("#costToCompleteBox").val(); - var committedCost = $("#committedCostBox").val(); - - dayoff = dayoff.map(item => parseInt(item)); - var workdays = _.difference(days, dayoff); - - // reset the dayoff first - for (var i = 0; i < days.length; i++) { - gantt.unsetWorkTime({ day: days[i], hours: false }); - } - - if (dayoff.length > 0) { - for (var i = 0; i < dayoff.length; i++) { - gantt.setWorkTime({ day: dayoff[i], hours: false }); - } - } - - let payload = { - "config_dayoff": dayoff.join(','), - "cost_to_complete": costToComplete ? costToComplete : 0, - "committed_cost": committedCost ? committedCost : 0 - } - - const result = await axiosInstance - .put(VERSION_GANTT_UPDATE_URL, payload, HEADER) - .then(res => res) - .catch((error) => error.response); - if (result && result.status === 200) { - $('#modal_gantt_setting').modal('hide'); - gantt.message("Settings updated"); - refresData(); - } - else { - gantt.alert({ type: "error", text: "Failed to update setting" }); - } - - gantt.render(); - - }); - $("#gantt_toggle_task_btn").on('click', function (event) { - toggleCollapseTasks(); - }); - - $("#dashboard-project").on('click', function (event) { - // window.location.href = `https://si.ospro.id/#/dashboard-project/${projectId}/${ganttId}false-header`; - window.location.href = `http://localhost:3000/#/dashboard-project/${projectId}/${ganttId}/false-header`; - }); - - $("#gantt-baseline").on('click', function (event) { - setBaseline(); - }); - - $("#save-activity").on('click', function (event) { - batchUpdate(); - }); - - $("#gantt-synchronize").on('click', function (event) { - setSynchronize(); - }); - - $("#compare-data").on('click', function (event) { - compareData(ganttTask); - }); - - $("#update-schedule").on('click', function (event) { - updateSchedule(); - }); - - initHolidays(); - initGanttSettings(); -}); - -async function initHolidays() { - let payload = { - "columns": [ - { "name": "version_gantt_id", "logic_operator": "=", "value": ganttId }, - { "name": "proyek_id", "logic_operator": "=", "value": proyekId } - ], - "joins": [], - "orders": { "columns": ["date"], "ascending": true }, - "paging": { "start": 0, "length": -1 } - } - - $.ajax({ - data: JSON.stringify(payload), - url: `${base_url}holiday/search`, - type: "POST", - success: function (result) { - let dataHolidays = result.data || [] - dataHolidays.map((val, index) => { - var a = moment(val.date); - var b = moment(a).add(val.duration, 'days'); - for (var m = moment(a); m.isBefore(b); m.add(1, 'days')) { - let holiday = new Date(m.format('YYYY-MM-DD')); - gantt.setWorkTime({ - date: holiday, - hours: false - }); - } - }); - gantt.render(); - }, - }); -} - -async function initGanttSettings() { - $("#scale1").attr('checked', true); - - // init to gantt chart view (holidays) - const result = await axiosInstance - .get(VERSION_GANTT_EDIT_URL, HEADER) - .then(res => res) - .catch((error) => error.response); - - if (result && result.status == 200) { - var config_dayoff = result.data.data.config_dayoff; - var type_gantt = result.data.data.calculation_type; - reRenderColumns(type_gantt); - var dayoff = []; - if (config_dayoff && config_dayoff.length > 0) { - dayoff = config_dayoff.split(','); - } - - // reset the dayoff first - for (var i = 0; i < days.length; i++) { - gantt.unsetWorkTime({ day: days[i], hours: false }); - } - - if (dayoff.length > 0) { - for (var i = 0; i < dayoff.length; i++) { - gantt.setWorkTime({ day: dayoff[i], hours: false }); - } - } - } -} - -function expandTask() { - gantt.eachTask(function (task) { - task.$open = true; - }); - // updateProperty({task_open:true}) - toggleTasks = "Collapse"; - $("#gantt_toggle_task_btn").prop('title', 'Collapse Activities'); - $("#gantt_toggle_task_btn").children().removeClass('fa-expand-alt'); - $("#gantt_toggle_task_btn").children().addClass('fa-compress-alt'); - gantt.render(); -} - -function toggleCollapseTasks() { - // collapse task / activity - gantt.eachTask(function (task) { - task.$open = toggleTasks == "Expand"; - }); - if (toggleTasks == "Expand") { - updateProperty({ task_open: true }) - toggleTasks = "Collapse"; - $("#gantt_toggle_task_btn").prop('title', 'Collapse Activities'); - $("#gantt_toggle_task_btn").children().removeClass('fa-expand-alt'); - $("#gantt_toggle_task_btn").children().addClass('fa-compress-alt'); // change icon to collapse - } else { - updateProperty({ task_open: false }) - toggleTasks = "Expand"; - $("#gantt_toggle_task_btn").prop('title', 'Expand Activities'); - $("#gantt_toggle_task_btn").children().removeClass('fa-compress-alt'); - $("#gantt_toggle_task_btn").children().addClass('fa-expand-alt'); // change icon to expand - } - gantt.render(); - setGanttOpen(); -} - - -// Function Show / Hide Columns -function getColumnsSelection(node) { - var selectedColumns = node.querySelectorAll(":checked"); - var unselectedColumn = node.querySelectorAll('input[type="checkbox"]:not(:checked)'); - // var allSelected = node.querySelector("#check-all").prop('checked'); - var checkedColumns = {}; - selectedColumns.forEach(function (node) { - checkedColumns[node.name] = true; - }); - unselectedColumn.forEach(function (node) { - checkedColumns[node.name] = false; - }); - return checkedColumns; -} - -function populateColumnsDropdown(node) { - var visibleColumns = {}; - // var preventHide = ['action']; - gantt.config.columns.forEach(function (col) { - visibleColumns[col.name] = true; - }); - - var lines = []; - allColumns.forEach(function (col) { - var checked = visibleColumns[col.name] ? "checked" : ""; - // skip action to be pushed - lines.push(``); - }); - node.innerHTML = 'Show / Hide Columns
' + lines.join("
"); -} - -function getDropdownNode() { - return document.querySelector("#gantt_dropdown"); -} - -gantt.$showDropdown = function (node) { - var position = node.getBoundingClientRect(); - var dropDown = getDropdownNode(); - dropDown.style.top = position.bottom + "px"; - dropDown.style.left = position.left - 150 + "px"; - dropDown.style.display = "block"; - populateColumnsDropdown(dropDown); - - dropDown.onchange = function () { - var selection = getColumnsSelection(dropDown); - if (readOnly && parseInt(readOnly) == 0) { - updateShowHideColumn(selection) - } - gantt.config.columns = createColumnsConfig(selection); - gantt.render(); - } - - dropDown.keep = true; - setTimeout(function () { - dropDown.keep = false; - }) -} - -gantt.$hideDropdown = function () { - var dropDown = getDropdownNode(); - dropDown.style.display = "none"; -} - -window.addEventListener("click", function (event) { - if (!event.target.closest("#gantt_dropdown") && !getDropdownNode().keep) { - gantt.$hideDropdown(); - } -}); - -// End Function Show / Hide Columns - - -// Set Baseline -function setBaseline() { - var box = gantt.confirm({ - text: "Set Baseline for this gantt chart?", - ok: "Yes", - cancel: "No", - callback: async function (result) { - if (result) { - // gantt.message("Yes!"); - // send to API - await setBaselineAPI(); - } else { - // gantt.message("No..."); - } - } - }); -} - -// Set Baseline Activity -function setBaselineActivity(activity_id, name) { - var box = gantt.confirm({ - text: `Set Baseline for this activity ${name}?`, - ok: "Yes", - cancel: "No", - callback: async function (result) { - if (result) { - await setBaselineActivityAPI(activity_id); - } - } - }); -} - -async function importUpdate() { - 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" - }); - }); -} - -async function setBaselineActivityAPI(activity_id) { - await importUpdate(); - const res = await axiosInstance - .get(ACTIVITY_SET_BASELINE_ACTIVITY_URL(activity_id), HEADER) - .then(res => res) - .catch((error) => error.response); - if (res && res.status === 200) { - gantt.message("Set baseline activity success!"); - window.location.reload(); - } else { - $("body").removeClass("loading"); - gantt.alert({ type: "error", text: "Failed to set baseline activity" }); - } - gantt.render(); -} - -async function setBaselineAPI() { - await importUpdate(); - const res = await axiosInstance - .get(ACTIVITY_SET_BASELINE_URL, HEADER) - .then(res => res) - .catch((error) => error.response); - if (res && res.status === 200) { - // $('#modal_gantt_setting').modal('hide'); - // gantt.alert("Settings updated"); - // gantt.message(result.data.message); - gantt.message("Set baseline success!"); - window.location.reload(); - } - else { - $("body").removeClass("loading"); - gantt.alert({ type: "error", text: "Failed to set baseline" }); - } - gantt.render(); -} - -function setSynchronize() { - if (!isBaselineSet) { - // gantt.alert({ - // title:"Synchronize to Report", - // type:"alert-error", - // text:"Please set baseline before continue." - // }); - gantt.confirm({ - text: "Plase set baseline before continue.", - ok: "Set Baseline", - cancel: "Cancel", - callback: async function (result) { - if (result) { - await setBaselineAPI(); - } - } - }); - return false; - } - - var box = gantt.confirm({ - text: "Synchronize to Report Activity?", - ok: "Yes", - cancel: "No", - callback: async function (result) { - if (result) { - // gantt.message("Yes!"); - // send to API - await setSynchronizeAPI() - } else { - // gantt.message("No..."); - } - } - }); -} - -function updateSchedule() { - $("body").addClass("loading"); - return gantt.ajax.get({ - headers: { - "Content-Type": "application/json", - "Authorization": `Bearer ${token}` - }, - url: base_url + "activity/update-schedule/" + ganttId - }).then(function (response) { - $("body").removeClass("loading"); - window.location.reload(); - }).catch(function (error) { - $("body").removeClass("loading") - gantt.alert({ - title: "Peringatan", - type: "alert-error", - text: "Update activity gagal" - }); - }); -} - -async function setSynchronizeAPI() { - const res = await axiosInstance - .get(ACTIVITY_SYNCHRONIZE_REPORT_URL, HEADER) - .then(res => res) - .catch((error) => error.response); - - if (res && res.status === 200) { - // $('#modal_gantt_setting').modal('hide'); - // gantt.alert("Settings updated"); - // gantt.message(result.data.message); - gantt.message("Synchronize to Report success!"); - window.location.reload(); - } - else { - gantt.alert({ type: "error", text: "Failed to Synchronize to Report" }); - } - gantt.render(); -} +// set work days + +// gantt.setWorkTime({ day:1, hours:false }); + +const VERSION_GANTT_EDIT_URL = `${base_url}version-gantt/edit/${ganttId}`; +const VERSION_GANTT_UPDATE_URL = `${base_url}version-gantt/update/${ganttId}`; +const ACTIVITY_SET_BASELINE_URL = `${base_url}project/set-baseline/${ganttId}`; +const ACTIVITY_SET_BASELINE_ACTIVITY_URL = (id) => { + return `${base_url}project/set-baseline-activity/${id}/${ganttId}`; +} +const ACTIVITY_SYNCHRONIZE_REPORT_URL = `${base_url}project/synchronize-report/${ganttId}`; +let projectId = getUrlParameter("proyek_id"); +var toggleTasks = "Collapse"; +var isBaselineSet = false; +var daysObj = [ + { + text: "Sunday", + value: "0" + }, + { + text: "Monday", + value: "1" + }, + { + text: "Tuesday", + value: "2" + }, + { + text: "Wednesday", + value: "3" + }, + { + text: "Thursday", + value: "4" + }, + { + text: "Friday", + value: "5" + }, + { + text: "Saturday", + value: "6" + } +]; +var days = [0, 1, 2, 3, 4, 5, 6]; // Sunday -> Saturday + +var selectDayOffChoices = null; + +$(document).ready(function () { + // init select multiple workdays + selectDayOffChoices = new Choices('#select_dayoff', { + removeItemButton: true, + shouldSort: false + // maxItemCount: 5, + // searchResultLimit: 5, + // renderChoiceLimit: 5 + }); + + $('#gantt_setting_btn').on('click', async function () { + const result = await axiosInstance + .get(VERSION_GANTT_EDIT_URL, HEADER) + .then(res => res) + .catch((error) => error.response); + + if (result && result.status == 200) { + if (result.data && result.data.data) { + var config_dayoff = null; + + if (result.data.data.config_dayoff !== null) { + config_dayoff = result.data.data.config_dayoff; + + if (config_dayoff && config_dayoff.length > 0) { + var config_dayoff_arr = config_dayoff.split(','); + for (var i = 0; i < config_dayoff_arr.length; i++) { + var day = daysObj.find(o => parseInt(o.value) === parseInt(config_dayoff_arr[i])); + selectDayOffChoices.setChoiceByValue(day.value); + } + } + } + } + } else { + gantt.alert({ type: "error", text: "Failed to get settings. Please check your internet connection." }); + } + $('#modal_gantt_setting').modal('show'); + }); + + $('#btn_save_setting').on('click', async function () { + var holidays = []; + var dayoff = $('#select_dayoff').val(); + var costToComplete = $("#costToCompleteBox").val(); + var committedCost = $("#committedCostBox").val(); + + dayoff = dayoff.map(item => parseInt(item)); + var workdays = _.difference(days, dayoff); + + // reset the dayoff first + for (var i = 0; i < days.length; i++) { + gantt.unsetWorkTime({ day: days[i], hours: false }); + } + + if (dayoff.length > 0) { + for (var i = 0; i < dayoff.length; i++) { + gantt.setWorkTime({ day: dayoff[i], hours: false }); + } + } + + let payload = { + "config_dayoff": dayoff.join(','), + "cost_to_complete": costToComplete ? costToComplete : 0, + "committed_cost": committedCost ? committedCost : 0 + } + + const result = await axiosInstance + .put(VERSION_GANTT_UPDATE_URL, payload, HEADER) + .then(res => res) + .catch((error) => error.response); + if (result && result.status === 200) { + $('#modal_gantt_setting').modal('hide'); + gantt.message("Settings updated"); + refresData(); + } + else { + gantt.alert({ type: "error", text: "Failed to update setting" }); + } + + gantt.render(); + + }); + $("#gantt_toggle_task_btn").on('click', function (event) { + toggleCollapseTasks(); + }); + + $("#dashboard-project").on('click', function (event) { + window.location.href = `https://si.ospro.id/#/dashboard-project/${projectId}/${ganttId}?dashboardGantt=${true}`; + // window.location.href = `http://localhost:3000/#/dashboard-project/${projectId}/${ganttId}?dashboardGantt=${true}`; + }); + + $("#gantt-baseline").on('click', function (event) { + setBaseline(); + }); + + $("#save-activity").on('click', function (event) { + batchUpdate(); + }); + + $("#gantt-synchronize").on('click', function (event) { + setSynchronize(); + }); + + $("#compare-data").on('click', function (event) { + compareData(ganttTask); + }); + + $("#update-schedule").on('click', function (event) { + updateSchedule(); + }); + + initHolidays(); + initGanttSettings(); +}); + +async function initHolidays() { + let payload = { + "columns": [ + { "name": "version_gantt_id", "logic_operator": "=", "value": ganttId }, + { "name": "proyek_id", "logic_operator": "=", "value": proyekId } + ], + "joins": [], + "orders": { "columns": ["date"], "ascending": true }, + "paging": { "start": 0, "length": -1 } + } + + $.ajax({ + data: JSON.stringify(payload), + url: `${base_url}holiday/search`, + type: "POST", + success: function (result) { + let dataHolidays = result.data || [] + dataHolidays.map((val, index) => { + var a = moment(val.date); + var b = moment(a).add(val.duration, 'days'); + for (var m = moment(a); m.isBefore(b); m.add(1, 'days')) { + let holiday = new Date(m.format('YYYY-MM-DD')); + gantt.setWorkTime({ + date: holiday, + hours: false + }); + } + }); + gantt.render(); + }, + }); +} + +async function initGanttSettings() { + $("#scale1").attr('checked', true); + + // init to gantt chart view (holidays) + const result = await axiosInstance + .get(VERSION_GANTT_EDIT_URL, HEADER) + .then(res => res) + .catch((error) => error.response); + + if (result && result.status == 200) { + var config_dayoff = result.data.data.config_dayoff; + var type_gantt = result.data.data.calculation_type; + const ganttName = result.data.data.name_version; + + document.getElementById("project-name-header").textContent = ganttName; + reRenderColumns(type_gantt); + var dayoff = []; + if (config_dayoff && config_dayoff.length > 0) { + dayoff = config_dayoff.split(','); + } + + // reset the dayoff first + for (var i = 0; i < days.length; i++) { + gantt.unsetWorkTime({ day: days[i], hours: false }); + } + + if (dayoff.length > 0) { + for (var i = 0; i < dayoff.length; i++) { + gantt.setWorkTime({ day: dayoff[i], hours: false }); + } + } + } +} + +function expandTask() { + gantt.eachTask(function (task) { + task.$open = true; + }); + // updateProperty({task_open:true}) + toggleTasks = "Collapse"; + $("#gantt_toggle_task_btn").prop('title', 'Collapse Activities'); + $("#gantt_toggle_task_btn").children().removeClass('fa-expand-alt'); + $("#gantt_toggle_task_btn").children().addClass('fa-compress-alt'); + gantt.render(); +} + +function toggleCollapseTasks() { + // collapse task / activity + gantt.eachTask(function (task) { + task.$open = toggleTasks == "Expand"; + }); + if (toggleTasks == "Expand") { + updateProperty({ task_open: true }) + toggleTasks = "Collapse"; + $("#gantt_toggle_task_btn").prop('title', 'Collapse Activities'); + $("#gantt_toggle_task_btn").children().removeClass('fa-expand-alt'); + $("#gantt_toggle_task_btn").children().addClass('fa-compress-alt'); // change icon to collapse + } else { + updateProperty({ task_open: false }) + toggleTasks = "Expand"; + $("#gantt_toggle_task_btn").prop('title', 'Expand Activities'); + $("#gantt_toggle_task_btn").children().removeClass('fa-compress-alt'); + $("#gantt_toggle_task_btn").children().addClass('fa-expand-alt'); // change icon to expand + } + gantt.render(); + setGanttOpen(); +} + + +// Function Show / Hide Columns +function getColumnsSelection(node) { + var selectedColumns = node.querySelectorAll(":checked"); + var unselectedColumn = node.querySelectorAll('input[type="checkbox"]:not(:checked)'); + // var allSelected = node.querySelector("#check-all").prop('checked'); + var checkedColumns = {}; + selectedColumns.forEach(function (node) { + checkedColumns[node.name] = true; + }); + unselectedColumn.forEach(function (node) { + checkedColumns[node.name] = false; + }); + return checkedColumns; +} + +function populateColumnsDropdown(node) { + var visibleColumns = {}; + // var preventHide = ['action']; + gantt.config.columns.forEach(function (col) { + visibleColumns[col.name] = true; + }); + + var lines = []; + allColumns.forEach(function (col) { + var checked = visibleColumns[col.name] ? "checked" : ""; + // skip action to be pushed + lines.push(``); + }); + node.innerHTML = 'Show / Hide Columns
' + lines.join("
"); +} + +function getDropdownNode() { + return document.querySelector("#gantt_dropdown"); +} + +gantt.$showDropdown = function (node) { + var position = node.getBoundingClientRect(); + var dropDown = getDropdownNode(); + dropDown.style.top = position.bottom + "px"; + dropDown.style.left = position.left - 150 + "px"; + dropDown.style.display = "block"; + populateColumnsDropdown(dropDown); + + dropDown.onchange = function () { + var selection = getColumnsSelection(dropDown); + if (readOnly && parseInt(readOnly) == 0) { + updateShowHideColumn(selection) + } + gantt.config.columns = createColumnsConfig(selection); + gantt.render(); + } + + dropDown.keep = true; + setTimeout(function () { + dropDown.keep = false; + }) +} + +gantt.$hideDropdown = function () { + var dropDown = getDropdownNode(); + dropDown.style.display = "none"; +} + +window.addEventListener("click", function (event) { + if (!event.target.closest("#gantt_dropdown") && !getDropdownNode().keep) { + gantt.$hideDropdown(); + } +}); + +// End Function Show / Hide Columns + + +// Set Baseline +function setBaseline() { + var box = gantt.confirm({ + text: "Set Baseline for this gantt chart?", + ok: "Yes", + cancel: "No", + callback: async function (result) { + if (result) { + // gantt.message("Yes!"); + // send to API + await setBaselineAPI(); + } else { + // gantt.message("No..."); + } + } + }); +} + +// Set Baseline Activity +function setBaselineActivity(activity_id, name) { + var box = gantt.confirm({ + text: `Set Baseline for this activity ${name}?`, + ok: "Yes", + cancel: "No", + callback: async function (result) { + if (result) { + await setBaselineActivityAPI(activity_id); + } + } + }); +} + +async function importUpdate() { + 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" + }); + }); +} + +async function setBaselineActivityAPI(activity_id) { + await importUpdate(); + const res = await axiosInstance + .get(ACTIVITY_SET_BASELINE_ACTIVITY_URL(activity_id), HEADER) + .then(res => res) + .catch((error) => error.response); + if (res && res.status === 200) { + gantt.message("Set baseline activity success!"); + window.location.reload(); + } else { + $("body").removeClass("loading"); + gantt.alert({ type: "error", text: "Failed to set baseline activity" }); + } + gantt.render(); +} + +async function setBaselineAPI() { + await importUpdate(); + const res = await axiosInstance + .get(ACTIVITY_SET_BASELINE_URL, HEADER) + .then(res => res) + .catch((error) => error.response); + if (res && res.status === 200) { + // $('#modal_gantt_setting').modal('hide'); + // gantt.alert("Settings updated"); + // gantt.message(result.data.message); + gantt.message("Set baseline success!"); + window.location.reload(); + } + else { + $("body").removeClass("loading"); + gantt.alert({ type: "error", text: "Failed to set baseline" }); + } + gantt.render(); +} + +function setSynchronize() { + if (!isBaselineSet) { + // gantt.alert({ + // title:"Synchronize to Report", + // type:"alert-error", + // text:"Please set baseline before continue." + // }); + gantt.confirm({ + text: "Plase set baseline before continue.", + ok: "Set Baseline", + cancel: "Cancel", + callback: async function (result) { + if (result) { + await setBaselineAPI(); + } + } + }); + return false; + } + + var box = gantt.confirm({ + text: "Synchronize to Report Activity?", + ok: "Yes", + cancel: "No", + callback: async function (result) { + if (result) { + // gantt.message("Yes!"); + // send to API + await setSynchronizeAPI() + } else { + // gantt.message("No..."); + } + } + }); +} + +function updateSchedule() { + $("body").addClass("loading"); + return gantt.ajax.get({ + headers: { + "Content-Type": "application/json", + "Authorization": `Bearer ${token}` + }, + url: base_url + "activity/update-schedule/" + ganttId + }).then(function (response) { + $("body").removeClass("loading"); + window.location.reload(); + }).catch(function (error) { + $("body").removeClass("loading") + gantt.alert({ + title: "Peringatan", + type: "alert-error", + text: "Update activity gagal" + }); + }); +} + +async function setSynchronizeAPI() { + const res = await axiosInstance + .get(ACTIVITY_SYNCHRONIZE_REPORT_URL, HEADER) + .then(res => res) + .catch((error) => error.response); + + if (res && res.status === 200) { + // $('#modal_gantt_setting').modal('hide'); + // gantt.alert("Settings updated"); + // gantt.message(result.data.message); + gantt.message("Synchronize to Report success!"); + window.location.reload(); + } + else { + gantt.alert({ type: "error", text: "Failed to Synchronize to Report" }); + } + gantt.render(); +} diff --git a/edit-mode/index.html b/edit-mode/index.html index 50d5732..a175110 100644 --- a/edit-mode/index.html +++ b/edit-mode/index.html @@ -67,7 +67,7 @@
-
+
Zoom: