import { Component, ComponentFactoryResolver, ViewChild, ViewContainerRef, } from '@angular/core'; import { Router } from '@angular/router'; import { EnvironmentComponent } from './environment.component'; import { AuthService } from 'jslib/abstractions/auth.service'; import { I18nService } from 'jslib/abstractions/i18n.service'; import { PlatformUtilsService } from 'jslib/abstractions/platformUtils.service'; import { StateService } from 'jslib/abstractions/state.service'; import { StorageService } from 'jslib/abstractions/storage.service'; import { SyncService } from 'jslib/abstractions/sync.service'; import { LoginComponent as BaseLoginComponent } from 'jslib/angular/components/login.component'; import { ModalComponent } from 'jslib/angular/components/modal.component'; @Component({ selector: 'app-login', templateUrl: 'login.component.html', }) export class LoginComponent extends BaseLoginComponent { @ViewChild('environment', { read: ViewContainerRef }) environmentModal: ViewContainerRef; showingModal = false; constructor(authService: AuthService, router: Router, i18nService: I18nService, syncService: SyncService, private componentFactoryResolver: ComponentFactoryResolver, storageService: StorageService, platformUtilsService: PlatformUtilsService, stateService: StateService) { super(authService, router, platformUtilsService, i18nService, storageService, stateService); super.onSuccessfulLogin = () => { return syncService.fullSync(true); }; } settings() { const factory = this.componentFactoryResolver.resolveComponentFactory(ModalComponent); const modal = this.environmentModal.createComponent(factory).instance; modal.onShown.subscribe(() => { this.showingModal = true; }); modal.onClosed.subscribe(() => { this.showingModal = false; modal.onShown.unsubscribe(); modal.onClosed.unsubscribe(); }); const childComponent = modal.show(EnvironmentComponent, this.environmentModal); childComponent.onSaved.subscribe(() => { modal.close(); }); } }