Skip to content

Open Source Wealth Management Software. Angular + NestJS + Prisma + Nx + TypeScript 🤍

Feature/add support to delete asset profile from dialog (#3165)

Thomas Kauleb853f05ae0b
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 37b4773deb..4407847581 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 7bdcdcb310..408141bebe 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<void>();
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 7522a2fc99..c4cdc3bdd4 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 0000000000..44319a7a38
--- /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 9157476f06..5011d0734f 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<void>();
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 fb5392a448..e1695ef6da 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 @@
>
<ng-container i18n>Gather Profile Data</ng-container>
</button>
+ <button
+ mat-menu-item
+ type="button"
+ [disabled]="assetProfile?.activitiesCount !== 0"
+ (click)="
+ onDeleteProfileData({
+ dataSource: data.dataSource,
+ symbol: data.symbol
+ })
+ "
+ >
+ <ng-container i18n>Delete</ng-container>
+ </button>
</mat-menu>
</div>
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 3726082792..846b5e599a 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 {}