ResourceModel

This class represent a single Resource in scheduler, usually added to a ResourceStore.

It is a subclass of Model. Please refer to the documentation for that class to become familiar with the base interface of the resource.

Fields and references

A resource has a few predefined fields, see Fields below. If you want to add more fields with meta data describing your resources then you should subclass this class:

class MyResource extends ResourceModel {
  static fields = [
      // "id" and "name" fields are already provided by the superclass
      { name: 'company', type : 'string' }
  ];
}

If you want to use other names in your data for the id and name fields you can configure them as seen below:

class MyResource extends ResourceModel {
  static fields = [
     { name: 'name', dataSource: 'userName' }
  ];
}

After load and project normalization, these references are accessible (assuming their respective stores are loaded):

  • assignments - The linked assignment records
  • events - The linked (through assignments) event records

Async resolving of references

As described above, a resource has links to assignments and events. These references are populated async, using the calculation engine of the project that the resource via its store is a part of. Because of this asyncness, references cannot be used immediately after assignment modifications:

assignment.resourceId = 2;
// resource.assignments is not yet up to date

To make sure references are updated, wait for calculations to finish:

assignment.resourceId = 2;
await assignment.project.commitAsync();
// resource.assignments is up to date

As an alternative, you can also use setAsync() to trigger calculations directly after the change:

await assignment.setAsync({ resourceId : 2});
// resource.assignments is up to date

Properties

69

Common

Returns all assignments for the resource

events: EventModel[]readonly

Get associated events

Returns the initials (first letter of the first & last space-separated word in the name) or an empty string if this resource has no name. You can override this method in a ResourceModel subclass to provide your own implementation

Get associated resource time ranges. Only available when using the ResourceTimeRanges feature.

Class hierarchy

isResourceModel: Boolean= truereadonly
Identifies an object as an instance of ResourceModel class, or subclass thereof.
isResourceModel: Boolean= truereadonlystatic
Identifies an object as an instance of ResourceModel class, or subclass thereof.
Identifies an object as an instance of ResourceModelMixin class, or subclass thereof.
isResourceModelMixin: Boolean= truereadonlystaticResourceModelMixin
Identifies an object as an instance of ResourceModelMixin class, or subclass thereof.
isGridRowModelGridRowModel
isModelModel
isModelLinkModelLink
isModelStmModelStm
isTreeNodeTreeNode

Editing

Returns true if the resource can be persisted. In a flat store, a resource is always considered persistable. In a tree store, a resource is considered persistable if its parent node is persistable.

copyOfModel
isValidModel

Fields

allFieldsstaticModel
autoExposeFieldsstaticModel
childrenFieldstaticModel
defaultsstaticModel
fieldMapstaticModel
fieldsstaticModel
idFieldstaticModel

Grouping

Identification

keyModel

JSON

jsonModel

Lifecycle

configBase

Linked records

hasLinksModelLink
isLinkedModelLink
recordLinksModelLink

Misc

stmModelStm

Other

$namestaticModel
relationsstaticModel

Parent & children

allChildrenTreeNode
childLevelTreeNode
firstChildTreeNode
isLeafTreeNode
isLoadedTreeNode
isParentTreeNode
isRootTreeNode
lastChildTreeNode
nextSiblingTreeNode
parentTreeNode
parentIdTreeNode

Functions

56

Editing

Set value for the specified field(s), triggering engine calculations immediately. See Model#set() for arguments.

This does not matter much on the resource itself, but is of importance when manipulating its references:

assignment.set('resourceId', 2);
// resource.assignments is not yet up to date

await assignment.setAsync('resourceId', 2);
// resource.assignments is up to date
ParameterTypeDescription
fieldString | Object

The field to set value for, or an object with multiple values to set in one call

value*

Value to set

silentBoolean

Set to true to not trigger events automatically.

copyModel
getDataModel
removeModel
setModel

Other

Unassigns this Resource from all its Events

Configuration

applyDefaultsstaticBase

Events

Fields

addFieldstaticModel
getModel
processFieldstaticModel
removeFieldstaticModel

Identification

asIdstaticModel
generateIdstaticModel

JSON

toJSONModel

Lifecycle

destroystaticBase

Misc

equalsModel
initClassstaticBase
isOfTypeNamestaticBase
linkModelLink
mixinstaticBase

Parent & children

appendChildTreeNode
bubbleTreeNode
bubbleWhileTreeNode
containsTreeNode
insertChildTreeNode
isExpandedTreeNode
removeChildTreeNode
traverseTreeNode

Typedefs

2

Config object used to set different values for top/left and bottom/right margin.

ParameterTypeDescription
startNumber

Margin top in horizontal mode, margin left in vertical mode

endNumber

Margin bottom in horizontal mode, margin right in vertical mode