@@ -249,11 +249,6 @@ export class CollectionSourceComponent extends AbstractTrackableComponent implem
249249 */
250250 formGroup : UntypedFormGroup ;
251251
252- /**
253- * Subscription to update the current form
254- */
255- updateSub : Subscription ;
256-
257252 /**
258253 * The content harvesting type used when harvesting is disabled
259254 */
@@ -273,28 +268,29 @@ export class CollectionSourceComponent extends AbstractTrackableComponent implem
273268 */
274269 displayedNotifications : INotification [ ] = [ ] ;
275270
276- public constructor ( public objectUpdatesService : ObjectUpdatesService ,
277- public notificationsService : NotificationsService ,
278- protected location : Location ,
279- protected formService : DynamicFormService ,
280- protected translate : TranslateService ,
281- protected route : ActivatedRoute ,
282- protected router : Router ,
283- protected collectionService : CollectionDataService ,
284- protected requestService : RequestService ) {
285- super ( objectUpdatesService , notificationsService , translate ) ;
271+ subs : Subscription [ ] = [ ] ;
272+
273+ public constructor (
274+ public objectUpdatesService : ObjectUpdatesService ,
275+ public notificationsService : NotificationsService ,
276+ public translateService : TranslateService ,
277+ public router : Router ,
278+ protected location : Location ,
279+ protected formService : DynamicFormService ,
280+ protected route : ActivatedRoute ,
281+ protected collectionService : CollectionDataService ,
282+ protected requestService : RequestService ,
283+ ) {
284+ super ( objectUpdatesService , notificationsService , translateService , router ) ;
286285 }
287286
288287 /**
289288 * Initialize properties to setup the Field Update and Form
290289 */
291290 ngOnInit ( ) : void {
291+ super . ngOnInit ( ) ;
292292 this . notificationsPrefix = 'collection.edit.tabs.source.notifications.' ;
293293 this . discardTimeOut = environment . collection . edit . undoTimeout ;
294- this . url = this . router . url ;
295- if ( this . url . indexOf ( '?' ) > 0 ) {
296- this . url = this . url . substr ( 0 , this . url . indexOf ( '?' ) ) ;
297- }
298294 this . formGroup = this . formService . createFormGroup ( this . formModel ) ;
299295 this . collectionRD$ = this . route . parent . data . pipe ( first ( ) , map ( ( data ) => data . dso ) ) ;
300296
@@ -308,10 +304,9 @@ export class CollectionSourceComponent extends AbstractTrackableComponent implem
308304 } ) ;
309305
310306 this . updateFieldTranslations ( ) ;
311- this . translate . onLangChange
312- . subscribe ( ( ) => {
313- this . updateFieldTranslations ( ) ;
314- } ) ;
307+ this . subs . push ( this . translateService . onLangChange . subscribe ( ( ) => {
308+ this . updateFieldTranslations ( ) ;
309+ } ) ) ;
315310 }
316311
317312 /**
@@ -326,7 +321,7 @@ export class CollectionSourceComponent extends AbstractTrackableComponent implem
326321 this . update$ = this . objectUpdatesService . getFieldUpdates ( this . url , [ initialContentSource ] ) . pipe (
327322 map ( ( updates : FieldUpdates ) => updates [ initialContentSource . uuid ] ) ,
328323 ) ;
329- this . updateSub = this . update$ . subscribe ( ( update : FieldUpdate ) => {
324+ this . subs . push ( this . update$ . subscribe ( ( update : FieldUpdate ) => {
330325 if ( update ) {
331326 const field = update . field as ContentSource ;
332327 let configId ;
@@ -353,7 +348,7 @@ export class CollectionSourceComponent extends AbstractTrackableComponent implem
353348 }
354349 this . contentSource . metadataConfigId = configId ;
355350 }
356- } ) ;
351+ } ) ) ;
357352 }
358353
359354 /**
@@ -387,18 +382,18 @@ export class CollectionSourceComponent extends AbstractTrackableComponent implem
387382 * @param fieldModel
388383 */
389384 private updateFieldTranslation ( fieldModel : DynamicFormControlModel ) {
390- fieldModel . label = this . translate . instant ( this . LABEL_KEY_PREFIX + fieldModel . id ) ;
385+ fieldModel . label = this . translateService . instant ( this . LABEL_KEY_PREFIX + fieldModel . id ) ;
391386 if ( isNotEmpty ( fieldModel . validators ) ) {
392387 fieldModel . errorMessages = { } ;
393388 Object . keys ( fieldModel . validators ) . forEach ( ( key ) => {
394- fieldModel . errorMessages [ key ] = this . translate . instant ( this . ERROR_KEY_PREFIX + fieldModel . id + '.' + key ) ;
389+ fieldModel . errorMessages [ key ] = this . translateService . instant ( this . ERROR_KEY_PREFIX + fieldModel . id + '.' + key ) ;
395390 } ) ;
396391 }
397392 if ( fieldModel instanceof DynamicOptionControlModel ) {
398393 if ( isNotEmpty ( fieldModel . options ) ) {
399394 fieldModel . options . forEach ( ( option ) => {
400395 if ( hasNoValue ( option . label ) ) {
401- option . label = this . translate . instant ( this . OPTIONS_KEY_PREFIX + fieldModel . id + '.' + option . value ) ;
396+ option . label = this . translateService . instant ( this . OPTIONS_KEY_PREFIX + fieldModel . id + '.' + option . value ) ;
402397 }
403398 } ) ;
404399 }
@@ -515,8 +510,6 @@ export class CollectionSourceComponent extends AbstractTrackableComponent implem
515510 * Make sure open subscriptions are closed
516511 */
517512 ngOnDestroy ( ) : void {
518- if ( this . updateSub ) {
519- this . updateSub . unsubscribe ( ) ;
520- }
513+ this . subs . forEach ( ( sub : Subscription ) => sub . unsubscribe ( ) ) ;
521514 }
522515}
0 commit comments