d2

d2.init~ d2

Source:

Members

analytics

Source:
See:

Analytics instance for requesting analytics data from various endpoints.

Example
d2.analytics.aggregate
 .addDimensions([
  'dx:Uvn6LCg7dVU;OdiHJayrsKo',
  'pe:LAST_4_QUARTERS',
  'ou:lc3eMKXaEfw;PMa2VCrupOd',
 ])
 .addFilter('pe:2016Q1;2016Q2')
 .getRawData({
   startDate: '2017-10-01',
   endDate: '2017-10-31'
 })
 .then(console.log)

Api

Source:
See:
  • module:api~Api#getApi

Api class that is used throughout the api interaction. This can be used to get hold of the module:Api singleton.

Example
d2.Api.getApi()      // Returns the api object
 .get('resources')   // Do a get request for /api/resources
 .then(resources => {
     console.log(resources);
 });

currentUser

Source:
See:
  • CurrentUser

An instance of CurrentUser

The currentUser can be used to retrieve data related to the currentUser.

These things primarily include:

  • currentUser properties retrieved from /api/me
  • Lazily request collections related to the user such as
    • userRoles
    • userGroups
    • organisationUnits
    • dataViewOrganisationUnits
  • authorities
  • userSettings
  • utility methods for ACL
Example
d2.currentUser.canCreate(d2.models.dataElement); // Returns true when the user can create either a private/public dataElement
d2.currentUser.canCreate(d2.models.organisationUnit); // Returns true the user can create an organisationUnit

dataStore

Source:
See:

Instance of the DataStore class for interaction with the dataStore api.

i18n

Source:
See:

I18n instance with the loaded translations.

Usually used for retrieving translations for a given key using getTranslation(key: string)

Example
d2.i18n.getTranslation('success'); // Returns "Success" for the english locale

model

Source:
Deprecated:
  • There is probably no point to expose this.

Collection of the module:model classes

models :Object.<string, ModelDefinition>

Source:

This is the entry point for the modelDefinitions that were loaded. To start interacting with the metadata api you would pick a modelDefinition from this object to interact with.

Type:
  • Object.<string, ModelDefinition>

system

Source:
See:
  • System

System instance to interact with system information like system settings, system info etc.

Example
console.log(d2.system.version.major); // 2 for DHIS 2.27