shared modal instance

This commit is contained in:
Kyle Spearrin 2018-02-09 12:36:33 -05:00
parent 481d04b2b9
commit 729c710466
1 changed files with 33 additions and 28 deletions

View File

@ -55,9 +55,7 @@ export class VaultComponent implements OnInit {
collectionId: string = null; collectionId: string = null;
addType: CipherType = null; addType: CipherType = null;
private passwordGeneratorModal: ModalComponent = null; private modal: ModalComponent = null;
private folderAddEditModal: ModalComponent = null;
private attachmentsModal: ModalComponent = null;
constructor(private route: ActivatedRoute, private router: Router, private location: Location, constructor(private route: ActivatedRoute, private router: Router, private location: Location,
private componentFactoryResolver: ComponentFactoryResolver, private i18nService: I18nService, private componentFactoryResolver: ComponentFactoryResolver, private i18nService: I18nService,
@ -200,19 +198,18 @@ export class VaultComponent implements OnInit {
} }
editCipherAttachments(cipher: CipherView) { editCipherAttachments(cipher: CipherView) {
if (this.attachmentsModal != null) { if (this.modal != null) {
this.attachmentsModal.close(); this.modal.close();
} }
const factory = this.componentFactoryResolver.resolveComponentFactory(ModalComponent); const factory = this.componentFactoryResolver.resolveComponentFactory(ModalComponent);
this.attachmentsModal = this.attachmentsModalRef.createComponent(factory).instance; this.modal = this.attachmentsModalRef.createComponent(factory).instance;
const childComponent = this.attachmentsModal.show<AttachmentsComponent>( const childComponent = this.modal.show<AttachmentsComponent>(AttachmentsComponent, this.attachmentsModalRef);
AttachmentsComponent, this.attachmentsModalRef);
childComponent.cipherId = cipher.id; childComponent.cipherId = cipher.id;
this.attachmentsModal.onClosed.subscribe(() => { this.modal.onClosed.subscribe(() => {
this.attachmentsModal = null; this.modal = null;
}); });
} }
@ -263,64 +260,72 @@ export class VaultComponent implements OnInit {
} }
async openPasswordGenerator(showSelect: boolean) { async openPasswordGenerator(showSelect: boolean) {
if (this.passwordGeneratorModal != null) { if (this.modal != null) {
this.passwordGeneratorModal.close(); this.modal.close();
} }
const factory = this.componentFactoryResolver.resolveComponentFactory(ModalComponent); const factory = this.componentFactoryResolver.resolveComponentFactory(ModalComponent);
this.passwordGeneratorModal = this.passwordGeneratorModalRef.createComponent(factory).instance; this.modal = this.passwordGeneratorModalRef.createComponent(factory).instance;
const childComponent = this.passwordGeneratorModal.show<PasswordGeneratorComponent>(PasswordGeneratorComponent, const childComponent = this.modal.show<PasswordGeneratorComponent>(PasswordGeneratorComponent,
this.passwordGeneratorModalRef); this.passwordGeneratorModalRef);
childComponent.showSelect = showSelect; childComponent.showSelect = showSelect;
childComponent.onSelected.subscribe((password: string) => { childComponent.onSelected.subscribe((password: string) => {
this.passwordGeneratorModal.close(); this.modal.close();
if (this.addEditComponent != null && this.addEditComponent.cipher != null && if (this.addEditComponent != null && this.addEditComponent.cipher != null &&
this.addEditComponent.cipher.login != null) { this.addEditComponent.cipher.login != null) {
this.addEditComponent.cipher.login.password = password; this.addEditComponent.cipher.login.password = password;
} }
}); });
this.passwordGeneratorModal.onClosed.subscribe(() => { this.modal.onClosed.subscribe(() => {
this.passwordGeneratorModal = null; this.modal = null;
}); });
} }
async addFolder() { async addFolder() {
if (this.modal != null) {
this.modal.close();
}
const factory = this.componentFactoryResolver.resolveComponentFactory(ModalComponent); const factory = this.componentFactoryResolver.resolveComponentFactory(ModalComponent);
this.folderAddEditModal = this.folderAddEditModalRef.createComponent(factory).instance; this.modal = this.folderAddEditModalRef.createComponent(factory).instance;
const childComponent = this.folderAddEditModal.show<FolderAddEditComponent>( const childComponent = this.modal.show<FolderAddEditComponent>(
FolderAddEditComponent, this.folderAddEditModalRef); FolderAddEditComponent, this.folderAddEditModalRef);
childComponent.folderId = null; childComponent.folderId = null;
childComponent.onSavedFolder.subscribe(async (folder: FolderView) => { childComponent.onSavedFolder.subscribe(async (folder: FolderView) => {
this.folderAddEditModal.close(); this.modal.close();
await this.groupingsComponent.loadFolders(); await this.groupingsComponent.loadFolders();
}); });
this.folderAddEditModal.onClosed.subscribe(() => { this.modal.onClosed.subscribe(() => {
this.folderAddEditModal = null; this.modal = null;
}); });
} }
async editFolder(folderId: string) { async editFolder(folderId: string) {
if (this.modal != null) {
this.modal.close();
}
const factory = this.componentFactoryResolver.resolveComponentFactory(ModalComponent); const factory = this.componentFactoryResolver.resolveComponentFactory(ModalComponent);
this.folderAddEditModal = this.folderAddEditModalRef.createComponent(factory).instance; this.modal = this.folderAddEditModalRef.createComponent(factory).instance;
const childComponent = this.folderAddEditModal.show<FolderAddEditComponent>( const childComponent = this.modal.show<FolderAddEditComponent>(
FolderAddEditComponent, this.folderAddEditModalRef); FolderAddEditComponent, this.folderAddEditModalRef);
childComponent.folderId = folderId; childComponent.folderId = folderId;
childComponent.onSavedFolder.subscribe(async (folder: FolderView) => { childComponent.onSavedFolder.subscribe(async (folder: FolderView) => {
this.folderAddEditModal.close(); this.modal.close();
await this.groupingsComponent.loadFolders(); await this.groupingsComponent.loadFolders();
}); });
childComponent.onDeletedFolder.subscribe(async (folder: FolderView) => { childComponent.onDeletedFolder.subscribe(async (folder: FolderView) => {
this.folderAddEditModal.close(); this.modal.close();
await this.groupingsComponent.loadFolders(); await this.groupingsComponent.loadFolders();
}); });
this.folderAddEditModal.onClosed.subscribe(() => { this.modal.onClosed.subscribe(() => {
this.folderAddEditModal = null; this.modal = null;
}); });
} }