bryntum / support

An issues-only repository for the Bryntum project management component suite which includes powerful Grid, Scheduler, Calendar, Kanban Task Board and Gantt chart components all built in pure JS / CSS / TypeScript
https://www.bryntum.com
54 stars 6 forks source link

Add a config to allow project start date to track the real earliest start date of all tasks #2274

Open pmiklashevych opened 3 years ago

pmiklashevych commented 3 years ago

Requested here: https://www.bryntum.com/forum/viewtopic.php?p=81782#p81782 https://www.bryntum.com/forum/viewtopic.php?p=81852#p81852

Testcase: Gantt/examples/_datasets/launch-saas.json

    "project" : {
        "calendar"     : "general",
        "hoursPerDay"  : 24,
        "daysPerWeek"  : 5,
        "daysPerMonth" : 20
    },
    "tasks" : {
        "rows" : [
            {
                "id": 1000,
                "name": "Launch SaaS Product",
                "percentDone": 50,
                "startDate": "2019-01-14",
                "expanded": true,
                "children": [
                    {
                        "id": 1,
                        "name": "Setup web server",
                        "percentDone": 50,
                        "duration": 10,
                        "constraintType": "startnoearlierthan",
                        "constraintDate": "2019-02-03",
                        "startDate": "2019-02-03",
                        "rollup": true
                    }
                ]
            }
        ]
    },

Run in console:

gantt.project.startDate
// Mon Jan 14 2019 00:00:00 GMT+0300 (GMT+03:00)

Expect it to be Mon Feb 04 2019 00:00:00 GMT+0300 (GMT+03:00) as the earliest start date among the tasks

NOT A BUG, since project start date is required to be passed to perform calculations. We take it as the earliest SPECIFIED date in the data. Not calculated date. And then we never update the project start date automatically.

Снимок экрана 2021-01-22 в 12 24 48
pmiklashevych commented 3 years ago

As a workaround users can update the project start date manually:

const calcStartDate = taskStore => {
    let startDate = taskStore.getTotalTimeSpan().endDate;

    if (startDate) {
        taskStore.forEach(task => {
            if (task.startDate.getTime() <= startDate.getTime()) {
                startDate = task.startDate;
            }
        });
    }

    return startDate;
};

gantt.project.on({
    dataReady : () => {
        const startDate = calcStartDate(gantt.taskStore);

        if (startDate && (startDate.getTime() !== gantt.project.startDate?.getTime())) {
            console.log('Project start date is updated');
            gantt.project.startDate = startDate;
        }
    }
});