TaskModel
This class represents a task in your Gantt project. Extend it to add your own custom task fields and methods.
Subclassing the TaskModel class
To subclass the TaskModel and add extra fields and API methods, please see the snippet below.
class MyTaskModel extends TaskModel {
static get fields() {
return [
{ name: 'importantDate', type: 'date' }
]
}
After creating your own Task model class, configure the taskModelClass on Project to use it:
new Gantt({
project : {
taskModelClass : MyTaskModel
}
});
Creating a new Task programmatically
To create a new task programmatically, simply call the TaskModel constructor and pass in any field values.
const newTask = new TaskModel({
name : 'My awesome task',
importantDate : new Date(2022, 0, 1),
percentDone : 80 // So awesome it's almost done
// ...
});
Async scheduling
A record created from an TaskModel is normally part of a TaskStore, which in turn is part of a project. When dates or the duration of a task is changed, the project performs async calculations of the other related fields (including the field of other tasks affected by the change). For example if duration is changed, it will recalculate endDate.
As a result of this being an async operation, the values of other fields are not guaranteed to be up to date immediately after a change. To ensure data is up to date, await the calculations to finish.
For example, endDate is not up to date after this operation:
taskRecord.duration = 5;
// taskRecord.endDate not yet calculated
But if calculations are awaited it is up to date:
taskRecord.duration = 5;
await taskRecord.project.commitAsync();
// endDate is calculated
In case of multiple changes no need to trigger recalculation after each of them:
// change taskRecord1 start and duration
taskRecord1.startDate = '2021-11-15';
taskRecord1.duration = 5;
// change taskRecord2 duration
taskRecord2.duration = 1;
// change taskRecord3 finish date
taskRecord3.endDate = '2021-11-17';
// now when all changes are done trigger rescheduling
await taskRecord.project.commitAsync();
Manually vs automatically scheduled tasks
A task can be either automatically (default) or manually scheduled. This is defined by the manuallyScheduled field. Manually scheduled tasks are not affected by the automatic scheduling process, which means their start/end dates are meant to be changed by user manually. Such tasks are not shifted by their predecessors nor such summary tasks rollup their children start/end dates. While automatically scheduled tasks start/end dates are calculated by the Gantt.
Start and end dates
For all tasks, the end date is non-inclusive: startDate <= date < endDate. Example: a task which starts at 2020/07/18 and has 2 days duration, should have the end date: 2020/07/20, not 2018/07/19 23:59:59. The start and end dates of tasks in are points on the time axis and if you specify that a task starts 01/01/2020 and has 1 day duration, that means the start point is 01/01/2020 00:00 and end point is 02/01/2020 00:00.
Changing default field values
Default values for fields can be changed without subclassing or redefining fields using applyDefaults. This should be called before data is loaded into stores:
// Change the default scheduling mode for all new tasks
TaskModel.applyDefaults({ schedulingMode : 'FixedDuration' });
Fields
Fields belong to a Model class and define the Model data structure-
A set of resources assigned to this task
-
The calculated effective scheduling direction of this event. See the direction field for details.
-
Unique identifier of task (mandatory)
-
Name of the task
-
A freetext note about the task.
-
Set this to true to roll up a task to its closest parent
-
Set this to true if this task should be shown in the Timeline widget
-
Specify false to prevent the event from being dragged (if TaskDrag feature is used)
-
Specify false to prevent the task from being resized (if TaskResize feature is used). You can also specify 'start' or 'end' to only allow resizing in one direction
-
The calendar, assigned to the task. Allows you to set the time when task can be performed.
-
Field defining the constraint boundary date or
nullif constraintType isnull. -
constraintType : 'finishnoearlierthan'/'finishnolaterthan'/'mustfinishon'/'muststarton'/'startnoearlierthan'+ 2 more
Field storing the task constraint alias or
nullif not constraint set. Valid values are:- "finishnoearlierthan"
- "finishnolaterthan"
- "mustfinishon"
- "muststarton"
- "startnoearlierthan"
- "startnolaterthan"
-
The total projected cost for the event.
-
A calculated field indicating if the task is critical. A task considered critical if its delaying causes the project delay. The field value is calculated based on totalSlack field value.
if (task.critical) { Toast.show(`The ${task.name} is critical!`); } -
This boolean flag defines what part of task data should be updated in the
FixedUnitsscheduling mode. If it istrue, then effort is kept intact, and duration is updated. If it isfalse- vice-versa. -
Calculated field which encapsulates the duration's magnitude and unit. This field will not be persisted, setting it will update the duration and durationUnit fields.
-
When set to
truethe task becomes inactive and stops taking part in the project scheduling (doesn't affect linked tasks, rolls up its attributes and affect its assigned resources allocation). -
When set to
true, the startDate of the task will not be changed by any of its incoming dependencies or constraints. -
Segments of the task that appear when the task gets splitToSegments.
-
A calculated field storing unit for the totalSlack value.
-
CSS class specifying an icon to apply to the task row
-
A CSS style string (applied to
style.cssText) or object (applied tostyle)record.style = 'color: red;font-weight: 800'; -
CSS class specifying an icon to apply to the task bar
-
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.
-
This is a read-only field provided in server synchronization packets to specify which record id is the parent of the record.
-
This is a read-only field provided in server synchronization packets to specify which position the node takes in the parent's children array. This index is set on load and gets updated automatically after row reordering, sorting, etc. To save the order, need to persist the field on the server and when data is fetched to be loaded, need to sort by this field.
-
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-
An EventStore instance or a config object.
Has a corresponding runtime taskStore property.
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 PartOfProject class, or subclass thereof.
-
Identifies an object as an instance of PercentDoneMixin class, or subclass thereof.
-
Identifies an object as an instance of TaskModel class, or subclass thereof.
-
Identifies an object as an instance of TimeZonedDatesMixin 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.
-
Returns all dependencies of this task (both incoming and outgoing)
-
An array of the assignments, related to this task
-
The event first segment or null if the event is not segmented.
-
A
Set<Gantt.model.DependencyModel>of the incoming dependencies for this task -
The event last segment or null if the event is not segmented.
-
A
Set<Gantt.model.DependencyModel>of the outgoing dependencies for this task -
Returns all direct predecessor tasks of a task
-
Returns all predecessor dependencies of this task
-
Returns count of all sibling nodes (including their children).
-
Returns all resources assigned to an event.
-
Returns all direct successor tasks of a task
-
Returns all successor dependencies of this task
-
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 TaskModel class, or subclass thereof.
-
Identifies an object as an instance of TimeSpan 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).
-
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.
-
Reference to STM manager, if used
-
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.
-
Returns the assignment store of the project this entity belongs to.
-
Returns the calendar manager store of the project this entity belongs to.
-
Returns the dependency store of the project this entity belongs to.
-
Returns the task store of the project this entity belongs to.
-
Returns the resource store of the project this entity belongs to.
-
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
-
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 the WBS code of this model (e.g '2.1.3'). Only relevant when part of a tree store, as in the Gantt chart.
-
Returns the project this entity belongs to.
-
Indicates if the task is complete (its percent completion is 100% (or greater)).
-
Indicates if the task is in progress (its percent completion is greater than zero and less than 100%).
-
Indicates if the task is started (its percent completion is greater than zero).
-
Human-friendly rounding. When task is completed < 99%, it rounds the value. It floors value between 99 and 100, to not show task as completed when it is for example 99.51% done.
-
Returns an array of dates in this range. If the range starts/ends not at the beginning of day, the whole day will be included.
-
Returns the task duration in milliseconds.
-
Deprecated:
Please note, the property is made for backward compatibility. Please use postponedConflict field instead.
A read only alias for postponedConflict field.
-
Returns true if record is a milestone.
-
Checks if the range record has both start and end dates set and start <= end
-
Returns the event raw duration in milliseconds. Calculated as a simple distance between the event start and end dates in milliseconds. And thus this value (in Scheduler Pro and Gantt) doesn't take into account non-working time nor the project conversion rates.
-
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.
-
Propagates changes to the dependent tasks. For example:
// double a task duration task.duration *= 2; // call commitAsync() to do further recalculations caused by the duration change task.commitAsync().then(() => console.log('Schedule updated')); -
Converts this task to a milestone (start date will match the end date).
-
Converts the milestone task to a regular task with a duration of 1 (keeping current durationUnit).
-
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