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 { MatDialog } from '@angular/material/dialog';
|
|
|
|
import { MatPaginator } from '@angular/material/paginator';
|
|
|
|
import { MatSort } from '@angular/material/sort';
|
|
|
|
import { MatTableDataSource } from '@angular/material/table';
|
|
|
|
import { ActivatedRoute, Router } from '@angular/router';
|
2021-07-10 14:57:03 +02:00
|
|
|
import { Type } from '@ghostfolio/api/services/interfaces/interfaces';
|
2021-05-16 22:11:14 +02:00
|
|
|
import { PortfolioPosition } from '@ghostfolio/common/interfaces';
|
2021-04-13 21:53:58 +02:00
|
|
|
import { Order as OrderModel } from '@prisma/client';
|
|
|
|
import { Subject, Subscription } from 'rxjs';
|
|
|
|
import { takeUntil } from 'rxjs/operators';
|
|
|
|
|
|
|
|
import { PositionDetailDialog } from '../position/position-detail-dialog/position-detail-dialog.component';
|
|
|
|
|
|
|
|
@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 = [];
|
2021-07-10 14:57:03 +02:00
|
|
|
public ignoreTypes = [Type.Cash];
|
2021-04-13 21:53:58 +02:00
|
|
|
public isLoading = true;
|
|
|
|
public pageSize = 7;
|
|
|
|
public routeQueryParams: Subscription;
|
|
|
|
|
|
|
|
private unsubscribeSubject = new Subject<void>();
|
|
|
|
|
|
|
|
public constructor(
|
|
|
|
private dialog: MatDialog,
|
|
|
|
private route: ActivatedRoute,
|
|
|
|
private router: Router
|
|
|
|
) {
|
|
|
|
this.routeQueryParams = route.queryParams
|
|
|
|
.pipe(takeUntil(this.unsubscribeSubject))
|
|
|
|
.subscribe((params) => {
|
|
|
|
if (
|
|
|
|
params['positionDetailDialog'] &&
|
|
|
|
params['symbol'] &&
|
|
|
|
params['title']
|
|
|
|
) {
|
|
|
|
this.openPositionDialog({
|
|
|
|
symbol: params['symbol'],
|
|
|
|
title: params['title']
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
public ngOnInit() {}
|
|
|
|
|
|
|
|
public ngOnChanges() {
|
|
|
|
this.displayedColumns = [
|
|
|
|
'symbol',
|
|
|
|
'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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*public applyFilter(event: Event) {
|
|
|
|
const filterValue = (event.target as HTMLInputElement).value;
|
|
|
|
this.dataSource.filter = filterValue.trim().toLowerCase();
|
|
|
|
}*/
|
|
|
|
|
|
|
|
public onOpenPositionDialog({
|
|
|
|
symbol,
|
|
|
|
title
|
|
|
|
}: {
|
|
|
|
symbol: string;
|
|
|
|
title: string;
|
|
|
|
}): void {
|
|
|
|
this.router.navigate([], {
|
|
|
|
queryParams: { positionDetailDialog: true, symbol, title }
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
public onShowAllPositions() {
|
|
|
|
this.pageSize = Number.MAX_SAFE_INTEGER;
|
|
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
this.dataSource.paginator = this.paginator;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
public openPositionDialog({
|
|
|
|
symbol,
|
|
|
|
title
|
|
|
|
}: {
|
|
|
|
symbol: string;
|
|
|
|
title: string;
|
|
|
|
}): void {
|
|
|
|
const dialogRef = this.dialog.open(PositionDetailDialog, {
|
|
|
|
autoFocus: false,
|
|
|
|
data: {
|
|
|
|
symbol,
|
|
|
|
title,
|
|
|
|
baseCurrency: this.baseCurrency,
|
|
|
|
deviceType: this.deviceType,
|
|
|
|
locale: this.locale
|
|
|
|
},
|
|
|
|
height: this.deviceType === 'mobile' ? '97.5vh' : '80vh',
|
|
|
|
width: this.deviceType === 'mobile' ? '100vw' : '50rem'
|
|
|
|
});
|
|
|
|
|
2021-07-08 21:28:28 +02:00
|
|
|
dialogRef
|
|
|
|
.afterClosed()
|
|
|
|
.pipe(takeUntil(this.unsubscribeSubject))
|
|
|
|
.subscribe(() => {
|
|
|
|
this.router.navigate(['.'], { relativeTo: this.route });
|
|
|
|
});
|
2021-04-13 21:53:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public ngOnDestroy() {
|
|
|
|
this.unsubscribeSubject.next();
|
|
|
|
this.unsubscribeSubject.complete();
|
|
|
|
}
|
|
|
|
}
|