Skip to content

Commit ff2a35d

Browse files
[DURACOM-383] restore & improve code
1 parent 2e3ed3c commit ff2a35d

File tree

1 file changed

+32
-11
lines changed

1 file changed

+32
-11
lines changed

src/app/item-page/edit-item-page/item-delete/item-delete.component.ts

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -417,18 +417,39 @@ export class ItemDeleteComponent
417417
*/
418418
performAction(): void {
419419
this.isDeleting$.next(true);
420-
const parameterValues = [ Object.assign(new ProcessParameter(), { name: '-i', value: this.item.uuid }) ];
421-
this.scriptDataService.invoke(DSPACE_OBJECT_DELETION_SCRIPT_NAME, parameterValues, [])
422-
.pipe(getFirstCompletedRemoteData())
423-
.subscribe((rd: RemoteData<Process>) => {
424-
if (rd.hasSucceeded && rd.payload) {
425-
this.notificationsService.success(this.translateService.get('item.edit.delete.success'));
426-
this.router.navigateByUrl(getProcessDetailRoute(rd.payload.processId));
427-
} else {
428-
this.notificationsService.error(this.translateService.get('item.edit.delete.error'));
429-
this.router.navigate([getItemEditRoute(this.item)]);
420+
this.subs.push(this.typeDTOs$.pipe(
421+
switchMap((types: RelationshipTypeDTO[]) =>
422+
combineLatest(
423+
types.map((type: RelationshipTypeDTO) => type.isSelected$),
424+
).pipe(
425+
defaultIfEmpty([]),
426+
map((selection: boolean[]) => types.filter(
427+
(type: RelationshipTypeDTO, index: number) => selection[index],
428+
)),
429+
map((selectedDtoTypes: RelationshipTypeDTO[]) => selectedDtoTypes.map((typeDto: RelationshipTypeDTO) => typeDto.relationshipType.id)),
430+
),
431+
),
432+
switchMap((types: string[]) => {
433+
const parameterValues = [ Object.assign(new ProcessParameter(), { name: '-i', value: this.item.uuid }) ];
434+
if (isNotEmpty(types)) {
435+
parameterValues.push(Object.assign(new ProcessParameter(), { name: '-c', value: types.join(',') }));
430436
}
431-
});
437+
return this.scriptDataService.invoke(DSPACE_OBJECT_DELETION_SCRIPT_NAME, parameterValues, []);
438+
}),
439+
getFirstCompletedRemoteData(),
440+
).subscribe((rd: RemoteData<Process>) => {
441+
this.notify(rd);
442+
}));
443+
}
444+
445+
notify(rd: RemoteData<Process>) {
446+
if (rd.hasSucceeded && rd.payload) {
447+
this.notificationsService.success(this.translateService.get('item.edit.delete.success'));
448+
this.router.navigateByUrl(getProcessDetailRoute(rd.payload.processId));
449+
} else {
450+
this.notificationsService.error(this.translateService.get('item.edit.delete.error'));
451+
this.router.navigate([getItemEditRoute(this.item)]);
452+
}
432453
}
433454

434455
/**

0 commit comments

Comments
 (0)