Working with Data

Loading Data

User Manager expects data loaded by the URL:

view:"usermanager", url:"remote/data"

Jet Services

User Manager has the following services to work with data:

  • Local - works with the client-side data
  • Operations - synchronizes the backend data with the client data
  • Prompt - service for adding new reports (User/Role by default) via a dialog
  • Progress - visualizes progress of operations on the client
  • Backend - works with the backend server

Data Operations

Getting Local Data

All loaded data from the users, roles and rules categories are stored in DataCollections. To access a collection use one of the self-named methods - .users(), .roles() or .rules() of the Local service respectively. Any of them takes the only parameter:

  • now (boolean) - if true, we assume that the collection data is available on the client.
const data = $$("um").getService("local");
 
// getting the 'users' collection
const collection = data.users();

Note that onсe loaded a collection is cached, so you can access it any time in a synchronous mode.

But if you're not sure whether it is loaded or not you can request the collection asynchronously. Data will be loaded in process:

data.roles(true).then(collection => {/* custom logic */});

Additionally, you can serialize the data collection to access the data elements themselves:

const rules = data.rules(true)
.then(collection => {
    collection.serialize(); // array of rules
});

Related sample:  User Manager: Data Operations

Getting Metadata

Getting the categories relations

When loaded the records do not contain any information on how users, roles and rules are related to one another. It is done for safety reasons.

You can access these relations by calling the .meta() method of the Local service. The method takes the only parameter:

  • now (boolean) - if true, we assume that the data is available on the client.
const data = $$("um").getService("local");
data.meta(true);

It returns an object with the following structure:

{
  "RoleRule":[[3,1]],
  "UserRole":[[4,3]], // a user with ID 4 has a role with ID 3
  "UserRule":[[2,6]]
}

Getting the last actions performed

You can access the list of the last actions performed by the users via the .logsMeta() method. The method takes the only parameter:

  • now (boolean) - if true, we assume that the data is available on the client.
const data = $$("um").getService("local");
data.meta(true);

It returns an object with the names of the actions and the categories they were performed in:

{
  "1":{"name":"User login","target":"user"},
  "2":{"name":"Role added","target":"role"},
  "3":{"name":"Role data changed","target":"role"}
}
Back to top