1
0
mirror of https://github.com/bitwarden/web synced 2025-12-19 17:53:22 +00:00

base cipher report component class

This commit is contained in:
Kyle Spearrin
2018-12-12 09:11:10 -05:00
parent 603a1ef046
commit 93c291dba1
6 changed files with 103 additions and 236 deletions

View File

@@ -0,0 +1,60 @@
import {
ComponentFactoryResolver,
ViewChild,
ViewContainerRef,
} from '@angular/core';
import { CipherView } from 'jslib/models/view/cipherView';
import { ModalComponent } from '../modal.component';
import { AddEditComponent } from '../vault/add-edit.component';
export class CipherReportComponent {
@ViewChild('cipherAddEdit', { read: ViewContainerRef }) cipherAddEditModalRef: ViewContainerRef;
loading = false;
hasLoaded = false;
ciphers: CipherView[] = [];
private modal: ModalComponent = null;
constructor(private componentFactoryResolver: ComponentFactoryResolver) { }
async load() {
this.loading = true;
await this.setCiphers();
this.loading = false;
this.hasLoaded = true;
}
selectCipher(cipher: CipherView) {
if (this.modal != null) {
this.modal.close();
}
const factory = this.componentFactoryResolver.resolveComponentFactory(ModalComponent);
this.modal = this.cipherAddEditModalRef.createComponent(factory).instance;
const childComponent = this.modal.show<AddEditComponent>(
AddEditComponent, this.cipherAddEditModalRef);
childComponent.cipherId = cipher == null ? null : cipher.id;
childComponent.onSavedCipher.subscribe(async (c: CipherView) => {
this.modal.close();
await this.load();
});
childComponent.onDeletedCipher.subscribe(async (c: CipherView) => {
this.modal.close();
await this.load();
});
this.modal.onClosed.subscribe(() => {
this.modal = null;
});
return childComponent;
}
protected async setCiphers() {
this.ciphers = [];
}
}