mirror of https://github.com/ghostfolio/ghostfolio
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
99 lines
2.7 KiB
99 lines
2.7 KiB
import { ChangeDetectorRef, Component, OnDestroy, OnInit } from '@angular/core';
|
|
import { DataService } from '@ghostfolio/client/services/data.service';
|
|
import { TokenStorageService } from '@ghostfolio/client/services/token-storage.service';
|
|
import { DEFAULT_DATE_FORMAT } from '@ghostfolio/common/config';
|
|
import { Access, User } from '@ghostfolio/common/interfaces';
|
|
import { hasPermission, permissions } from '@ghostfolio/common/permissions';
|
|
import { Currency } from '@prisma/client';
|
|
import { Subject } from 'rxjs';
|
|
import { takeUntil } from 'rxjs/operators';
|
|
|
|
@Component({
|
|
selector: 'gf-account-page',
|
|
templateUrl: './account-page.html',
|
|
styleUrls: ['./account-page.scss']
|
|
})
|
|
export class AccountPageComponent implements OnDestroy, OnInit {
|
|
public accesses: Access[];
|
|
public baseCurrency: Currency;
|
|
public currencies: Currency[] = [];
|
|
public defaultDateFormat = DEFAULT_DATE_FORMAT;
|
|
public hasPermissionForSubscription: boolean;
|
|
public hasPermissionToUpdateUserSettings: boolean;
|
|
public user: User;
|
|
|
|
private unsubscribeSubject = new Subject<void>();
|
|
|
|
/**
|
|
* @constructor
|
|
*/
|
|
public constructor(
|
|
private cd: ChangeDetectorRef,
|
|
private dataService: DataService,
|
|
private tokenStorageService: TokenStorageService
|
|
) {
|
|
this.dataService
|
|
.fetchInfo()
|
|
.pipe(takeUntil(this.unsubscribeSubject))
|
|
.subscribe(({ currencies, globalPermissions }) => {
|
|
this.currencies = currencies;
|
|
|
|
this.hasPermissionForSubscription = hasPermission(
|
|
globalPermissions,
|
|
permissions.enableSubscription
|
|
);
|
|
});
|
|
|
|
this.tokenStorageService
|
|
.onChangeHasToken()
|
|
.pipe(takeUntil(this.unsubscribeSubject))
|
|
.subscribe(() => {
|
|
this.dataService.fetchUser().subscribe((user) => {
|
|
this.user = user;
|
|
|
|
this.hasPermissionToUpdateUserSettings = hasPermission(
|
|
this.user.permissions,
|
|
permissions.updateUserSettings
|
|
);
|
|
|
|
this.cd.markForCheck();
|
|
});
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Initializes the controller
|
|
*/
|
|
public ngOnInit() {
|
|
this.update();
|
|
}
|
|
|
|
public onChangeBaseCurrency({ value: currency }: { value: Currency }) {
|
|
this.dataService
|
|
.putUserSettings({ currency })
|
|
.pipe(takeUntil(this.unsubscribeSubject))
|
|
.subscribe(() => {
|
|
this.dataService.fetchUser().subscribe((user) => {
|
|
this.user = user;
|
|
|
|
this.cd.markForCheck();
|
|
});
|
|
});
|
|
}
|
|
|
|
public ngOnDestroy() {
|
|
this.unsubscribeSubject.next();
|
|
this.unsubscribeSubject.complete();
|
|
}
|
|
|
|
private update() {
|
|
this.dataService
|
|
.fetchAccesses()
|
|
.pipe(takeUntil(this.unsubscribeSubject))
|
|
.subscribe((response) => {
|
|
this.accesses = response;
|
|
|
|
this.cd.markForCheck();
|
|
});
|
|
}
|
|
}
|
|
|