Browse Source

View mode scroll fix

pull/1/head
Wahyu Ramadhan 1 year ago
parent
commit
91095287bd
  1. 30
      view-mode/function/function.js
  2. 30
      view-mode/function/ganttEvent.js
  3. 6
      view-mode/function/restActivityLink.js

30
view-mode/function/function.js

@ -522,3 +522,33 @@ function replaceAll(str, find, replace) {
}
return str
}
// Function to get the earliest planned start date among all tasks
function getEarliestTaskDate() {
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;
}

30
view-mode/function/ganttEvent.js

@ -98,3 +98,33 @@ gantt.attachEvent("onGanttRender", function(){
gantt.config.readonly = true;
}
});
gantt.attachEvent("onGanttScroll", function (left, top){
var left_date = gantt.dateFromPos(left)
var right_date = gantt.dateFromPos(left + gantt.$task.offsetWidth)
let taskCount = gantt.getTaskCount();
if (taskCount > 0) {
gantt.config.start_date = gantt.config.start_date || gantt.getState().min_date;
gantt.config.end_date = gantt.config.end_date || gantt.getState().max_date;
var min_allowed_date = gantt.date.add(gantt.config.start_date, 1, "day");
var max_allowed_date = gantt.date.add(gantt.config.end_date, -1, "day");
var repaint = false;
if (earliest && +left_date <= +min_allowed_date && +left_date >= +earliest){
gantt.config.start_date = gantt.date.add(gantt.config.start_date, -1, "day");
repaint = true;
}
if (latest && +right_date >= +max_allowed_date && +right_date <= +latest){
gantt.config.end_date = gantt.date.add(gantt.config.end_date, 1, "day");
repaint = true;
}
if (repaint) {
setTimeout(function(){
gantt.render()
},20)
}
}
});

6
view-mode/function/restActivityLink.js

@ -1,4 +1,6 @@
var parts = [];
let latest;
let earliest;
window.parent.postMessage({ action: 'getUrl' }, '*');
window.addEventListener('message', function(event) {
if (event.data && event.data.action === 'sendUrl') {
@ -40,6 +42,8 @@ gantt.ajax.get({
if(!parts[2]){
gantt.silent(function () {
gantt.parse(data);
earliest = getEarliestTaskDate();
latest = getLatestTaskDate();
});
}
});
@ -62,6 +66,8 @@ function refresData(id){
if(!parts[2]){
gantt.silent(function () {
gantt.parse(data);
earliest = getEarliestTaskDate();
latest = getLatestTaskDate();
});
}
if(id){

Loading…
Cancel
Save