tree-manager

0.0.2 • Public • Published

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 = require('../lib/treemanager');
var rootDir = __dirname + '/test_dir_root';
var treeManager = new 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.walkDir(rootDir, function (err, tree) {
  console.log(tree);
});

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.join(req.query.id, req.query.text);
treeManager.createNode(filename, type, function (res) {
  console.log(res);
});

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.renameNode('some_dir/note.txt', 'note_changed.txt', function (res) {
  console.log(res);
});

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.deleteNode('some_dir/notes.txt', function (res) {
  console.log(res);
});

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.moveNode('some_dir/notes.txt', 'next_level/other_dir', function (res) {
  res.send(res);
});

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

Package Sidebar

Install

npm i tree-manager

Weekly Downloads

1

Version

0.0.2

License

MIT

Last publish

Collaborators

  • baniol