diff --git a/src/modules/edc-demo/components/asset-viewer/asset-viewer.component.ts b/src/modules/edc-demo/components/asset-viewer/asset-viewer.component.ts index 1384babab..24f9e8f60 100644 --- a/src/modules/edc-demo/components/asset-viewer/asset-viewer.component.ts +++ b/src/modules/edc-demo/components/asset-viewer/asset-viewer.component.ts @@ -23,10 +23,10 @@ export class AssetViewerComponent implements OnInit { constructor(private assetService: AssetService, private notificationService: NotificationService, private readonly dialog: MatDialog) { - } +} - private showError(error: string) { - this.notificationService.showError("This asset cannot be deleted"); + private showError(error: string, errorMessage: string) { + this.notificationService.showError(errorMessage); console.error(error); } @@ -51,28 +51,35 @@ export class AssetViewerComponent implements OnInit { } onDelete(asset: Asset) { - const dialogData = ConfirmDialogModel.forDelete("asset", `"${asset.name}"`) const ref = this.dialog.open(ConfirmationDialogComponent, {maxWidth: "20%", data: dialogData}); - - ref.afterClosed().subscribe(res => { - if (res) { - this.assetService.removeAsset(asset.id).subscribe(() => this.fetch$.next(null), - err => this.showError(err), - () => this.notificationService.showInfo("Successfully deleted") - ); + + ref.afterClosed().subscribe({ + next: res => { + if (res) { + this.assetService.removeAsset(asset.id).subscribe({ + next: () => this.fetch$.next(null), + error: err => this.showError(err, "This asset cannot be deleted"), + complete: () => this.notificationService.showInfo("Successfully deleted") + }); + } } }); - } - + onCreate() { const dialogRef = this.dialog.open(AssetEditorDialog); - dialogRef.afterClosed().pipe(first()).subscribe((result: { assetEntryDto?: AssetEntryDto }) => { - const newAsset = result?.assetEntryDto; - if (newAsset) { - this.assetService.createAsset(newAsset).subscribe(() => this.fetch$.next(null), error => this.showError(error), () => this.notificationService.showInfo("Successfully created")); + dialogRef.afterClosed().pipe(first()).subscribe({ + next: (result: { assetEntryDto?: AssetEntryDto }) => { + const newAsset = result?.assetEntryDto; + if (newAsset) { + this.assetService.createAsset(newAsset).subscribe({ + next: () => this.fetch$.next(null), + error: error => this.showError(error, "This asset cannot be created"), + complete: () => this.notificationService.showInfo("Successfully created") + }); + } } }); - } + } } diff --git a/src/modules/edc-demo/components/policy-view/policy-view.component.ts b/src/modules/edc-demo/components/policy-view/policy-view.component.ts index bebe9fedf..f7008d6fd 100644 --- a/src/modules/edc-demo/components/policy-view/policy-view.component.ts +++ b/src/modules/edc-demo/components/policy-view/policy-view.component.ts @@ -25,12 +25,12 @@ export class PolicyViewComponent implements OnInit { this.errorOrUpdateSubscriber = { next: x => this.fetch$.next(null), - error: err => this.showError(err), + error: err => this.showError(err, "An error occurred."), complete: () => { this.notificationService.showInfo("Successfully completed") }, } - + } ngOnInit(): void { @@ -49,14 +49,21 @@ export class PolicyViewComponent implements OnInit { } onCreate() { - const dialogRef = this.dialog.open(NewPolicyDialogComponent) - dialogRef.afterClosed().pipe(first()).subscribe((result: PolicyDefinitionResponseDto) => { - if (result) { - this.policyService.createPolicy(result).subscribe(this.errorOrUpdateSubscriber); + const dialogRef = this.dialog.open(NewPolicyDialogComponent); + dialogRef.afterClosed().pipe(first()).subscribe({ + next: (result: PolicyDefinitionResponseDto) => { + if (result) { + this.policyService.createPolicy(result).subscribe( + { + next: (response: IdResponseDto) => this.errorOrUpdateSubscriber.next(response), + error: (error: Error) => this.showError(error, "An error occurred while creating the policy.") + } + ); + } } - }) + }); } - + /** * simple full-text search - serialize to JSON and see if "searchText" * is contained @@ -71,16 +78,24 @@ export class PolicyViewComponent implements OnInit { const dialogData = ConfirmDialogModel.forDelete("policy", policyId); const ref = this.dialog.open(ConfirmationDialogComponent, {maxWidth: '20%', data: dialogData}); + + ref.afterClosed().subscribe({ - ref.afterClosed().subscribe(res => { - if (res) { - this.policyService.deletePolicy(policyId).subscribe(this.errorOrUpdateSubscriber); + next: (res: any) => { + if (res) { + this.policyService.deletePolicy(policyId).subscribe( + { + next: (response: IdResponseDto) => this.errorOrUpdateSubscriber.next(response), + error: (error: Error) => this.showError(error, "An error occurred while deleting the policy.") + } + ); + } } }); } - private showError(error: Error) { - console.error(error) - this.notificationService.showError('This policy cannot be deleted'); + private showError(error: Error, errorMessage: string) { + console.error(error); + this.notificationService.showError(errorMessage); } }