Broker System for Supercredit
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

79 satır
2.4KB

  1. import { Component, OnDestroy, OnInit, ViewChild, ViewEncapsulation } from '@angular/core';
  2. import { Subscription } from 'rxjs';
  3. import { LoanEditComponent } from './loan-edit/loan-edit.component';
  4. import { mainMenuItems } from './main-menu-items';
  5. import { AuthService } from './service/auth.service';
  6. import { MenuService } from './service/menu.service';
  7. import {apiV1LoginResponse} from './models/api-v1-login-response';
  8. import {WebSocketService} from './websocket';
  9. @Component({
  10. selector: 'app-root',
  11. templateUrl: './app.component.html',
  12. styleUrls: ['./app.component.scss'],
  13. encapsulation: ViewEncapsulation.None
  14. })
  15. export class AppComponent implements OnInit , OnDestroy {
  16. title = 'SFM broker';
  17. public login = false;
  18. public items: any[] = mainMenuItems;
  19. kendokaAvatar = './assets/img/avatar.png';
  20. @ViewChild('loanEditComponent', {static: true}) loanEdit: LoanEditComponent;
  21. private loginSub: Subscription;
  22. constructor(private menuService: MenuService, private authService: AuthService, private wsService: WebSocketService){
  23. wsService.createObservableSocket(this.authService.apiWsUrl)
  24. .subscribe(m => {
  25. console.log('websocket server send this :', m);
  26. });
  27. }
  28. // check menuItem has fontawesome
  29. public menuItemHasFontawesome (item: any) : boolean {
  30. return item.hasOwnProperty('fa');
  31. }
  32. // menuItem clicked
  33. public onSelect({ item }): void {
  34. if (!item.items) {
  35. this.menuService.itemClicked.emit(item);
  36. // console.log("emit on select : " + item.text);
  37. if ( item.popup == "loanEdit"){
  38. this.loanEdit.somedata = "" + Math.random() + "changed";
  39. this.loanEdit.open('dialog');
  40. }
  41. if (item.text === 'Logout'){
  42. this.authService.logout();
  43. this.login = false;
  44. // this.authService.loginSuccess.emit("loggedout");
  45. }
  46. }
  47. }
  48. // tslint:disable-next-line:typedef
  49. ngOnInit() {
  50. this.loginSub = this.authService.loginSuccess.subscribe(
  51. (rsp: apiV1LoginResponse) => {
  52. this.login = rsp.login;
  53. }
  54. );
  55. this.authService.AutoLogin();
  56. setTimeout(() => {
  57. const specialCommand = 'send dummy string for 500 times';
  58. this.wsService.sendMessage(specialCommand);
  59. }, 2000);
  60. }
  61. // tslint:disable-next-line:typedef
  62. ngOnDestroy() {
  63. this.loginSub.unsubscribe();
  64. }
  65. }