File Manager is a backend-oriented component and expects data loaded by the URL:
view:"filemanager", url:"remote/data"
File Manager expects JSON data where each array element (file) contains the following fields:
File Manager expects JSON data where each array element (folder) contains the following fields:
Depending on the type of the files, backend generates icons and preview images for them.
File Manager has the following services for data:
1. Local Data
// update the file data on the client side
const data = {
value:"myadventures.txt",
date: new Date(),
size:1231,
id:"/myadventures.txt",
type:"code"
};
$$("files").getService("local").updateFile(data.id, {
size: data.size, date: data.date
});
2. Upload
const upload = $$("fm").getService("upload");
upload.fileDialog(id); // opens a dialog for uploading
3. Progress
this.app.getService("progress").files(label, files, callback => {
// do something with files
});
4. Operations
// open a file in a new browser tab
const file = {
value:"pixeljuice.pdf",
date: new Date(),
size:7231,
id:"/pixeljuice.pdf",
type:"document"
};
$$("files").getService("operations").open(file);
5. Backend
const back = $$("fm").getService("backend");
back.folders(id).then((data) => console.log(data));
Study the models folder in the source code for method signatures.
All loaded directories are stored in DataCollections. You can access a collection by calling the getState method and referring to the path property of the resulting object:
const path = $$("fm").getState().path;
To access files in the current working directory, call the files() method of the Local service with the following parameters:
const path = $$("fm").getState().path;
const data = $$("fm").getService("local");
const collection = data.files(path, true);
If you're not sure whether the directory is loaded or not you can request files asynchronously:
data.files("/some/path").then((collection) => { /*custom logic*/} );
Additionally, you can serialize the data collection to access the data elements themselves:
const myfiles = data.files(path, true).serialize();
The tree of all the directories is loaded at once and is stored in a view-less TreeCollection. To get all the directories, use the code below:
Getting all the folders
const data = $$("fm").getService("local");
data.folders();
By default the root element of the folders collection is "My Files" with the "../files" path.
You can remove all elements from the currently opened directory by calling the clearAll() method of its collection:
const data = $$("fm").getService("local");
const path = $$("fm").getState().path;
data.files(path).then((collection) => collection.clearAll());
To remove all the files from all the directories iterate the cache map and apply clearAll() to each file collection:
const data = $$("fm").getService("local");
data.fscache.each(collection => {
collection.clearAll();
});
data.folders().then((collection) => collection.clearAll());
To reload all the files in the currently opened directory call the refresh method of the Local Service with the current path as a parameter:
const data = $$("fm").getService("local");
const path = $$("fm").getState().path;
data.refresh(path);
Folder tree can be reloaded by calling folders method of the Local Service and passing the argument true to it:
const data = $$("fm").getService("local");
data.folders(true);
Related sample: File Manager: Data Operations
Note that when called without a parameter, the method will return the current folder structure.
Back to top