From 230fbb352215e7ba4373c2f840e1fad3b9b74e60 Mon Sep 17 00:00:00 2001
From: jojohoch <joachim.hoch@iqb.hu-berlin.de>
Date: Mon, 28 Feb 2022 10:15:15 +0100
Subject: [PATCH] [player] Delete form service

---
 .../components/layout/layout.component.html   |  3 --
 .../app/components/page/page.component.html   |  1 -
 .../src/app/components/page/page.component.ts | 24 +-----------
 .../components/section/section.component.ts   | 22 +----------
 .../unit-state/unit-state.component.ts        | 20 +++++-----
 .../player/src/app/services/form.service.ts   | 38 -------------------
 .../src/app/services/unit-state.service.ts    |  1 -
 7 files changed, 13 insertions(+), 96 deletions(-)
 delete mode 100644 projects/player/src/app/services/form.service.ts

diff --git a/projects/player/src/app/components/layout/layout.component.html b/projects/player/src/app/components/layout/layout.component.html
index a9382ff6d..da5f0d32f 100644
--- a/projects/player/src/app/components/layout/layout.component.html
+++ b/projects/player/src/app/components/layout/layout.component.html
@@ -40,7 +40,6 @@
           {{'alwaysVisiblePage' | translate}}
         </div>
         <aspect-page [parentArrayIndex]="alwaysVisibleUnitPageIndex"
-                     [parentForm]="parentForm"
                      [isLastPage]="false"
                      [pagesContainer]="alwaysVisiblePageContainer"
                      [page]="alwaysVisiblePage">
@@ -83,7 +82,6 @@
              [style.padding.px]="page.margin"
              [style.max-width]="page.hasMaxWidth ? page.maxWidth + 'px' : '100%'">
           <aspect-page [parentArrayIndex]="scrollPagesIndices[i]"
-                       [parentForm]="parentForm"
                        [isLastPage]="last"
                        [pagesContainer]="pagesContainer"
                        [page]="page">
@@ -110,7 +108,6 @@
         {{'pageIndication' | translate: {index: i + 1} }}
       </div>
       <aspect-page [parentArrayIndex]="scrollPagesIndices[i]"
-                   [parentForm]="parentForm"
                    [pagesContainer]="pagesContainer"
                    [page]="page"
                    [isLastPage]="last"
diff --git a/projects/player/src/app/components/page/page.component.html b/projects/player/src/app/components/page/page.component.html
index 72931c77a..607f272e3 100644
--- a/projects/player/src/app/components/page/page.component.html
+++ b/projects/player/src/app/components/page/page.component.html
@@ -8,7 +8,6 @@
                   [style.backgroundColor]="section.dynamicPositioning ? null : section.backgroundColor"
                   [style.minHeight]="section.dynamicPositioning ? 'auto' : section.height + 'px'"
                   [pageIndex]=parentArrayIndex
-                  [parentForm]="pageForm"
                   [parentArrayIndex]="i"
                   [section]="section">
   </aspect-section>
diff --git a/projects/player/src/app/components/page/page.component.ts b/projects/player/src/app/components/page/page.component.ts
index 88913c7f7..8438f0451 100644
--- a/projects/player/src/app/components/page/page.component.ts
+++ b/projects/player/src/app/components/page/page.component.ts
@@ -1,8 +1,6 @@
 import {
   Component, Input, OnInit, Output, EventEmitter
 } from '@angular/core';
-import { FormBuilder, FormGroup } from '@angular/forms';
-import { FormService } from '../../services/form.service';
 import { UnitStateService } from '../../services/unit-state.service';
 import { Page } from '../../../../../common/interfaces/unit';
 
@@ -12,32 +10,14 @@ import { Page } from '../../../../../common/interfaces/unit';
   styleUrls: ['./page.component.css']
 })
 
-export class PageComponent implements OnInit {
+export class PageComponent{
   @Input() page!: Page;
   @Input() isLastPage!: boolean;
-  @Input() parentForm!: FormGroup;
   @Input() parentArrayIndex!: number;
   @Input() pagesContainer!: HTMLElement;
   @Output() selectedIndexChange = new EventEmitter<number>();
 
-  pageForm!: FormGroup;
-
-  constructor(private formService: FormService,
-              private unitStateService: UnitStateService,
-              private formBuilder: FormBuilder) {}
-
-  ngOnInit(): void {
-    this.pageForm = this.formBuilder.group({
-      id: this.page.id,
-      sections: this.formBuilder.array([])
-    });
-    this.formService.registerFormGroup({
-      formGroup: this.pageForm,
-      parentForm: this.parentForm,
-      parentArray: 'pages',
-      parentArrayIndex: this.parentArrayIndex
-    });
-  }
+  constructor(private unitStateService: UnitStateService) {}
 
   onIntersection(): void {
     this.selectedIndexChange.emit(this.parentArrayIndex);
diff --git a/projects/player/src/app/components/section/section.component.ts b/projects/player/src/app/components/section/section.component.ts
index f49a86571..fbb74dbca 100644
--- a/projects/player/src/app/components/section/section.component.ts
+++ b/projects/player/src/app/components/section/section.component.ts
@@ -3,7 +3,6 @@ import {
 } from '@angular/core';
 import { FormBuilder, FormGroup } from '@angular/forms';
 import { DOCUMENT } from '@angular/common';
-import { FormService } from '../../services/form.service';
 import { Section } from '../../../../../common/interfaces/unit';
 
 @Component({
@@ -11,28 +10,11 @@ import { Section } from '../../../../../common/interfaces/unit';
   templateUrl: './section.component.html',
   styleUrls: ['./section.component.css']
 })
-export class SectionComponent implements OnInit {
+export class SectionComponent {
   @Input() parentForm!: FormGroup;
   @Input() section!: Section;
   @Input() parentArrayIndex!: number;
   @Input() pageIndex!: number;
 
-  sectionForm!: FormGroup;
-
-  constructor(private formService: FormService,
-              private formBuilder: FormBuilder,
-              @Inject(DOCUMENT) public document: Document) {
-  }
-
-  ngOnInit(): void {
-    this.sectionForm = new FormGroup({
-      elements: this.formBuilder.array([])
-    });
-    this.formService.registerFormGroup({
-      formGroup: this.sectionForm,
-      parentForm: this.parentForm,
-      parentArray: 'sections',
-      parentArrayIndex: this.parentArrayIndex
-    });
-  }
+  constructor(@Inject(DOCUMENT) public document: Document) {}
 }
diff --git a/projects/player/src/app/components/unit-state/unit-state.component.ts b/projects/player/src/app/components/unit-state/unit-state.component.ts
index 9259d40ae..fd8366c09 100644
--- a/projects/player/src/app/components/unit-state/unit-state.component.ts
+++ b/projects/player/src/app/components/unit-state/unit-state.component.ts
@@ -7,7 +7,6 @@ import {
 import { Subject } from 'rxjs';
 import { takeUntil } from 'rxjs/operators';
 import { TranslateService } from '@ngx-translate/core';
-import { FormService } from '../../services/form.service';
 import { VeronaSubscriptionService } from '../../services/verona-subscription.service';
 import { VeronaPostService } from '../../services/verona-post.service';
 import { MessageService } from '../../../../../common/services/message.service';
@@ -36,7 +35,6 @@ export class UnitStateComponent implements OnInit, OnDestroy {
   private ngUnsubscribe = new Subject<void>();
 
   constructor(private formBuilder: FormBuilder,
-              private formService: FormService,
               private unitStateService: UnitStateService,
               private mediaPlayerService: MediaPlayerService,
               private veronaSubscriptionService: VeronaSubscriptionService,
@@ -55,15 +53,15 @@ export class UnitStateComponent implements OnInit, OnDestroy {
   }
 
   private initSubscriptions(): void {
-    this.formService.groupAdded
-      .pipe(takeUntil(this.ngUnsubscribe))
-      .subscribe((group: ChildFormGroup): void => this.addGroup(group));
-    this.formService.controlAdded
-      .pipe(takeUntil(this.ngUnsubscribe))
-      .subscribe((control: FormControlElement): void => this.addControl(control));
-    this.formService.validatorsAdded
-      .pipe(takeUntil(this.ngUnsubscribe))
-      .subscribe((validations: FormControlValidators): void => this.setValidators(validations));
+    // this.formService.groupAdded
+    //   .pipe(takeUntil(this.ngUnsubscribe))
+    //   .subscribe((group: ChildFormGroup): void => this.addGroup(group));
+    // this.formService.controlAdded
+    //   .pipe(takeUntil(this.ngUnsubscribe))
+    //   .subscribe((control: FormControlElement): void => this.addControl(control));
+    // this.formService.validatorsAdded
+    //   .pipe(takeUntil(this.ngUnsubscribe))
+    //   .subscribe((validations: FormControlValidators): void => this.setValidators(validations));
     this.mediaPlayerService.mediaStatusChanged
       .pipe(takeUntil(this.ngUnsubscribe))
       .subscribe((): void => this.onMediaStatusChanged());
diff --git a/projects/player/src/app/services/form.service.ts b/projects/player/src/app/services/form.service.ts
deleted file mode 100644
index 4980ad78f..000000000
--- a/projects/player/src/app/services/form.service.ts
+++ /dev/null
@@ -1,38 +0,0 @@
-import { Injectable } from '@angular/core';
-import { Observable, Subject } from 'rxjs';
-import {
-  FormControlElement, FormControlValidators, ChildFormGroup
-} from '../models/form';
-
-@Injectable({
-  providedIn: 'root'
-})
-export class FormService {
-  private _controlAdded = new Subject<FormControlElement>();
-  private _groupAdded = new Subject<ChildFormGroup>();
-  private _validatorsAdded = new Subject<FormControlValidators>();
-
-  get controlAdded(): Observable<FormControlElement> {
-    return this._controlAdded.asObservable();
-  }
-
-  get groupAdded(): Observable<ChildFormGroup> {
-    return this._groupAdded.asObservable();
-  }
-
-  get validatorsAdded(): Observable<FormControlValidators> {
-    return this._validatorsAdded.asObservable();
-  }
-
-  registerFormControl(control: FormControlElement): void {
-    this._controlAdded.next(control);
-  }
-
-  registerFormGroup(group: ChildFormGroup): void {
-    this._groupAdded.next(group);
-  }
-
-  setValidators(validators: FormControlValidators): void {
-    this._validatorsAdded.next(validators);
-  }
-}
diff --git a/projects/player/src/app/services/unit-state.service.ts b/projects/player/src/app/services/unit-state.service.ts
index 2f003f916..b62a24d96 100644
--- a/projects/player/src/app/services/unit-state.service.ts
+++ b/projects/player/src/app/services/unit-state.service.ts
@@ -108,7 +108,6 @@ export class UnitStateService {
       unitStateElementCode.value = value;
       this._unitStateElementCodeChanged.next(unitStateElementCode);
     }
-    console.log(this.unitStateElementCodes);
   }
 
   private setUnitStateElementCodeStatus(id: string, status: UnitStateElementCodeStatus): void {
-- 
GitLab