v7.3.0
SupportExamplesFree Trial

ProjectModel

Scheduler Pro Project model class - a central place for all data.

It holds and links the stores usually used by Scheduler Pro:

The project uses a scheduling engine to calculate dates, durations and such. 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 Pro UI but which you must know about when performing 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 flow illustrates 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

Please refer to this guide for more information.

Built-in CrudManager

Scheduler Pro's project has a CrudManager built-in. Using it is the recommended way of syncing data between Scheduler Pro and a backend. Example usage:

const scheduler = new SchedulerPro({
    project : {
        // Configure urls used by the built-in CrudManager
        transport : {
            load : {
                url : 'php/load.php'
            },
            sync : {
                url : 'php/sync.php'
            }
        }
    }
});

// Load data from the backend scheduler.project.load()

URLs may also be specified using shortcut configs:

const scheduler = new SchedulerPro({
    project : {
        loadUrl : 'php/load.php'
        syncUrl : 'php/sync.php'
    }
});

scheduler.project.load()

For more information on CrudManager, see Schedulers docs on CrudManager. For a detailed description of the protocol used by CrudManager, see the Crud manager guide

You can access the current Project data changes anytime using the changes property.

Working with inline data

The project provides an inlineData getter/setter that can be used to manage data from all Project stores at once. Populating the stores this way can be useful if you do not want to use the CrudManager for server communication but instead load data using Axios or similar.

Getting data

const data = scheduler.project.inlineData;

// use the data in your application

You can read the inline data by console.log(scheduler.project.inlineData);:

{
    "calendars": [],
    "events": [
        {
            "id": 1,
            "startDate": "2020-03-23T07:00:00+05:00",
        },
        {
            "id": 2,
            "startDate": "2020-03-23T11:00:00+05:00",
        }
    ],
    "resources": [
        {
            "id": 1,
            "parentId": null,
            "name": "George",
            "eventColor": "blue",
        },
        {
            "id": 2,
            "parentId": null,
            "name": "Rob",
            "eventColor": "blue",
        }
    ],
    "assignments": [
        { id : 1, resource : 1, event : 1 },
        { id : 2, resource : 2, event : 1 },
        { id : 3, resource : 1, event : 2 },
    ],
    "dependencies": [
        {
            "id": 1,
            "type": 2,
            "cls": "",
            "lag": 0,
            "lagUnit": "day",
            "fromEvent": 1,
            "toEvent": 2,
            "active": true
        }
    ],
    "timeRanges": [],
    "resourceTimeRanges": [],
    "project": {
        "expanded": true,
        "hoursPerDay": 24,
        "daysPerWeek": 7
    }
}

The xxData properties are deprecated and will be removed in the future. Use xx instead. For example eventsData is deprecated, use events instead. For now, both naming schemes are included in the data object

Setting data

// Get data from server manually
const data = await axios.get('/project?id=12345');

// Feed it to the project scheduler.project.inlineData = data;

It should have the following structure:

scheduler.project.loadInlineData = {
  resources: [
    {
      id   : 1,
      name : 'George',
      type : 'Operators',
    },
    {
      id   : 2,
      name : 'Rob',
      type : 'Operators',
    },
    {
      id   : 3,
      name : 'Mike',
      type : 'Main'
    },
  ],
  events: [
    {
      id           : 1,
      name         : 'Meeting',
      startDate    : '2020-03-23T07:00',
      duration     : 4,
      durationUnit : 'hour',
      percentDone  : 100,
    },
    {
      id           : 2,
      startDate    : '2020-03-23T11:00',
      name         : 'Get parts',
      durationUnit : 'hour',
      duration     : 3,
      percentDone  : 40,
    },
  ],
  assignment : [
      { id : 1, resource : 1, event : 1 },
      { id : 2, resource : 2, event : 1 },
      { id : 3, resource : 2, event : 2 },
      { id : 4, resource : 3, event : 2 },
  ],
  dependencies: [
    {
      id        : 1,
      fromEvent : 1,
      toEvent   : 2
    },
  ],
};

You can also use loadInlineData() function:

scheduler.project.loadInlineData({
   resources    : [],
   events       : [],
   dependencies : []
})

Either you can pass the response in this format directly:

{
     resource     : [],
     events       : [],
     dependencies : []
}

Or you can modify the response once received and pass it to the loadInlineData() function or assign it to inlineData.

See also loadInlineData

The xxData properties are deprecated and will be removed in the future. Use xx instead. For example eventsData is deprecated, use events instead. For now, both naming schemes are included in the data object

Getting changed records

You can access the changes in the current Project dataset anytime using the changes property. It returns an object with all changes:

const changes = project.changes;

console.log(changes);

The changes object has the following structure:

{
  events : {
      updated : [{
          name : 'My task',
          id   : 12
      }]
  },
  assignments : {
      added : [{
          event      : 12,
          resource   : 7,
          units      : 100,
          $PhantomId : 'abc123'
      }]
    }
};

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 SchedulerPro({
    project: {
        listeners : {
            change({ store, action, records }) {
                const { $name } = store.constructor;

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

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

Processing the data loaded from the server

If you want to process the data received from the server after loading, you can use the beforeLoadApply or beforeSyncApply events:

const gantt = new Gantt({
    project: {
        listeners : {
            beforeLoadApply({ response }) {
                // do something with load-response object before data is fed to the stores
            }
        }
    }
});

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). By default, it is only used while editing tasks using the task editor, the editor updates tasks live and uses STM to rollback changes if canceled. But you can enable it to track all project store changes:

// Enable automatic transaction creation and start recording
project.stm.autoRecord = true;
project.stm.enable();

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

// Redo project.stm.redo();

Check out the undoredo demo to see it in action.

Useful configs

Config Description
calendar The project calendar
hoursPerDay Hours per day for duration conversion
silenceInitialCommit Silence propagation on data load
maxCalendarRange Max range for calendar iteration
enableProgressNotifications Enable calculation progress events
delayCalculation Postpone calculations for early paint

See also

No results

Fields

Fields belong to a Model class and define the Model data structure
  • true to enable automatic % done calculation for summary tasks, false to disable it.

  • When true (default) adjacent or overlapping event segments get merged automatically.

  • The project calendar.

  • dependenciesCalendar : 'ToEvent'/'FromEvent'/'Project''ToEvent'

    The source of the calendar for dependencies (the calendar used for taking dependencies lag into account). Possible values are:

    • ToEvent - successor calendar will be used (default);
    • FromEvent - predecessor calendar will be used;
    • Project - the project calendar will be used.

Configs

Configs are options you supply in a configuration object when creating an instance of this class
  • Set to true to reset the undo/redo queues of the internal StateTrackingManager after the Project has loaded. Defaults to false

  • Configuration options to provide to the STM manager

    Has a corresponding runtime stm property.

  • true to automatically persist store changes after edits are made in any of the stores monitored. Please note that sync request will not be invoked immediately but only after autoSyncTimeout interval.

  • The timeout in milliseconds to wait before persisting changes to the server. Used when autoSync is set to true.

  • Configuration of the JSON encoder used by the Crud Manager.

    • requestData : Object

      Static data to send with the data request.

      new CrudManager({
          // add static "foo" property to all requests data
          encoder : {
              requestData : {
                  foo : 'Bar'
              }
          },
          ...
      });
      

      The above snippet will result adding "foo" property to all requests data:

          {
              "requestId"   : 756,
              "type"        : "load",
      
              "foo"         : "Bar",
      
              "stores"      : [
                  ...
      
  • Specify as true to force sync requests to be sent when calling sync(), even if there are no local changes. Useful in a polling scenario, to keep client up to date with the backend.

    Has a corresponding runtime forceSync property.

  • Set to true to make STM ignore changes coming from the backend. This will allow user to only undo redo local changes.

    Has a corresponding runtime ignoreRemoteChangesInSTM property.

  • Field name to be used to transfer a phantom record identifier.

  • Field name to be used to transfer a phantom parent record identifier.

  • True to reset identifiers (defined by idField config) of phantom records before submitting them to the server.

  • When true treats parsed responses without success property as successful. In this mode a parsed response is treated as invalid if it has explicitly set success : false.

  • If true, project changes API will also report project model changes: start/end date, calendar, effort, duration, etc.

    Has a corresponding runtime trackProjectModelChanges property.

  • When true forces the CRUD manager to process responses depending on their type attribute. So load request may be responded with sync response for example. Can be used for smart server logic allowing the server to decide when it's better to respond with a complete data set (load response) or it's enough to return just a delta (sync response).

  • true to write all fields from the record to the server. If set to false it will only send the fields that were modified. Note that any fields that have persist set to false will still be ignored and fields having alwaysWrite set to true will always be included.

  • Internal listeners, that cannot be removed by the user.

  • Data use to fill the assignmentStore. Should be an array of AssignmentModels or its configuration objects.

    Has a corresponding runtime assignments property.

  • Data use to fill the eventStore. Should be a CalendarModel array or its configuration objects.

    Has a corresponding runtime calendars property.

  • Data use to fill the dependencyStore. Should be an array of DependencyModels or its configuration objects.

    Has a corresponding runtime dependencies property.

  • Data use to fill the eventStore. Should be an array of EventModels or its configuration objects.

    Has a corresponding runtime events property.

  • Data use to fill the resourceTimeRangeStore. Should be an array of ResourceTimeRangeModels or its configuration objects.

    Has a corresponding runtime resourceTimeRanges property.

  • Data use to fill the resourceStore. Should be an array of ResourceModels or its configuration objects.

    Has a corresponding runtime resources property.

  • Data use to fill the timeRangeStore. Should be an array of TimeSpans or its configuration objects.

    Has a corresponding runtime timeRanges property.

  • The number of Resource records each page should contain, when using remotePaging

  • Deprecated:

    6.3.0 Use assignments instead

    The initial data, to fill the assignmentStore with. Should be an array of AssignmentModels or its configuration objects.

  • The initial data, to fill the calendarManagerStore with. Should be an array of CalendarModel or its configuration objects.

  • Deprecated:

    6.3.0 Use dependencies instead

    The initial data, to fill the dependencyStore with. Should be an array of DependencyModels or its configuration objects.

  • eventsData : EventModel[]
    DEPRECATED
    Deprecated:

    6.3.0 Use events instead

    The initial data, to fill the eventStore with. Should be an array of EventModels or its configuration objects.

  • Deprecated:

    6.3.0 This config will be removed when the eventsData, resourcesData etc. properties are removed in a future release.

    Whether to include legacy data properties in the JSON / inlineData output. The legacy data properties are the xxData (eventsData, resourcesData etc.) properties that are deprecated and will be removed in the future.

    Has a corresponding runtime includeLegacyDataProperties property.

  • Deprecated:

    6.3.0 Use resourceTimeRanges instead

    The initial data, to fill the resourceTimeRangeStore with. Should be an array of ResourceTimeRangeModel or it's configuration objects.

  • Deprecated:

    6.3.0 Use resources instead

    The initial data, to fill the resourceStore with. Should be an array of ResourceModels or its configuration objects.

  • Deprecated:

    6.3.0 Use timeRanges instead

    The initial data, to fill the timeRangeStore with. Should be an array of TimeSpan or its configuration objects.

  • The constructor of the assignment model class, to be used in the project. Will be set as the modelClass property of the assignmentStore

  • An AssignmentStore instance or a config object.

    Has a corresponding runtime assignmentStore property.

  • The constructor to create an assignment store instance with. Should be a class, subclassing the AssignmentStore

  • A CalendarManagerStore instance or a config object.

    Has a corresponding runtime calendarManagerStore property.

  • The constructor to create a calendar store instance with. Should be a class, subclassing the CalendarManagerStore

  • The constructor of the calendar model class, to be used in the project. Will be set as the modelClass property of the calendarManagerStore

  • The constructor of the dependency model class, to be used in the project. Will be set as the modelClass property of the dependencyStore

  • A DependencyStore instance or a config object.

    Has a corresponding runtime dependencyStore property.

  • The constructor to create a dependency store instance with. Should be a class, subclassing the DependencyStore

  • The constructor of the event model class, to be used in the project. Will be set as the modelClass property of the eventStore

  • An EventStore instance or a config object.

    Has a corresponding runtime eventStore property.

  • The constructor to create an event store instance with. Should be a class, subclassing the EventStore

  • Class implementing resource allocation report used by resource histogram and resource utilization views for collecting resource allocation.

  • The constructor of the resource model class, to be used in the project. Will be set as the modelClass property of the resourceStore

  • A ResourceStore instance or a config object.

    Has a corresponding runtime resourceStore property.

  • The constructor to create a resource store instance with. Should be a class, subclassing the ResourceStore

  • A ResourceTimeRangeStore instance or a config object.

    Has a corresponding runtime resourceTimeRangeStore property.

  • The constructor to create a resource time range store instance with. Should be a class subclassing the ResourceTimeRangeStore

  • An EventStore instance or a config object.

  • A Store instance or a config object.

    Has a corresponding runtime timeRangeStore property.

  • The constructor to create a time range store instance with. Should be a class subclassing the TimeRangeStore

Properties

Properties are getters/setters or publicly accessible variables on this class
  • Identifies an object as an instance of AbstractCrudManagerMixin class, or subclass thereof.
  • Identifies an object as an instance of AbstractCrudManagerValidation class, or subclass thereof.
  • isAjaxTransport : Booleantrue
    READONLY
    static
    ADVANCED
    AjaxTransport
    Identifies an object as an instance of AjaxTransport class, or subclass thereof.
  • isDelayable : Booleantrue
    READONLY
    static
    ADVANCED
    Delayable
    Identifies an object as an instance of Delayable class, or subclass thereof.
  • isEvents : Booleantrue
    READONLY
    static
    ADVANCED
    Events
    Identifies an object as an instance of Events class, or subclass thereof.
  • isJsonEncoder : Booleantrue
    READONLY
    static
    ADVANCED
    JsonEncoder
    Identifies an object as an instance of JsonEncoder class, or subclass thereof.
  • isLazyLoadCrudManager : Booleantrue
    READONLY
    static
    ADVANCED
    LazyLoadCrudManager
    Identifies an object as an instance of LazyLoadCrudManager class, or subclass thereof.
  • isPartOfProject : Booleantrue
    READONLY
    static
    ADVANCED
    PartOfProject
    Identifies an object as an instance of PartOfProject class, or subclass thereof.
  • Identifies an object as an instance of ProjectChangeHandlerMixin class, or subclass thereof.
  • isProjectCrudManager : Booleantrue
    READONLY
    static
    ADVANCED
    ProjectCrudManager
    Identifies an object as an instance of ProjectCrudManager class, or subclass thereof.
  • isProjectModel : Booleantrue
    READONLY
    static
    ADVANCED
    Identifies an object as an instance of ProjectModel class, or subclass thereof.
  • isProjectModelCommon : Booleantrue
    READONLY
    static
    ADVANCED
    ProjectModelCommon
    Identifies an object as an instance of ProjectModelCommon class, or subclass thereof.
  • Identifies an object as an instance of ProjectModelTimeZoneMixin class, or subclass thereof.
  • Identifies an object as an instance of ProjectRevisionHandlerMixin class, or subclass thereof.
  • Returns the data from all CrudManager crudStores in a format that can be consumed by inlineData.

  • Enables/disables the calculation progress notifications.

    Has a corresponding enableProgressNotifications config.

  • State tracking manager instance the project relies on

    Has a corresponding stm config.

  • The server revision stamp. The revision stamp is a number which should be incremented after each server-side change. This property reflects the current version of the data retrieved from the server and gets updated after each load and sync call.

  • A list of registered stores whose server communication will be collected into a single batch. Each store is represented by a store descriptor.

    Has a corresponding crudStores config.

  • Specify as true to force sync requests to be sent when calling sync(), even if there are no local changes. Useful in a polling scenario, to keep client up to date with the backend.

    Has a corresponding forceSync config.

  • Set to true to make STM ignore changes coming from the backend. This will allow user to only undo redo local changes.

    Has a corresponding ignoreRemoteChangesInSTM config.

  • Returns true if changes tracking is suspended

  • Returns true if the crud manager is currently loading data

  • Returns true if the crud manager is currently syncing data

  • Generates unique request identifier.

  • An array of stores presenting an alternative sync responses apply order. Each store is represented by a store descriptor.

    Has a corresponding syncApplySequence config.

  • If true, project changes API will also report project model changes: start/end date, calendar, effort, duration, etc.

    Has a corresponding trackProjectModelChanges config.

  • isProjectModel : Booleantrue
    READONLY
    ADVANCED
    Identifies an object as an instance of ProjectModel class, or subclass thereof.
  • Identifies an object as an instance of ProjectModelMixin class, or subclass thereof.
  • If set to true, or a config object, this makes the CrudManager load records only when needed. When a record or a date range that is not already loaded is requested, a load request will be made to the specified URL. More more details about lazy loading, see the guide

    Has a corresponding lazyLoad config.

  • Deprecated:

    6.3.0 This config will be removed when the eventsData, resourcesData etc. properties are removed in a future release.

    Whether to include legacy data properties in the JSON / inlineData output. The legacy data properties are the xxData (eventsData, resourcesData etc.) properties that are deprecated and will be removed in the future.

    Has a corresponding includeLegacyDataProperties config.

Functions

Functions are methods available for calling on the class
  • Accepts all changes in all stores, resets the modification tracking:

    • Clears change tracking for all records
    • Clears added
    • Clears modified
    • Clears removed Leaves the store in an "unmodified" state.
  • Reverts all changes in all stores and re-inserts any records that were removed locally. Any new uncommitted records will be removed.

  • Suspends automatic sync upon store changes. Can be called multiple times (it uses an internal counter).

  • Suspends hasChanges and noChanges events.

  • Internal function used to hook destroy() calls when using thisObj

  • Internal function used restore hooked destroy() calls when using thisObj

  • doDestroy( )
    internal
    Events

    Auto detaches listeners registered from start, if set as detachable

  • once( )
    private
    Events

    Internal function used to run a callback function after an event is triggered

  • Removes all listeners registered to this object by the application.

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