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 recordsevents- 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
See also
- ResourceStore - Store for resources
- EventModel - Event data model
- AssignmentModel - Assignment data model
- Scheduler - Scheduler widget
Properties
Properties are getters/setters or publicly accessible variables on this class-
Identifies an object as an instance of ResourceModel class, or subclass thereof.
-
Get associated events
-
Get associated resource time ranges. Only available when using the
ResourceTimeRangesfeature. -
Identifies an object as an instance of ResourceModel class, or subclass thereof.