bitwarden-estensione-browser/src/app/vault/ciphers.component.ts

73 lines
1.7 KiB
TypeScript
Raw Normal View History

2018-01-24 04:21:14 +01:00
import * as template from './ciphers.component.html';
import {
Component,
2018-01-24 06:06:05 +01:00
EventEmitter,
2018-01-24 04:21:14 +01:00
Input,
2018-01-26 21:44:02 +01:00
OnInit,
2018-01-24 06:06:05 +01:00
Output,
2018-01-24 04:21:14 +01:00
} from '@angular/core';
2018-01-24 18:20:01 +01:00
import { CipherView } from 'jslib/models/view/cipherView';
2018-01-26 21:44:02 +01:00
import { CipherService } from 'jslib/abstractions/cipher.service';
2018-01-24 04:21:14 +01:00
@Component({
selector: 'app-vault-ciphers',
template: template,
})
2018-01-26 21:44:02 +01:00
export class CiphersComponent implements OnInit {
@Input() activeCipherId: string = null;
2018-01-26 20:56:54 +01:00
@Output() onCipherClicked = new EventEmitter<CipherView>();
2018-01-24 23:41:57 +01:00
@Output() onAddCipher = new EventEmitter();
2018-01-24 04:21:14 +01:00
2018-01-26 21:44:02 +01:00
ciphers: CipherView[] = [];
searchText: string;
2018-01-30 03:54:39 +01:00
searchPlaceholder: string = null;
2018-01-27 05:32:03 +01:00
private filter: (cipher: CipherView) => boolean = null;
2018-01-26 21:44:02 +01:00
constructor(private cipherService: CipherService) {
}
async ngOnInit() {
2018-01-27 05:56:43 +01:00
//await this.load();
2018-01-27 05:32:03 +01:00
}
async load(filter: (cipher: CipherView) => boolean = null) {
this.filter = filter;
let ciphers = await this.cipherService.getAllDecrypted();
if (this.filter == null) {
this.ciphers = ciphers;
} else {
this.ciphers = ciphers.filter(this.filter);
}
2018-01-26 21:44:02 +01:00
}
async refresh() {
2018-01-27 05:32:03 +01:00
await this.load(this.filter);
2018-01-26 21:44:02 +01:00
}
updateCipher(cipher: CipherView) {
const i = this.ciphers.findIndex((c) => c.id === cipher.id);
if (i > -1) {
this.ciphers[i] = cipher;
}
}
removeCipher(cipherId: string) {
const i = this.ciphers.findIndex((c) => c.id === cipherId);
if (i > -1) {
this.ciphers.splice(i, 1);
}
}
2018-01-24 18:20:01 +01:00
cipherClicked(cipher: CipherView) {
2018-01-26 20:56:54 +01:00
this.onCipherClicked.emit(cipher);
2018-01-24 23:41:57 +01:00
}
addCipher() {
this.onAddCipher.emit();
2018-01-24 05:38:56 +01:00
}
2018-01-24 04:21:14 +01:00
}