|
@ -1,11 +1,21 @@ |
|
|
import { DataService } from '@ghostfolio/client/services/data.service'; |
|
|
import { DataService } from '@ghostfolio/client/services/data.service'; |
|
|
import { ImpersonationStorageService } from '@ghostfolio/client/services/impersonation-storage.service'; |
|
|
import { ImpersonationStorageService } from '@ghostfolio/client/services/impersonation-storage.service'; |
|
|
import { UserService } from '@ghostfolio/client/services/user/user.service'; |
|
|
import { UserService } from '@ghostfolio/client/services/user/user.service'; |
|
|
import { PortfolioPosition, User } from '@ghostfolio/common/interfaces'; |
|
|
import { |
|
|
|
|
|
PortfolioPosition, |
|
|
|
|
|
UniqueAsset, |
|
|
|
|
|
User |
|
|
|
|
|
} from '@ghostfolio/common/interfaces'; |
|
|
import { hasPermission, permissions } from '@ghostfolio/common/permissions'; |
|
|
import { hasPermission, permissions } from '@ghostfolio/common/permissions'; |
|
|
import { HoldingType, ToggleOption } from '@ghostfolio/common/types'; |
|
|
import { |
|
|
|
|
|
HoldingType, |
|
|
|
|
|
HoldingViewMode, |
|
|
|
|
|
ToggleOption |
|
|
|
|
|
} from '@ghostfolio/common/types'; |
|
|
|
|
|
|
|
|
import { ChangeDetectorRef, Component, OnDestroy, OnInit } from '@angular/core'; |
|
|
import { ChangeDetectorRef, Component, OnDestroy, OnInit } from '@angular/core'; |
|
|
|
|
|
import { FormControl } from '@angular/forms'; |
|
|
|
|
|
import { Router } from '@angular/router'; |
|
|
import { DeviceDetectorService } from 'ngx-device-detector'; |
|
|
import { DeviceDetectorService } from 'ngx-device-detector'; |
|
|
import { Subject } from 'rxjs'; |
|
|
import { Subject } from 'rxjs'; |
|
|
import { takeUntil } from 'rxjs/operators'; |
|
|
import { takeUntil } from 'rxjs/operators'; |
|
@ -18,6 +28,7 @@ import { takeUntil } from 'rxjs/operators'; |
|
|
export class HomeHoldingsComponent implements OnDestroy, OnInit { |
|
|
export class HomeHoldingsComponent implements OnDestroy, OnInit { |
|
|
public deviceType: string; |
|
|
public deviceType: string; |
|
|
public hasImpersonationId: boolean; |
|
|
public hasImpersonationId: boolean; |
|
|
|
|
|
public hasPermissionToAccessHoldingsChart: boolean; |
|
|
public hasPermissionToCreateOrder: boolean; |
|
|
public hasPermissionToCreateOrder: boolean; |
|
|
public holdings: PortfolioPosition[]; |
|
|
public holdings: PortfolioPosition[]; |
|
|
public holdingType: HoldingType = 'ACTIVE'; |
|
|
public holdingType: HoldingType = 'ACTIVE'; |
|
@ -26,6 +37,7 @@ export class HomeHoldingsComponent implements OnDestroy, OnInit { |
|
|
{ label: $localize`Closed`, value: 'CLOSED' } |
|
|
{ label: $localize`Closed`, value: 'CLOSED' } |
|
|
]; |
|
|
]; |
|
|
public user: User; |
|
|
public user: User; |
|
|
|
|
|
public viewModeFormControl = new FormControl<HoldingViewMode>('TABLE'); |
|
|
|
|
|
|
|
|
private unsubscribeSubject = new Subject<void>(); |
|
|
private unsubscribeSubject = new Subject<void>(); |
|
|
|
|
|
|
|
@ -34,6 +46,7 @@ export class HomeHoldingsComponent implements OnDestroy, OnInit { |
|
|
private dataService: DataService, |
|
|
private dataService: DataService, |
|
|
private deviceService: DeviceDetectorService, |
|
|
private deviceService: DeviceDetectorService, |
|
|
private impersonationStorageService: ImpersonationStorageService, |
|
|
private impersonationStorageService: ImpersonationStorageService, |
|
|
|
|
|
private router: Router, |
|
|
private userService: UserService |
|
|
private userService: UserService |
|
|
) {} |
|
|
) {} |
|
|
|
|
|
|
|
@ -53,20 +66,17 @@ export class HomeHoldingsComponent implements OnDestroy, OnInit { |
|
|
if (state?.user) { |
|
|
if (state?.user) { |
|
|
this.user = state.user; |
|
|
this.user = state.user; |
|
|
|
|
|
|
|
|
|
|
|
this.hasPermissionToAccessHoldingsChart = hasPermission( |
|
|
|
|
|
this.user.permissions, |
|
|
|
|
|
permissions.accessHoldingsChart |
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
this.hasPermissionToCreateOrder = hasPermission( |
|
|
this.hasPermissionToCreateOrder = hasPermission( |
|
|
this.user.permissions, |
|
|
this.user.permissions, |
|
|
permissions.createOrder |
|
|
permissions.createOrder |
|
|
); |
|
|
); |
|
|
|
|
|
|
|
|
this.holdings = undefined; |
|
|
this.initialize(); |
|
|
|
|
|
|
|
|
this.fetchHoldings() |
|
|
|
|
|
.pipe(takeUntil(this.unsubscribeSubject)) |
|
|
|
|
|
.subscribe(({ holdings }) => { |
|
|
|
|
|
this.holdings = holdings; |
|
|
|
|
|
|
|
|
|
|
|
this.changeDetectorRef.markForCheck(); |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
this.changeDetectorRef.markForCheck(); |
|
|
this.changeDetectorRef.markForCheck(); |
|
|
} |
|
|
} |
|
@ -76,16 +86,16 @@ export class HomeHoldingsComponent implements OnDestroy, OnInit { |
|
|
public onChangeHoldingType(aHoldingType: HoldingType) { |
|
|
public onChangeHoldingType(aHoldingType: HoldingType) { |
|
|
this.holdingType = aHoldingType; |
|
|
this.holdingType = aHoldingType; |
|
|
|
|
|
|
|
|
this.holdings = undefined; |
|
|
this.initialize(); |
|
|
|
|
|
} |
|
|
this.fetchHoldings() |
|
|
|
|
|
.pipe(takeUntil(this.unsubscribeSubject)) |
|
|
|
|
|
.subscribe(({ holdings }) => { |
|
|
|
|
|
this.holdings = holdings; |
|
|
|
|
|
|
|
|
|
|
|
this.changeDetectorRef.markForCheck(); |
|
|
public onSymbolClicked({ dataSource, symbol }: UniqueAsset) { |
|
|
|
|
|
if (dataSource && symbol) { |
|
|
|
|
|
this.router.navigate([], { |
|
|
|
|
|
queryParams: { dataSource, symbol, holdingDetailDialog: true } |
|
|
}); |
|
|
}); |
|
|
} |
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
public ngOnDestroy() { |
|
|
public ngOnDestroy() { |
|
|
this.unsubscribeSubject.next(); |
|
|
this.unsubscribeSubject.next(); |
|
@ -104,4 +114,27 @@ export class HomeHoldingsComponent implements OnDestroy, OnInit { |
|
|
range: this.user?.settings?.dateRange |
|
|
range: this.user?.settings?.dateRange |
|
|
}); |
|
|
}); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private initialize() { |
|
|
|
|
|
this.viewModeFormControl.disable(); |
|
|
|
|
|
|
|
|
|
|
|
if ( |
|
|
|
|
|
this.hasPermissionToAccessHoldingsChart && |
|
|
|
|
|
this.holdingType === 'ACTIVE' |
|
|
|
|
|
) { |
|
|
|
|
|
this.viewModeFormControl.enable(); |
|
|
|
|
|
} else if (this.holdingType === 'CLOSED') { |
|
|
|
|
|
this.viewModeFormControl.setValue('TABLE'); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
this.holdings = undefined; |
|
|
|
|
|
|
|
|
|
|
|
this.fetchHoldings() |
|
|
|
|
|
.pipe(takeUntil(this.unsubscribeSubject)) |
|
|
|
|
|
.subscribe(({ holdings }) => { |
|
|
|
|
|
this.holdings = holdings; |
|
|
|
|
|
|
|
|
|
|
|
this.changeDetectorRef.markForCheck(); |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|