datasurvey/src/main/webapp/app/admin/tracker/tracker.component.ts

50 lines
1.4 KiB
TypeScript
Raw Normal View History

2021-07-03 21:48:27 +00:00
import { Component, OnInit, OnDestroy } from '@angular/core';
import { Subscription } from 'rxjs';
import { TrackerService } from 'app/core/tracker/tracker.service';
import { TrackerActivity } from 'app/core/tracker/tracker-activity.model';
@Component({
selector: 'jhi-tracker',
templateUrl: './tracker.component.html',
})
export class TrackerComponent implements OnInit, OnDestroy {
activities: TrackerActivity[] = [];
subscription?: Subscription;
constructor(private trackerService: TrackerService) {}
showActivity(activity: TrackerActivity): void {
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(): void {
this.trackerService.subscribe();
this.subscription = this.trackerService.receive().subscribe((activity: TrackerActivity) => {
this.showActivity(activity);
});
}
ngOnDestroy(): void {
this.trackerService.unsubscribe();
if (this.subscription) {
this.subscription.unsubscribe();
}
}
}