@@ -3,7 +3,7 @@ import { UntypedFormGroup } from '@angular/forms';
33import { DynamicFormControlModel , DynamicFormService , DynamicInputModel } from '@ng-dynamic-forms/core' ;
44import { TranslateService } from '@ngx-translate/core' ;
55import { FileUploader } from 'ng2-file-upload' ;
6- import { BehaviorSubject , combineLatest as observableCombineLatest , Observable , Subscription } from 'rxjs' ;
6+ import { BehaviorSubject , combineLatest as observableCombineLatest , Observable , Subscription , switchMap } from 'rxjs' ;
77import { AuthService } from '../../../../core/auth/auth.service' ;
88import { ObjectCacheService } from '../../../../core/cache/object-cache.service' ;
99import { ComColDataService } from '../../../../core/data/comcol-data.service' ;
@@ -24,8 +24,7 @@ import { getFirstCompletedRemoteData } from '../../../../core/shared/operators';
2424import { NgbModal , NgbModalRef } from '@ng-bootstrap/ng-bootstrap' ;
2525import { followLink } from '../../../utils/follow-link-config.model' ;
2626import { ConfirmationModalComponent } from '../../../confirmation-modal/confirmation-modal.component' ;
27- import { map , take , tap } from 'rxjs/operators' ;
28- import { DSpaceObject } from '../../../../core/shared/dspace-object.model' ;
27+ import { filter , take } from 'rxjs/operators' ;
2928
3029/**
3130 * A form for creating and editing Communities or Collections
@@ -124,6 +123,8 @@ export class ComColFormComponent<T extends Collection | Community> implements On
124123
125124 public uploader = new FileUploader ( this . uploadFilesOptions ) ;
126125
126+ protected readonly refreshDSO$ = new EventEmitter < void > ( ) ;
127+
127128 public constructor ( protected formService : DynamicFormService ,
128129 protected translate : TranslateService ,
129130 protected notificationsService : NotificationsService ,
@@ -168,6 +169,14 @@ export class ComColFormComponent<T extends Collection | Community> implements On
168169 this . initializedUploaderOptions . next ( true ) ;
169170 }
170171 }
172+
173+ this . subs . push (
174+ this . refreshDSO$ . pipe (
175+ switchMap ( ( ) => this . refreshDsoCache ( ) ) ,
176+ filter ( rd => rd . hasSucceeded ) ,
177+ ) . subscribe ( ( { payload } ) => this . dso = payload )
178+ ) ;
179+
171180 }
172181
173182 /**
@@ -304,7 +313,7 @@ export class ComColFormComponent<T extends Collection | Community> implements On
304313 * @param successMessageKey Translation key for success message
305314 */
306315 private handleSuccessfulDeletion ( successMessageKey : string ) : void {
307- this . refreshDsoCache ( ) ;
316+ this . refreshDSO$ . next ( ) ;
308317 this . notificationsService . success (
309318 this . translate . get ( `${ successMessageKey } .title` ) ,
310319 this . translate . get ( `${ successMessageKey } .content` )
@@ -342,15 +351,10 @@ export class ComColFormComponent<T extends Collection | Community> implements On
342351 /**
343352 * Fetches the latest data for the dso
344353 */
345- private fetchUpdatedDso ( ) : Observable < DSpaceObject | null > {
354+ private fetchUpdatedDso ( ) : Observable < RemoteData < T > > {
346355 return this . dsoService . findById ( this . dso . id , false , true , followLink ( 'logo' ) ) . pipe (
347- tap ( ( rd : RemoteData < T > ) => {
348- if ( rd . hasSucceeded ) {
349- this . dso = rd . payload ;
350- }
351- } ) ,
352- map ( ( rd : RemoteData < T > ) => rd . hasSucceeded ? rd . payload : null )
353- ) ;
356+ getFirstCompletedRemoteData ( )
357+ ) as Observable < RemoteData < T > > ;
354358 }
355359
356360
@@ -360,7 +364,7 @@ export class ComColFormComponent<T extends Collection | Community> implements On
360364 */
361365 public onCompleteItem ( ) {
362366 if ( hasValue ( this . dso . id ) ) {
363- this . refreshDsoCache ( ) ;
367+ this . refreshDSO$ . next ( ) ;
364368 }
365369 if ( this . isCreation ) {
366370 this . finish . emit ( ) ;
@@ -379,6 +383,7 @@ export class ComColFormComponent<T extends Collection | Community> implements On
379383 * Unsubscribe from open subscriptions
380384 */
381385 ngOnDestroy ( ) : void {
386+ this . refreshDSO$ . complete ( ) ;
382387 this . subs
383388 . filter ( ( subscription ) => hasValue ( subscription ) )
384389 . forEach ( ( subscription ) => subscription . unsubscribe ( ) ) ;
0 commit comments