2021-08-07 07:12:40 +02:00
|
|
|
import { ChangeDetectorRef, Component, OnDestroy, OnInit } from '@angular/core';
|
2021-09-24 20:12:17 +02:00
|
|
|
import { DataService } from '@ghostfolio/client/services/data.service';
|
2021-08-07 07:12:40 +02:00
|
|
|
import { UserService } from '@ghostfolio/client/services/user/user.service';
|
|
|
|
import { User } from '@ghostfolio/common/interfaces';
|
2021-09-24 20:12:17 +02:00
|
|
|
import { hasPermission, permissions } from '@ghostfolio/common/permissions';
|
2021-08-07 07:12:40 +02:00
|
|
|
import { Subject } from 'rxjs';
|
|
|
|
import { takeUntil } from 'rxjs/operators';
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'gf-portfolio-page',
|
|
|
|
templateUrl: './portfolio-page.html',
|
|
|
|
styleUrls: ['./portfolio-page.scss']
|
|
|
|
})
|
|
|
|
export class PortfolioPageComponent implements OnDestroy, OnInit {
|
2021-09-24 20:12:17 +02:00
|
|
|
public hasPermissionForSubscription: boolean;
|
2021-08-07 07:12:40 +02:00
|
|
|
public user: User;
|
|
|
|
|
|
|
|
private unsubscribeSubject = new Subject<void>();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @constructor
|
|
|
|
*/
|
|
|
|
public constructor(
|
|
|
|
private changeDetectorRef: ChangeDetectorRef,
|
2021-09-24 20:12:17 +02:00
|
|
|
private dataService: DataService,
|
2021-08-07 07:12:40 +02:00
|
|
|
private userService: UserService
|
2021-09-24 20:12:17 +02:00
|
|
|
) {
|
|
|
|
const { globalPermissions } = this.dataService.fetchInfo();
|
|
|
|
|
|
|
|
this.hasPermissionForSubscription = hasPermission(
|
|
|
|
globalPermissions,
|
|
|
|
permissions.enableSubscription
|
|
|
|
);
|
|
|
|
}
|
2021-08-07 07:12:40 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Initializes the controller
|
|
|
|
*/
|
|
|
|
public ngOnInit() {
|
|
|
|
this.userService.stateChanged
|
|
|
|
.pipe(takeUntil(this.unsubscribeSubject))
|
|
|
|
.subscribe((state) => {
|
|
|
|
if (state?.user) {
|
|
|
|
this.user = state.user;
|
|
|
|
|
|
|
|
this.changeDetectorRef.markForCheck();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
public ngOnDestroy() {
|
|
|
|
this.unsubscribeSubject.next();
|
|
|
|
this.unsubscribeSubject.complete();
|
|
|
|
}
|
|
|
|
}
|