mirror of
https://github.com/bitwarden/browser.git
synced 2024-11-23 11:56:00 +01:00
store parent node
This commit is contained in:
parent
d4b3a16fd1
commit
aa0b274f8f
@ -5,7 +5,7 @@ import {
|
|||||||
|
|
||||||
export class ServiceUtils {
|
export class ServiceUtils {
|
||||||
static nestedTraverse(nodeTree: Array<TreeNode<ITreeNodeObject>>, partIndex: number, parts: string[],
|
static nestedTraverse(nodeTree: Array<TreeNode<ITreeNodeObject>>, partIndex: number, parts: string[],
|
||||||
obj: ITreeNodeObject, delimiter: string) {
|
obj: ITreeNodeObject, parent: ITreeNodeObject, delimiter: string) {
|
||||||
if (parts.length <= partIndex) {
|
if (parts.length <= partIndex) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -17,21 +17,23 @@ export class ServiceUtils {
|
|||||||
if (nodeTree[i].node.name === parts[partIndex]) {
|
if (nodeTree[i].node.name === parts[partIndex]) {
|
||||||
if (end && nodeTree[i].node.id !== obj.id) {
|
if (end && nodeTree[i].node.id !== obj.id) {
|
||||||
// Another node with the same name.
|
// Another node with the same name.
|
||||||
nodeTree.push(new TreeNode(obj, partName));
|
nodeTree.push(new TreeNode(obj, partName, parent));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
ServiceUtils.nestedTraverse(nodeTree[i].children, partIndex + 1, parts, obj, delimiter);
|
ServiceUtils.nestedTraverse(nodeTree[i].children, partIndex + 1, parts,
|
||||||
|
obj, nodeTree[i].node, delimiter);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (nodeTree.filter((n) => n.node.name === partName).length === 0) {
|
if (nodeTree.filter((n) => n.node.name === partName).length === 0) {
|
||||||
if (end) {
|
if (end) {
|
||||||
nodeTree.push(new TreeNode(obj, partName));
|
nodeTree.push(new TreeNode(obj, partName, parent));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const newPartName = parts[partIndex] + delimiter + parts[partIndex + 1];
|
const newPartName = parts[partIndex] + delimiter + parts[partIndex + 1];
|
||||||
ServiceUtils.nestedTraverse(nodeTree, 0, [newPartName, ...parts.slice(partIndex + 2)], obj, delimiter);
|
ServiceUtils.nestedTraverse(nodeTree, 0, [newPartName, ...parts.slice(partIndex + 2)],
|
||||||
|
obj, parent, delimiter);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,8 +1,10 @@
|
|||||||
export class TreeNode<T extends ITreeNodeObject> {
|
export class TreeNode<T extends ITreeNodeObject> {
|
||||||
|
parent: T;
|
||||||
node: T;
|
node: T;
|
||||||
children: Array<TreeNode<T>> = [];
|
children: Array<TreeNode<T>> = [];
|
||||||
|
|
||||||
constructor(node: T, name: string) {
|
constructor(node: T, name: string, parent: T) {
|
||||||
|
this.parent = parent;
|
||||||
this.node = node;
|
this.node = node;
|
||||||
this.node.name = name;
|
this.node.name = name;
|
||||||
}
|
}
|
||||||
|
@ -106,7 +106,8 @@ export class CollectionService implements CollectionServiceAbstraction {
|
|||||||
collections.forEach((f) => {
|
collections.forEach((f) => {
|
||||||
const collectionCopy = new CollectionView();
|
const collectionCopy = new CollectionView();
|
||||||
collectionCopy.id = f.id;
|
collectionCopy.id = f.id;
|
||||||
ServiceUtils.nestedTraverse(nodes, 0, f.name.split(NestingDelimiter), collectionCopy, NestingDelimiter);
|
ServiceUtils.nestedTraverse(nodes, 0, f.name.split(NestingDelimiter), collectionCopy,
|
||||||
|
null, NestingDelimiter);
|
||||||
});
|
});
|
||||||
return nodes;
|
return nodes;
|
||||||
}
|
}
|
||||||
|
@ -105,7 +105,8 @@ export class FolderService implements FolderServiceAbstraction {
|
|||||||
const folderCopy = new FolderView();
|
const folderCopy = new FolderView();
|
||||||
folderCopy.id = f.id;
|
folderCopy.id = f.id;
|
||||||
folderCopy.revisionDate = f.revisionDate;
|
folderCopy.revisionDate = f.revisionDate;
|
||||||
ServiceUtils.nestedTraverse(nodes, 0, f.name.split(NestingDelimiter), folderCopy, NestingDelimiter);
|
ServiceUtils.nestedTraverse(nodes, 0, f.name.split(NestingDelimiter), folderCopy,
|
||||||
|
null, NestingDelimiter);
|
||||||
});
|
});
|
||||||
return nodes;
|
return nodes;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user