mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-02 15:38:15 +00:00
Wiki bugs fix (#2311)
This commit is contained in:
committed by
Daniel Pan
parent
74cfd3cf74
commit
2ab330ab86
@@ -35,6 +35,141 @@ class Tree {
|
||||
node.children.splice(insertIndex, 0, child);
|
||||
}
|
||||
|
||||
removeChildNode(node, child) {
|
||||
let children = node.children;
|
||||
let removeNode = null;
|
||||
let index = null;
|
||||
for (let i = 0; i < children.length; i++) {
|
||||
if (child.path === children[i].path) {
|
||||
removeNode = children[i];
|
||||
index = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
child.parent = null;
|
||||
node.children.splice(index, 1);
|
||||
return removeNode ? removeNode : null;
|
||||
}
|
||||
|
||||
addNodeToTree(node) {
|
||||
let parentNode = this.getNodeParentFromTree(node);
|
||||
this.addChildToNode(parentNode, node);
|
||||
}
|
||||
|
||||
removeNodeFromTree(node) {
|
||||
let parentNode = this.getNodeParentFromTree(node);
|
||||
this.removeChildNode(parentNode, node);
|
||||
}
|
||||
|
||||
getNodeParentFromTree(node) {
|
||||
let parentNode = node.parent;
|
||||
let findNode = null;
|
||||
function cb(node) {
|
||||
if(parentNode.path === node.path){
|
||||
findNode = node;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
this.traverseBF(cb);
|
||||
return findNode;
|
||||
}
|
||||
|
||||
getNodeByPath(path) {
|
||||
let findNode = null;
|
||||
function cb(node){
|
||||
if (node.path === path) {
|
||||
findNode = node;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
this.traverseBF(cb);
|
||||
return findNode;
|
||||
}
|
||||
|
||||
traverseDF(callback) {
|
||||
let stack = [];
|
||||
let found = false;
|
||||
stack.unshift(this.root);
|
||||
let currentNode = stack.shift();
|
||||
while (!found && currentNode) {
|
||||
found = callback(currentNode) == true ? true : false;
|
||||
if (!found) {
|
||||
stack.unshift(...currentNode.children);
|
||||
currentNode = stack.shift();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
traverseBF(callback) {
|
||||
let queue = [];
|
||||
let found = false;
|
||||
queue.push(this.root);
|
||||
let currentNode = queue.shift();
|
||||
while (!found && currentNode) {
|
||||
found = callback(currentNode) === true ? true : false;
|
||||
if (!found) {
|
||||
queue.push(...currentNode.children);
|
||||
currentNode = queue.shift();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
setOneNodeToActived({node}) {
|
||||
this.setNoneNodeActived();
|
||||
let root = this.root;
|
||||
root.isExpanded = true;
|
||||
let layer2 = root.hasChildren() ? root.children : null; // direct to replace root child;
|
||||
let isLayer2 = false;
|
||||
for (let i = 0; i < layer2.length; i++) {
|
||||
if (node.path === layer2[i].path) {
|
||||
isLayer2 = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (isLayer2) {
|
||||
return;
|
||||
}
|
||||
let replaceNode = null;
|
||||
let needReplacedNode = null;
|
||||
while (node.parent) {
|
||||
let flag = false;
|
||||
node.parent.isExpanded = true;
|
||||
for (let i = 0; i < layer2.length; i++) {
|
||||
if (node.parent.path === layer2[i].path) {
|
||||
replaceNode = node.parent;
|
||||
needReplacedNode = layer2[i];
|
||||
flag = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (flag) {
|
||||
break;
|
||||
}
|
||||
node = node.parent;
|
||||
}
|
||||
|
||||
this.removeChildNode(root, needReplacedNode);
|
||||
this.addChildToNode(root, replaceNode);
|
||||
}
|
||||
|
||||
setNoneNodeActived() {
|
||||
function setNodeToDeactived(node) {
|
||||
if (node.isExpanded) {
|
||||
node.isExpanded = false;
|
||||
if (node.hasChildren()) {
|
||||
let children = node.children;
|
||||
children.forEach(function(child) {
|
||||
setNodeToDeactived(child);
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
setNodeToDeactived(this.root);
|
||||
this.root.isExpanded = true; // default to show;
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
* parse tree from javascript object
|
||||
|
Reference in New Issue
Block a user