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
Properties
69
Properties
69Common
Returns all assignments for the resource
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
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.
JSON
Parent & children
Functions
56
Functions
56Editing
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
| Parameter | Type | Description |
|---|---|---|
field | String | Object | The field to set value for, or an object with multiple values to set in one call |
value | * | Value to set |
silent | Boolean | Set to |
Configuration
Events
Parent & children
Typedefs
2
Typedefs
2Config object used to set different values for top/left and bottom/right margin.
| Parameter | Type | Description |
|---|---|---|
start | Number | Margin top in horizontal mode, margin left in vertical mode |
end | Number | Margin bottom in horizontal mode, margin right in vertical mode |