mirror of
https://github.com/bitwarden/browser
synced 2025-01-28 03:59:50 +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[]>;
|
getAll: () => Promise<Collection[]>;
|
||||||
getAllDecrypted: () => Promise<CollectionView[]>;
|
getAllDecrypted: () => Promise<CollectionView[]>;
|
||||||
getAllNested: (collections?: CollectionView[]) => Promise<Array<TreeNode<CollectionView>>>;
|
getAllNested: (collections?: CollectionView[]) => Promise<Array<TreeNode<CollectionView>>>;
|
||||||
|
getNested: (id: string) => Promise<TreeNode<CollectionView>>;
|
||||||
upsert: (collection: CollectionData | CollectionData[]) => Promise<any>;
|
upsert: (collection: CollectionData | CollectionData[]) => Promise<any>;
|
||||||
replace: (collections: { [id: string]: CollectionData; }) => Promise<any>;
|
replace: (collections: { [id: string]: CollectionData; }) => Promise<any>;
|
||||||
clear: (userId: string) => Promise<any>;
|
clear: (userId: string) => Promise<any>;
|
||||||
|
@ -15,6 +15,7 @@ export abstract class FolderService {
|
|||||||
getAll: () => Promise<Folder[]>;
|
getAll: () => Promise<Folder[]>;
|
||||||
getAllDecrypted: () => Promise<FolderView[]>;
|
getAllDecrypted: () => Promise<FolderView[]>;
|
||||||
getAllNested: () => Promise<Array<TreeNode<FolderView>>>;
|
getAllNested: () => Promise<Array<TreeNode<FolderView>>>;
|
||||||
|
getNested: (id: string) => Promise<TreeNode<FolderView>>;
|
||||||
saveWithServer: (folder: Folder) => Promise<any>;
|
saveWithServer: (folder: Folder) => Promise<any>;
|
||||||
upsert: (folder: FolderData | FolderData[]) => Promise<any>;
|
upsert: (folder: FolderData | FolderData[]) => Promise<any>;
|
||||||
replace: (folders: { [id: string]: FolderData; }) => Promise<any>;
|
replace: (folders: { [id: string]: FolderData; }) => Promise<any>;
|
||||||
|
@ -16,9 +16,7 @@ import { FolderService } from '../../abstractions/folder.service';
|
|||||||
|
|
||||||
export class GroupingsComponent {
|
export class GroupingsComponent {
|
||||||
@Input() showFolders = true;
|
@Input() showFolders = true;
|
||||||
@Input() loadNestedFolders = false;
|
|
||||||
@Input() showCollections = true;
|
@Input() showCollections = true;
|
||||||
@Input() loadNestedCollections = false;
|
|
||||||
@Input() showFavorites = true;
|
@Input() showFavorites = true;
|
||||||
|
|
||||||
@Output() onAllClicked = new EventEmitter();
|
@Output() onAllClicked = new EventEmitter();
|
||||||
@ -63,20 +61,16 @@ export class GroupingsComponent {
|
|||||||
} else {
|
} else {
|
||||||
this.collections = collections;
|
this.collections = collections;
|
||||||
}
|
}
|
||||||
if (this.loadNestedCollections) {
|
|
||||||
this.nestedCollections = await this.collectionService.getAllNested(this.collections);
|
this.nestedCollections = await this.collectionService.getAllNested(this.collections);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
async loadFolders() {
|
async loadFolders() {
|
||||||
if (!this.showFolders) {
|
if (!this.showFolders) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.folders = await this.folderService.getAllDecrypted();
|
this.folders = await this.folderService.getAllDecrypted();
|
||||||
if (this.loadNestedFolders) {
|
|
||||||
this.nestedFolders = await this.folderService.getAllNested();
|
this.nestedFolders = await this.folderService.getAllNested();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
selectAll() {
|
selectAll() {
|
||||||
this.clearSelections();
|
this.clearSelections();
|
||||||
|
@ -20,7 +20,7 @@ export class ServiceUtils {
|
|||||||
nodeTree.push(new TreeNode(obj, partName));
|
nodeTree.push(new TreeNode(obj, partName));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.nestedTraverse(nodeTree[i].children, partIndex + 1, parts, obj, delimiter);
|
ServiceUtils.nestedTraverse(nodeTree[i].children, partIndex + 1, parts, obj, delimiter);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -31,7 +31,21 @@ export class ServiceUtils {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const newPartName = parts[partIndex] + delimiter + parts[partIndex + 1];
|
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;
|
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> {
|
async upsert(collection: CollectionData | CollectionData[]): Promise<any> {
|
||||||
const userId = await this.userService.getUserId();
|
const userId = await this.userService.getUserId();
|
||||||
let collections = await this.storageService.get<{ [id: string]: CollectionData; }>(
|
let collections = await this.storageService.get<{ [id: string]: CollectionData; }>(
|
||||||
|
@ -110,6 +110,11 @@ export class FolderService implements FolderServiceAbstraction {
|
|||||||
return nodes;
|
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> {
|
async saveWithServer(folder: Folder): Promise<any> {
|
||||||
const request = new FolderRequest(folder);
|
const request = new FolderRequest(folder);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user