ResourceModel

This class represent a single Resource in Scheduler Pro, 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 get fields() {
    return [
      // "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 get fields() {
    return [
       { 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

70

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 ´ResourceTimeRange` 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

Scheduling

This resource´s effective calendar. Returns the project calendar if the resource has no own calendar provided.

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

60

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

Adds a rate table to the resource

ParameterTypeDescription
rateTableResourceRateModel | ResourceRateModel[] | ResourceRateModelConfig | ResourceRateModelConfig[]

A rate table instance or data object (or an array of instances or data objects to add multiple tables)

Returns: ResourceRateModel[] -

An array of the added tables

Returns the resource calendar.

Returns: CalendarModel -

The resource calendar.

Removes a rate table or multiple rate tables from the resource

ParameterTypeDescription
rateTableResourceRateModel | ResourceRateModel[]

A rate table or an array of tables to remove

Returns: ResourceRateModel[] -

An array of the removed tables

Sets the calendar of the task. Will cause the schedule to be updated - returns a Promise

ParameterTypeDescription
calendarCalendarModel

The new calendar. Provide null to use the project calendar.

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

7

An object containing info on the assignment effort in a certain time interval.

The object is used when rendering interval bars and tooltips so it additionally provides a rectConfig property which contains a configuration object for therect SVG-element representing the interval bar.

ParameterTypeDescription
assignmentAssignmentModel

The assignment which allocation is displayed.

effortNumber

Amount of work performed by the assigned resource in the interval

tickTickInfo

The interval of time the allocation is collected for

unitsNumber

Assignment units value

rectConfigObject

The rectangle DOM configuration object

inEventTimeSpanBoolean

Indicates if the interval is in the middle of the event timespan.

Resource allocation information.

ParameterTypeDescription
resourceResourceModel

Resource model.

ownerResourceAllocationInfo

The allocation report this instance is part of.

totalResourceAllocationInterval[]

The resource allocation data collected.

byAssignmentsMap

A Map keyed by AssignmentModel containing the resource allocation collected for individual assignments.

Class implementing resource allocation report - data representing the provided resource utilization in the provided period of time. The data is grouped by the provided time intervals (ticks).

ParameterTypeDescription
resourceResourceModel

Resource model.

allocationResourceAllocation

The collected allocation info.

ticksCalendarModel

A calendar specifying intervals to group the collected allocation by. Working time intervals of the calendars will be used for grouping. This also specifies the time period to collect allocation for. So the first interval startDate is treated as the period start and the last interval endDate is the period end.

includeInactiveEventsBoolean

true indicates inactive events allocation is included and false - it's skipped.

An object containing info on the resource allocation in a certain time interval.

The object is used when rendering interval bars and tooltips so it additionally provides a rectConfig property which contains a configuration object for the rect SVG-element representing the interval bar.

ParameterTypeDescription
resourceResourceModel

Resource model

assignmentsSet

Set of ongoing assignments for the interval

assignmentIntervalsMap

Individual ongoing assignments allocation indexed by assignments

effortNumber

Resource effort in the interval (in milliseconds)

isOverallocatedBoolean

true if the interval contains a fact of the resource overallocation

isUnderallocatedBoolean

true if the resource is underallocated in the interval

maxEffortNumber

Maximum possible resource effort in the interval (in milliseconds)

tickTickInfo

The time interval

unitsNumber

Resource allocation in percents

inEventTimeSpanBoolean

Indicates if the interval is in the middle of the event timespan.

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

An object representing a certain time interval.

ParameterTypeDescription
startDateDate

The interval start date

endDateDate

The interval end date

Fields

9

Common

Specifies which rate table to use by default when assigning the resource.

The unit of measure for the material resource.

maxUnits: Number= 100

A maximum units "capacity" for this resource, in percents. Corresponds to units field. Default value is 100%. If the sum of all "units" of all assignments of a resource for a certain period exceeds this value, such resource is marked as "over-allocated" in the resource histogram.

You should increase this field's value, if it is normal for the resource to have more than 100% allocation. This is for example if resource actually represents a team from several people.

Contains the resource rate tables.

Other

type: work | material | cost= 'work'

Indicates whether the resource is a work, material or a cost resource. Work resources are people and equipment. Material resources are consumable supplies, such as concrete, or soil. And cost resources let to apply a cost to an event by assigning a cost item (like an extra expenditure on flights) to that event.

type: work | material | cost= 'work'

Indicates whether the resource is a work, material or a cost resource. Work resources are people and equipment. Material resources are consumable supplies, such as concrete, or soil. And cost resources let to apply a cost to an event by assigning a cost item (like an extra expenditure on flights) to that event.

Scheduling

The calendar, assigned to the entity. Allows you to set the time when entity can perform the work.

cost: Number

The total projected cost for the resource.

costAccrual: start | prorated | end= 'prorated'

Specifies how and when the resource cost are to be charged, or accrued, to the cost of an event. The options are:

  • 'start' - costs are charged when events start
  • 'prorated' - costs are prorated across event durations
  • 'end' - costs are charged when events finish