|
|
@ -1,4 +1,5 @@ |
|
|
import { WebAuthnService } from '@ghostfolio/client/services/web-authn.service'; |
|
|
import { WebAuthnService } from '@ghostfolio/client/services/web-authn.service'; |
|
|
|
|
|
import { getStoredDateRange } from '@ghostfolio/common/date-range.helper'; |
|
|
import { Filter, User } from '@ghostfolio/common/interfaces'; |
|
|
import { Filter, User } from '@ghostfolio/common/interfaces'; |
|
|
import { hasPermission, permissions } from '@ghostfolio/common/permissions'; |
|
|
import { hasPermission, permissions } from '@ghostfolio/common/permissions'; |
|
|
|
|
|
|
|
|
@ -9,7 +10,7 @@ import { MatDialog } from '@angular/material/dialog'; |
|
|
import { ObservableStore } from '@codewithdan/observable-store'; |
|
|
import { ObservableStore } from '@codewithdan/observable-store'; |
|
|
import { parseISO } from 'date-fns'; |
|
|
import { parseISO } from 'date-fns'; |
|
|
import { DeviceDetectorService } from 'ngx-device-detector'; |
|
|
import { DeviceDetectorService } from 'ngx-device-detector'; |
|
|
import { Observable, of } from 'rxjs'; |
|
|
import { EMPTY, Observable, of } from 'rxjs'; |
|
|
import { throwError } from 'rxjs'; |
|
|
import { throwError } from 'rxjs'; |
|
|
import { catchError, map } from 'rxjs/operators'; |
|
|
import { catchError, map } from 'rxjs/operators'; |
|
|
|
|
|
|
|
|
@ -24,6 +25,8 @@ export class UserService extends ObservableStore<UserStoreState> { |
|
|
() => this.deviceDetectorService.deviceInfo().deviceType |
|
|
() => this.deviceDetectorService.deviceInfo().deviceType |
|
|
); |
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
private hasRestoredDateRange = false; |
|
|
|
|
|
|
|
|
private readonly destroyRef = inject(DestroyRef); |
|
|
private readonly destroyRef = inject(DestroyRef); |
|
|
private readonly deviceDetectorService = inject(DeviceDetectorService); |
|
|
private readonly deviceDetectorService = inject(DeviceDetectorService); |
|
|
private readonly dialog = inject(MatDialog); |
|
|
private readonly dialog = inject(MatDialog); |
|
|
@ -161,6 +164,8 @@ export class UserService extends ObservableStore<UserStoreState> { |
|
|
); |
|
|
); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
this.restoreStoredDateRange(user); |
|
|
|
|
|
|
|
|
this.setState({ user }, UserStoreActions.GetUser); |
|
|
this.setState({ user }, UserStoreActions.GetUser); |
|
|
|
|
|
|
|
|
if ( |
|
|
if ( |
|
|
@ -194,6 +199,38 @@ export class UserService extends ObservableStore<UserStoreState> { |
|
|
); |
|
|
); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* Restores the date range selected last on this device once per page load, |
|
|
|
|
|
* e.g. if the stored user setting has been changed from another device. |
|
|
|
|
|
*/ |
|
|
|
|
|
private restoreStoredDateRange(user: User) { |
|
|
|
|
|
if (this.hasRestoredDateRange || !user.settings) { |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
this.hasRestoredDateRange = true; |
|
|
|
|
|
|
|
|
|
|
|
const storedDateRange = getStoredDateRange(); |
|
|
|
|
|
|
|
|
|
|
|
if ( |
|
|
|
|
|
!storedDateRange || |
|
|
|
|
|
storedDateRange === user.settings.dateRange || |
|
|
|
|
|
user.settings.viewMode === 'ZEN' |
|
|
|
|
|
) { |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
user.settings.dateRange = storedDateRange; |
|
|
|
|
|
|
|
|
|
|
|
this.http |
|
|
|
|
|
.put('/api/v1/user/setting', { dateRange: storedDateRange }) |
|
|
|
|
|
.pipe( |
|
|
|
|
|
catchError(() => EMPTY), |
|
|
|
|
|
takeUntilDestroyed(this.destroyRef) |
|
|
|
|
|
) |
|
|
|
|
|
.subscribe(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
private handleError(error: any) { |
|
|
private handleError(error: any) { |
|
|
if (error.error instanceof Error) { |
|
|
if (error.error instanceof Error) { |
|
|
const errMessage = error.error.message; |
|
|
const errMessage = error.error.message; |
|
|
|