2018-04-05 17:12:00 +02:00
|
|
|
import {
|
|
|
|
EventEmitter,
|
|
|
|
Input,
|
|
|
|
Output,
|
|
|
|
} from '@angular/core';
|
|
|
|
|
|
|
|
import { CipherService } from '../../abstractions/cipher.service';
|
|
|
|
|
|
|
|
import { CipherView } from '../../models/view/cipherView';
|
|
|
|
|
|
|
|
export class CiphersComponent {
|
|
|
|
@Input() activeCipherId: string = null;
|
|
|
|
@Output() onCipherClicked = new EventEmitter<CipherView>();
|
|
|
|
@Output() onCipherRightClicked = new EventEmitter<CipherView>();
|
|
|
|
@Output() onAddCipher = new EventEmitter();
|
|
|
|
@Output() onAddCipherOptions = new EventEmitter();
|
|
|
|
|
|
|
|
loaded: boolean = false;
|
|
|
|
ciphers: CipherView[] = [];
|
|
|
|
searchText: string;
|
|
|
|
searchPlaceholder: string = null;
|
2018-07-04 05:33:15 +02:00
|
|
|
|
|
|
|
protected allCiphers: CipherView[] = [];
|
|
|
|
protected filter: (cipher: CipherView) => boolean = null;
|
2018-04-05 17:12:00 +02:00
|
|
|
|
|
|
|
constructor(protected cipherService: CipherService) { }
|
|
|
|
|
|
|
|
async load(filter: (cipher: CipherView) => boolean = null) {
|
2018-07-04 05:33:15 +02:00
|
|
|
this.allCiphers = await this.cipherService.getAllDecrypted();
|
|
|
|
this.applyFilter(filter);
|
2018-04-05 17:12:00 +02:00
|
|
|
this.loaded = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
async refresh() {
|
|
|
|
this.loaded = false;
|
|
|
|
this.ciphers = [];
|
|
|
|
await this.load(this.filter);
|
|
|
|
}
|
|
|
|
|
2018-07-04 05:33:15 +02:00
|
|
|
async applyFilter(filter: (cipher: CipherView) => boolean = null) {
|
|
|
|
this.filter = filter;
|
|
|
|
if (this.filter == null) {
|
|
|
|
this.ciphers = this.allCiphers;
|
|
|
|
} else {
|
|
|
|
this.ciphers = this.allCiphers.filter(this.filter);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-05 17:12:00 +02:00
|
|
|
selectCipher(cipher: CipherView) {
|
|
|
|
this.onCipherClicked.emit(cipher);
|
|
|
|
}
|
|
|
|
|
|
|
|
rightClickCipher(cipher: CipherView) {
|
|
|
|
this.onCipherRightClicked.emit(cipher);
|
|
|
|
}
|
|
|
|
|
|
|
|
addCipher() {
|
|
|
|
this.onAddCipher.emit();
|
|
|
|
}
|
|
|
|
|
|
|
|
addCipherOptions() {
|
|
|
|
this.onAddCipherOptions.emit();
|
|
|
|
}
|
|
|
|
}
|