|
|
@ -11,7 +11,6 @@ import { MatSort } from '@angular/material/sort'; |
|
|
|
import { MatTableDataSource } from '@angular/material/table'; |
|
|
|
import { ActivatedRoute, Router } from '@angular/router'; |
|
|
|
import { AdminService } from '@ghostfolio/client/services/admin.service'; |
|
|
|
import { DataService } from '@ghostfolio/client/services/data.service'; |
|
|
|
import { UserService } from '@ghostfolio/client/services/user/user.service'; |
|
|
|
import { getDateFormatString } from '@ghostfolio/common/helper'; |
|
|
|
import { Filter, UniqueAsset, User } from '@ghostfolio/common/interfaces'; |
|
|
@ -26,6 +25,8 @@ import { AssetProfileDialog } from './asset-profile-dialog/asset-profile-dialog. |
|
|
|
import { AssetProfileDialogParams } from './asset-profile-dialog/interfaces/interfaces'; |
|
|
|
import { CreateAssetProfileDialog } from './create-asset-profile-dialog/create-asset-profile-dialog.component'; |
|
|
|
import { CreateAssetProfileDialogParams } from './create-asset-profile-dialog/interfaces/interfaces'; |
|
|
|
import { DEFAULT_PAGE_SIZE } from '@ghostfolio/common/config'; |
|
|
|
import { MatPaginator, PageEvent } from '@angular/material/paginator'; |
|
|
|
|
|
|
|
@Component({ |
|
|
|
changeDetection: ChangeDetectionStrategy.OnPush, |
|
|
@ -34,6 +35,7 @@ import { CreateAssetProfileDialogParams } from './create-asset-profile-dialog/in |
|
|
|
templateUrl: './admin-market-data.html' |
|
|
|
}) |
|
|
|
export class AdminMarketDataComponent implements OnDestroy, OnInit { |
|
|
|
@ViewChild(MatPaginator) paginator: MatPaginator; |
|
|
|
@ViewChild(MatSort) sort: MatSort; |
|
|
|
|
|
|
|
public activeFilters: Filter[] = []; |
|
|
@ -75,6 +77,8 @@ export class AdminMarketDataComponent implements OnDestroy, OnInit { |
|
|
|
public filters$ = new Subject<Filter[]>(); |
|
|
|
public isLoading = false; |
|
|
|
public placeholder = ''; |
|
|
|
public pageSize = DEFAULT_PAGE_SIZE; |
|
|
|
public totalItems = 0; |
|
|
|
public user: User; |
|
|
|
|
|
|
|
private unsubscribeSubject = new Subject<void>(); |
|
|
@ -82,7 +86,6 @@ export class AdminMarketDataComponent implements OnDestroy, OnInit { |
|
|
|
public constructor( |
|
|
|
private adminService: AdminService, |
|
|
|
private changeDetectorRef: ChangeDetectorRef, |
|
|
|
private dataService: DataService, |
|
|
|
private deviceService: DeviceDetectorService, |
|
|
|
private dialog: MatDialog, |
|
|
|
private route: ActivatedRoute, |
|
|
@ -117,34 +120,22 @@ export class AdminMarketDataComponent implements OnDestroy, OnInit { |
|
|
|
); |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
this.filters$ |
|
|
|
.pipe(distinctUntilChanged(), takeUntil(this.unsubscribeSubject)) |
|
|
|
.subscribe((filters) => { |
|
|
|
this.activeFilters = filters; |
|
|
|
|
|
|
|
this.loadData(); |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
public ngOnInit() { |
|
|
|
this.deviceType = this.deviceService.getDeviceInfo().deviceType; |
|
|
|
} |
|
|
|
|
|
|
|
this.filters$ |
|
|
|
.pipe( |
|
|
|
distinctUntilChanged(), |
|
|
|
switchMap((filters) => { |
|
|
|
this.isLoading = true; |
|
|
|
this.activeFilters = filters; |
|
|
|
this.placeholder = |
|
|
|
this.activeFilters.length <= 0 ? $localize`Filter by...` : ''; |
|
|
|
|
|
|
|
return this.dataService.fetchAdminMarketData({ |
|
|
|
filters: this.activeFilters |
|
|
|
}); |
|
|
|
}), |
|
|
|
takeUntil(this.unsubscribeSubject) |
|
|
|
) |
|
|
|
.subscribe(({ marketData }) => { |
|
|
|
this.dataSource = new MatTableDataSource(marketData); |
|
|
|
this.dataSource.sort = this.sort; |
|
|
|
|
|
|
|
this.isLoading = false; |
|
|
|
|
|
|
|
this.changeDetectorRef.markForCheck(); |
|
|
|
}); |
|
|
|
public onChangePage(page: PageEvent) { |
|
|
|
this.loadData(page.pageIndex); |
|
|
|
} |
|
|
|
|
|
|
|
public onDeleteProfileData({ dataSource, symbol }: UniqueAsset) { |
|
|
@ -212,6 +203,35 @@ export class AdminMarketDataComponent implements OnDestroy, OnInit { |
|
|
|
this.unsubscribeSubject.complete(); |
|
|
|
} |
|
|
|
|
|
|
|
private loadData(aPageIndex = 0) { |
|
|
|
this.isLoading = true; |
|
|
|
|
|
|
|
if (aPageIndex === 0 && this.paginator) { |
|
|
|
this.paginator.pageIndex = 0; |
|
|
|
} |
|
|
|
|
|
|
|
this.placeholder = |
|
|
|
this.activeFilters.length <= 0 ? $localize`Filter by...` : ''; |
|
|
|
|
|
|
|
this.adminService |
|
|
|
.fetchAdminMarketData({ |
|
|
|
filters: this.activeFilters, |
|
|
|
skip: aPageIndex * this.pageSize, |
|
|
|
take: this.pageSize |
|
|
|
}) |
|
|
|
.pipe(takeUntil(this.unsubscribeSubject)) |
|
|
|
.subscribe(({ count, marketData }) => { |
|
|
|
this.totalItems = count; |
|
|
|
|
|
|
|
this.dataSource = new MatTableDataSource(marketData); |
|
|
|
this.dataSource.sort = this.sort; |
|
|
|
|
|
|
|
this.isLoading = false; |
|
|
|
|
|
|
|
this.changeDetectorRef.markForCheck(); |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
private openAssetProfileDialog({ |
|
|
|
dataSource, |
|
|
|
symbol |
|
|
@ -274,8 +294,9 @@ export class AdminMarketDataComponent implements OnDestroy, OnInit { |
|
|
|
this.isLoading = true; |
|
|
|
this.changeDetectorRef.markForCheck(); |
|
|
|
|
|
|
|
return this.dataService.fetchAdminMarketData({ |
|
|
|
filters: this.activeFilters |
|
|
|
return this.adminService.fetchAdminMarketData({ |
|
|
|
filters: this.activeFilters, |
|
|
|
take: this.pageSize |
|
|
|
}); |
|
|
|
}), |
|
|
|
takeUntil(this.unsubscribeSubject) |
|
|
|