MicroApp Dev: App Data Object - EscherLabs/Graphene GitHub Wiki

The app data object (as referenced by app.data), is available within your app's local context, and provides access to all data affiliated with your app's resources, as well as the app options and the current user.

Table of Contents
app.data."resource_name"
app.data.options
app.data.user
app.data.user.params
app.data.user.options
app.data.user.tags
app.data.user.groups

app.data."resource_name"

This is the primary way to access the data returned by your application's "pre-fetched" resources. For example, if you have a resource called 'cats', which fetches an array of cats from a given endpoint, that data would be accessible at runtime by referencing app.data.cats.

Example:

console.log(app.data.cats)
[
  {"id":1,"name":"sad cat","url":"https://www.catster.com/wp-content/uploads/2018/05/A-gray-cat-crying-looking-upset.jpg"},
  {"id":2,"name":"tiny kitten","url":"http://origin-www.readersdigest.ca/wp-content/uploads/sites/14/2011/01/4-ways-cheer-up-depressed-cat.jpg"},
  {"id":3,"name":"belly","url":"http://sites.psu.edu/siowfa15/wp-content/uploads/sites/29639/2015/10/cat.jpg"}
]

app.data.options

This is an object which contains the app's administrative options, as configured by an admin within the app instance. Note: this is different from user options, which are defined within app.data.user.options.

Example:

console.log(app.data.options)
{"color":"blue","max_length":7}

app.data.user

This is an object which contains all information about the currently authenticated user. Within this object is:

  • app.data.user.unique_id
  • app.data.user.first_name
  • app.data.user.last_name
  • app.data.user.email

Example:

console.log(app.data.user.unique_id)
"12345"
console.log(app.data.user.first_name)
"John"
console.log(app.data.user.last_name)
"Doe"
console.log(app.data.user.email)
"[email protected]"

app.data.user.params

In addition to the standard user parameters available within data.user (above), you may additionally reference other parameters within the data.user.params object. Note: This is entirely dependent upon the Graphene configuration, as these additional parameters are defined by the SSO configuration, as well as by the Graphene Group Sync APIs. As an example, an app may reference a given user's favorite pizza topping as follows:

Example:

console.log(app.data.user.params.pizza_topping)
"pepperoni"

app.data.user.options

These are the user defined options for a given app / app instance.

Example:

console.log(app.data.user.options)
{"color":"blue","max_length":7}

app.data.user.tags

These are all of the tags associated with the currently-logged-in user. Note: tags are assigned to users based on their group memberships, so user who is a member of the "Undergraduate" group might have a tags as follows:

Example:

console.log(app.data.user.tags)
status:["UG"]

app.data.user.groups

This is an array of group id's for the groups from which the current user is a member.

Example:

console.log(app.data.user.groups)
[1,3,5,7,9]