Skip to content
Snippets Groups Projects
Commit 0e8b4c77 authored by jojohoch's avatar jojohoch
Browse files

[player] Implement support for enableReHide to toggle display of section

parent 8f0f8a65
No related branches found
No related tags found
No related merge requests found
Pipeline #48336 passed
...@@ -55,7 +55,7 @@ ...@@ -55,7 +55,7 @@
</button> </button>
<button *ngIf="controlIds.length" <button *ngIf="controlIds.length"
mat-button mat-button
[mat-dialog-close]="{visibilityRules, visibilityDelay, animatedVisibility:animatedVisibility}"> [mat-dialog-close]="{visibilityRules, visibilityDelay, animatedVisibility, enableReHide}">
{{'save' | translate}} {{'save' | translate}}
</button> </button>
</div> </div>
...@@ -16,8 +16,8 @@ export class SectionVisibilityHandlingDirective implements OnInit, OnDestroy { ...@@ -16,8 +16,8 @@ export class SectionVisibilityHandlingDirective implements OnInit, OnDestroy {
@Input() section!: Section; @Input() section!: Section;
@Input() pageSections!: Section[]; @Input() pageSections!: Section[];
private isSectionSeen: boolean = false;
private ngUnsubscribe = new Subject<void>(); private ngUnsubscribe = new Subject<void>();
private rulesAreFulfilled: boolean = false;
constructor( constructor(
private elementRef: ElementRef, private elementRef: ElementRef,
...@@ -26,6 +26,13 @@ export class SectionVisibilityHandlingDirective implements OnInit, OnDestroy { ...@@ -26,6 +26,13 @@ export class SectionVisibilityHandlingDirective implements OnInit, OnDestroy {
ngOnInit(): void { ngOnInit(): void {
if (this.section.visibilityRules.length) { if (this.section.visibilityRules.length) {
this.addSubscription();
}
}
private addSubscription(): void {
if (this.section.enableReHide || !this.hasSeenElements()) {
this.displayHiddenSection();
this.unitStateService.elementCodeChanged this.unitStateService.elementCodeChanged
.pipe(takeUntil(this.ngUnsubscribe)) .pipe(takeUntil(this.ngUnsubscribe))
.subscribe(code => { .subscribe(code => {
...@@ -33,9 +40,6 @@ export class SectionVisibilityHandlingDirective implements OnInit, OnDestroy { ...@@ -33,9 +40,6 @@ export class SectionVisibilityHandlingDirective implements OnInit, OnDestroy {
this.displayHiddenSection(); this.displayHiddenSection();
} }
}); });
this.isSectionSeen = this.hasSeenElements();
} else {
this.isSectionSeen = true;
} }
} }
...@@ -65,14 +69,14 @@ export class SectionVisibilityHandlingDirective implements OnInit, OnDestroy { ...@@ -65,14 +69,14 @@ export class SectionVisibilityHandlingDirective implements OnInit, OnDestroy {
} }
private displayHiddenSection(): void { private displayHiddenSection(): void {
if (this.areVisibilityRulesFulfilled()) { if (this.areVisibilityRulesFulfilled() || this.rulesAreFulfilled) {
if (this.section.visibilityDelay) { if (this.section.visibilityDelay) {
if (!this.unitStateService.getElementCodeById(this.timerStateVariableId)) { if (!this.unitStateService.getElementCodeById(this.timerStateVariableId)) {
this.rulesAreFulfilled = true;
this.initTimerStateVariable(); this.initTimerStateVariable();
} }
this.setVisibility( this.setVisibility((this.unitStateService
(this.unitStateService .getElementCodeById(this.timerStateVariableId)?.value as number) >= this.section.visibilityDelay);
.getElementCodeById(this.timerStateVariableId)?.value as number) >= this.section.visibilityDelay);
} else { } else {
this.setVisibility(true); this.setVisibility(true);
} }
...@@ -83,15 +87,24 @@ export class SectionVisibilityHandlingDirective implements OnInit, OnDestroy { ...@@ -83,15 +87,24 @@ export class SectionVisibilityHandlingDirective implements OnInit, OnDestroy {
private setVisibility(visible: boolean): void { private setVisibility(visible: boolean): void {
this.elementRef.nativeElement.style.display = visible ? null : 'none'; this.elementRef.nativeElement.style.display = visible ? null : 'none';
if (visible && this.section.animatedVisibility && !this.isSectionSeen) { if (visible) {
this.isSectionSeen = true; if (this.section.animatedVisibility && !this.hasSeenElements()) {
this.elementRef.nativeElement.style.scrollMarginTop = 100; this.scrollIntoView();
setTimeout(() => { }
this.elementRef.nativeElement.scrollIntoView({ behavior: 'smooth', block: 'start' }); if (!this.section.enableReHide) {
}); this.ngUnsubscribe.next();
this.ngUnsubscribe.complete();
}
} }
} }
private scrollIntoView(): void {
this.elementRef.nativeElement.style.scrollMarginTop = 100;
setTimeout(() => {
this.elementRef.nativeElement.scrollIntoView({ behavior: 'smooth', block: 'start' });
});
}
private areVisibilityRulesFulfilled(): boolean { private areVisibilityRulesFulfilled(): boolean {
return this.section.visibilityRules.some(rule => { return this.section.visibilityRules.some(rule => {
if (this.unitStateService.getElementCodeById(rule.id)) { if (this.unitStateService.getElementCodeById(rule.id)) {
...@@ -119,7 +132,9 @@ export class SectionVisibilityHandlingDirective implements OnInit, OnDestroy { ...@@ -119,7 +132,9 @@ export class SectionVisibilityHandlingDirective implements OnInit, OnDestroy {
private hasSeenElements(): boolean { private hasSeenElements(): boolean {
return this.section.getAllElements() return this.section.getAllElements()
.map(element => this.unitStateService.getElementCodeById(element.id)) .map(element => this.unitStateService.getElementCodeById(element.id))
.some(code => (code ? ElementCodeStatusValue[code.status] > ElementCodeStatusValue.NOT_REACHED : false)); .some(code => (code ?
ElementCodeStatusValue[code.status] > ElementCodeStatusValue.NOT_REACHED :
false));
} }
ngOnDestroy(): void { ngOnDestroy(): void {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment