mirror of https://github.com/ghostfolio/ghostfolio
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
63 lines
1.7 KiB
63 lines
1.7 KiB
import {
|
|
ChangeDetectionStrategy,
|
|
ChangeDetectorRef,
|
|
Component,
|
|
Input,
|
|
OnDestroy,
|
|
OnInit,
|
|
ViewChild
|
|
} from '@angular/core';
|
|
import { MatSort } from '@angular/material/sort';
|
|
import { MatTableDataSource } from '@angular/material/table';
|
|
import { DataService } from '@ghostfolio/client/services/data.service';
|
|
import { AccountBalancesResponse } from '@ghostfolio/common/interfaces';
|
|
import { get } from 'lodash';
|
|
import { Subject, takeUntil } from 'rxjs';
|
|
|
|
@Component({
|
|
changeDetection: ChangeDetectionStrategy.OnPush,
|
|
selector: 'gf-account-balances',
|
|
styleUrls: ['./account-balances.component.scss'],
|
|
templateUrl: './account-balances.component.html'
|
|
})
|
|
export class AccountBalancesComponent implements OnDestroy, OnInit {
|
|
@Input() accountId: string;
|
|
@Input() locale: string;
|
|
|
|
@ViewChild(MatSort) sort: MatSort;
|
|
|
|
public dataSource: MatTableDataSource<
|
|
AccountBalancesResponse['balances'][0]
|
|
> = new MatTableDataSource();
|
|
public displayedColumns: string[] = ['date', 'value'];
|
|
|
|
private unsubscribeSubject = new Subject<void>();
|
|
|
|
public constructor(
|
|
private changeDetectorRef: ChangeDetectorRef,
|
|
private dataService: DataService
|
|
) {}
|
|
|
|
public ngOnInit() {
|
|
this.fetchBalances();
|
|
}
|
|
|
|
public ngOnDestroy() {
|
|
this.unsubscribeSubject.next();
|
|
this.unsubscribeSubject.complete();
|
|
}
|
|
|
|
private fetchBalances() {
|
|
this.dataService
|
|
.fetchAccountBalances(this.accountId)
|
|
.pipe(takeUntil(this.unsubscribeSubject))
|
|
.subscribe(({ balances }) => {
|
|
this.dataSource = new MatTableDataSource(balances);
|
|
|
|
this.dataSource.sort = this.sort;
|
|
this.dataSource.sortingDataAccessor = get;
|
|
|
|
this.changeDetectorRef.markForCheck();
|
|
});
|
|
}
|
|
}
|
|
|