diff --git a/dmp-frontend/src/app/ui/description/editor/description-form/visibility-rules/visibility-rules.service.ts b/dmp-frontend/src/app/ui/description/editor/description-form/visibility-rules/visibility-rules.service.ts index c55d4b16a..a4aa7d700 100644 --- a/dmp-frontend/src/app/ui/description/editor/description-form/visibility-rules/visibility-rules.service.ts +++ b/dmp-frontend/src/app/ui/description/editor/description-form/visibility-rules/visibility-rules.service.ts @@ -18,9 +18,16 @@ export class VisibilityRulesService { private allDescriptionTemplateFields: DescriptionTemplateField[] = null; private allDescriptionTemplateFieldSets: DescriptionTemplateFieldSet[] = null; + public rulesChangedSubject: Subject<{ [key: string]: boolean }>; + constructor( protected formService: FormService ) { + this.rulesChangedSubject = new Subject<{ [key: string]: boolean }>(); + } + + public getRulesChangedObservable(): Observable<{ [key: string]: boolean }> { + return this.rulesChangedSubject.asObservable(); } public setContext(definition: DescriptionTemplateDefinition, form: AbstractControl) { @@ -75,6 +82,8 @@ export class VisibilityRulesService { this.hideParentIfAllChildrenAreHidden(propertyDefinition); this.ensureFieldSetVisibility(propertyDefinition); this.isVisibleMap = this._isVisibleMap; + + this.rulesChangedSubject.next(this._isVisibleMap); } private initRules(){ diff --git a/dmp-frontend/src/app/ui/description/editor/table-of-contents/table-of-contents.component.ts b/dmp-frontend/src/app/ui/description/editor/table-of-contents/table-of-contents.component.ts index a88095d80..d6d860445 100644 --- a/dmp-frontend/src/app/ui/description/editor/table-of-contents/table-of-contents.component.ts +++ b/dmp-frontend/src/app/ui/description/editor/table-of-contents/table-of-contents.component.ts @@ -84,11 +84,12 @@ export class TableOfContentsComponent extends BaseComponent implements OnInit, O ngOnInit(): void { + this.visibilityRulesService.getRulesChangedObservable().pipe(takeUntil(this._destroyed)).subscribe(data => { + this.hiddenEntries = this._findHiddenEntries(this.tocentries); + }); if (this.descriptionTemplate) { this.tocentries = this.getTocEntries(this.descriptionTemplate); - if (this.visibilityRulesService) { - this.hiddenEntries = this._findHiddenEntries(this.tocentries); - } + this.hiddenEntries = this._findHiddenEntries(this.tocentries); } else { @@ -178,8 +179,6 @@ export class TableOfContentsComponent extends BaseComponent implements OnInit, O return invisibleEntries; } - - private _visibilityRulesSubscription: Subscription; ngOnChanges(changes: SimpleChanges) { if (this.selectedFieldsetId) { @@ -198,36 +197,8 @@ export class TableOfContentsComponent extends BaseComponent implements OnInit, O } if (changes['descriptionTemplate'] && changes.descriptionTemplate != null) { this.tocentries = this.getTocEntries(this.descriptionTemplate); - // if (this.visibilityRulesService) { - // this.hiddenEntries = this._findHiddenEntries(this.tocentries); - // } + this.hiddenEntries = this._findHiddenEntries(this.tocentries); } - - if ('visibilityRulesService') { - if (this._visibilityRulesSubscription) { - this._visibilityRulesSubscription.unsubscribe(); - this._visibilityRulesSubscription = null; - } - - if (!this.visibilityRulesService) return; - - // this._visibilityRulesSubscription = this.visibilityRulesService.visibilityChange - // .pipe(takeUntil(this._destroyed)) - // .pipe(debounceTime(200)) - // .subscribe(_ => { - // if (this.hasFocus) { - // this._resetObserver(); - // // this.hiddenEntries = this._findHiddenEntries(this.tocentries); - // } - // }); - // this.hiddenEntries = this._findHiddenEntries(this.tocentries); - } - // if (!this.isActive && this.links && this.links.length > 0) { - // this.links.forEach(link => { - // link.selected = false; - // }) - // this.links[0].selected = true; - // } }