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

75 lines
2.4 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';
2018-04-05 16:29:11 +02:00
import { CipherType } from 'jslib/enums/cipherType';
import { CipherView } from 'jslib/models/view/cipherView';
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) {
super(collectionService, folderService);
}
async ngOnInit() {
this.load();
this.loaded = false;
await this.loadCiphers();
this.loaded = true;
}
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
}
}