import { ChangeDetectorRef, Component, ElementRef, EventEmitter, Injector, Output, ViewChild } from '@angular/core'; import { AppComponentBase } from '@shared/common/app-component-base'; import { SubsystemUserDto, UserServiceProxy, SubAppDto } from '@shared/service-proxies/service-proxies'; import { ModalDirective } from 'ngx-bootstrap'; @Component({ selector: 'createOrEditSubsystemUserModal', templateUrl: './create-or-edit-SubsystemUser-modal.component.html' }) export class CreateOrEditSubsystemUserModalComponent extends AppComponentBase { @ViewChild('createOrEditModal') modal: ModalDirective; @Output() subsystemUserAdd: EventEmitter = new EventEmitter(); active = false; saving = false; subsystemUser: SubsystemUserDto; subAppDtoItem: SubAppDto[] = []; selectSubApp; constructor( injector: Injector, private _changeDetector: ChangeDetectorRef, private _userService: UserServiceProxy, ) { super(injector); } onShown(): void { } show(subAppUser: SubsystemUserDto): void { this.subsystemUser = new SubsystemUserDto(); this._userService.getSubApp().subscribe(result => { this.subAppDtoItem = result; if (subAppUser) { this.subsystemUser = subAppUser; this.selectSubApp = subAppUser.subAppId; } this.active = true; this.modal.show(); this._changeDetector.detectChanges(); }); } save(): void { const createInput = new SubsystemUserDto(); createInput.subAppId = this.selectSubApp; createInput.subAppName = this.subAppDtoItem.find( a => a.id === this.selectSubApp).name; createInput.subsystemUserCode = this.subsystemUser.subsystemUserCode; createInput.id = this.subsystemUser.id; this.close(); this.subsystemUserAdd.emit(createInput); } close(): void { this.subsystemUser = null; this.modal.hide(); this.active = false; } }