tree-manager
nodejs connector for jstree library.
To run the example go to example
folder run npm install
and point your browser to localhost:5000
.
Initialization
var TreeManager = ;var rootDir = __dirname + '/test_dir_root';var treeManager = rootDir;
Set the root path whil instantiating the module.
You can change the root directory on the fly by calling treeManager.setRoot(path)
with a path as an argument.
Methods
walkDir
Walks down recursivelly the root folder.
Example:
treeManager;
Parameters:
- rootDirectory - absolute path to rd
- callback - function called on success or error, returns error object or an object with the directory structure
createNode
Creates a new file or folder
Example:
var type = 'file';var filename = path;treeManager;
Parameters:
- name - path to a new file or folder
- type - file or folder
- callback - function called on success or error, returns error object or new folder or file name.
renameNode
Renames a file or folder
Example:
treeManager;
Parameters:
- oldPath - path to the current file or folder
- newName - new name for the file or folder
- callback - function called on success or error, returns error object or changed file path
deleteNode
Removes file or folder. Folders are removed recursivelly.
Example:
treeManager;
Parameters:
- nodePath Relative path of the node to be removed
- callback - function called on success or error, returns error object or path of the removed node
moveNode
Moves node
Example:
treeManager;
Parameters:
- nodePath Relative path of the node to be moved
- nodeParent Relative path of the parent target node
- callback - function called on success returns new path to the node
Tests
To perform tests run npm test
in the tree-manager
root directory.
TODO
- 2 option for folder removal - recursive with all subfolders and files and only empty
- check performance of walkDir function for larger directory structure
- check uniqueness after renaming and moving - server side
- write file to example