Last active
March 15, 2020 14:04
-
-
Save balvinder294/7d4722850fc5f16403cbd2cc2a711b75 to your computer and use it in GitHub Desktop.
Sample Tracker COmponent from Jhipster for Tracking users logged in --- Tekraze.com
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { Component, OnInit, OnDestroy } from '@angular/core'; | |
| import { JhiTrackerService } from 'app/core'; | |
| @Component({ | |
| selector: 'jhi-tracker', | |
| templateUrl: './tracker.component.html' | |
| }) | |
| export class JhiTrackerComponent implements OnInit, OnDestroy { | |
| activities: any[] = []; | |
| constructor(private trackerService: JhiTrackerService) {} | |
| showActivity(activity: any) { | |
| let existingActivity = false; | |
| for (let index = 0; index < this.activities.length; index++) { | |
| if (this.activities[index].sessionId === activity.sessionId) { | |
| existingActivity = true; | |
| if (activity.page === 'logout') { | |
| this.activities.splice(index, 1); | |
| } else { | |
| this.activities[index] = activity; | |
| } | |
| } | |
| } | |
| if (!existingActivity && activity.page !== 'logout') { | |
| this.activities.push(activity); | |
| } | |
| } | |
| ngOnInit() { | |
| this.trackerService.subscribe(); | |
| this.trackerService.receive().subscribe(activity => { | |
| this.showActivity(activity); | |
| }); | |
| } | |
| ngOnDestroy() { | |
| this.trackerService.unsubscribe(); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment