| import { Component, OnDestroy, OnInit, ViewChild, ViewEncapsulation } from '@angular/core'; | import { Component, OnDestroy, OnInit, ViewChild, ViewEncapsulation } from '@angular/core'; | ||||
| import { Subscription } from 'rxjs'; | import { Subscription } from 'rxjs'; | ||||
| import { LoanEditComponent } from './loan-edit/loan-edit.component'; | import { LoanEditComponent } from './loan-edit/loan-edit.component'; | ||||
| import { AuthService } from './service/auth.service'; | import { AuthService } from './service/auth.service'; | ||||
| import { MenuService } from './service/menu.service'; | import { MenuService } from './service/menu.service'; | ||||
| import {WebSocketService} from './websocket'; | import {WebSocketService} from './websocket'; | ||||
| import {AppConfig} from './app.config'; | |||||
| import {Title} from '@angular/platform-browser'; | import {Title} from '@angular/platform-browser'; | ||||
| import {WsLoginEventModel} from './models/websocket/ws.login.event.model'; | |||||
| import {SessionService} from './service/session.service'; | |||||
| @Component({ | @Component({ | ||||
| selector: 'app-root', | selector: 'app-root', | ||||
| constructor(private menuService: MenuService, | constructor(private menuService: MenuService, | ||||
| private authService: AuthService, | private authService: AuthService, | ||||
| private config: AppConfig, | |||||
| private ss: SessionService, | |||||
| private wsService: WebSocketService, | private wsService: WebSocketService, | ||||
| private titleService: Title){ | private titleService: Title){ | ||||
| this.webSocketSubscription = wsService.subscribe(m => { | this.webSocketSubscription = wsService.subscribe(m => { | ||||
| }); | }); | ||||
| this.wsLoginSub = this.wsService.LoginEvent.subscribe( m => { | this.wsLoginSub = this.wsService.LoginEvent.subscribe( m => { | ||||
| console.log('login event ', m); | |||||
| this.onWSLogin(m); | |||||
| }); | }); | ||||
| this.titleService.setTitle(this.title); | this.titleService.setTitle(this.title); | ||||
| listenToMenuEvent(): void { | listenToMenuEvent(): void { | ||||
| this.menuItemSub = this.menuService.itemClicked.subscribe( | this.menuItemSub = this.menuService.itemClicked.subscribe( | ||||
| (item:any) =>{ | |||||
| (item: any) => { | |||||
| // console.log("emit on select : " + item.text); | // console.log("emit on select : " + item.text); | ||||
| if ( item.popup === 'loanEdit'){ | if ( item.popup === 'loanEdit'){ | ||||
| // this.loanEdit.somedata = '' + Math.random() + 'changed'; | |||||
| // this.loanEdit.open('dialog'); | |||||
| } | } | ||||
| } | } | ||||
| ); | ); | ||||
| } | } | ||||
| ngOnDestroy(): void { | ngOnDestroy(): void { | ||||
| this.wsLoginSub.unsubscribe(); | this.wsLoginSub.unsubscribe(); | ||||
| } | } | ||||
| onWSLogin(e: WsLoginEventModel): void { | |||||
| if ( e.Mid === this.ss.loggedIn.machineId && e.Sid === this.ss.loggedIn.session ){ | |||||
| if ( e.Uid !== this.ss.loggedIn.User.Id && e.Uid !== '') { | |||||
| this.ss.logout(); | |||||
| } | |||||
| } | |||||
| } | |||||
| } | } |