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.

Configs

31

Advanced

silenceInitialCommit: Boolean= true

Silences propagations caused by the project loading.

Applying the loaded data to the project occurs in two basic stages:

  1. Data gets into the engine graph which triggers changes propagation
  2. The changes caused by the propagation get written to related stores

Setting this flag to true makes the component perform step 2 silently without triggering events causing reactions on those changes (like sending changes back to the server if autoSync is enabled) and keeping stores in unmodified state.

This is safe if the loaded data is consistent so propagation doesn't really do any adjustments. By default the system treats the data as consistent so this option is true.

new Scheduler({
    project : {
        // We want scheduling engine to recalculate the data properly
        // so then we could save it back to the server
        silenceInitialCommit : false
    }
    ...
})

Configuration options to provide to the STM manager

Inline data

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

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

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

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

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

Legacy inline data

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

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

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

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

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

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

Models & Stores

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

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

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

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

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

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

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

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

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

Other

adjustDurationToDST: Boolean= false

A flag, indicating whether the dates and duration calculations should adjust the result to DST time shift.

Properties

76

Advanced

State tracking manager instance the project relies on

Class hierarchy

isProjectModel: Boolean= truereadonly
Identifies an object as an instance of ProjectModel class, or subclass thereof.
isProjectModel: Boolean= truereadonlystatic
Identifies an object as an instance of ProjectModel class, or subclass thereof.
Identifies an object as an instance of ProjectModelMixin class, or subclass thereof.
isProjectModelMixin: Boolean= truereadonlystaticProjectModelMixin
Identifies an object as an instance of ProjectModelMixin class, or subclass thereof.
isModelModel
isModelLinkModelLink
isModelStmModelStm
isTreeNodeTreeNode

Inline data

Get/set assignmentStore data.

Always returns an array of AssignmentModels but also accepts an array of its configuration objects as input.

Get/set dependencyStore data.

Always returns an array of DependencyModels but also accepts an array of its configuration objects as input.

Get/set eventStore data.

Always returns an array of EventModels but also accepts an array of its configuration objects as input.

Get/set resourceStore data.

Always returns an array of ResourceModels but also accepts an array of its configuration objects as input.

Get/set resourceTimeRangeStore data.

Always returns an array of ResourceTimeRangeModels but also accepts an array of its configuration objects as input.

Get/set timeRangeStore data.

Always returns an array of TimeRangeModels but also accepts an array of its configuration objects as input.

Models & Stores

The store holding the assignments information.

See also AssignmentModel

The store holding the dependencies information.

See also DependencyModel

The store holding the events information.

See also EventModel

The store holding the resources that can be assigned to the events in the event store.

See also ResourceModel

The store holding the time ranges information.

See also TimeSpan

Editing

copyOfModel
isValidModel

Fields

allFieldsstaticModel
autoExposeFieldsstaticModel
childrenFieldstaticModel
defaultsstaticModel
fieldMapstaticModel
fieldsstaticModel
idFieldstaticModel

Grouping

Identification

keyModel

JSON

jsonModel

Lifecycle

configBase

Linked records

hasLinksModelLink
isLinkedModelLink
recordLinksModelLink

Misc

Other

$namestaticModel
relationsstaticModel

Parent & children

allChildrenTreeNode
childLevelTreeNode
firstChildTreeNode
isLeafTreeNode
isLoadedTreeNode
isParentTreeNode
isRootTreeNode
lastChildTreeNode
nextSiblingTreeNode
parentTreeNode
parentIdTreeNode

Functions

56

Common

Project changes (CRUD operations to records in its stores) are automatically committed on a buffer to the underlying graph based calculation engine. The engine performs it calculations async.

By calling this function, the commit happens right away. And by awaiting it you are sure that project calculations are finished and that references between records are up to date.

The returned promise is resolved with an object. If that object has rejectedWith set, there has been a conflict and the calculation failed.

// Move an event in time
eventStore.first.shift(1);

// Trigger calculations directly and wait for them to finish
const result = await project.commitAsync();

if (result.rejectedWith) {
    // there was a conflict during the scheduling
}

Inline data

Accepts a "data package" consisting of data for the projects stores, which is then loaded into the stores.

The package can hold data for EventStore, AssignmentStore, ResourceStore, DependencyStore, TimeRangeStore and ResourceTimeRangeStore. It uses the same format as when creating a project with inline data:

await project.loadInlineData({
    events : [
        { id : 1, name : 'Proof-read docs', startDate : '2017-01-02', endDate : '2017-01-09' },
        { id : 2, name : 'Release docs', startDate : '2017-01-09', endDate : '2017-01-10' }
    ],
    resources : [
        { id : 1, name : 'Arcady' },
        { id : 2, name : 'Don' }
    ],
    dependencies : [
        { fromEvent : 1, toEvent : 2 }
    ],
    assignments : [
         { 'event' : 1, 'resource' : 1 },
         { 'event' : 2, 'resource' : 2 }
     ],
    resourceTimeRanges : [
        { id : 1, name : 'Resource range', resourceId : 1, startDate : '2017-01-08', endDate : '2017-01-10' }
    ],
    timeRanges : [
         { id : 1, startDate : '2017-01-26', name : 'Cool line' }
    ]
});

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

After populating the stores it commits the project, starting its calculations. By awaiting loadInlineData() you can be sure that project calculations are finished.

ParameterTypeDescription
dataPackageObject

A data package as described above

Configuration

applyDefaultsstaticBase

Editing

copyModel
getDataModel
removeModel
setModel

Events

Fields

addFieldstaticModel
getModel
processFieldstaticModel
removeFieldstaticModel

Identification

asIdstaticModel
generateIdstaticModel

JSON

toJSONModel

Lifecycle

destroystaticBase

Misc

equalsModel
initClassstaticBase
isOfTypeNamestaticBase
linkModelLink
mixinstaticBase

Other

Parent & children

appendChildTreeNode
bubbleTreeNode
bubbleWhileTreeNode
containsTreeNode
insertChildTreeNode
isExpandedTreeNode
removeChildTreeNode
traverseTreeNode

Events

2

Fired when data in any of the projects stores changes.

Basically a relayed version of each stores own change event, decorated with which store it originates from. See the store change event documentation for more information.

// Adding a listener using the "on" method
projectModel.on('change', ({ source, store, action, record, records, changes }) => {

});
ParameterTypeDescription
sourceProjectModel

This project

storeStore

Affected store

actionremove | removeAll | add | clearchanges | filter | update | dataset | replace

Name of action which triggered the change. May be one of:

  • 'remove'
  • 'removeAll'
  • 'add'
  • 'clearchanges'
  • 'filter'
  • 'update'
  • 'dataset'
  • 'replace'
recordModel

Changed record, for actions that affects exactly one record ('update')

recordsModel[]

Changed records, passed for all actions except 'removeAll'

changesObject

Passed for the 'update' action, info on which record fields changed

Fired when the engine has finished its calculations and the results has been written back to the records.

scheduler.project.on({
    dataReady() {
       console.log('Calculations finished');
    }
});

scheduler.eventStore.first.duration = 10;

// At some point a bit later it will log 'Calculations finished'
// Adding a listener using the "on" method
projectModel.on('dataReady', ({ source, isInitialCommit, records }) => {

});
ParameterTypeDescription
sourceProjectModel

The project

isInitialCommitBoolean

Flag that shows if this commit is initial

recordsSet

Set of all Models that were modified in the completed transaction. Use the modifications property of each Model to identify modified fields.

Event handlers

2

Called when data in any of the projects stores changes.

Basically a relayed version of each stores own change event, decorated with which store it originates from. See the store change event documentation for more information.

new ProjectModel({
    onChange({ source, store, action, record, records, changes }) {

    }
});
ParameterTypeDescription
sourceProjectModel

This project

storeStore

Affected store

actionremove | removeAll | add | clearchanges | filter | update | dataset | replace

Name of action which triggered the change. May be one of:

  • 'remove'
  • 'removeAll'
  • 'add'
  • 'clearchanges'
  • 'filter'
  • 'update'
  • 'dataset'
  • 'replace'
recordModel

Changed record, for actions that affects exactly one record ('update')

recordsModel[]

Changed records, passed for all actions except 'removeAll'

changesObject

Passed for the 'update' action, info on which record fields changed

Called when the engine has finished its calculations and the results has been written back to the records.

scheduler.project.on({
    dataReady() {
       console.log('Calculations finished');
    }
});

scheduler.eventStore.first.duration = 10;

// At some point a bit later it will log 'Calculations finished'
new ProjectModel({
    onDataReady({ source, isInitialCommit, records }) {

    }
});
ParameterTypeDescription
sourceProjectModel

The project

isInitialCommitBoolean

Flag that shows if this commit is initial

recordsSet

Set of all Models that were modified in the completed transaction. Use the modifications property of each Model to identify modified fields.

Typedefs

1