|
- import { Component, OnDestroy, OnInit, ViewChild, ViewEncapsulation } from '@angular/core';
- import { Subscription } from 'rxjs';
- import { LoanEditComponent } from './loan-edit/loan-edit.component';
-
- import { mainMenuItems } from './main-menu-items';
- import { AuthService } from './service/auth.service';
- import { MenuService } from './service/menu.service';
- import {apiV1LoginResponse} from './models/api-v1-login-response';
- import {WebSocketService} from './websocket';
-
- @Component({
- selector: 'app-root',
- templateUrl: './app.component.html',
- styleUrls: ['./app.component.scss'],
- encapsulation: ViewEncapsulation.None
- })
- export class AppComponent implements OnInit , OnDestroy {
- title = 'SFM broker';
- public login = false;
- public items: any[] = mainMenuItems;
- kendokaAvatar = './assets/img/avatar.png';
- @ViewChild('loanEditComponent', {static: true}) loanEdit: LoanEditComponent;
-
- private loginSub: Subscription;
-
- constructor(private menuService: MenuService, private authService: AuthService, private wsService: WebSocketService){
- wsService.createObservableSocket(this.authService.apiWsUrl)
- .subscribe(m => {
- console.log('websocket server send this :', m);
- });
- }
-
- // check menuItem has fontawesome
- public menuItemHasFontawesome (item: any) : boolean {
- return item.hasOwnProperty('fa');
- }
-
- // menuItem clicked
- public onSelect({ item }): void {
- if (!item.items) {
- this.menuService.itemClicked.emit(item);
- // console.log("emit on select : " + item.text);
- if ( item.popup == "loanEdit"){
- this.loanEdit.somedata = "" + Math.random() + "changed";
- this.loanEdit.open('dialog');
- }
-
- if (item.text === 'Logout'){
- this.authService.logout();
- this.login = false;
- // this.authService.loginSuccess.emit("loggedout");
- }
- }
- }
-
-
- // tslint:disable-next-line:typedef
- ngOnInit() {
- this.loginSub = this.authService.loginSuccess.subscribe(
- (rsp: apiV1LoginResponse) => {
- this.login = rsp.login;
- }
- );
-
- this.authService.AutoLogin();
-
- setTimeout(() => {
- const specialCommand = 'send dummy string for 500 times';
- this.wsService.sendMessage(specialCommand);
- }, 2000);
- }
-
- // tslint:disable-next-line:typedef
- ngOnDestroy() {
- this.loginSub.unsubscribe();
- }
-
- }
|