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-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-31 23:20:27 +01:00
|
|
|
export class CiphersComponent {
|
2018-01-29 23:57:58 +01:00
|
|
|
@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-02-01 03:59:39 +01:00
|
|
|
loaded: boolean = false;
|
2018-01-26 21:44:02 +01:00
|
|
|
ciphers: CipherView[] = [];
|
2018-01-30 03:41:00 +01:00
|
|
|
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-01-31 23:20:27 +01:00
|
|
|
constructor(private cipherService: CipherService) {}
|
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-02-01 03:59:39 +01:00
|
|
|
|
|
|
|
this.loaded = true;
|
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
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|