1+ // eslint-disable-next-line max-classes-per-file
12import {
23 AsyncPipe ,
34 NgForOf ,
@@ -68,6 +69,34 @@ import { ModifyItemOverviewComponent } from '../modify-item-overview/modify-item
6869import { AbstractSimpleItemActionComponent } from '../simple-item-action/abstract-simple-item-action.component' ;
6970import { VirtualMetadata } from '../virtual-metadata/virtual-metadata.component' ;
7071
72+ /**
73+ * Data Transfer Object used to prevent the HTML template to call function returning Observables
74+ */
75+ class RelationshipTypeDTO {
76+
77+ relationshipType : RelationshipType ;
78+
79+ isSelected$ : Observable < boolean > ;
80+
81+ label$ : Observable < string > ;
82+
83+ relationshipDTOs$ : Observable < RelationshipDTO [ ] > ;
84+
85+ }
86+
87+ /**
88+ * Data Transfer Object used to prevent the HTML template to call function returning Observables
89+ */
90+ class RelationshipDTO {
91+
92+ relationship : Relationship ;
93+
94+ relatedItem$ : Observable < Item > ;
95+
96+ virtualMetadata$ : Observable < VirtualMetadata [ ] > ;
97+
98+ }
99+
71100@Component ( {
72101 selector : 'ds-item-delete' ,
73102 templateUrl : '../item-delete/item-delete.component.html' ,
@@ -106,7 +135,7 @@ export class ItemDeleteComponent
106135 * A list of the relationship types for which this item has relations as an observable.
107136 * The list doesn't contain duplicates.
108137 */
109- types $ : BehaviorSubject < RelationshipType [ ] > = new BehaviorSubject ( [ ] ) ;
138+ typeDTOs $ : BehaviorSubject < RelationshipTypeDTO [ ] > = new BehaviorSubject ( [ ] ) ;
110139
111140 /**
112141 * A map which stores the relationships of this item for each type as observable lists
@@ -135,6 +164,8 @@ export class ItemDeleteComponent
135164 */
136165 private subs : Subscription [ ] = [ ] ;
137166
167+ public isDeleting$ : BehaviorSubject < boolean > = new BehaviorSubject ( false ) ;
168+
138169 constructor ( protected route : ActivatedRoute ,
139170 protected router : Router ,
140171 protected notificationsService : NotificationsService ,
@@ -189,13 +220,24 @@ export class ItemDeleteComponent
189220 ) ,
190221 ) ;
191222 } ) ,
192- ) . subscribe ( ( types : RelationshipType [ ] ) => this . types$ . next ( types ) ) ) ;
223+ ) . subscribe ( ( types : RelationshipType [ ] ) => this . typeDTOs$ . next ( types . map ( ( relationshipType : RelationshipType ) => Object . assign ( new RelationshipTypeDTO ( ) , {
224+ relationshipType : relationshipType ,
225+ isSelected$ : this . isSelected ( relationshipType ) ,
226+ label$ : this . getLabel ( relationshipType ) ,
227+ relationshipDTOs$ : this . getRelationships ( relationshipType ) . pipe (
228+ map ( ( relationships : Relationship [ ] ) => relationships . map ( ( relationship : Relationship ) => Object . assign ( new RelationshipDTO ( ) , {
229+ relationship : relationship ,
230+ relatedItem$ : this . getRelatedItem ( relationship ) ,
231+ virtualMetadata$ : this . getVirtualMetadata ( relationship ) ,
232+ } as RelationshipDTO ) ) ) ,
233+ ) ,
234+ } ) ) ) ) ) ;
193235 }
194236
195- this . subs . push ( this . types $. pipe (
237+ this . subs . push ( this . typeDTOs $. pipe (
196238 take ( 1 ) ,
197- ) . subscribe ( ( types ) =>
198- this . objectUpdatesService . initialize ( this . url , types , this . item . lastModified ) ,
239+ ) . subscribe ( ( types : RelationshipTypeDTO [ ] ) =>
240+ this . objectUpdatesService . initialize ( this . url , types . map ( ( relationshipTypeDto : RelationshipTypeDTO ) => relationshipTypeDto . relationshipType ) , this . item . lastModified ) ,
199241 ) ) ;
200242 }
201243
@@ -368,34 +410,33 @@ export class ItemDeleteComponent
368410 * @param selected whether the type should be selected
369411 */
370412 setSelected ( type : RelationshipType , selected : boolean ) : void {
371- this . objectUpdatesService . setSelectedVirtualMetadata ( this . url , this . item . uuid , type . uuid , selected ) ;
413+ if ( this . isDeleting$ . value === false ) {
414+ this . objectUpdatesService . setSelectedVirtualMetadata ( this . url , this . item . uuid , type . uuid , selected ) ;
415+ }
372416 }
373417
374418 /**
375419 * Perform the delete operation
376420 */
377- performAction ( ) {
378-
379- this . subs . push ( this . types $. pipe (
380- switchMap ( ( types ) =>
421+ performAction ( ) : void {
422+ this . isDeleting$ . next ( true ) ;
423+ this . subs . push ( this . typeDTOs $. pipe (
424+ switchMap ( ( types : RelationshipTypeDTO [ ] ) =>
381425 combineLatest (
382- types . map ( ( type ) => this . isSelected ( type ) ) ,
426+ types . map ( ( type : RelationshipTypeDTO ) => type . isSelected$ ) ,
383427 ) . pipe (
384428 defaultIfEmpty ( [ ] ) ,
385- map ( ( selection ) => types . filter (
386- ( type , index ) => selection [ index ] ,
429+ map ( ( selection : boolean [ ] ) => types . filter (
430+ ( type : RelationshipTypeDTO , index : number ) => selection [ index ] ,
387431 ) ) ,
388- map ( ( selectedTypes ) => selectedTypes . map ( ( type ) => type . id ) ) ,
432+ map ( ( selectedDtoTypes : RelationshipTypeDTO [ ] ) => selectedDtoTypes . map ( ( typeDto : RelationshipTypeDTO ) => typeDto . relationshipType . id ) ) ,
389433 ) ,
390434 ) ,
391- switchMap ( ( types ) =>
392- this . itemDataService . delete ( this . item . id , types ) . pipe ( getFirstCompletedRemoteData ( ) ) ,
393- ) ,
394- ) . subscribe (
395- ( rd : RemoteData < NoContent > ) => {
396- this . notify ( rd . hasSucceeded ) ;
397- } ,
398- ) ) ;
435+ switchMap ( ( types : string [ ] ) => this . itemDataService . delete ( this . item . id , types ) ) ,
436+ getFirstCompletedRemoteData ( ) ,
437+ ) . subscribe ( ( rd : RemoteData < NoContent > ) => {
438+ this . notify ( rd . hasSucceeded ) ;
439+ } ) ) ;
399440 }
400441
401442 /**
@@ -405,10 +446,10 @@ export class ItemDeleteComponent
405446 notify ( succeeded : boolean ) {
406447 if ( succeeded ) {
407448 this . notificationsService . success ( this . translateService . get ( 'item.edit.' + this . messageKey + '.success' ) ) ;
408- this . router . navigate ( [ '' ] ) ;
449+ void this . router . navigate ( [ '' ] ) ;
409450 } else {
410451 this . notificationsService . error ( this . translateService . get ( 'item.edit.' + this . messageKey + '.error' ) ) ;
411- this . router . navigate ( [ getItemEditRoute ( this . item ) ] ) ;
452+ void this . router . navigate ( [ getItemEditRoute ( this . item ) ] ) ;
412453 }
413454 }
414455
0 commit comments