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

105 lines
2.7 KiB
TypeScript
Raw Normal View History

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';
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-25 17:21:08 +01:00
constructor(private cipherService: CipherService, private route: ActivatedRoute, private router: Router,
private location: Location) {
}
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']) {
2018-01-26 20:56:54 +01:00
const cipherView = new CipherView();
cipherView.id = params['cipherId'];
2018-01-25 17:21:08 +01:00
if (params['action'] === 'edit') {
2018-01-26 20:56:54 +01:00
this.editCipher(cipherView);
2018-01-25 17:21:08 +01:00
} else {
2018-01-26 20:56:54 +01:00
this.viewCipher(cipherView);
2018-01-25 17:21:08 +01:00
}
} 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-26 20:56:54 +01:00
viewCipher(cipher: CipherView) {
if (this.action === 'view' && this.cipherId === cipher.id) {
2018-01-25 17:28:52 +01:00
return;
}
2018-01-26 20:56:54 +01:00
this.cipherId = cipher.id;
2018-01-25 17:21:08 +01:00
this.action = 'view';
2018-01-26 20:56:54 +01:00
this.go({ action: this.action, cipherId: this.cipherId });
2018-01-24 06:06:05 +01:00
}
2018-01-24 23:41:57 +01:00
2018-01-26 20:56:54 +01:00
editCipher(cipher: CipherView) {
if (this.action === 'edit' && this.cipherId === cipher.id) {
2018-01-25 17:28:52 +01:00
return;
}
2018-01-26 20:56:54 +01:00
this.cipherId = cipher.id;
2018-01-25 17:21:08 +01:00
this.action = 'edit';
2018-01-26 20:56:54 +01:00
this.go({ action: this.action, cipherId: this.cipherId });
2018-01-24 23:41:57 +01:00
}
addCipher() {
2018-01-25 17:28:52 +01:00
if (this.action === 'add') {
return;
}
2018-01-25 17:21:08 +01:00
this.action = 'add';
2018-01-26 20:56:54 +01:00
this.cipherId = null;
this.go({ action: this.action, cipherId: this.cipherId });
}
savedCipher(cipher: CipherView) {
this.cipherId = cipher.id;
this.action = 'view';
this.go({ action: this.action, cipherId: this.cipherId });
}
deletedCipher(cipher: CipherView) {
}
editCipherAttachments(cipher: CipherView) {
}
cancelledAddEdit(cipher: CipherView) {
this.cipherId = cipher.id;
this.action = this.cipherId != null ? 'view' : null;
this.go({ action: this.action, cipherId: this.cipherId });
2018-01-25 17:21:08 +01:00
}
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
}