Skip to content
Snippets Groups Projects
Commit 8d9c0ab7 authored by jojohoch's avatar jojohoch
Browse files

[player] Prevent multiple sending of "intersect" events of elements

parent fdbae1f6
No related branches found
No related tags found
No related merge requests found
...@@ -4,9 +4,9 @@ import { DOCUMENT } from '@angular/common'; ...@@ -4,9 +4,9 @@ import { DOCUMENT } from '@angular/common';
import { import {
Progress, StatusChangeElement, ElementCode, ElementCodeStatus, ElementCodeStatusValue Progress, StatusChangeElement, ElementCode, ElementCodeStatus, ElementCodeStatusValue
} from 'player/modules/verona/models/verona'; } from 'player/modules/verona/models/verona';
import { IntersectionDetector } from '../classes/intersection-detector';
import { LogService } from 'player/modules/logging/services/log.service'; import { LogService } from 'player/modules/logging/services/log.service';
import { InputElementValue, ValueChangeElement } from 'common/models/elements/element'; import { InputElementValue, ValueChangeElement } from 'common/models/elements/element';
import { IntersectionDetector } from '../classes/intersection-detector';
@Injectable({ @Injectable({
providedIn: 'root' providedIn: 'root'
...@@ -81,8 +81,10 @@ export class UnitStateService { ...@@ -81,8 +81,10 @@ export class UnitStateService {
this.intersectionDetector.observe(domElement, elementId); this.intersectionDetector.observe(domElement, elementId);
this.intersectionDetector.intersecting this.intersectionDetector.intersecting
.subscribe((id: string) => { .subscribe((id: string) => {
this.changeElementCodeStatus({ id: id, status: 'DISPLAYED' }); if (elementId === id) {
this.intersectionDetector.unobserve(id); this.changeElementCodeStatus({ id: id, status: 'DISPLAYED' });
this.intersectionDetector.unobserve(id);
}
}); });
} }
...@@ -115,7 +117,7 @@ export class UnitStateService { ...@@ -115,7 +117,7 @@ export class UnitStateService {
} }
private buildPresentedPages(): void { private buildPresentedPages(): void {
const uniqPages = [...new Set( Object.values(this.elementIdPageIndexMap))]; const uniqPages = [...new Set(Object.values(this.elementIdPageIndexMap))];
uniqPages.forEach(pageIndex => this uniqPages.forEach(pageIndex => this
.checkPresentedPageStatus(pageIndex)); .checkPresentedPageStatus(pageIndex));
} }
...@@ -144,11 +146,9 @@ export class UnitStateService { ...@@ -144,11 +146,9 @@ export class UnitStateService {
unitStateElementCode = { id: id, value: value, status: 'NOT_REACHED' }; unitStateElementCode = { id: id, value: value, status: 'NOT_REACHED' };
this.elementCodes.push(unitStateElementCode); this.elementCodes.push(unitStateElementCode);
this._elementCodeChanged.next(unitStateElementCode); this._elementCodeChanged.next(unitStateElementCode);
} else { } else if (Object.keys(this.elementIdPageIndexMap).length === this.elementCodes.length) {
// if all elements are registered, we can rebuild the presentedPages array // if all elements are registered, we can rebuild the presentedPages array
if (Object.keys(this.elementIdPageIndexMap).length === this.elementCodes.length) { this.buildPresentedPages();
this.buildPresentedPages();
}
} }
if (unitStateElementCode.status === 'NOT_REACHED') { if (unitStateElementCode.status === 'NOT_REACHED') {
this.addIntersectionDetection(id, domElement); this.addIntersectionDetection(id, domElement);
......
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