Skip to content

Instantly share code, notes, and snippets.

@balvinder294
Last active March 15, 2020 14:04
Show Gist options
  • Select an option

  • Save balvinder294/7d4722850fc5f16403cbd2cc2a711b75 to your computer and use it in GitHub Desktop.

Select an option

Save balvinder294/7d4722850fc5f16403cbd2cc2a711b75 to your computer and use it in GitHub Desktop.
Sample Tracker COmponent from Jhipster for Tracking users logged in --- Tekraze.com
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