1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-18 01:03:35 +00:00
Files
browser/src/app/vault/vault.component.ts
Kyle Spearrin 15868ab541 routing updates
2018-01-25 11:28:52 -05:00

82 lines
2.0 KiB
TypeScript

import * as template from './vault.component.html';
import {
Component,
OnInit,
} from '@angular/core';
import {
ActivatedRoute,
Router,
} from '@angular/router';
import { Location } from '@angular/common';
import { CipherService } from 'jslib/abstractions/cipher.service';
import { CipherView } from 'jslib/models/view/cipherView';
@Component({
selector: 'app-vault',
template: template,
})
export class VaultComponent implements OnInit {
ciphers: CipherView[];
cipherId: string;
action: string;
constructor(private cipherService: CipherService, private route: ActivatedRoute, private router: Router,
private location: Location) {
}
async ngOnInit() {
this.ciphers = await this.cipherService.getAllDecrypted();
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();
}
});
}
viewCipher(id: string) {
if (this.action === 'view' && this.cipherId === id) {
return;
}
this.cipherId = id;
this.action = 'view';
this.go({ action: this.action, cipherId: id });
}
editCipher(id: string) {
if (this.action === 'edit' && this.cipherId === id) {
return;
}
this.cipherId = id;
this.action = 'edit';
this.go({ action: this.action, cipherId: id });
}
addCipher() {
if (this.action === 'add') {
return;
}
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);
}
}