From acd982a7ebf7ce60165103d1e1e3b2ffd97661a8 Mon Sep 17 00:00:00 2001 From: Wahyu Ramadhan Date: Fri, 21 Jul 2023 11:33:34 +0700 Subject: [PATCH] Add task open state --- edit-mode/function/function.js | 31 ++++++++++++++++++++++++++ edit-mode/function/ganttEvent.js | 8 +++++++ edit-mode/function/restActivityLink.js | 14 +++++++----- 3 files changed, 47 insertions(+), 6 deletions(-) diff --git a/edit-mode/function/function.js b/edit-mode/function/function.js index 9d9af19..c62e1b3 100644 --- a/edit-mode/function/function.js +++ b/edit-mode/function/function.js @@ -355,6 +355,37 @@ function initializationColumn() }); } +function setGanttOpen(){ + let ganttOpen = []; + gantt.eachTask(function (task) { + const existingIndex = ganttOpen.findIndex(item => item.id === task.id); + if (existingIndex !== -1) { + ganttOpen[existingIndex].open = task.$open; + } else { + ganttOpen.push({ + "id": task.id, + "open": task.$open + }); + } + }); + localStorage.setItem('ganttOpen', JSON.stringify(ganttOpen)); +} + +function getGanttOpen(){ + let ganttOpen = localStorage.getItem('ganttOpen'); + if (ganttOpen) { + // Parse the stored data into a JavaScript object + ganttOpen = JSON.parse(ganttOpen); + gantt.eachTask(function (task) { + const index = ganttOpen.findIndex(item => item.id == task.id); + if (index !== -1) { + task.$open = ganttOpen[index].open; + } else { + task.$open = false; + } + }); + } +} $(document).ready(function () { $("#critalPathBox").on("change", function (){ diff --git a/edit-mode/function/ganttEvent.js b/edit-mode/function/ganttEvent.js index 4a19431..8c7fd4e 100644 --- a/edit-mode/function/ganttEvent.js +++ b/edit-mode/function/ganttEvent.js @@ -117,3 +117,11 @@ gantt.attachEvent("onGanttRender", function(){ gantt.config.readonly = true; } }); + +gantt.attachEvent("onTaskOpened", function (id) { + setGanttOpen() +}); + +gantt.attachEvent("onTaskClosed", function (id) { + setGanttOpen() +}); \ No newline at end of file diff --git a/edit-mode/function/restActivityLink.js b/edit-mode/function/restActivityLink.js index 7a1115c..8b39953 100644 --- a/edit-mode/function/restActivityLink.js +++ b/edit-mode/function/restActivityLink.js @@ -27,9 +27,10 @@ gantt.ajax.get({ "geom": element.geom }) }); - gantt.silent(function () { - gantt.parse(data); - }); + gantt.silent(function () { + gantt.parse(data); + getGanttOpen(); + }); if (Date.now() < timestamp) { gantt.ajax.post({ headers: { @@ -78,9 +79,10 @@ function refresData(id){ "geom": element.geom }) }); - gantt.silent(function () { - gantt.parse(data); - }); + gantt.silent(function () { + gantt.parse(data); + getGanttOpen(); + }); if(id){ if(gantt.isTaskExists(id)){ expandTask();