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:
- Something changes which requires the project to recalculate, for example adding a new task:
const [event] = project.eventStore.add({ startDate, endDate });
- A recalculation is scheduled, thus:
event.duration; // <- Not yet calculated
- 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.
Fields
Fields belong to a Model class and define the Model data structure-
Start expanded or not (only valid for tree data)
-
This is a read-only field provided in server synchronization packets to specify which position the node takes in the parent's ordered children array. This index is set on load and gets updated on reordering nodes in tree. Sorting and filtering have no effect on it.
-
Deprecated:
This field has been deprecated. Please read the guide to find out if your app needs to use the new isFullyLoaded field.
This field is added to the class at runtime when the Store is configured with lazyLoad. The number specified should reflect the total amount of children of a parent node, including nested descendants.
Configs
Configs are options you supply in a configuration object when creating an instance of this class-
A flag, indicating whether the dates and duration calculations should adjust the result to DST time shift.
-
Configuration options to provide to the STM manager
Has a corresponding runtime stm property.
-
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 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 TimeRangeModels or its configuration objects.
Has a corresponding runtime timeRanges property.
-
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.
-
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.
-
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,resourcesDataetc.) 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
-
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
-
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
-
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 ModelLink class, or subclass thereof.
-
Identifies an object as an instance of ModelStm class, or subclass thereof.
-
Identifies an object as an instance of ProjectModel class, or subclass thereof.
-
Identifies an object as an instance of ProjectModelCommon class, or subclass thereof.
-
Identifies an object as an instance of ProjectModelMixin class, or subclass thereof.
-
Identifies an object as an instance of ProjectModelTimeZoneMixin class, or subclass thereof.
-
Identifies an object as an instance of TreeNode class, or subclass thereof.
-
A class property getter for the default values of internal properties for this class.
-
An array containing all the defined fields for this Model class. This will include all superclass's defined fields.
-
An object containing all the defined fields for this Model class. This will include all superclass's defined fields through its prototype chain. So be aware that
Object.keysandObject.entrieswill only access this class's defined fields. -
The data source for the id field which provides the ID of instances of this Model.
-
State tracking manager instance the project relies on
Has a corresponding stm config.
-
An empty array that can be used as a default value.
-
An empty object that can be used as a default value.
-
Identifies an object as an instance of Model class, or subclass thereof.
-
Identifies an object as an instance of ProjectModel class, or subclass thereof.
-
For copied records, this property links to the original model instance from which it was copied.
-
True if this Model is currently batching its changes.
-
True if this models changes are currently being committed.
-
True if this model has any uncommitted changes.
-
Check if record has valid data. Default implementation returns true, override in your model to do actual validation.
-
Get a map of the modified fields in form of an object. The field´s dataSource is used as the property name in the returned object. The record's id is included unless its persist config is
false. -
Get a map of the modified data fields along with any alwaysWrite fields, in form of an object. The field´s dataSource is used as the property name in the returned object. Used internally by AjaxStore / CrudManager when sending updates.
-
Returns data for allpersistable fields in form of an object, using dataSource if present.
-
Returns a map of the modified persistable fields
-
Returns the string value for display purposes of an instance of this Model class. Needs to be overridden in subclasses.
-
When called on a group header row returns list of records in that group. Returns
undefinedotherwise. -
Returns true for a group header record
-
Gets the records internalId. It is assigned during creation, guaranteed to be globally unique among models.
-
Returns true if the record is new and has not been persisted (and received a proper id).
-
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,resourcesDataetc.) properties that are deprecated and will be removed in the future.Has a corresponding includeLegacyDataProperties config.
-
Returns a copy of the full configuration which was used to configure this object.
-
This property is set to
truebefore theconstructorreturns. -
This property is set to
trueon entry to the destroy method. It remains on the objects after returning fromdestroy(). If isDestroyed istrue, this property will also betrue, so there is no need to test for both (for example,comp.isDestroying || comp.isDestroyed). -
Are other records linked to this record?
-
Is this record linked to another record?
-
Get the original record this record is linked to.
-
Get links to this record.
-
Get the first store that this model is assigned to.
-
This yields
trueif this record is eligible for syncing with the server. It can yieldfalseif the record is in the middle of a batched update, or if it is a tentative record yet to be confirmed as a new addition. -
Returns true if this record is not part of any store.
-
Retrieve all children, excluding filtered out nodes (by traversing sub nodes)
-
Retrieve all children, including filtered out nodes (by traversing sub nodes)
-
Depth in the tree at which this node exists. First visual level of nodes are at level 0, their direct children at level 1 and so on.
-
Count all children (including sub-children) for a node (in its `firstStore´)
-
Get the first child of this node
-
Returns index path to this node. This is the index of each node in the node path starting from the topmost parent. (only relevant when its part of a tree store).
-
Is a leaf node in a tree structure?
-
Returns true for parent nodes with children loaded (there might still be no children)
-
Is a parent node in a tree structure?
-
Returns
trueif this node is the root of the tree -
Get the last child of this node
-
Get the next sibling of this node
-
This is a read-only property providing access to the parent node.
-
Get the previous sibling of this node
-
Returns count of all preceding sibling nodes (including their children).
-
Array of tree nodes without any filter applied. On first filter, will take order from sorted
children, but is not thereafter kept in sorted order, so order should not be relied upon. -
Count visible (expanded) children (including sub-children) for a node (in its
firstStore) -
Returns values of the persistable tree-defining fields: parentId, orderedParentIndex, and parentIndex or sparseIndex. parentIndex is omitted when sparseIndex is used.
Functions
Functions are methods available for calling on the class-
This optional class method is called when a class is mixed in using the mixin() method.
-
Registers this class type with its Factory
-
Makes getters and setters for related records. Populates a Model#relation array with the relations, to allow it to be modified later when assigning stores.
-
cancelBatch( ) Model
Cancels current batch operation. Any changes during the batch are discarded.
-
Reverts changes in this back to their original values.
-
Called from insertChild to notify StateTrackingManager about children insertion. Provides it with all necessary context information collected in beforeInsertChild required to undo/redo the action.
-
Called from removeChild to notify StateTrackingManager about children removing. Provides it with all necessary context information collected in beforeRemoveChild required to undo/redo the action.
-
Called during creation to also turn any children into Models joined to the same stores as this model
-
Initializes model relations. Called from store when adding a record.
-
Removes all records from the rootNode