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

Implement Markables for text as compound child

parent 3ff3706f
No related branches found
No related tags found
No related merge requests found
import { import {
AfterViewInit, Component, OnInit, ViewChild AfterViewInit, ApplicationRef, Component, OnInit, Renderer2, ViewChild
} from '@angular/core'; } from '@angular/core';
import { takeUntil } from 'rxjs/operators'; import { takeUntil } from 'rxjs/operators';
import { ElementComponent } from 'common/directives/element-component.directive'; import { ElementComponent } from 'common/directives/element-component.directive';
...@@ -33,6 +33,7 @@ import { TextComponent } from 'common/components/text/text.component'; ...@@ -33,6 +33,7 @@ import { TextComponent } from 'common/components/text/text.component';
import { TextMarkingSupport } from 'player/src/app/classes/text-marking-support'; import { TextMarkingSupport } from 'player/src/app/classes/text-marking-support';
import { TextElement } from 'common/models/elements/text/text'; import { TextElement } from 'common/models/elements/text/text';
import { TextMarkingUtils } from 'player/src/app/classes/text-marking-utils'; import { TextMarkingUtils } from 'player/src/app/classes/text-marking-utils';
import { MarkableSupport } from 'player/src/app/classes/markable-support';
import { UnitStateService } from '../../../services/unit-state.service'; import { UnitStateService } from '../../../services/unit-state.service';
import { ElementModelElementCodeMappingService } from '../../../services/element-model-element-code-mapping.service'; import { ElementModelElementCodeMappingService } from '../../../services/element-model-element-code-mapping.service';
import { ValidationService } from '../../../services/validation.service'; import { ValidationService } from '../../../services/validation.service';
...@@ -62,6 +63,7 @@ export class CompoundGroupElementComponent extends TextInputGroupDirective imple ...@@ -62,6 +63,7 @@ export class CompoundGroupElementComponent extends TextInputGroupDirective imple
savedTexts: { [key: string]: string } = {}; savedTexts: { [key: string]: string } = {};
savedMarks: { [key: string]: string[] } = {}; savedMarks: { [key: string]: string[] } = {};
textMarkingSupports: { [key: string]: TextMarkingSupport } = {}; textMarkingSupports: { [key: string]: TextMarkingSupport } = {};
markableSupports: { [key: string]: MarkableSupport } = {};
constructor( constructor(
public keyboardService: KeyboardService, public keyboardService: KeyboardService,
...@@ -76,7 +78,9 @@ export class CompoundGroupElementComponent extends TextInputGroupDirective imple ...@@ -76,7 +78,9 @@ export class CompoundGroupElementComponent extends TextInputGroupDirective imple
private anchorService: AnchorService, private anchorService: AnchorService,
public validationService: ValidationService, public validationService: ValidationService,
private stateVariableStateService: StateVariableStateService, private stateVariableStateService: StateVariableStateService,
public mediaPlayerService: MediaPlayerService public mediaPlayerService: MediaPlayerService,
private renderer: Renderer2,
private applicationRef: ApplicationRef
) { ) {
super(); super();
} }
...@@ -99,6 +103,7 @@ export class CompoundGroupElementComponent extends TextInputGroupDirective imple ...@@ -99,6 +103,7 @@ export class CompoundGroupElementComponent extends TextInputGroupDirective imple
private setTextMarkingSupportForText(element: TextElement): void { private setTextMarkingSupportForText(element: TextElement): void {
this.textMarkingSupports[element.id] = new TextMarkingSupport(this.nativeEventService, this.anchorService); this.textMarkingSupports[element.id] = new TextMarkingSupport(this.nativeEventService, this.anchorService);
this.markableSupports[element.id] = new MarkableSupport(this.renderer, this.applicationRef);
this.savedMarks[element.id] = this.elementModelElementCodeMappingService this.savedMarks[element.id] = this.elementModelElementCodeMappingService
.mapToElementModelValue(this.unitStateService .mapToElementModelValue(this.unitStateService
.getElementCodeById(element.id)?.value, element) as string[]; .getElementCodeById(element.id)?.value, element) as string[];
...@@ -158,8 +163,12 @@ export class CompoundGroupElementComponent extends TextInputGroupDirective imple ...@@ -158,8 +163,12 @@ export class CompoundGroupElementComponent extends TextInputGroupDirective imple
initialValue = null; initialValue = null;
break; break;
case 'text': case 'text':
if (childModel.markingMode === 'word' || childModel.markingMode === 'range') {
this.markableSupports[childModel.id]
.createMarkables(this.savedMarks[childModel.id], child as TextComponent);
}
initialValue = ElementModelElementCodeMappingService.mapToElementCodeValue( initialValue = ElementModelElementCodeMappingService.mapToElementCodeValue(
this.textChildModelValue(childModel as TextElement), this.getTextChildModelValue(childModel as TextElement),
childModel.type, childModel.type,
{ {
markingMode: (childModel as TextElement).markingMode, markingMode: (childModel as TextElement).markingMode,
...@@ -175,7 +184,7 @@ export class CompoundGroupElementComponent extends TextInputGroupDirective imple ...@@ -175,7 +184,7 @@ export class CompoundGroupElementComponent extends TextInputGroupDirective imple
}); });
} }
private textChildModelValue(childModel: TextElement): string | string[] { private getTextChildModelValue(childModel: TextElement): string | string[] {
return childModel.markingMode === 'word' || childModel.markingMode === 'range' ? return childModel.markingMode === 'word' || childModel.markingMode === 'range' ?
this.savedMarks[childModel.id] : this.savedMarks[childModel.id] :
this.savedTexts[childModel.id]; this.savedTexts[childModel.id];
...@@ -196,7 +205,11 @@ export class CompoundGroupElementComponent extends TextInputGroupDirective imple ...@@ -196,7 +205,11 @@ export class CompoundGroupElementComponent extends TextInputGroupDirective imple
if (childModel.type === 'text') { if (childModel.type === 'text') {
this.addMarkingDataChangedSubscription(child as TextComponent, childModel); this.addMarkingDataChangedSubscription(child as TextComponent, childModel);
this.addTextSelectionStartSubscription(child as TextComponent, childModel); this.addTextSelectionStartSubscription(child as TextComponent, childModel);
this.addElementCodeValueSubscription(child as TextComponent, childModel); this.addElementCodeValueSubscription(
child as TextComponent,
childModel,
{ markingMode: 'word', color: 'yellow' }
);
} }
if (childModel.type === 'image') { if (childModel.type === 'image') {
this.addElementCodeValueSubscription(child as ImageComponent, childModel); this.addElementCodeValueSubscription(child as ImageComponent, childModel);
...@@ -239,7 +252,8 @@ export class CompoundGroupElementComponent extends TextInputGroupDirective imple ...@@ -239,7 +252,8 @@ export class CompoundGroupElementComponent extends TextInputGroupDirective imple
private addElementCodeValueSubscription( private addElementCodeValueSubscription(
child: ImageComponent | AudioComponent | TextComponent, child: ImageComponent | AudioComponent | TextComponent,
childModel: UIElement childModel: UIElement,
options?: Record<string, string>
): void { ): void {
child.elementValueChanged child.elementValueChanged
.pipe(takeUntil(this.ngUnsubscribe)) .pipe(takeUntil(this.ngUnsubscribe))
...@@ -247,7 +261,7 @@ export class CompoundGroupElementComponent extends TextInputGroupDirective imple ...@@ -247,7 +261,7 @@ export class CompoundGroupElementComponent extends TextInputGroupDirective imple
this.unitStateService.changeElementCodeValue({ this.unitStateService.changeElementCodeValue({
id: value.id, id: value.id,
value: ElementModelElementCodeMappingService value: ElementModelElementCodeMappingService
.mapToElementCodeValue(value.value, childModel.type) .mapToElementCodeValue(value.value, childModel.type, options)
}); });
}); });
} }
......
...@@ -59,13 +59,11 @@ export class TextGroupElementComponent extends ElementGroupDirective implements ...@@ -59,13 +59,11 @@ export class TextGroupElementComponent extends ElementGroupDirective implements
if (this.elementModel.markingMode === 'word' || this.elementModel.markingMode === 'range') { if (this.elementModel.markingMode === 'word' || this.elementModel.markingMode === 'range') {
this.markableSupport.createMarkables(this.savedMarks, this.elementComponent); this.markableSupport.createMarkables(this.savedMarks, this.elementComponent);
} }
const elementModelValue = (this.elementModel as TextElement).markingMode === 'word' ||
(this.elementModel as TextElement).markingMode === 'range' ? this.savedMarks : this.savedText;
this.registerAtUnitStateService( this.registerAtUnitStateService(
this.elementModel.id, this.elementModel.id,
ElementModelElementCodeMappingService ElementModelElementCodeMappingService
.mapToElementCodeValue( .mapToElementCodeValue(
elementModelValue, this.getElementModelValue(),
this.elementModel.type, this.elementModel.type,
{ {
markingMode: (this.elementModel as TextElement).markingMode, markingMode: (this.elementModel as TextElement).markingMode,
...@@ -75,6 +73,11 @@ export class TextGroupElementComponent extends ElementGroupDirective implements ...@@ -75,6 +73,11 @@ export class TextGroupElementComponent extends ElementGroupDirective implements
this.pageIndex); this.pageIndex);
} }
private getElementModelValue(): string | string[] {
return (this.elementModel as TextElement).markingMode === 'word' ||
(this.elementModel as TextElement).markingMode === 'range' ? this.savedMarks : this.savedText;
}
changeElementCodeValue(value: ValueChangeElement): void { changeElementCodeValue(value: ValueChangeElement): void {
this.unitStateService.changeElementCodeValue({ this.unitStateService.changeElementCodeValue({
id: value.id, id: value.id,
......
import { TestBed } from '@angular/core/testing';
import { MarkableService } from './markable.service';
describe('MarkableService', () => {
let service: MarkableService;
beforeEach(() => {
TestBed.configureTestingModule({});
service = TestBed.inject(MarkableService);
});
it('should be created', () => {
expect(service).toBeTruthy();
});
});
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