v7.3.0

ProjectModel

This class represents a global project of your Scheduler - a central place for all data.

It holds and links the stores usually used by Scheduler:

The project uses a calculation engine to normalize dates and durations. It is also responsible for handling references between models, for example to link an event via an assignment to a resource. These operations are asynchronous, a fact that is hidden when working in the Scheduler UI but which you must know about when performing more advanced operations on the data level.

When there is a change to data that requires something else to be recalculated, the project schedules a calculation (a commit) which happens moments later. It is also possible to trigger these calculations directly. This snippet illustrate the process:

  1. Something changes which requires the project to recalculate, for example adding a new task:
const [event] = project.eventStore.add({ startDate, endDate });
  1. A recalculation is scheduled, thus:
event.duration; // <- Not yet calculated
  1. Calculate now instead of waiting for the scheduled calculation
await project.commitAsync();

event.duration; // <- Now available

Using inline data

The project provides settable property inlineData that can be used to get data from all its stores at once and to set this data as well. Populating the stores this way can be useful if you cannot or you do not want to use CrudManager for server requests but you pull the data by other means and have it ready outside of ProjectModel. Also, the data from all stores is available in a single assignment statement.

Getting data

const data = scheduler.project.inlineData;

// use the data in your application

Setting data

const data = // your function to pull server data

scheduler.project.inlineData = data;

Monitoring data changes

While it is possible to listen for data changes on the projects individual stores, it is sometimes more convenient to have a centralized place to handle all data changes. By listening for the change event your code gets notified when data in any of the stores changes. Useful for example to keep an external data model up to date:

const scheduler = new Scheduler({
    project: {
        listeners : {
            change({ store, action, records }) {
                const { $name } = store.constructor;

if (action === 'add') { externalDataModel.add($name, records); }

if (action === 'remove') { externalDataModel.remove($name, records); } } } } });

Built-in StateTrackingManager

The project also has a built-in StateTrackingManager (STM for short), that handles undo/redo for the project stores (additional stores can also be added). You can enable it to track all project store changes:

// Turn on auto recording when you create your Scheduler:
const scheduler = new Scheduler({
   project : {
       stm : {
           autoRecord : true
       }
   }
});

// Undo a transaction project.stm.undo();

// Redo project.stm.redo();

Check out the undoredo demo to see it in action.

No results

Configs

Configs are options you supply in a configuration object when creating an instance of this class

Properties

Properties are getters/setters or publicly accessible variables on this class

Functions

Functions are methods available for calling on the class

    Events

    Events are triggered for certain actions in this class and can be listened for to react to those actions in your code

    Event handlers

    Event handlers are callbacks called as a result of certain actions in this class

    Source path

    Scheduler/model/ProjectModel.js

    Contents