AssignmentStore
A store representing a collection of assignments between events in the EventStore and resources in the ResourceStore.
This store only accepts a model class inheriting from AssignmentModel.
An AssignmentStore is usually connected to a project, which binds it to other related stores (EventStore, ResourceStore and DependencyStore). The project also handles references (event, resource) to related records for the records in the store.
Resolving the references happens async, records are not guaranteed to have up to date references until calculations
are finished. To be certain that references are resolved, call await project.commitAsync() after store actions. Or
use one of the xxAsync functions, such as loadDataAsync().
Using commitAsync():
assignmentStore.data = [{ eventId, resourceId }, ...];
// references (event, resource) not resolved yet
await assignmentStore.project.commitAsync();
// now they are
Using loadDataAsync():
await assignmentStore.loadDataAsync([{ eventId, resourceId }, ...]);
// references (event, resource) are resolved
Configs
80
Configs
80Common
Advanced
Chained store
Filtering
Other
Paging
Records
Remote
Tree
Properties
77
Properties
77Common
Class hierarchy
Records
Applies a new dataset to the AssignmentStore. Use it to plug externally fetched data into the store.
NOTE: References (assignments, resources) on the assignments are determined async by a calculation engine. Thus they cannot be directly accessed after assigning the new dataset.
For example:
assignmentStore.data = [{ eventId, resourceId }];
// assignmentStore.first.event is not yet available
To guarantee references are available, wait for calculations for finish:
assignmentStore.data = [{ eventId, resourceId }];
await assignmentStore.project.commitAsync();
// assignmentStore.first.event is available
Alternatively use loadDataAsync() instead:
await assignmentStore.loadDataAsync([{ eventId, resourceId }]);
// assignmentStore.first.event is available
Advanced
CRUD
Filtering
Misc
Models & Stores
Other
Remote
Functions
115
Functions
115Assign
Creates and adds assignment record(s) for a given event and resource(s).
| Parameter | Type | Description |
|---|---|---|
event | TimeSpan | |
resources | ResourceModel | ResourceModel[] | The resource(s) to assign to the event |
assignmentSetupFn | function | A hook function which takes an assignment as its argument and must return an assignment. |
removeExistingAssignments | Boolean |
|
An array with the created assignment(s)
Removes assignment record for a given event and resource.
| Parameter | Type | Description |
|---|---|---|
event | TimeSpan | String | Number | |
resources | ResourceModel | String | Number | The resource to unassign the event from. If omitted, all resources of the events will be unassigned |
Assignments
Returns an assignment record for a given event and resource
| Parameter | Type | Description |
|---|---|---|
event | EventModel | String | Number | The event or its id |
resource | ResourceModel | String | Number | The resource or its id |
Returns all assignments for a given event.
| Parameter | Type | Description |
|---|---|---|
event | EventModel | The event to get assignments for |
Array of assignments for the event
Returns all assignments for a given resource.
| Parameter | Type | Description |
|---|---|---|
resource | ResourceModel |
Returns all events assigned to a resource
| Parameter | Type | Description |
|---|---|---|
resource | ResourceModel | String | Number |
Returns all resources assigned to an event.
| Parameter | Type | Description |
|---|---|---|
event | EventModel |
Checks whether an event is assigned to a resource.
| Parameter | Type | Description |
|---|---|---|
event | EventModel | String | Number | Event record or id |
resource | ResourceModel | String | Number | Resource record or id |
Maps over event assignments.
| Parameter | Type | Description |
|---|---|---|
event | EventModel | |
fn | function | |
filterFn | function |
Maps over resource assignments.
| Parameter | Type | Description |
|---|---|---|
resource | ResourceModel | Number | String | |
fn | function | |
filterFn | function |
Removes all assignments for given event
| Parameter | Type | Description |
|---|---|---|
event | TimeSpan |
Removes all assignments for given resource
| Parameter | Type | Description |
|---|---|---|
resource | ResourceModel | * |
CRUD
Add assignments to the store.
NOTE: References (event, resource) on the assignments are determined async by a calculation engine. Thus they cannot be directly accessed after using this function.
For example:
const [assignment] = assignmentStore.add({ eventId, resourceId });
// assignment.event is not yet available
To guarantee references are set up, wait for calculations for finish:
const [assignment] = assignmentStore.add({ eventId, resourceId });
await assignmentStore.project.commitAsync();
// assignment.event is available (assuming EventStore is loaded and so on)
Alternatively use addAsync() instead:
const [assignment] = await assignmentStore.addAsync({ eventId, resourceId });
// assignment.event is available (assuming EventStore is loaded and so on)
| Parameter | Type | Description |
|---|---|---|
records | AssignmentModel | AssignmentModel[] | AssignmentModelConfig | AssignmentModelConfig[] | Array of records/data or a single record/data to add to store |
silent | Boolean | Specify |
Added records
Add assignments to the store and triggers calculations directly after. Await this function to have up to date references on the added assignments.
const [assignment] = await assignmentStore.addAsync({ eventId, resourceId });
// assignment.event is available (assuming EventStore is loaded and so on)
| Parameter | Type | Description |
|---|---|---|
records | AssignmentModel | AssignmentModel[] | AssignmentModelConfig | AssignmentModelConfig[] | Array of records/data or a single record/data to add to store |
silent | Boolean | Specify |
Added records
Applies a new dataset to the AssignmentStore and triggers calculations directly after. Use it to plug externally fetched data into the store.
await assignmentStore.loadDataAsync([{ eventId, resourceId }]);
// assignmentStore.first.event is available
| Parameter | Type | Description |
|---|---|---|
data | AssignmentModelConfig[] | Array of AssignmentModel data objects |