EventStore
A store holding all the events to be rendered into a Scheduler.
This store only accepts a model class inheriting from EventModel.
An EventStore is usually connected to a project, which binds it to other related stores (AssignmentStore,
ResourceStore and DependencyStore). The project also handles normalization/calculation of the data on the records in
the store. For example if a record is added with a startDate and an endDate, it will calculate the duration.
The calculations happens async, records are not guaranteed to have up to date data until they are finished. To be
certain that calculations have finished, call await project.commitAsync() after store actions. Or use one of the
xxAsync functions, such as loadDataAsync().
Using commitAsync():
eventStore.data = [{ startDate, endDate }, ...];
// duration of the record is not yet calculated
await eventStore.project.commitAsync();
// now it is
Using loadDataAsync():
await eventStore.loadDataAsync([{ startDate, endDate }, ...]);
// duration is calculated
Using recurring events
When recurring events are in the database, all recurring event definitions which started before the requested start date, and have not yet finished recurring MUST be loaded into the EventStore.
Only the base recurring event definitions are stored in the EventStore. You do not need to calculate the future occurrence dates of these events. This is all handled by the EventStore.
When asked to yield a set of events for a certain date range for creating a UI through getEvents, the EventStore automatically interpolates any occurrences of recurring events into the results. They do not occupy slots in the EventStore for every date in their repetition range (that would be very inefficient, and might be infinite).
Configs
82
Configs
82Common
Class used to represent records
Configure with true to also remove the event when removing the last assignment from the linked
AssignmentStore. This config has no effect when using EventStore in legacy resourceId-mode.
Configure with true to force single-resource mode, an event can only be assigned to a single resource.
If not provided, the mode will be inferred from
- presence of an assignment store (i.e. multi-assignment)
- presence of
resourceIdin the event store data (i.e. single assignment mode)
Advanced
Chained store
Filtering
Other
Paging
Records
Remote
Tree
Properties
79
Properties
79Common
Class hierarchy
Records
Applies a new dataset to the EventStore. Use it to plug externally fetched data into the store.
NOTE: Dates, durations and relations (assignments, resources) on the events are determined async by a calculation engine. Thus they cannot be directly accessed after assigning the new dataset.
For example:
eventStore.data = [{ startDate, duration }];
// eventStore.first.endDate is not yet calculated
To guarantee data is in a calculated state, wait for calculations for finish:
eventStore.data = [{ startDate, duration }];
await eventStore.project.commitAsync();
// eventStore.first.endDate is calculated
Alternatively use loadDataAsync() instead:
await eventStore.loadDataAsync([{ startDate, duration }]);
// eventStore.first.endDate is calculated
Class used to represent records. Defaults to class EventModel.
Advanced
CRUD
Filtering
Misc
Models & Stores
Other
Remote
Functions
122
Functions
122Assignment
Creates and adds assignment record for a given event and a resource.
| Parameter | Type | Description |
|---|---|---|
event | EventModel | String | Number | |
resource | ResourceModel | String | Number | ResourceModel[] | String[] | Number[] | The resource(s) to assign to the event |
removeExistingAssignments | Boolean |
|
An array with the created assignment(s)
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 | String | Number |
Checks whether an event is assigned to a resource.
| Parameter | Type | Description |
|---|---|---|
event | EventModel | String | Number | |
resource | ResourceModel | String | Number |
Reassigns an event from an old resource to a new resource
| Parameter | Type | Description |
|---|---|---|
event | EventModel | An event or id of the event to reassign |
oldResource | ResourceModel | ResourceModel[] | A resource or id to unassign from |
newResource | ResourceModel | ResourceModel[] | A resource or id to assign to |
Removes all assignments for given event
| Parameter | Type | Description |
|---|---|---|
event | EventModel | String | Number |
Removes all assignments for given resource
| Parameter | Type | Description |
|---|---|---|
resource | ResourceModel | String | Number |
Removes assignment record for a given event and a resource.
| Parameter | Type | Description |
|---|---|---|
event | EventModel | String | Number | |
resource | ResourceModel | String | Number |
CRUD
Add events to the store.
NOTE: Dates, durations and references (assignments, resources) on the events are determined async by a calculation engine. Thus they cannot be directly accessed after using this function.
For example:
eventStore.add({ startDate, duration });
// endDate is not yet calculated
To guarantee data is in a calculated state, wait for calculations for finish:
eventStore.add({ startDate, duration });
await eventStore.project.commitAsync();
// endDate is calculated
Alternatively use addAsync() instead:
await eventStore.addAsync({ startDate, duration });
// endDate is calculated
| Parameter | Type | Description |
|---|---|---|
records | EventModel | EventModel[] | EventModelConfig | EventModelConfig[] | Array of records/data or a single record/data to add to store |
silent | Boolean | Specify |
Added records
Add events to the store and triggers calculations directly after. Await this function to have up to date data on the added events.
await eventStore.addAsync({ startDate, duration });
// endDate is calculated
| Parameter | Type | Description |
|---|---|---|
records | EventModel | EventModel[] | EventModelConfig | EventModelConfig[] | Array of records/data or a single record/data to add to store |
silent | Boolean | Specify |
Added records
Appends a new record to the store
| Parameter | Type | Description |
|---|---|---|
record | EventModel | The record to append to the store |
Applies a new dataset to the EventStore and triggers calculations directly after. Use it to plug externally fetched data into the store.
await eventStore.loadDataAsync([{ startDate, duration }]);
// eventStore.first.endDate is calculated
| Parameter | Type | Description |
|---|---|---|
data | EventModelConfig[] | Array of EventModel data objects |
Events
Calls the supplied iterator function once for every scheduled event, providing these arguments
- event : the event record
- startDate : the event start date
- endDate : the event end date
Returning false cancels the iteration.
| Parameter | Type | Description |
|---|---|---|
fn | function | iterator function |
thisObj | Object |
|
Returns a Map, keyed by YYYY-MM-DD date keys containing event counts for all the days
between the passed startDate and endDate. Occurrences of recurring events are included.
Example:
eventCounts = eventStore.getEventCounts({
startDate : scheduler.timeAxis.startDate,
endDate : scheduler.timeAxis.endDate
});
| Parameter | Type | Description |
|---|---|---|
options | Object | An options object determining which events to return |
options.startDate | Date | The start date for the range of events to include. |
options.endDate | Date | The end date for the range of events to include. |
Returns an object defining the earliest start date and the latest end date of all the events in the store.
An object with 'startDate' and 'endDate' properties (or null values if data is missing).
Checks if given event record is persistable. By default it always is, override EventModels isPersistable if you
need custom logic.
| Parameter | Type | Description |
|---|---|---|
event | EventModel |
Resource
Returns all events assigned to a resource. NOTE: this does not include occurrences of recurring events. Use the getEvents API to include occurrences of recurring events.
| Parameter | Type | Description |
|---|---|---|
resource | ResourceModel | String | Number | Resource or resource id. |
Returns all resources assigned to an event.
| Parameter | Type | Description |
|---|---|---|
event | EventModel | String | Number |