Advertisement
Guest User

Untitled

a guest
Jun 21st, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.62 KB | None | 0 0
  1. import { Component } from '@angular/core';
  2. import {
  3. NgZone
  4. } from '@angular/core';
  5. import { SignalRService } from './signal/signal-r.service';
  6. //import { Notification } from 'rxjs/internal/Notification';
  7. import {Notification} from './models/notification.model'
  8.  
  9. @Component({
  10. selector: 'app-root',
  11. templateUrl: './app.component.html',
  12. styleUrls: ['./app.component.css']
  13. })
  14. export class AppComponent {
  15. title = 'app';
  16.  
  17. isConnected: Boolean;
  18. notifications: string[] = [];
  19. message:string;
  20.  
  21. constructor(private _signalRService: SignalRService, private ngZone: NgZone)
  22. {
  23. this.isConnected = false;
  24. }
  25.  
  26. ngOnInit()
  27. {
  28. this.checkConnection();
  29. this.subscribeForNotifications();
  30. }
  31.  
  32. private checkConnection(){
  33. this._signalRService.connectionEstablished.subscribe(e => {this.isConnected = e;
  34. if (e) {
  35. this._signalRService.sendHello()
  36. }
  37. });
  38. }
  39.  
  40. private subscribeForNotifications () {
  41. this._signalRService.notificationReceived.subscribe(e => this.onNotification(e));
  42. }
  43.  
  44. public onNotification(notif: Notification) {
  45.  
  46. this.ngZone.run(() => {
  47. debugger;
  48. if(localStorage.role == 'Admin'){
  49. alert(notif.Text);
  50. }
  51. });
  52. }
  53.  
  54. logout()
  55. {
  56. localStorage.removeItem('jwt');
  57. localStorage.removeItem('role');
  58. }
  59.  
  60. public localStorageJWT(): string {
  61. return localStorage.jwt;
  62. }
  63.  
  64. public showAddType(): boolean {
  65. return localStorage.role == 'Admin';
  66. }
  67.  
  68. public showUser(): boolean {
  69. return localStorage.role == 'AppUser';
  70. }
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement