From eb853f05ae0bea43b8452410f3789dfbe9aaf56f Mon Sep 17 00:00:00 2001 From: Thomas Kaul <4159106+dtslvr@users.noreply.github.com> Date: Tue, 19 Mar 2024 19:27:16 +0100 Subject: [PATCH] Feature/add support to delete asset profile from dialog (#3165) * Add support to delete asset profile from dialog * Update changelog --- CHANGELOG.md | 1 + .../admin-market-data.component.ts | 17 +++--------- .../admin-market-data.module.ts | 2 ++ .../admin-market-data.service.ts | 26 +++++++++++++++++++ .../asset-profile-dialog.component.ts | 10 ++++++- .../asset-profile-dialog.html | 13 ++++++++++ .../asset-profile-dialog.module.ts | 2 ++ 7 files changed, 56 insertions(+), 15 deletions(-) create mode 100644 apps/client/src/app/components/admin-market-data/admin-market-data.service.ts diff --git a/CHANGELOG.md b/CHANGELOG.md index 37b4773de..440784758 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added - Added the symbol and ISIN number to the position detail dialog +- Added support to delete an asset profile in the asset profile details dialog of the admin control ### Changed diff --git a/apps/client/src/app/components/admin-market-data/admin-market-data.component.ts b/apps/client/src/app/components/admin-market-data/admin-market-data.component.ts index 7bdcdcb31..408141beb 100644 --- a/apps/client/src/app/components/admin-market-data/admin-market-data.component.ts +++ b/apps/client/src/app/components/admin-market-data/admin-market-data.component.ts @@ -26,6 +26,7 @@ import { DeviceDetectorService } from 'ngx-device-detector'; import { Subject } from 'rxjs'; import { distinctUntilChanged, switchMap, takeUntil } from 'rxjs/operators'; +import { AdminMarketDataService } from './admin-market-data.service'; import { AssetProfileDialog } from './asset-profile-dialog/asset-profile-dialog.component'; import { AssetProfileDialogParams } from './asset-profile-dialog/interfaces/interfaces'; import { CreateAssetProfileDialog } from './create-asset-profile-dialog/create-asset-profile-dialog.component'; @@ -108,6 +109,7 @@ export class AdminMarketDataComponent private unsubscribeSubject = new Subject(); public constructor( + private adminMarketDataService: AdminMarketDataService, private adminService: AdminService, private changeDetectorRef: ChangeDetectorRef, private deviceService: DeviceDetectorService, @@ -181,20 +183,7 @@ export class AdminMarketDataComponent } public onDeleteProfileData({ dataSource, symbol }: UniqueAsset) { - const confirmation = confirm( - $localize`Do you really want to delete this asset profile?` - ); - - if (confirmation) { - this.adminService - .deleteProfileData({ dataSource, symbol }) - .pipe(takeUntil(this.unsubscribeSubject)) - .subscribe(() => { - setTimeout(() => { - window.location.reload(); - }, 300); - }); - } + this.adminMarketDataService.deleteProfileData({ dataSource, symbol }); } public onGather7Days() { diff --git a/apps/client/src/app/components/admin-market-data/admin-market-data.module.ts b/apps/client/src/app/components/admin-market-data/admin-market-data.module.ts index 7522a2fc9..c4cdc3bdd 100644 --- a/apps/client/src/app/components/admin-market-data/admin-market-data.module.ts +++ b/apps/client/src/app/components/admin-market-data/admin-market-data.module.ts @@ -12,6 +12,7 @@ import { RouterModule } from '@angular/router'; import { NgxSkeletonLoaderModule } from 'ngx-skeleton-loader'; import { AdminMarketDataComponent } from './admin-market-data.component'; +import { AdminMarketDataService } from './admin-market-data.service'; import { GfAssetProfileDialogModule } from './asset-profile-dialog/asset-profile-dialog.module'; import { GfCreateAssetProfileDialogModule } from './create-asset-profile-dialog/create-asset-profile-dialog.module'; @@ -31,6 +32,7 @@ import { GfCreateAssetProfileDialogModule } from './create-asset-profile-dialog/ NgxSkeletonLoaderModule, RouterModule ], + providers: [AdminMarketDataService], schemas: [CUSTOM_ELEMENTS_SCHEMA] }) export class GfAdminMarketDataModule {} diff --git a/apps/client/src/app/components/admin-market-data/admin-market-data.service.ts b/apps/client/src/app/components/admin-market-data/admin-market-data.service.ts new file mode 100644 index 000000000..44319a7a3 --- /dev/null +++ b/apps/client/src/app/components/admin-market-data/admin-market-data.service.ts @@ -0,0 +1,26 @@ +import { AdminService } from '@ghostfolio/client/services/admin.service'; +import { UniqueAsset } from '@ghostfolio/common/interfaces'; + +import { Injectable } from '@angular/core'; +import { takeUntil } from 'rxjs'; + +@Injectable() +export class AdminMarketDataService { + public constructor(private adminService: AdminService) {} + + public deleteProfileData({ dataSource, symbol }: UniqueAsset) { + const confirmation = confirm( + $localize`Do you really want to delete this asset profile?` + ); + + if (confirmation) { + this.adminService + .deleteProfileData({ dataSource, symbol }) + .subscribe(() => { + setTimeout(() => { + window.location.reload(); + }, 300); + }); + } + } +} diff --git a/apps/client/src/app/components/admin-market-data/asset-profile-dialog/asset-profile-dialog.component.ts b/apps/client/src/app/components/admin-market-data/asset-profile-dialog/asset-profile-dialog.component.ts index 9157476f0..5011d0734 100644 --- a/apps/client/src/app/components/admin-market-data/asset-profile-dialog/asset-profile-dialog.component.ts +++ b/apps/client/src/app/components/admin-market-data/asset-profile-dialog/asset-profile-dialog.component.ts @@ -1,8 +1,9 @@ import { UpdateAssetProfileDto } from '@ghostfolio/api/app/admin/update-asset-profile.dto'; import { UpdateMarketDataDto } from '@ghostfolio/api/app/admin/update-market-data.dto'; +import { AdminMarketDataService } from '@ghostfolio/client/components/admin-market-data/admin-market-data.service'; import { AdminService } from '@ghostfolio/client/services/admin.service'; import { DataService } from '@ghostfolio/client/services/data.service'; -import { DATE_FORMAT, parseDate } from '@ghostfolio/common/helper'; +import { DATE_FORMAT } from '@ghostfolio/common/helper'; import { AdminMarketDataDetails, Currency, @@ -83,6 +84,7 @@ export class AssetProfileDialog implements OnDestroy, OnInit { private unsubscribeSubject = new Subject(); public constructor( + private adminMarketDataService: AdminMarketDataService, private adminService: AdminService, private changeDetectorRef: ChangeDetectorRef, @Inject(MAT_DIALOG_DATA) public data: AssetProfileDialogParams, @@ -172,6 +174,12 @@ export class AssetProfileDialog implements OnDestroy, OnInit { this.dialogRef.close(); } + public onDeleteProfileData({ dataSource, symbol }: UniqueAsset) { + this.adminMarketDataService.deleteProfileData({ dataSource, symbol }); + + this.dialogRef.close(); + } + public onGatherProfileDataBySymbol({ dataSource, symbol }: UniqueAsset) { this.adminService .gatherProfileDataBySymbol({ dataSource, symbol }) diff --git a/apps/client/src/app/components/admin-market-data/asset-profile-dialog/asset-profile-dialog.html b/apps/client/src/app/components/admin-market-data/asset-profile-dialog/asset-profile-dialog.html index fb5392a44..e1695ef6d 100644 --- a/apps/client/src/app/components/admin-market-data/asset-profile-dialog/asset-profile-dialog.html +++ b/apps/client/src/app/components/admin-market-data/asset-profile-dialog/asset-profile-dialog.html @@ -44,6 +44,19 @@ > Gather Profile Data + diff --git a/apps/client/src/app/components/admin-market-data/asset-profile-dialog/asset-profile-dialog.module.ts b/apps/client/src/app/components/admin-market-data/asset-profile-dialog/asset-profile-dialog.module.ts index 372608279..846b5e599 100644 --- a/apps/client/src/app/components/admin-market-data/asset-profile-dialog/asset-profile-dialog.module.ts +++ b/apps/client/src/app/components/admin-market-data/asset-profile-dialog/asset-profile-dialog.module.ts @@ -1,4 +1,5 @@ import { GfAdminMarketDataDetailModule } from '@ghostfolio/client/components/admin-market-data-detail/admin-market-data-detail.module'; +import { AdminMarketDataService } from '@ghostfolio/client/components/admin-market-data/admin-market-data.service'; import { GfCurrencySelectorModule } from '@ghostfolio/ui/currency-selector/currency-selector.module'; import { GfPortfolioProportionChartModule } from '@ghostfolio/ui/portfolio-proportion-chart/portfolio-proportion-chart.module'; import { GfValueModule } from '@ghostfolio/ui/value'; @@ -36,6 +37,7 @@ import { AssetProfileDialog } from './asset-profile-dialog.component'; ReactiveFormsModule, TextFieldModule ], + providers: [AdminMarketDataService], schemas: [CUSTOM_ELEMENTS_SCHEMA] }) export class GfAssetProfileDialogModule {}