mirror of
https://github.com/bitwarden/browser
synced 2025-01-26 11:15:03 +01:00
getNested tree object by node id
This commit is contained in:
parent
b0eea9d7ce
commit
d4b3a16fd1
@ -15,6 +15,7 @@ export abstract class CollectionService {
|
||||
getAll: () => Promise<Collection[]>;
|
||||
getAllDecrypted: () => Promise<CollectionView[]>;
|
||||
getAllNested: (collections?: CollectionView[]) => Promise<Array<TreeNode<CollectionView>>>;
|
||||
getNested: (id: string) => Promise<TreeNode<CollectionView>>;
|
||||
upsert: (collection: CollectionData | CollectionData[]) => Promise<any>;
|
||||
replace: (collections: { [id: string]: CollectionData; }) => Promise<any>;
|
||||
clear: (userId: string) => Promise<any>;
|
||||
|
@ -15,6 +15,7 @@ export abstract class FolderService {
|
||||
getAll: () => Promise<Folder[]>;
|
||||
getAllDecrypted: () => Promise<FolderView[]>;
|
||||
getAllNested: () => Promise<Array<TreeNode<FolderView>>>;
|
||||
getNested: (id: string) => Promise<TreeNode<FolderView>>;
|
||||
saveWithServer: (folder: Folder) => Promise<any>;
|
||||
upsert: (folder: FolderData | FolderData[]) => Promise<any>;
|
||||
replace: (folders: { [id: string]: FolderData; }) => Promise<any>;
|
||||
|
@ -16,9 +16,7 @@ import { FolderService } from '../../abstractions/folder.service';
|
||||
|
||||
export class GroupingsComponent {
|
||||
@Input() showFolders = true;
|
||||
@Input() loadNestedFolders = false;
|
||||
@Input() showCollections = true;
|
||||
@Input() loadNestedCollections = false;
|
||||
@Input() showFavorites = true;
|
||||
|
||||
@Output() onAllClicked = new EventEmitter();
|
||||
@ -63,9 +61,7 @@ export class GroupingsComponent {
|
||||
} else {
|
||||
this.collections = collections;
|
||||
}
|
||||
if (this.loadNestedCollections) {
|
||||
this.nestedCollections = await this.collectionService.getAllNested(this.collections);
|
||||
}
|
||||
this.nestedCollections = await this.collectionService.getAllNested(this.collections);
|
||||
}
|
||||
|
||||
async loadFolders() {
|
||||
@ -73,9 +69,7 @@ export class GroupingsComponent {
|
||||
return;
|
||||
}
|
||||
this.folders = await this.folderService.getAllDecrypted();
|
||||
if (this.loadNestedFolders) {
|
||||
this.nestedFolders = await this.folderService.getAllNested();
|
||||
}
|
||||
this.nestedFolders = await this.folderService.getAllNested();
|
||||
}
|
||||
|
||||
selectAll() {
|
||||
|
@ -20,7 +20,7 @@ export class ServiceUtils {
|
||||
nodeTree.push(new TreeNode(obj, partName));
|
||||
return;
|
||||
}
|
||||
this.nestedTraverse(nodeTree[i].children, partIndex + 1, parts, obj, delimiter);
|
||||
ServiceUtils.nestedTraverse(nodeTree[i].children, partIndex + 1, parts, obj, delimiter);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -31,7 +31,21 @@ export class ServiceUtils {
|
||||
return;
|
||||
}
|
||||
const newPartName = parts[partIndex] + delimiter + parts[partIndex + 1];
|
||||
this.nestedTraverse(nodeTree, 0, [newPartName, ...parts.slice(partIndex + 2)], obj, delimiter);
|
||||
ServiceUtils.nestedTraverse(nodeTree, 0, [newPartName, ...parts.slice(partIndex + 2)], obj, delimiter);
|
||||
}
|
||||
}
|
||||
|
||||
static getTreeNodeObject(nodeTree: Array<TreeNode<ITreeNodeObject>>, id: string): TreeNode<ITreeNodeObject> {
|
||||
for (let i = 0; i < nodeTree.length; i++) {
|
||||
if (nodeTree[i].node.id === id) {
|
||||
return nodeTree[i];
|
||||
} else if (nodeTree[i].children != null) {
|
||||
const node = ServiceUtils.getTreeNodeObject(nodeTree[i].children, id);
|
||||
if (node !== null) {
|
||||
return node;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -111,6 +111,11 @@ export class CollectionService implements CollectionServiceAbstraction {
|
||||
return nodes;
|
||||
}
|
||||
|
||||
async getNested(id: string): Promise<TreeNode<CollectionView>> {
|
||||
const collections = await this.getAllNested();
|
||||
return ServiceUtils.getTreeNodeObject(collections, id) as TreeNode<CollectionView>;
|
||||
}
|
||||
|
||||
async upsert(collection: CollectionData | CollectionData[]): Promise<any> {
|
||||
const userId = await this.userService.getUserId();
|
||||
let collections = await this.storageService.get<{ [id: string]: CollectionData; }>(
|
||||
|
@ -110,6 +110,11 @@ export class FolderService implements FolderServiceAbstraction {
|
||||
return nodes;
|
||||
}
|
||||
|
||||
async getNested(id: string): Promise<TreeNode<FolderView>> {
|
||||
const folders = await this.getAllNested();
|
||||
return ServiceUtils.getTreeNodeObject(folders, id) as TreeNode<FolderView>;
|
||||
}
|
||||
|
||||
async saveWithServer(folder: Folder): Promise<any> {
|
||||
const request = new FolderRequest(folder);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user