|
@ -1,22 +1,34 @@ |
|
|
import { DataService } from '@ghostfolio/client/services/data.service'; |
|
|
import { DataService } from '@ghostfolio/client/services/data.service'; |
|
|
import { UserService } from '@ghostfolio/client/services/user/user.service'; |
|
|
import { UserService } from '@ghostfolio/client/services/user/user.service'; |
|
|
import { AssetProfileIdentifier, User } from '@ghostfolio/common/interfaces'; |
|
|
import { Benchmark, User } from '@ghostfolio/common/interfaces'; |
|
|
|
|
|
|
|
|
import { ChangeDetectorRef, Component, OnDestroy, OnInit } from '@angular/core'; |
|
|
import { |
|
|
|
|
|
ChangeDetectionStrategy, |
|
|
|
|
|
ChangeDetectorRef, |
|
|
|
|
|
Component, |
|
|
|
|
|
OnDestroy, |
|
|
|
|
|
OnInit |
|
|
|
|
|
} from '@angular/core'; |
|
|
|
|
|
import { MatDialog } from '@angular/material/dialog'; |
|
|
|
|
|
import { ActivatedRoute, 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'; |
|
|
|
|
|
|
|
|
|
|
|
import { CreateWatchlistItemDialog } from './create-watchlist-item-dialog/create-watchlist-item-dialog.component'; |
|
|
|
|
|
import { CreateWatchlistItemDialogParams } from './create-watchlist-item-dialog/interfaces/interfaces'; |
|
|
|
|
|
|
|
|
@Component({ |
|
|
@Component({ |
|
|
|
|
|
changeDetection: ChangeDetectionStrategy.OnPush, |
|
|
selector: 'gf-home-watchlist', |
|
|
selector: 'gf-home-watchlist', |
|
|
styleUrls: ['./home-watchlist.scss'], |
|
|
styleUrls: ['./home-watchlist.scss'], |
|
|
templateUrl: './home-watchlist.html', |
|
|
templateUrl: './home-watchlist.html', |
|
|
standalone: false |
|
|
standalone: false |
|
|
}) |
|
|
}) |
|
|
export class HomeWatchlistComponent implements OnDestroy, OnInit { |
|
|
export class HomeWatchlistComponent implements OnDestroy, OnInit { |
|
|
public watchlist: AssetProfileIdentifier[]; |
|
|
|
|
|
public deviceType: string; |
|
|
public deviceType: string; |
|
|
public user: User; |
|
|
public user: User; |
|
|
|
|
|
public watchlist: Benchmark[]; |
|
|
|
|
|
|
|
|
private unsubscribeSubject = new Subject<void>(); |
|
|
private unsubscribeSubject = new Subject<void>(); |
|
|
|
|
|
|
|
@ -24,10 +36,21 @@ export class HomeWatchlistComponent implements OnDestroy, OnInit { |
|
|
private changeDetectorRef: ChangeDetectorRef, |
|
|
private changeDetectorRef: ChangeDetectorRef, |
|
|
private dataService: DataService, |
|
|
private dataService: DataService, |
|
|
private deviceService: DeviceDetectorService, |
|
|
private deviceService: DeviceDetectorService, |
|
|
|
|
|
private dialog: MatDialog, |
|
|
|
|
|
private route: ActivatedRoute, |
|
|
|
|
|
private router: Router, |
|
|
private userService: UserService |
|
|
private userService: UserService |
|
|
) { |
|
|
) { |
|
|
this.deviceType = this.deviceService.getDeviceInfo().deviceType; |
|
|
this.deviceType = this.deviceService.getDeviceInfo().deviceType; |
|
|
|
|
|
|
|
|
|
|
|
this.route.queryParams |
|
|
|
|
|
.pipe(takeUntil(this.unsubscribeSubject)) |
|
|
|
|
|
.subscribe((params) => { |
|
|
|
|
|
if (params['createWatchlistItemDialog']) { |
|
|
|
|
|
this.openCreateWatchlistItemDialog(); |
|
|
|
|
|
} |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
this.userService.stateChanged |
|
|
this.userService.stateChanged |
|
|
.pipe(takeUntil(this.unsubscribeSubject)) |
|
|
.pipe(takeUntil(this.unsubscribeSubject)) |
|
|
.subscribe((state) => { |
|
|
.subscribe((state) => { |
|
@ -40,18 +63,68 @@ export class HomeWatchlistComponent implements OnDestroy, OnInit { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public ngOnInit() { |
|
|
public ngOnInit() { |
|
|
|
|
|
this.loadWatchlistData(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public ngOnDestroy() { |
|
|
|
|
|
this.unsubscribeSubject.next(); |
|
|
|
|
|
this.unsubscribeSubject.complete(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private loadWatchlistData() { |
|
|
this.dataService |
|
|
this.dataService |
|
|
.fetchWatchlist() |
|
|
.fetchWatchlist() |
|
|
.pipe(takeUntil(this.unsubscribeSubject)) |
|
|
.pipe(takeUntil(this.unsubscribeSubject)) |
|
|
.subscribe((watchlist) => { |
|
|
.subscribe((watchlist) => { |
|
|
this.watchlist = watchlist; |
|
|
this.watchlist = watchlist.map((item) => ({ |
|
|
|
|
|
dataSource: item.dataSource, |
|
|
|
|
|
symbol: item.symbol, |
|
|
|
|
|
name: item.symbol, |
|
|
|
|
|
marketCondition: 'NEUTRAL_MARKET', |
|
|
|
|
|
performances: { |
|
|
|
|
|
allTimeHigh: { |
|
|
|
|
|
date: new Date(), |
|
|
|
|
|
performancePercent: 0 |
|
|
|
|
|
} |
|
|
|
|
|
}, |
|
|
|
|
|
trend200d: 'UNKNOWN', |
|
|
|
|
|
trend50d: 'UNKNOWN' |
|
|
|
|
|
})); |
|
|
|
|
|
|
|
|
this.changeDetectorRef.markForCheck(); |
|
|
this.changeDetectorRef.markForCheck(); |
|
|
}); |
|
|
}); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public ngOnDestroy() { |
|
|
private openCreateWatchlistItemDialog() { |
|
|
this.unsubscribeSubject.next(); |
|
|
this.userService |
|
|
this.unsubscribeSubject.complete(); |
|
|
.get() |
|
|
|
|
|
.pipe(takeUntil(this.unsubscribeSubject)) |
|
|
|
|
|
.subscribe((user) => { |
|
|
|
|
|
this.user = user; |
|
|
|
|
|
|
|
|
|
|
|
const dialogRef = this.dialog.open(CreateWatchlistItemDialog, { |
|
|
|
|
|
autoFocus: false, |
|
|
|
|
|
data: { |
|
|
|
|
|
deviceType: this.deviceType, |
|
|
|
|
|
locale: this.user?.settings?.locale |
|
|
|
|
|
} as CreateWatchlistItemDialogParams, |
|
|
|
|
|
width: this.deviceType === 'mobile' ? '100vw' : '50rem' |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
dialogRef |
|
|
|
|
|
.afterClosed() |
|
|
|
|
|
.pipe(takeUntil(this.unsubscribeSubject)) |
|
|
|
|
|
.subscribe(({ dataSource, symbol } = {}) => { |
|
|
|
|
|
if (dataSource && symbol) { |
|
|
|
|
|
this.dataService |
|
|
|
|
|
.postWatchlist({ dataSource, symbol }) |
|
|
|
|
|
.pipe(takeUntil(this.unsubscribeSubject)) |
|
|
|
|
|
.subscribe({ |
|
|
|
|
|
next: () => this.loadWatchlistData() |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
|
|
|
this.router.navigate(['.'], { relativeTo: this.route }); |
|
|
|
|
|
}); |
|
|
|
|
|
}); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|