Page 1 of 2

[REACT] Preventing constraints from being added on event drag

Posted: Fri May 13, 2022 11:13 pm
by dcporter

In the Scheduler Pro when an event with no constraint is moved or resized, a constraint of startnoearlierthan is applied to the event. Is there a way to prevent this?


Re: [REACT] Preventing constraints from being added on event drag

Posted: Mon May 16, 2022 6:36 am
by alex.l

Hi dcporter,

We always need reasons to have event started in some specific date. If event has no dependencies or constraints, it will start with project's start date (In case of using default forward schedule direction). If there are dependencies, event start date will be calculated according to those constraints.
When you manually move an event on a TimeAxis, an algorithm applies constraints (reasons) to have that event in some specific date, independent of (or together with) dependencies. So, it applies constraint date.

Full description of events scheduling https://bryntum.com/docs/scheduler-pro/guide/engine/schedulerpro_events_scheduling

You could try to use another constraints, as example make your event manually scheduled https://bryntum.com/docs/scheduler-pro/api/SchedulerPro/model/EventModel#field-manuallyScheduled

Btw, I don't see any constraints applied after I resize an event. How exactly did you get constraint date applied after resizing?


Re: [REACT] Preventing constraints from being added on event drag

Posted: Wed May 18, 2022 9:26 pm
by dcporter

I'm not too sure I understand. It is currently possible to initialize the scheduler with an event that has a startDate and an endDate with no constraint.

Look at your demo here: https://bryntum.com/examples/scheduler-pro/constraints/

There are events in this demo that do not yet have any constraints on them. So clearly it is possible for an event to exist without any constraints. If I can initialize an event with no constraints, why can I not continue to leave it with no constraints after I move it?


Re: [REACT] Preventing constraints from being added on event drag

Posted: Thu May 19, 2022 5:35 am
by alex.l

When I said "constraints", I mean dependencies as well.
If event has no constraints, no dependencies, no parent tasks and calendars with non working intervals or other things that may affect on event, the event will always be starting with project's startDate.

Scheduling Engine by default using forward direction of the scheduling, this means events will be scheduled to be happen ASAP. It's fully described in the guide I mentioned https://bryntum.com/docs/scheduler-pro/guide/engine/schedulerpro_events_scheduling

This means, the event needs to have a reason why its startDate should not be changed by the Engine.


Re: [REACT] Preventing constraints from being added on event drag

Posted: Tue May 24, 2022 6:50 pm
by dcporter

I still don't quite understand. Based on what you're saying, if I change an event's constraint type to 'None', the event should move back to the project's startDate? This isn't the case. If I change the constraint type to 'None', the event is still placed on the event's startDate.


Re: [REACT] Preventing constraints from being added on event drag

Posted: Wed May 25, 2022 7:32 am
by arcady

What Alex described is 100% correct for the Gantt scheduling logic.
But Scheduler Pro logic has a twist: events that do not have any restrictions (constraints/incoming dependencies) just use their start/end dates as-is (well just taking working time into account).

So events having incoming dependencies fallback to their predecessors but events having no such dependencies just stay at their start/end dates.
When user changes an event start date (by dragging or cell editing) the Engine always enforces the change by setting a constraint which pins the event to a proper position regardless if it has or has no predecessors.


Re: [REACT] Preventing constraints from being added on event drag

Posted: Wed May 25, 2022 8:06 am
by dcporter

Thanks for the clarification. I have 2 questions:

When user changes an event start date (by dragging or cell editing) the Engine always enforces the change by setting a constraint which pins the event to a proper position regardless if it has or has no predecessors.

1) This is the part I was originally asking about. Is there a way to prevent this? I'd like to be able to move an event without a constraint being added. It seems like there's no logical reason against having this functionality right?

2) What is the difference between an event that has a constraint type of 'None' versus an event that has a blank constraint type? For example, in your constraints demo, there are events that have a blank constraint type (no thumbtack icon). Once a constraint is set on these events, there is no way to change back to an empty constraint type. Even when I set it to 'None', the thumbtack icon persists. Why is this?


Re: [REACT] Preventing constraints from being added on event drag

Posted: Wed May 25, 2022 9:43 am
by arcady

1) This is the part I was originally asking about. Is there a way to prevent this? I'd like to be able to move an event without a constraint being added. It seems like there's no logical reason against having this functionality right?

Yes, unless we talk about an event that has a predecessor and we drag it forward. Then the event needs a constraint otherwise it will fallback to the predecessor according to the dependency.

And in the Gantt it won't work completely since as Alex told the event will fallback to the project start.

Anyway you can override standard EventModel class to implement your custom logic.
The code that sets a constraint in such cases is located in HasDateConstraintMixin class (Engine/quark/model/scheduler_pro/HasDateConstraintMixin.ts file). Check writeStartDate and writeEndDate methods there:

        writeStartDate (me : Identifier, transaction : Transaction, quark : Quark, date : Date, keepDuration : boolean = true) {
            // get constraint type that should be used to enforce start date or
            // null if the change cannot be enforced (happens when the task is manually scheduled so no need for enforcement or
            // some constraint is already set)

            const project = this.getProject()

            // `writeStartDate` will be called for initial write to the `startDate` at the point of adding it to graph
            // at that time there possibly be no `direction` identifier yet
            // it seems this line relies on the fact, that `direction` field is declared after the `startDate`
            if (transaction.graph.hasIdentifier(this.$.direction) && !(project && project.getStm().isRestoring)) {
                const constrainType = this.getStartDatePinConstraintType()

                if (constrainType) {
                    this.constraintType = constrainType
                    this.constraintDate = date
                }
            }

            return superProto.writeStartDate.call(this, me, transaction, quark, date, keepDuration)
        }

So you can override the method to use any logic you want.

class MyEventModel extends EventModel {
    writeStartDate (me, transaction, quark, date, keepDuration) {
        ...
    }
}

new SchedulerPro({
    project : {
        eventModelClass : MyEventModel,

2) What is the difference between an event that has a constraint type of 'None' versus an event that has a blank constraint type? For example, in your constraints demo, there are events that have a blank constraint type (no thumbtack icon). Once a constraint is set on these events, there is no way to change back to an empty constraint type. Even when I set it to 'None', the thumbtack icon persists. Why is this?

The event bars seem not re-rendered when a constraint is reset. Looks like a bug. Here is a ticket for that: https://github.com/bryntum/support/issues/4675


Re: [REACT] Preventing constraints from being added on event drag

Posted: Thu Jun 09, 2022 8:24 pm
by dcporter

Can I put in a feature request to be able to turn off automatically adding startnoearlierthan when an event without a constraint is moved in the Scheduler Pro? I would prefer not to monkeypatch the writeStartDate function as seen in the comment above. I want to avoid difficult-to-debug side effects especially when upgrading versions.


Re: [REACT] Preventing constraints from being added on event drag

Posted: Fri Jun 10, 2022 12:07 pm
by arcady