1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-17 16:53:34 +00:00

WIP: add support for nested folders and collection

This commit is contained in:
Kyle Spearrin
2018-10-26 12:37:55 -04:00
parent 9d1f8e43d9
commit 69e664a154
10 changed files with 162 additions and 32 deletions

View File

@@ -25,6 +25,10 @@ import { StateService } from 'jslib/abstractions/state.service';
import { CipherType } from 'jslib/enums/cipherType';
import { CipherView } from 'jslib/models/view/cipherView';
import { CollectionView } from 'jslib/models/view/collectionView';
import { FolderView } from 'jslib/models/view/folderView';
import { TreeNode } from 'jslib/models/domain/treeNode';
import { BroadcasterService } from 'jslib/angular/services/broadcaster.service';
@@ -45,6 +49,8 @@ export class CiphersComponent extends BaseCiphersComponent implements OnInit, On
folderId: string = null;
type: CipherType = null;
pagedCiphers: CipherView[] = [];
nestedFolders: Array<TreeNode<FolderView>>;
nestedCollections: Array<TreeNode<CollectionView>>;
private didScroll = false;
private selectedTimeout: number;
@@ -88,9 +94,11 @@ export class CiphersComponent extends BaseCiphersComponent implements OnInit, On
this.folderId = params.folderId === 'none' ? null : params.folderId;
this.searchPlaceholder = this.i18nService.t('searchFolder');
if (this.folderId != null) {
const folder = await this.folderService.get(this.folderId);
if (folder != null) {
this.groupingTitle = (await folder.decrypt()).name;
const folderNode = await this.folderService.getNested(this.folderId);
if (folderNode != null && folderNode.node != null) {
this.groupingTitle = folderNode.node.name;
this.nestedFolders = folderNode.children != null && folderNode.children.length > 0 ?
folderNode.children : null;
}
} else {
this.groupingTitle = this.i18nService.t('noneFolder');
@@ -99,9 +107,11 @@ export class CiphersComponent extends BaseCiphersComponent implements OnInit, On
} else if (params.collectionId) {
this.showAdd = false;
this.searchPlaceholder = this.i18nService.t('searchCollection');
const collection = await this.collectionService.get(params.collectionId);
if (collection != null) {
this.groupingTitle = (await collection.decrypt()).name;
const collectionNode = await this.collectionService.getNested(params.collectionId);
if (collectionNode != null && collectionNode.node != null) {
this.groupingTitle = collectionNode.node.name;
this.nestedCollections = collectionNode.children != null && collectionNode.children.length > 0 ?
collectionNode.children : null;
}
await super.load((c) => c.collectionIds != null && c.collectionIds.indexOf(params.collectionId) > -1);
} else {
@@ -115,6 +125,16 @@ export class CiphersComponent extends BaseCiphersComponent implements OnInit, On
this.searchText = this.state.searchText;
}
window.setTimeout(() => this.popupUtils.setContentScrollY(window, this.state.scrollY), 0);
// TODO: This is pushing a new page onto the browser navigation history. Figure out how to now do that
// so that we don't have to hit back button twice
const newUrl = this.router.createUrlTree([], {
queryParams: { direction: null },
queryParamsHandling: 'merge',
preserveFragment: true,
replaceUrl: true,
}).toString();
this.location.go(newUrl);
});
this.broadcasterService.subscribe(ComponentId, (message: any) => {
@@ -151,6 +171,16 @@ export class CiphersComponent extends BaseCiphersComponent implements OnInit, On
}, 200);
}
selectFolder(folder: FolderView) {
if (folder.id != null) {
this.router.navigate(['/ciphers'], { queryParams: { folderId: folder.id, direction: 'f' } });
}
}
selectCollection(collection: CollectionView) {
this.router.navigate(['/ciphers'], { queryParams: { collectionId: collection.id, direction: 'f' } });
}
async launchCipher(cipher: CipherView) {
if (cipher.type !== CipherType.Login || !cipher.login.canLaunch) {
return;
@@ -200,6 +230,10 @@ export class CiphersComponent extends BaseCiphersComponent implements OnInit, On
return !searching && this.ciphers.length > this.pageSize;
}
routerCanReuse() {
return false;
}
async resetPaging() {
this.pagedCiphers = [];
this.loadMore();