|
|
@ -10,7 +10,10 @@ import { FormBuilder } from '@angular/forms'; |
|
|
|
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog'; |
|
|
|
import { UpdateAssetProfileDto } from '@ghostfolio/api/app/admin/update-asset-profile.dto'; |
|
|
|
import { AdminService } from '@ghostfolio/client/services/admin.service'; |
|
|
|
import { EnhancedSymbolProfile } from '@ghostfolio/common/interfaces'; |
|
|
|
import { |
|
|
|
EnhancedSymbolProfile, |
|
|
|
UniqueAsset |
|
|
|
} from '@ghostfolio/common/interfaces'; |
|
|
|
import { MarketData } from '@prisma/client'; |
|
|
|
import { Subject } from 'rxjs'; |
|
|
|
import { takeUntil } from 'rxjs/operators'; |
|
|
@ -42,8 +45,8 @@ export class AssetProfileDialog implements OnDestroy, OnInit { |
|
|
|
public constructor( |
|
|
|
private adminService: AdminService, |
|
|
|
private changeDetectorRef: ChangeDetectorRef, |
|
|
|
public dialogRef: MatDialogRef<AssetProfileDialog>, |
|
|
|
@Inject(MAT_DIALOG_DATA) public data: AssetProfileDialogParams, |
|
|
|
public dialogRef: MatDialogRef<AssetProfileDialog>, |
|
|
|
private formBuilder: FormBuilder |
|
|
|
) {} |
|
|
|
|
|
|
@ -51,10 +54,65 @@ export class AssetProfileDialog implements OnDestroy, OnInit { |
|
|
|
this.initialize(); |
|
|
|
} |
|
|
|
|
|
|
|
public initialize() { |
|
|
|
this.adminService |
|
|
|
.fetchAdminMarketDataBySymbol({ |
|
|
|
dataSource: this.data.dataSource, |
|
|
|
symbol: this.data.symbol |
|
|
|
}) |
|
|
|
.pipe(takeUntil(this.unsubscribeSubject)) |
|
|
|
.subscribe(({ assetProfile, marketData }) => { |
|
|
|
this.assetProfile = assetProfile; |
|
|
|
this.countries = {}; |
|
|
|
this.marketDataDetails = marketData; |
|
|
|
this.sectors = {}; |
|
|
|
|
|
|
|
if (assetProfile?.countries?.length > 0) { |
|
|
|
for (const country of assetProfile.countries) { |
|
|
|
this.countries[country.code] = { |
|
|
|
name: country.name, |
|
|
|
value: country.weight |
|
|
|
}; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (assetProfile?.sectors?.length > 0) { |
|
|
|
for (const sector of assetProfile.sectors) { |
|
|
|
this.sectors[sector.name] = { |
|
|
|
name: sector.name, |
|
|
|
value: sector.weight |
|
|
|
}; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
this.assetProfileForm.setValue({ |
|
|
|
symbolMapping: JSON.stringify(this.assetProfile?.symbolMapping) |
|
|
|
}); |
|
|
|
|
|
|
|
this.assetProfileForm.markAsPristine(); |
|
|
|
|
|
|
|
this.changeDetectorRef.markForCheck(); |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
public onClose(): void { |
|
|
|
this.dialogRef.close(); |
|
|
|
} |
|
|
|
|
|
|
|
public onGatherProfileDataBySymbol({ dataSource, symbol }: UniqueAsset) { |
|
|
|
this.adminService |
|
|
|
.gatherProfileDataBySymbol({ dataSource, symbol }) |
|
|
|
.pipe(takeUntil(this.unsubscribeSubject)) |
|
|
|
.subscribe(() => {}); |
|
|
|
} |
|
|
|
|
|
|
|
public onGatherSymbol({ dataSource, symbol }: UniqueAsset) { |
|
|
|
this.adminService |
|
|
|
.gatherSymbol({ dataSource, symbol }) |
|
|
|
.pipe(takeUntil(this.unsubscribeSubject)) |
|
|
|
.subscribe(() => {}); |
|
|
|
} |
|
|
|
|
|
|
|
public onMarketDataChanged(withRefresh: boolean = false) { |
|
|
|
if (withRefresh) { |
|
|
|
this.initialize(); |
|
|
@ -89,43 +147,4 @@ export class AssetProfileDialog implements OnDestroy, OnInit { |
|
|
|
this.unsubscribeSubject.next(); |
|
|
|
this.unsubscribeSubject.complete(); |
|
|
|
} |
|
|
|
|
|
|
|
private initialize() { |
|
|
|
this.adminService |
|
|
|
.fetchAdminMarketDataBySymbol({ |
|
|
|
dataSource: this.data.dataSource, |
|
|
|
symbol: this.data.symbol |
|
|
|
}) |
|
|
|
.pipe(takeUntil(this.unsubscribeSubject)) |
|
|
|
.subscribe(({ assetProfile, marketData }) => { |
|
|
|
this.assetProfile = assetProfile; |
|
|
|
this.countries = {}; |
|
|
|
this.marketDataDetails = marketData; |
|
|
|
this.sectors = {}; |
|
|
|
|
|
|
|
if (assetProfile?.countries?.length > 0) { |
|
|
|
for (const country of assetProfile.countries) { |
|
|
|
this.countries[country.code] = { |
|
|
|
name: country.name, |
|
|
|
value: country.weight |
|
|
|
}; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (assetProfile?.sectors?.length > 0) { |
|
|
|
for (const sector of assetProfile.sectors) { |
|
|
|
this.sectors[sector.name] = { |
|
|
|
name: sector.name, |
|
|
|
value: sector.weight |
|
|
|
}; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
this.assetProfileForm.setValue({ |
|
|
|
symbolMapping: JSON.stringify(this.assetProfile?.symbolMapping) |
|
|
|
}); |
|
|
|
|
|
|
|
this.changeDetectorRef.markForCheck(); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|