bitwarden-estensione-browser/src/popup2/vault/groupings.component.ts

93 lines
3.1 KiB
TypeScript
Raw Normal View History

2018-04-05 16:29:11 +02:00
import * as template from './groupings.component.html';
2018-04-05 04:59:42 +02:00
import {
Component,
OnInit,
} from '@angular/core';
import { Router } from '@angular/router';
2018-04-05 16:29:11 +02:00
import { CipherType } from 'jslib/enums/cipherType';
import { CollectionView } from 'jslib/models/view/collectionView';
2018-04-05 16:29:11 +02:00
import { CipherView } from 'jslib/models/view/cipherView';
import { FolderView } from 'jslib/models/view/folderView';
2018-04-05 16:29:11 +02:00
import { CollectionService } from 'jslib/abstractions/collection.service';
import { CipherService } from 'jslib/abstractions/cipher.service';
import { FolderService } from 'jslib/abstractions/folder.service';
import { GroupingsComponent as BaseGroupingsComponent } from 'jslib/angular/components/groupings.component';
2018-04-05 04:59:42 +02:00
@Component({
selector: 'app-vault-groupings',
2018-04-05 16:29:11 +02:00
template: template,
2018-04-05 04:59:42 +02:00
})
2018-04-05 16:29:11 +02:00
export class GroupingsComponent extends BaseGroupingsComponent implements OnInit {
ciphers: CipherView[];
favoriteCiphers: CipherView[];
folderCounts = new Map<string, number>();
collectionCounts = new Map<string, number>();
typeCounts = new Map<CipherType, number>();
constructor(collectionService: CollectionService, folderService: FolderService,
private cipherService: CipherService, private router: Router) {
2018-04-05 16:29:11 +02:00
super(collectionService, folderService);
}
async ngOnInit() {
super.load();
super.loaded = false;
2018-04-05 16:29:11 +02:00
await this.loadCiphers();
super.loaded = true;
2018-04-05 16:29:11 +02:00
}
async loadCiphers() {
this.ciphers = await this.cipherService.getAllDecrypted();
this.ciphers.forEach((c) => {
if (c.favorite) {
if (this.favoriteCiphers == null) {
this.favoriteCiphers = [];
}
this.favoriteCiphers.push(c);
}
if (this.typeCounts.has(c.type)) {
this.typeCounts.set(c.type, this.typeCounts.get(c.type) + 1);
} else {
this.typeCounts.set(c.type, 1);
}
if (this.folderCounts.has(c.folderId)) {
this.folderCounts.set(c.folderId, this.folderCounts.get(c.folderId) + 1);
} else {
this.folderCounts.set(c.folderId, 1);
}
2018-04-05 04:59:42 +02:00
2018-04-05 16:29:11 +02:00
if (c.collectionIds != null) {
c.collectionIds.forEach((colId) => {
if (this.collectionCounts.has(colId)) {
this.collectionCounts.set(colId, this.collectionCounts.get(colId) + 1);
} else {
this.collectionCounts.set(colId, 1);
}
});
}
});
2018-04-05 04:59:42 +02:00
}
selectType(type: CipherType) {
super.selectType(type);
this.router.navigate(['/ciphers', { queryParams: { type: type } }]);
}
selectFolder(folder: FolderView) {
super.selectFolder(folder);
this.router.navigate(['/ciphers', { queryParams: { folderId: folder.id } }]);
}
selectCollection(collection: CollectionView) {
super.selectCollection(collection);
this.router.navigate(['/ciphers', { queryParams: { collectionId: collection.id } }]);
}
2018-04-05 04:59:42 +02:00
}