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

68 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-24 06:06:05 +01:00
Output,
2018-01-24 04:21:14 +01:00
} from '@angular/core';
2018-01-26 21:44:02 +01:00
import { CipherService } from 'jslib/abstractions/cipher.service';
2018-02-08 16:37:54 +01:00
import { CipherView } from 'jslib/models/view/cipherView';
2018-01-24 04:21:14 +01:00
@Component({
selector: 'app-vault-ciphers',
template: template,
})
export class CiphersComponent {
@Input() activeCipherId: string = null;
2018-01-26 20:56:54 +01:00
@Output() onCipherClicked = new EventEmitter<CipherView>();
@Output() onCipherRightClicked = new EventEmitter<CipherView>();
2018-01-24 23:41:57 +01:00
@Output() onAddCipher = new EventEmitter();
@Output() onAddCipherOptions = new EventEmitter();
2018-01-24 04:21:14 +01:00
loaded: boolean = false;
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
2018-02-12 21:06:39 +01:00
constructor(private cipherService: CipherService) { }
2018-01-27 05:32:03 +01:00
async load(filter: (cipher: CipherView) => boolean = null) {
this.filter = filter;
2018-02-08 16:37:54 +01:00
const ciphers = await this.cipherService.getAllDecrypted();
2018-01-27 05:32:03 +01:00
if (this.filter == null) {
this.ciphers = ciphers;
} else {
this.ciphers = ciphers.filter(this.filter);
}
this.loaded = true;
2018-01-26 21:44:02 +01:00
}
async refresh() {
2018-02-12 21:06:39 +01:00
this.loaded = false;
this.ciphers = [];
2018-01-27 05:32:03 +01:00
await this.load(this.filter);
2018-01-26 21:44:02 +01:00
}
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
}
cipherRightClicked(cipher: CipherView) {
this.onCipherRightClicked.emit(cipher);
}
2018-01-24 23:41:57 +01:00
addCipher() {
this.onAddCipher.emit();
2018-01-24 05:38:56 +01:00
}
addCipherOptions() {
this.onAddCipherOptions.emit();
}
2018-01-24 04:21:14 +01:00
}