In addition to Backend Service Document Manager has Users and Tags services to work with on the server side.
Document Manager is a backend-oriented component and expects a server to fetch data from. You can provide a link to it by the url setting:
webix.ui({
view: "docmanager",
url:"http://localhost:3200/"
});
Sample backend for Document Manager is available for downloading.
If you do not have a backend server, you should override the methods of the Backend service and return promises of client-side data.
Icons and preview images for files are generated by a backend service.
Document Manager does not load all the data to the client at once:
These data are loaded on demand and cached:
Contents of other directories are loaded on demand, when opened, and cached.
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.
In general the process of overriding a service is the same as for File Manager:
1. Extend it.
2. Use the override setting of Document Manager.
class MyBackend extends docManager.services.Backend {
// define and override methods here
}
webix.ui({
view: "docmanager",
url: "https://docs.webix.com/docmanager-backend/",
override: new Map([[docManager.services.Backend, MyBackend]]),
});
You can send AJAX requests to your backend server:
class MyBackend extends docManager.services.Backend {
files(id, source) {
return webix.ajax("//localhost:3200/files", { id, source })
.then((data) => data.json());
}
}
If you have client-side data, you can return them inside of a promise:
class MyBackend extends docManager.services.Backend {
getInfo() {
return Promise.resolve({
stats:{
free: 52 * 1000 * 1000,
total: 250 * 1000 * 1000,
used: 198.4 * 1000 * 1000,
}
});
}
}
Related sample: Document Manager: Data Source
Document Manager has the same methods as File Manager Backend Service does, and proposes several of its own. Below you can find descriptions of the following methods:
This method redefines files from File Manager Backend service. The method is called when the user opens a folder.
Parameters:
Returns: a promise that resolves with an array of objects.
Request:
GET http://localhost:3200/files?id=%2F&source=shared
Response:
The server returns an array of objects found on the directory.
[
{"value":"lalala.txt","id":"/lalala.txt","size":0,
"date":1587121183,"type":"code","users":[4,2,1,3]
},
{"value":"New file.txt","id":"/widgets/New file.txt","size":0,
"date":1587133267,"type":"code","star":true,"users":[1,2]
},
// other
]
Permanently removes a file or directory. The method is called when a user removes a file or directory from Trash.
Parameters:
Returns: a promise that resolves with a server response (success or error).
Request:
DELETE http://localhost:3200/delete?id=259
If the request fails the server returns an error object:
{
invalid: true,
err: "Some error message here"
}
Restores a removed file or directory from Trash.
Parameters:
Returns: a promise that resolves with file or directory data object.
Request:
PUT http://localhost:3200/delete
Form Data
id: 258
Response:
The server returns an object with the file or directory data.
{
"value":"New file.txt","id":"/123/New file.txt","size":0,
"date":1587128389,"type":"code"
}
If the request fails the server returns an error object:
{
invalid: true,
err: "Some error message here"
}
Is called when user adds a file/directory to Favorite.
Parameters:
Returns: a promise that resolves with a server response (success or error).
Request:
POST http://localhost:3200/favorite
Form Data
id: /mycat.png
Is called when user removes a file/directory from Favorite.
Parameters:
Returns: a promise that resolves with a server response (success or error).
Request:
DELETE http://localhost:3200/favorite?id=%2Fmycat.png
Is called upon saving binary files (in Document Manager it's used for saving Excel files).
Parameters:
Returns: a promise that resolves with the file data object.
Request:
POST http://localhost:3200/direct?id=%2FSpread.xlsx
Form Data
upload: (binary)
Response:
The server returns a promise that resolves with the file data object.
{
"value":"Spread.xlsx","id":"/Spread.xlsx","size":129848,
"date":1587383690,"type":"file"
}
The service works with the user-related operations through the following methods:
Is used by other methods for preparing URLs for server requests.
Parameters:
Returns: the full path.
Is called when user opens file preview.
Returns: a promise that resolves with an array of users objects.
Request:
GET http://localhost:3200/users/all
Response:
The server returns an array with users data objects.
[
{"id":1,"name":"Alastor Moody","email":"alastor@ya.ru",
"avatar":"/users/1/avatar/1.jpg"},
{"id":2,"name":"Sirius Black","email":"sirius@gmail.com",
"avatar":"/users/3/avatar/3.jpg"}
]
Shares a file or directory with a user. The shared file or directory is being added to the Shared group folder.
Parameters:
Returns: a promise that resolves with a server response (success or error).
Request:
POST http://localhost:3200/share
Form Data
id: /mycat.png
user: 3
Removes a user from the "shared-with" list.
Parameters:
Returns: a promise that resolves with a server response (success or error).
Request:
DELETE http://localhost:3200/share?id=%2Fmycat.png&user=3
Is called when user opens comments section.
Parameters:
Returns: a promise that resolves with an array of comments objects (an empty array if there are no comments left).
Request:
GET http://localhost:3200/comments?id=%2Fmycat.png
Response:
The server returns an array of comments data objects if any.
[
{
"id":45,"text":"He's my patronus!!","date":"2020-04-20T07:56:49Z","user_id":1
}
]
Leaves a comment under a specified file.
Parameters:
Returns: a promise that resolves with a server response (success or error).
Request:
POST http://localhost:3200/comments?id=%2Fmycat.png
Form Data
value: Accio!
Updates a specified comment.
Parameters:
Returns: a promise that resolves with a server response (success or error).
Request:
PUT http://localhost:3200/comments/1
Form Data
value: Edited text
Removes a specified comment.
Parameters:
Returns: a promise that resolves with a server response (success or error).
Request:
DELETE http://localhost:3200/comments/1
The service works with the tags-related operations through the following methods:
Is used by other methods for preparing URLs for server requests.
Parameters:
Returns: the full path.
Is called when user opens file preview.
Returns: a promise that resolves with an array of all tags (an empty array if there are no tags).
Request:
GET http://localhost:3200/tags/all
Response:
The server returns a promise that resolves with an array of object tags.
[
{"id":1,"name":"Review","value":"Review"},
{"id":2,"name":"Accepted","value":"Accepted"},
{"id":3,"name":"Denied","value":"Denied"},
{"id":4,"name":"Personal","value":"Personal"}
]
Adds a tag to the tags list.
Parameters:
Returns: a promise that resolves with a server response (success or error).
Request:
POST http://localhost:3200/tags
Form Data
name: New
color: #0bbed7
Response:
The server returns a data object of the added tag.
{
"id":13,
"name":"New",
"value":"New",
"color":"#0bbed7"
}
Note that by default, length of the tag name cannot exceed 32 characters. If you need a custom length you should change the corresponding table on the backend.
Updates an already existing tag.
Parameters:
Returns: a promise that resolves with a server response (success or error).
Request:
PUT http://localhost:3200/tags/13
Form Data
name: University
color: #c87095
Response :
The server returns a data object of the updated tag.
{
"id":13,
"name":"University",
"value":"University",
"color":"#c87095" // color was changed
}
Note that by default, length of the tag name cannot exceed 32 characters. If you need a custom length you should change the corresponding table on the backend.
Removes a specified tag from the tags list.
Parameters:
Returns: a promise that resolves with a server response (success or error).
Request:
DELETE http://localhost:3200/tags/3
Is called when user opens the preview of a specified file.
Parameters:
Returns: a promise that resolves with an array of tags (an empty array if there are no tags).
Request:
GET http://localhost:3200/tags?id=%2FNew%20file.txt
Response:
The server returns an array of the tags' IDs.
[
4,2
]
Saves tags of a file.
Parameters:
Returns: a promise that resolves with a server response (success or error).
Request:
PUT http://localhost:3200/tags
Form Data
id: /New file.txt
value: 0,1
The service works with the version history of text (type "code") and Excel files through the following methods:
Is used by other methods for preparing URLs for server requests.
Parameters:
Returns: the full path.
Is called when user opens the version history of a specified file.
Parameters:
Returns: a promise that resolves with an array of all versions (an empty array if there version history is empty).
Request:
GET http://localhost:3200/versions?id=%2Fdocker-compose.yml
Response:
The server returns an array of version objects.
[
{
"id":20,
"date":"2020-07-07T08:51:00Z",
"user":1,
"content":"",
"origin":null
}
]
Is called when user selects a file version from the history.
Parameters:
Returns: a promise that resolves with a version compared to the previous version of a text file.
Request:
GET http://localhost:3200/versions/20?mode=text&diff=true
Form Data
mode: text
Response:
The server returns an HTML string like the following:
`
<span>version: "3"
services:
worker:
networks:
- app
- web
restart: always
</span><span class='webix_docmanager_diff_remove'>↲<br></span>
<span class='webix_docmanager_diff_insert'>someNewKey<br></span>
`
Is called when user restores a specified version.
Parameters:
Returns: a promise that resolves with with the data of a new version.
Request:
POST http://localhost:3200/versions
Form Data
id: /docker-compose.yml
version: 26
Response:
The server returns file object:
{
"value":"docker-compose.yml",
"id":"/docker-compose.yml",
"size":162,
"date":1594114235,
"type":"code"
}
Is called when user opens an Excel file.
Parameters:
Returns: URL for a request to get a version of the Excel file.
Back to top