Our state of the art Gantt chart


Post by isadogan »

Hi,

I want to show a warning message when the user planned the same resource for different tasks on the same dates as 100%.

Here is the scenario:

Task : Demo Task 1
Planned Resource : İsa (100%) between 03.29.2023 - 03.30.2023

Another Task : Demo Task 2
Planned Resource : İsa (100%) between 03.29.2023 - 03.30.2023

Any way to do this?

Thanks


Post by Animal »

You could write a function which interrogates the EventStore using public APIs to answer the question.

https://www.bryntum.com/products/scheduler/docs/api/Scheduler/data/EventStore#function-getEventsForResource

https://www.bryntum.com/products/scheduler/docs/api/Core/helper/DateHelper#function-intersectSpans-static

    /**
     * Returns an array of events for the passed resource which overlap the time range passed.
     * @param {Date} start The start date
     * @param {Date} end The end date
     * @param {Scheduler.model.EventModel|null} excludeEvent An event to exclude from the check (or null)
     * @param {Scheduler.model.ResourceModel|Scheduler.model.ResourceModel[]} resourceRecords The resources(s) to check.
     * @return {Scheduler.model.EventModel[]} The events for the resource which overlap the time range
     */
    function getConflictingEvents(eventStore, start, end, excludeEvent, resourceRecords) {
        
        if (!Array.isArray(resourceRecords)) {
            resourceRecords = [resourceRecords];
        }

        // This should be an array of unique event records
        const allEvents = [];

        // Collect all events assigned to the resource(s)
        for (let i = 0, { length } = resourceRecords; i < length; i++) {
            allEvents.push(...eventStore.getEventsForResource(resourceRecords[i], excludeEvent));
        }

        // return all the events which overlap the "start"->"end" range
        return [...new Set(allEvents)].reduce((result, event) => {
            if (event.isScheduled && DateHelper.intersectSpans(start, end, event.startDate, event.endDate)) {
                result.push(event);
            }
            return result;
        }, []);
    }

Disclaimer. This is just suggested code. You may write something similar in your application.


Post by isadogan »

I'll try it. Thank you for your quick response Animal.


Post Reply