Working with Server

If you do not have a backend server, you should override the methods of the Backend service and return promises of client data.

Backend Service

Backend is a server-side model. It is defined as an object and has methods for sending requests.
Check out the full list of methods.

How to Override Backend Service

How to override Backend:

  • extend it
  • use the override setting of User Manager
class MyBackend extends userManager.services.Backend {
    // define and override methods here
}
 
webix.ui({
    view: "usermanager",
    url: "//localhost:3200/",
    override: new Map([[userManager.services.Backend, MyBackend]]),
});

Calls to Backend Server

You can send AJAX requests to your backend server:

class MyBackend extends userManager.services.Backend {
  addUser(data) {
    return webix.ajax("//localhost:3200/users", { data })
      .then((data) => data.json());
  }
}

Working with Client Data

If you have client data, you can return it inside of a promise:

class MyBackend extends userManager.services.Backend {
  logsMeta() {
    return Promise.resolve({
      audit:{
        "1":{"name":"User login","target":"user"},
        "2":{"name":"Role added","target":"role"},
        "3":{"name":"Role data changed","target":"role"}
      }
    });
  }
}

Backend Service methods

get(path)

This helper method is called for all data fetching operations. It issues a GET request for the defined path and returns a promise.

Parameters:

  • path (string) - a relative path.

Returns:

  • promise (promise) - promise that resolves with the data.

save(path, data, mode)

This helper method is called for all data saving operations. It issues a POST/DELETE/PUT request, depending on user action.

Parameters:

  • path (string) - a relative path.
  • data (object) - an object with data for the operation
  • mode (number) - mode, where numbers 0, 1 or 2 stand for POST, DELETE or PUT request method

Returns:

  • promise (promise) - promise that resolves with the data.

users()

The method returns a path to the users.

Returns:

  • users (promise) - a promise that resolves with an array of the users objects

Request info:

  • Method: GET
  • URL example:
http://localhost:3200/users

Contains the URL segment.

Response from the server:

The server returns an array with object(s) containing information about user(s).

[
  {"id":87,"name":"Berni Mayour","email":"","details":"",
  "visited":"2020-05-21T10:02:06Z","registered":"2020-05-21T10:02:06Z",
  "avatar":"http://localhost:3200/users/87/avatar/503723673.jpg",
  "status":1},
 
  {"id":95,"name":"John Doe","email":"","details":"",
  "visited":"2020-05-31T17:21:12Z","registered":"2020-05-31T17:21:12Z",
  "avatar":"","status":0}
]

addUser(data)

The method adds a new user to the users list.

Parameters:

  • data (object) - user data

Returns:

  • id (promise) - a promise that resolves with an object ID of the new user

Request info:

  • Method: POST
  • URL example:
http://localhost:3200/users

Contains the URL segment.

Response from the server:

The server returns the ID object of a new user.

{"id":99}

Request Payload example:

{
  name: "Walter Scott"
}

deleteUser(id)

The method removes a user from the users list.

Parameters:

  • id (string) - the ID of the user to delete

Returns:

  • id (promise) - a promise that resolves with an object ID of the deleted user

Request info:

  • Method: DELETE
  • URL example:
http://localhost:3200/users/98

Contains the URL segment and the ID of the user to delete.

Response from the server:

The server returns the ID object of the deleted user.

{"id":98}

updateUser(id, data)

The method updates user's data.

Parameters:

  • id (string) - the ID of the user to update
  • data (object) - new data

Returns:

  • id (promise) - a promise that resolves with an object ID of the updated user

Request info:

  • Method: PUT
  • URL example:
http://localhost:3200/users/99

Contains the URL segment and the ID of the user to update.

Response from the server:

The server returns the ID object of the user being updated.

{"id":98}

Request Payload example:

{
  avatar: ""
  details: ""
  email: "elly.soyer@example.com"
  id: 98
  name: "Elly Soyer"
  registered: "2020-05-31T17:42:34Z"
  status: 1
  visited: "2020-05-31T17:42:34Z"
}

roles()

The method returns a path to the roles.

Returns:

  • roles (promise) - a promise that resolves with an array of the roles objects

Request info:

  • Method: GET
  • URL example:
http://localhost:3200/roles

Contains the URL segment.

Response from the server:

The server returns an array with object(s) containing information about role(s).

[
  {"id":1,"name":"The Creator","color":"#00a037","details":""},
  {"id":2,"name":"Sales","color":"#e7a90b","details":""},
  {"id":3,"name":"Admin","color":"#038cd9","details":""}
]

addRole(data)

The method adds a new role to the roles list.

Parameters:

  • data (object) - role data

Returns:

  • id (promise) - a promise that resolves with an object ID of the new role

Request info:

  • Method: POST
  • URL example:
http://localhost:3200/roles

Contains the URL segment.

Response from the server:

The server returns the ID object of a new role.

{"id":5}

Request Payload exaple:

{
  name: "Manager"
}

deleteRole(id)

The method removes a role from the roles list.

Parameters:

  • id (string) - the ID of the role to delete

Returns:

  • id (promise) - a promise that resolves with an object ID of the deleted role

Request info:

  • Method: DELETE
  • URL example:
http://localhost:3200/roles/3

Contains the URL segment and the ID of the role being deleted.

Response from the server:

The server returns the ID object of the deleted role.

{"id":3}

updateRole(id, data)

The method updates role data.

Parameters:

  • id (string) - the ID of the role being update
  • data (object) - new data

Returns:

  • id (promise) - a promise that resolves with an object ID of the updated role

Request info:

  • Method: PUT
  • URL example:
http://localhost:3200/roles/7

Contains the URL segment and the ID of the role to update.

Response from the server:

The server returns the ID object of the role being updated.

{"id":7}

Request Payload example:

{
  color: "#006EDD"
  details: ""
  id: 7
  name: "Designer"
  rules: [7, 1]
}

rules()

The method returns a path to the rules.

Returns:

  • rules (promise) - a promise that resolves with an array of the rules objects

Request info:

  • Method: GET
  • URL example:
http://localhost:3200/rules

Contains the URL segment.

Response from the server:

The server returns an array with object(s) containing information about rule(s).

[
  {"id":1,"short":"CanSeeUsers","long":"Can see user details and access levels"},
  {"id":2,"short":"CanEditUsers","long":"Can modify user details and access levels"},
  {"id":3,"short":"CanAdminProjects","long":"Can create projects"}
]

meta()

The method returns the metadata of the categories.

Returns:

  • meta (promise) - a promise that resolves with an object of the categories relations

Request info:

  • Method: GET
  • URL example:
http://localhost:3200/meta

Contains the URL segment.

Response from the server:

The server returns an object containing information on how the categories are related to one another. This object has the following structure:

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

avatar(id)

The method is called when user uploads a new avatar.

Parameters:

  • id (string) - the ID of the user the avatar being uploaded for

Returns:

  • data (object) - an object with the avatar data

Request info:

  • Method: POST
  • URL example:
http://localhost:3200/users/95/avatar

Contains the URL segments and the ID of the user.

Response from the server:

The server returns an object containing information about uploaded avatar.

{
  "status":"server",
  "value":"http://localhost:3200/users/95/avatar/photo.jpg"
}

credentials(id)

The method is called when user go to the edit area.

Parameters:

  • id (string) - the ID of the user being edited

Returns:

  • data (promise) - a promise that resolves with an array of the user credentials

Request info:

  • Method: GET
  • URL example:
http://localhost:3200/user/87/credentials

Contains the URL segments and the ID of the user being edited.

addCredentials(id, data)

The method adds a credential to the user.

Parameters:

  • id (string) - the ID of the user
  • data (object) - new data

Returns:

  • id (promise) - a promise that resolves with the object ID of the new credential

Request info:

  • Method: POST
  • URL example:
http://localhost:3200/user/100/credentials

Contains the URL segments and the ID of the user.

Response from the server:

The server returns the ID object of the user.

{"id":100}

Request Payload example:

{
  record: "test"
  source: 1
  user_id: 100
}

resetPassword(id, data)

The method is called upon resetting user's password.

Parameters:

  • id (string) - the ID of the user
  • data (object) - new password

Returns:

  • id (promise) - a promise that resolves with the object ID of the password credential

Request info:

  • Method: PUT
  • URL example:
http://localhost:3200/user/100/credentials

Contains the URL segments and the ID of the user.

Response from the server:

The server returns the ID object of the user.

{"id":100}

Request Payload example:

{
  id: 23
  record: "qwerty123"
}

Contains the ID of the credential and the new password.

deleteCredentials(id, credId)

The method is called upon deleting user's credential.

Parameters:

  • id (string) - the ID of the user
  • credId (string) - the ID of the credential

Returns:

  • id (promise) - a promise that resolves with the object ID of the credential

Request info:

  • Method: DELETE
  • URL example:
http://localhost:3200/user/100/credentials/23

Contains the URL segments, the ID of the user and the ID of the deleted credential.

Response from the server:

The server returns the ID object of the deleted credential.

{"id":23}

logs(type, id)

The method is called when user go to the audit area and triggers one of the records (logins, changes to or changes by)

Parameters:

  • type (string) - type of the record. Can be login, user or by-user
  • id (string) - the ID of the user

Returns:

  • data (promise) - a promise that resolves with an array of audit data objects

Request info:

  • Method: GET
  • URL example:
http://localhost:3200/logs/by-user/100

Contains the URL segment, type of the record and the user's ID.

Response from the server:

The server returns an array containing audit information. Below it is audit for the changes to record.

[
  {"id":506,"user_id":1,"target_id":87,"type":5,
  "details":"Berni Mayour","date":"2020-05-21T10:02:06Z"},
  {"id":524,"user_id":1,"target_id":87,"type":6,
  "details":"role Guest added","date":"2020-05-21T14:36:56Z"}
]

logsMeta()

The method is called when user go to the audit area.

Returns:

  • data (promise) - a promise that resolves with an array of the actions performed in User Manager

Request info:

  • Method: GET
  • URL example:
http://localhost:3200/logs/meta

Contains the URL segments.

Response from the server:

The server returns an object containing the audit of the actions performed in User Manager.

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