ProjectModelCommon

Configs

5

Common

useRawData: Boolean

By default, the stores of a project use the raw data objects passed to them as the data source for their records if data is loaded remotely (using an AjaxStore or a CrudManager). For data supplied inline, the data objects are instead by default cloned to avoid the original data object being modified by the store.

See useRawData for more information on the mechanics of this.

This can be explicitly controlled per store by setting the useRawData config on the store:

// Opt in for a single store
const project = new ProjectModel({
    eventStore : {
      useRawData : true
    },
    ...
});

Or you can control it for all the default stores in the project by setting this config on the project:

// Opt in for all stores in the project
const project = new ProjectModel({
   useRawData : true,
   ...
});

Advanced

Experimental hook that lets the app determine if a bound dataset needs syncing with the store or not, and if it does - which records that should be processed. Only called for stores that are configured with syncDataOnLoad: true (which is the default in the React, Angular and Vue wrappers).

This is an experimental API that might change in any release until it has been finalized.

The main use case for this is for frameworks that update all state on any state change (like React), to not have to reapply the full bound dataset each time (which becomes costly).

If the app has a cheap way of determining (for example using a timestamp) that the dataset has no changes, return false from this hook to prevent the store from syncing at all at that time.

shouldSyncDataOnLoad({ store, data }) {
  if (store === myEventStore && timestamp <= lastUpdateTimestamp) {
    // Prevent sync when the event store has not changed since last time
    // (pseudocode)
    return false;
  }
}

If the app knows that something has changed, return a Set with ids for the records that should be further processed by the sync logic.

shouldSyncDataOnLoad({ store, data }) {
  if (store === myEventStore && timestamp > lastUpdateTimestamp) {
    // Sync only these records (pseudocode)
    return new Set([6, 110, 586]);
  }
}
ParameterTypeDescription
optionsObject

Options passed by the store to this hook

options.storeStore

Store about to be synced

options.recordsModel

Records currently in the store

options.dataObject[]

Incoming data

Returns: Set | Boolean -

Return false to prevent the store from syncing, or a set of record ids that need further processing (for records that has some kind of change, eg. an update, removal or addition)

Inline data

Project data as a JSON string, used to populate its stores.

const project = new ProjectModel({
    json : '{"events":[...],"resources":[...],...}'
}

The xxData properties are deprecated and will be removed in the future. Use xx instead. For example eventsData is deprecated, use events instead. For now, both naming schemes are included in the data object

toJSONResultFormat: inlineData | model

Specifies the output format of toJSON.

  • inlineData - Return all crud store data, plus this project fields (under the project key). For example:
{
    "project" : {
        "startDate"    : "2024-03-22",
        "endDate"      : "2024-04-22",
        "hoursPerDay"  : 8,
        "daysPerWeek"  : 5,
        "daysPerMonth" : 20
    },
    "events"             : [...],
    "resources"          : [...],
    "assignments"        : [...],
    "dependencies"       : [...],
    "resourceTimeRanges" : [...],
    "timeRanges"         : [...]
}
  • model - Return only the project fields. For example:
{
    "startDate"    : "2024-03-22",
    "endDate"      : "2024-04-22",
    "hoursPerDay"  : 8,
    "daysPerWeek"  : 5,
    "daysPerMonth" : 20
}

Legacy inline data

Whether to include legacy data properties in the JSON / inlineData output. The legacy data properties are the xxData (eventsData, resourcesData etc.) properties that are deprecated and will be removed in the future.

Properties

6

Advanced

Experimental hook that lets the app determine if a bound dataset needs syncing with the store or not, and if it does - which records that should be processed. Only called for stores that are configured with syncDataOnLoad: true (which is the default in the React, Angular and Vue wrappers).

This is an experimental API that might change in any release until it has been finalized.

The main use case for this is for frameworks that update all state on any state change (like React), to not have to reapply the full bound dataset each time (which becomes costly).

If the app has a cheap way of determining (for example using a timestamp) that the dataset has no changes, return false from this hook to prevent the store from syncing at all at that time.

shouldSyncDataOnLoad({ store, data }) {
  if (store === myEventStore && timestamp <= lastUpdateTimestamp) {
    // Prevent sync when the event store has not changed since last time
    // (pseudocode)
    return false;
  }
}

If the app knows that something has changed, return a Set with ids for the records that should be further processed by the sync logic.

shouldSyncDataOnLoad({ store, data }) {
  if (store === myEventStore && timestamp > lastUpdateTimestamp) {
    // Sync only these records (pseudocode)
    return new Set([6, 110, 586]);
  }
}
ParameterTypeDescription
optionsObject

Options passed by the store to this hook

options.storeStore

Store about to be synced

options.recordsModel

Records currently in the store

options.dataObject[]

Incoming data

Returns: Set | Boolean -

Return false to prevent the store from syncing, or a set of record ids that need further processing (for records that has some kind of change, eg. an update, removal or addition)

Class hierarchy

isProjectModelCommon: Boolean= truereadonly
Identifies an object as an instance of ProjectModelCommon class, or subclass thereof.
isProjectModelCommon: Boolean= truereadonlystatic
Identifies an object as an instance of ProjectModelCommon class, or subclass thereof.

Inline data

inlineData: Object

Get or set data of project stores. The returned data is identical to what toJSON returns:

const data = scheduler.project.inlineData;

// data:
{
    project            : { ... },
    events             : [...],
    resources          : [...],
    dependencies       : [...],
    assignments        : [...],
    resourceTimeRanges : [...],
    timeRanges         : [...]
}


// Plug it back in later
scheduler.project.inlineData = data;

The xxData properties are deprecated and will be removed in the future. Use xx instead. For example eventsData is deprecated, use events instead. For now, both naming schemes are included in the data object.

To stop including the legacy data properties, set includeLegacyDataProperties to false.

Get or set project data (records from its stores) as a JSON string.

Get a JSON string:

const project = new ProjectModel({
    events       : [...],
    resources    : [...],
    assignments  : [...],
    dependencies : [...]
});

const jsonString = project.json;

// jsonString:
'{"events":[...],"resources":[...],...}'

Set a JSON string (to populate the project stores):

project.json = '{"events":[...],"resources":[...],...}'

The xxData properties are deprecated and will be removed in the future. Use xx instead. For example eventsData is deprecated, use events instead. For now, both naming schemes are included in the data object

Legacy inline data

Whether to include legacy data properties in the JSON / inlineData output. The legacy data properties are the xxData (eventsData, resourcesData etc.) properties that are deprecated and will be removed in the future.

Functions

1

Returns the data from the records of the projects stores, in a format that can be consumed by loadInlineData().

Used by JSON.stringify to correctly convert this record to json.

The output format is determined by the value of toJSONResultFormat, as follows:

  • inlineData - Returns all crud store data, plus the project fields (under the project key)
  • model - Returns only the project fields
const project = new ProjectModel({
    // Include both store data and project model fields in toJSON() result
    toJSONResultFormat     : 'inlineData',
    events             : [...],
    resources          : [...],
    assignments        : [...],
    dependencies       : [...],
    resourceTimeRanges : [...],
    timeRanges         : [...]
});

const json = project.toJSON();

// json:
{
    events             : [...],
    resources          : [...],
    assignments        : [...],
    dependencies       : [...],
    ...
    project                : {
        addConstraintOnDateSet : false,
        daysPerMonth           : 13
        daysPerWeek            : 3
        ...
    },
    ...
}

The xxData properties are deprecated and will be removed in the future. Use xx instead. For example eventsData is deprecated, use events instead. For now, both naming schemes are included in the data object

Output can be consumed by loadInlineData():

const json = project.toJSON();

// Plug it back in later
project.loadInlineData(json);
Returns: Object