2018-01-16 22:12:26 +01:00
|
|
|
import * as template from './vault.component.html';
|
|
|
|
|
|
|
|
import {
|
|
|
|
Component,
|
|
|
|
OnInit,
|
|
|
|
} from '@angular/core';
|
|
|
|
|
2018-01-25 17:21:08 +01:00
|
|
|
import {
|
|
|
|
ActivatedRoute,
|
|
|
|
Router,
|
|
|
|
} from '@angular/router';
|
|
|
|
|
|
|
|
import { Location } from '@angular/common';
|
|
|
|
|
2018-01-23 22:58:32 +01:00
|
|
|
import { CipherService } from 'jslib/abstractions/cipher.service';
|
|
|
|
|
2018-01-24 18:20:01 +01:00
|
|
|
import { CipherView } from 'jslib/models/view/cipherView';
|
|
|
|
|
2018-01-16 22:12:26 +01:00
|
|
|
@Component({
|
|
|
|
selector: 'app-vault',
|
|
|
|
template: template,
|
|
|
|
})
|
|
|
|
export class VaultComponent implements OnInit {
|
2018-01-24 18:20:01 +01:00
|
|
|
ciphers: CipherView[];
|
2018-01-24 23:41:57 +01:00
|
|
|
cipherId: string;
|
2018-01-25 17:21:08 +01:00
|
|
|
action: string;
|
2018-01-23 22:58:32 +01:00
|
|
|
|
2018-01-25 17:21:08 +01:00
|
|
|
constructor(private cipherService: CipherService, private route: ActivatedRoute, private router: Router,
|
|
|
|
private location: Location) {
|
2018-01-23 22:58:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
async ngOnInit() {
|
2018-01-24 05:05:23 +01:00
|
|
|
this.ciphers = await this.cipherService.getAllDecrypted();
|
2018-01-25 17:21:08 +01:00
|
|
|
|
|
|
|
this.route.queryParams.subscribe((params) => {
|
|
|
|
if (params['cipherId']) {
|
|
|
|
if (params['action'] === 'edit') {
|
|
|
|
this.editCipher(params['cipherId']);
|
|
|
|
} else {
|
|
|
|
this.viewCipher(params['cipherId']);
|
|
|
|
}
|
|
|
|
} else if (params['action'] === 'add') {
|
|
|
|
this.addCipher();
|
|
|
|
}
|
|
|
|
});
|
2018-01-16 22:12:26 +01:00
|
|
|
}
|
2018-01-24 06:06:05 +01:00
|
|
|
|
2018-01-24 23:41:57 +01:00
|
|
|
viewCipher(id: string) {
|
|
|
|
this.cipherId = id;
|
2018-01-25 17:21:08 +01:00
|
|
|
this.action = 'view';
|
|
|
|
this.go({ action: this.action, cipherId: id });
|
2018-01-24 06:06:05 +01:00
|
|
|
}
|
2018-01-24 23:41:57 +01:00
|
|
|
|
|
|
|
editCipher(id: string) {
|
|
|
|
this.cipherId = id;
|
2018-01-25 17:21:08 +01:00
|
|
|
this.action = 'edit';
|
|
|
|
this.go({ action: this.action, cipherId: id });
|
2018-01-24 23:41:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
addCipher() {
|
2018-01-25 17:21:08 +01:00
|
|
|
this.action = 'add';
|
|
|
|
this.go({ action: this.action });
|
|
|
|
}
|
|
|
|
|
|
|
|
private go(queryParams: any) {
|
|
|
|
const url = this.router.createUrlTree(['vault'], { queryParams: queryParams }).toString();
|
|
|
|
this.location.go(url);
|
2018-01-24 23:41:57 +01:00
|
|
|
}
|
2018-01-16 22:12:26 +01:00
|
|
|
}
|