Skip to content
Snippets Groups Projects
text-group-element.component.ts 2.44 KiB
Newer Older
  • Learn to ignore specific revisions
  • jojohoch's avatar
    jojohoch committed
    import {
    
      AfterViewInit,
      Component,
      OnDestroy,
      OnInit,
      ViewChild
    
    jojohoch's avatar
    jojohoch committed
    } from '@angular/core';
    
    import { TextComponent } from 'common/components/text/text.component';
    
    import { TextElement } from 'common/models/elements/text/text';
    
    import { ValueChangeElement } from 'common/models/elements/element';
    
    import { AnchorService } from 'player/src/app/services/anchor.service';
    
    import { TextMarkingSupport } from 'player/src/app/classes/text-marking-support';
    
    import { NativeEventService } from '../../../services/native-event.service';
    import { UnitStateService } from '../../../services/unit-state.service';
    import { ElementGroupDirective } from '../../../directives/element-group.directive';
    import { ElementModelElementCodeMappingService } from '../../../services/element-model-element-code-mapping.service';
    
    jojohoch's avatar
    jojohoch committed
    
    @Component({
    
      selector: 'aspect-text-group-element',
      templateUrl: './text-group-element.component.html',
      styleUrls: ['./text-group-element.component.scss']
    
    jojohoch's avatar
    jojohoch committed
    })
    
    export class TextGroupElementComponent extends ElementGroupDirective implements OnInit, AfterViewInit, OnDestroy {
    
      @ViewChild('elementComponent') elementComponent!: TextComponent;
    
    jojohoch's avatar
    jojohoch committed
      TextElement!: TextElement;
    
      textMarkingSupport:TextMarkingSupport;
      savedText: string = '';
    
      constructor(
        private nativeEventService: NativeEventService,
    
        private anchorService: AnchorService,
        private elementModelElementCodeMappingService: ElementModelElementCodeMappingService,
    
        public unitStateService: UnitStateService
    
        this.textMarkingSupport = new TextMarkingSupport(nativeEventService, anchorService);
    
    jojohoch's avatar
    jojohoch committed
    
      ngOnInit(): void {
    
        this.savedText = this.elementModelElementCodeMappingService
    
          .mapToElementModelValue(
            this.unitStateService.getElementCodeById(this.elementModel.id)?.value, this.elementModel
    
          ) as string;
      }
    
      ngAfterViewInit(): void {
    
        this.registerAtUnitStateService(
          this.elementModel.id,
    
          this.elementModelElementCodeMappingService
            .mapToElementCodeValue(this.savedText, this.elementModel.type, this.elementModel),
    
          this.elementComponent,
          this.pageIndex);
    
      changeElementCodeValue(value: ValueChangeElement): void {
        this.unitStateService.changeElementCodeValue({
          id: value.id,
    
          value: this.elementModelElementCodeMappingService
            .mapToElementCodeValue(value.value, this.elementModel.type, this.elementModel)
    
    jojohoch's avatar
    jojohoch committed
      ngOnDestroy(): void {
    
        this.textMarkingSupport.destroy();