2021-04-13 21:53:58 +02:00
|
|
|
import {
|
|
|
|
ChangeDetectionStrategy,
|
|
|
|
Component,
|
|
|
|
EventEmitter,
|
|
|
|
Input,
|
|
|
|
OnChanges,
|
2021-07-08 21:28:28 +02:00
|
|
|
OnDestroy,
|
2021-04-13 21:53:58 +02:00
|
|
|
OnInit,
|
|
|
|
Output,
|
|
|
|
ViewChild
|
|
|
|
} from '@angular/core';
|
|
|
|
import { MatPaginator } from '@angular/material/paginator';
|
|
|
|
import { MatSort } from '@angular/material/sort';
|
|
|
|
import { MatTableDataSource } from '@angular/material/table';
|
2021-12-31 09:51:30 +01:00
|
|
|
import { Router } from '@angular/router';
|
2022-03-12 13:44:47 +01:00
|
|
|
import { ASSET_SUB_CLASS_EMERGENCY_FUND } from '@ghostfolio/common/config';
|
2022-02-28 21:35:52 +01:00
|
|
|
import { PortfolioPosition, UniqueAsset } from '@ghostfolio/common/interfaces';
|
|
|
|
import { AssetClass, Order as OrderModel } from '@prisma/client';
|
2021-04-13 21:53:58 +02:00
|
|
|
import { Subject, Subscription } from 'rxjs';
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'gf-positions-table',
|
|
|
|
changeDetection: ChangeDetectionStrategy.OnPush,
|
|
|
|
templateUrl: './positions-table.component.html',
|
|
|
|
styleUrls: ['./positions-table.component.scss']
|
|
|
|
})
|
2021-07-08 21:28:28 +02:00
|
|
|
export class PositionsTableComponent implements OnChanges, OnDestroy, OnInit {
|
2021-04-13 21:53:58 +02:00
|
|
|
@Input() baseCurrency: string;
|
|
|
|
@Input() deviceType: string;
|
|
|
|
@Input() locale: string;
|
|
|
|
@Input() positions: PortfolioPosition[];
|
|
|
|
|
|
|
|
@Output() transactionDeleted = new EventEmitter<string>();
|
|
|
|
@Output() transactionToUpdate = new EventEmitter<OrderModel>();
|
|
|
|
|
|
|
|
@ViewChild(MatPaginator) paginator: MatPaginator;
|
|
|
|
@ViewChild(MatSort) sort: MatSort;
|
|
|
|
|
2021-07-08 21:28:28 +02:00
|
|
|
public dataSource: MatTableDataSource<PortfolioPosition> =
|
|
|
|
new MatTableDataSource();
|
2021-04-13 21:53:58 +02:00
|
|
|
public displayedColumns = [];
|
2022-03-12 13:44:47 +01:00
|
|
|
public ignoreAssetSubClasses = [
|
|
|
|
AssetClass.CASH.toString(),
|
|
|
|
ASSET_SUB_CLASS_EMERGENCY_FUND
|
|
|
|
];
|
2021-04-13 21:53:58 +02:00
|
|
|
public isLoading = true;
|
|
|
|
public pageSize = 7;
|
|
|
|
public routeQueryParams: Subscription;
|
|
|
|
|
|
|
|
private unsubscribeSubject = new Subject<void>();
|
|
|
|
|
2021-12-31 09:51:30 +01:00
|
|
|
public constructor(private router: Router) {}
|
2021-04-13 21:53:58 +02:00
|
|
|
|
|
|
|
public ngOnInit() {}
|
|
|
|
|
|
|
|
public ngOnChanges() {
|
|
|
|
this.displayedColumns = [
|
|
|
|
'symbol',
|
2021-11-21 17:55:58 +01:00
|
|
|
'value',
|
2021-04-13 21:53:58 +02:00
|
|
|
'performance',
|
2021-05-15 10:12:12 +02:00
|
|
|
'allocationInvestment',
|
|
|
|
'allocationCurrent'
|
2021-04-13 21:53:58 +02:00
|
|
|
];
|
|
|
|
|
|
|
|
this.isLoading = true;
|
|
|
|
|
|
|
|
if (this.positions) {
|
|
|
|
this.dataSource = new MatTableDataSource(this.positions);
|
|
|
|
this.dataSource.paginator = this.paginator;
|
|
|
|
this.dataSource.sort = this.sort;
|
|
|
|
|
|
|
|
this.isLoading = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-28 21:35:52 +01:00
|
|
|
public onOpenPositionDialog({ dataSource, symbol }: UniqueAsset): void {
|
2021-04-13 21:53:58 +02:00
|
|
|
this.router.navigate([], {
|
2022-01-29 16:51:37 +01:00
|
|
|
queryParams: { dataSource, symbol, positionDetailDialog: true }
|
2021-04-13 21:53:58 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
public onShowAllPositions() {
|
|
|
|
this.pageSize = Number.MAX_SAFE_INTEGER;
|
|
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
this.dataSource.paginator = this.paginator;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
public ngOnDestroy() {
|
|
|
|
this.unsubscribeSubject.next();
|
|
|
|
this.unsubscribeSubject.complete();
|
|
|
|
}
|
|
|
|
}
|