bitwarden-estensione-browser/src/popup2/vault/ciphers.component.ts

87 lines
2.6 KiB
TypeScript
Raw Normal View History

2018-04-06 05:49:04 +02:00
import { Location } from '@angular/common';
import {
2018-04-06 21:33:20 +02:00
ChangeDetectorRef,
Component,
2018-04-06 21:33:20 +02:00
NgZone,
OnDestroy,
OnInit,
} from '@angular/core';
import {
ActivatedRoute,
Router,
} from '@angular/router';
import { CipherService } from 'jslib/abstractions/cipher.service';
import { CipherView } from 'jslib/models/view/cipherView';
2018-04-06 21:33:20 +02:00
import { BroadcasterService } from 'jslib/angular/services/broadcaster.service';
import { CiphersComponent as BaseCiphersComponent } from 'jslib/angular/components/ciphers.component';
2018-04-06 21:33:20 +02:00
const BroadcasterSubscriptionId = 'CiphersComponent';
@Component({
selector: 'app-vault-ciphers',
2018-04-06 17:48:45 +02:00
templateUrl: 'ciphers.component.html',
})
2018-04-06 21:33:20 +02:00
export class CiphersComponent extends BaseCiphersComponent implements OnInit, OnDestroy {
2018-04-09 16:50:28 +02:00
searchText: string;
2018-04-06 05:09:49 +02:00
constructor(cipherService: CipherService, private route: ActivatedRoute,
2018-04-06 21:33:20 +02:00
private router: Router, private location: Location,
private ngZone: NgZone, private broadcasterService: BroadcasterService,
private changeDetectorRef: ChangeDetectorRef) {
super(cipherService);
}
async ngOnInit() {
this.route.queryParams.subscribe(async (params) => {
if (params.type) {
const t = parseInt(params.type, null);
await super.load((c) => c.type === t);
} else if (params.folderId) {
await super.load((c) => c.folderId === params.folderId);
} else if (params.collectionId) {
await super.load((c) => c.collectionIds.indexOf(params.collectionId) > -1);
} else {
await super.load();
}
});
2018-04-06 21:33:20 +02:00
this.broadcasterService.subscribe(BroadcasterSubscriptionId, (message: any) => {
this.ngZone.run(async () => {
switch (message.command) {
case 'syncCompleted':
window.setTimeout(() => {
this.load();
}, 500);
break;
default:
break;
}
this.changeDetectorRef.detectChanges();
})
});
}
ngOnDestroy() {
this.broadcasterService.unsubscribe(BroadcasterSubscriptionId);
}
selectCipher(cipher: CipherView) {
super.selectCipher(cipher);
2018-04-06 05:09:49 +02:00
this.router.navigate(['/view-cipher'], { queryParams: { cipherId: cipher.id } });
}
2018-04-06 05:49:04 +02:00
addCipher() {
super.addCipher();
this.router.navigate(['/add-cipher']);
}
back() {
this.location.back();
}
}