Added portal-FE-common - angular upgrade code
[portal.git] / portal-FE-common / src / app / layout / components / userbar / userbar.component.ts
1 import { Component, OnInit } from '@angular/core';
2 import { UserbarService, UserProfileService } from 'src/app/shared/services';
3 import { DomSanitizer } from '@angular/platform-browser';
4
5 @Component({
6   selector: 'app-userbar',
7   templateUrl: './userbar.component.html',
8   styleUrls: ['./userbar.component.scss']
9 })
10 export class UserbarComponent implements OnInit {
11
12   userList;
13   isOpen: boolean;
14   intervalPromise = null;
15   updateRate: number;
16   myservice: UserbarService;
17   constructor(private sanitizer: DomSanitizer, private userbarService: UserbarService, private userProfileService: UserProfileService) { }
18
19   ngOnInit() {
20     this.userList = [];
21     this.myservice = this.userbarService;
22     this.isOpen = true;
23     // this.userbarService.getOnlineUserUpdateRate().subscribe((_res: any) => {
24     //   if (_res != null) {
25     //     var rate = parseInt(_res.onlineUserUpdateRate);
26     //     var duration = parseInt(_res.onlineUserUpdateDuration);
27     //     this.userbarService.setMaxRefreshCount((duration / rate) + 1);
28     //     this.userbarService.setRefreshCount(this.userbarService.maxCount);
29     //     if (rate != NaN && duration != NaN) {
30     //       // $log.debug('UserbarCtlr: scheduling function at interval ' + millis);
31     //       this.updateRate = rate;
32     //       this.start(this.updateRate);
33     //     }
34     //   }
35     // })
36     this.updateActiveUsers();
37   }
38
39   updateActiveUsers() {
40     // this.userbarService.decrementRefreshCount();
41     this.userProfileService.getActiveUser().subscribe((_res: any) => {
42       if (_res == null) {
43         // $log.error('UserbarCtrl::updateActiveUsers: failed to get active user');
44         this.stop();
45       } else {
46         var maxItems = 25;
47         if (_res.length < maxItems)
48           maxItems = _res.length;
49         for (var i = 0; i < maxItems; i++) {
50           var data = {
51             userId: _res[i],
52             linkQ: this.sanitizer.bypassSecurityTrustResourceUrl('qto://talk/' + _res[i]),
53             linkPic: 'https://tspace.web.att.com/profiles/photo.do?uid=' + _res[i]
54           }
55           this.userList.push(data);
56         }
57       }
58
59     }, (err) => {
60       this.userList = [];
61       this.stop();
62     })
63
64     // .add(() => {
65     //   var footerOff = $('#online-userbar').offset().top;
66     //   var headOff = $('#footer').offset().top;
67     //   var defaultOffSet = 45;
68     //   $(".online-user-container").css({
69     //     "height": headOff - footerOff - defaultOffSet
70     //   });
71     // })
72
73   }
74
75   toggleSidebar() {
76     this.isOpen = !this.isOpen;
77   }
78
79   start(rate) {
80     // stops any running interval to avoid two intervals running at the same time
81     this.stop();
82     // store the interval promise
83     this.intervalPromise = setInterval(this.updateActiveUsers, rate);
84   };
85
86
87   stop() {
88     if (this.intervalPromise != null) {
89       clearInterval(this.intervalPromise);
90       this.intervalPromise = null;
91     }
92   };
93
94
95
96 }