diff --git a/projects/player/src/app/app.module.ts b/projects/player/src/app/app.module.ts index a066d9aa2fc23894fe39ef7f3074a396cf912033..887b466ea276ed4a049ed98d2a1bab415c6a085a 100644 --- a/projects/player/src/app/app.module.ts +++ b/projects/player/src/app/app.module.ts @@ -9,7 +9,6 @@ import { AppComponent } from './app.component'; import { PageComponent } from './components/page/page.component'; import { SectionComponent } from './components/section/section.component'; import { SharedModule } from '../../../common/shared.module'; -import { UnitStateComponent } from './components/unit-state/unit-state.component'; import { PlayerStateComponent } from './components/player-state/player-state.component'; import { PlayerTranslateLoader } from './classes/player-translate-loader'; import { LayoutComponent } from './components/layout/layout.component'; @@ -44,7 +43,6 @@ import { AppComponent, PageComponent, SectionComponent, - UnitStateComponent, PlayerStateComponent, LayoutComponent, AlertDialogComponent, diff --git a/projects/player/src/app/components/unit-state/form.component.css b/projects/player/src/app/components/unit-state/form.component.css deleted file mode 100644 index 8b137891791fe96927ad78e64b0aad7bded08bdc..0000000000000000000000000000000000000000 --- a/projects/player/src/app/components/unit-state/form.component.css +++ /dev/null @@ -1 +0,0 @@ - diff --git a/projects/player/src/app/components/unit-state/unit-state.component.html b/projects/player/src/app/components/unit-state/unit-state.component.html deleted file mode 100644 index 71780bd2455521cc8f2e3e3f49c446801a261162..0000000000000000000000000000000000000000 --- a/projects/player/src/app/components/unit-state/unit-state.component.html +++ /dev/null @@ -1,6 +0,0 @@ -<form [formGroup]="form"> - <aspect-player-state [parentForm]="form" - [playerConfig]="playerConfig" - [pages]="pages"> - </aspect-player-state> -</form> 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 deleted file mode 100644 index fd8366c094aac5944e036955dcdc1f171a3bb473..0000000000000000000000000000000000000000 --- a/projects/player/src/app/components/unit-state/unit-state.component.ts +++ /dev/null @@ -1,169 +0,0 @@ -import { - ChangeDetectorRef, Component, Input, OnDestroy, OnInit -} from '@angular/core'; -import { - FormArray, FormBuilder, FormControl, FormGroup -} from '@angular/forms'; -import { Subject } from 'rxjs'; -import { takeUntil } from 'rxjs/operators'; -import { TranslateService } from '@ngx-translate/core'; -import { VeronaSubscriptionService } from '../../services/verona-subscription.service'; -import { VeronaPostService } from '../../services/verona-post.service'; -import { MessageService } from '../../../../../common/services/message.service'; -import { MetaDataService } from '../../services/meta-data.service'; -import { - FormControlElement, FormControlValidators, ChildFormGroup -} from '../../models/form'; -import { - PlayerConfig, Progress, UnitState, VopNavigationDeniedNotification -} from '../../models/verona'; -import { UnitStateService } from '../../services/unit-state.service'; -import { MediaPlayerService } from '../../services/media-player.service'; -import { Page } from '../../../../../common/interfaces/unit'; - -@Component({ - selector: 'aspect-unit-state', - templateUrl: './unit-state.component.html' -}) -export class UnitStateComponent implements OnInit, OnDestroy { - @Input() pages: Page[] = []; - @Input() playerConfig!: PlayerConfig; - - form!: FormGroup; - - private validationControls: FormControl[] = []; - private ngUnsubscribe = new Subject<void>(); - - constructor(private formBuilder: FormBuilder, - private unitStateService: UnitStateService, - private mediaPlayerService: MediaPlayerService, - private veronaSubscriptionService: VeronaSubscriptionService, - private veronaPostService: VeronaPostService, - private messageService: MessageService, - private metaDataService: MetaDataService, - private translateService: TranslateService, - private changeDetectorRef: ChangeDetectorRef) { - } - - ngOnInit(): void { - this.form = this.formBuilder.group({ - pages: this.formBuilder.array([]) - }); - this.initSubscriptions(); - } - - 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.mediaPlayerService.mediaStatusChanged - .pipe(takeUntil(this.ngUnsubscribe)) - .subscribe((): void => this.onMediaStatusChanged()); - this.unitStateService.presentedPageAdded - .pipe(takeUntil(this.ngUnsubscribe)) - .subscribe((): void => this.onPresentedPageAdded()); - this.unitStateService.unitStateElementCodeChanged - .pipe(takeUntil(this.ngUnsubscribe)) - .subscribe((): void => this.onUnitStateElementCodeChanged()); - this.veronaSubscriptionService.vopNavigationDeniedNotification - .pipe(takeUntil(this.ngUnsubscribe)) - .subscribe((message: VopNavigationDeniedNotification): void => this.onNavigationDenied(message)); - } - - private get responseProgress(): Progress { - if (this.form.valid) { - return 'complete'; - } - return this.validationControls.some(control => control.valid) ? 'some' : 'none'; - } - - private get presentationProgress(): Progress { - const mediaStatus = this.mediaPlayerService.mediaStatus; - return mediaStatus === this.unitStateService.presentedPagesProgress ? mediaStatus : 'some'; - } - - private addControl = (control: FormControlElement): void => { - control.formGroup.addControl(control.id, control.formControl); - }; - - private registerValidationControl(control: FormControl): void { - if (!this.validationControls.includes(control)) { - this.validationControls.push(control); - } - } - - private setValidators = (validators: FormControlValidators): void => { - validators.formGroup.controls[validators.id].setValidators(validators.validators); - validators.formGroup.controls[validators.id].updateValueAndValidity(); - this.registerValidationControl(validators.formGroup.controls[validators.id] as FormControl); - this.changeDetectorRef.detectChanges(); - }; - - private onNavigationDenied(message: VopNavigationDeniedNotification): void { - // eslint-disable-next-line no-console - console.log('player: onNavigationDenied', message); - const reasons = message.reason?.map((reason: string) => this.translateService.instant(reason)); - this.messageService.showWarning(reasons?.join(', ') || this.translateService.instant('noReason')); - if (message.reason && message.reason.find(reason => reason === 'responsesIncomplete')) { - this.form.markAllAsTouched(); - } - } - - private addGroup = (group: ChildFormGroup): void => { - const formArray: FormArray = group.parentForm.get(group.parentArray) as FormArray; - if (group.parentArrayIndex < formArray.length) { - formArray.insert(group.parentArrayIndex, group.formGroup); - } else { - formArray.push(group.formGroup); - } - }; - - private onUnitStateElementCodeChanged(): void { - // eslint-disable-next-line no-console - console.log('player: onUnitStateElementCodeChanged', this.unitStateService.unitStateElementCodes); - this.sendVopStateChangedNotification(); - } - - private onPresentedPageAdded(): void { - // eslint-disable-next-line no-console - console.log('player: onPresentedPageAdded'); - this.sendVopStateChangedNotification(); - } - - private onMediaStatusChanged(): void { - // eslint-disable-next-line no-console - console.log('player: onMediaStatusChanged', this.mediaPlayerService.mediaStatus); - this.sendVopStateChangedNotification(); - } - - private sendVopStateChangedNotification(): void { - // give the form time to change its valid status - Promise.resolve().then(() => { - // eslint-disable-next-line no-console - console.log('player: this.unitStateService.unitStateElementCodes', - this.unitStateService.unitStateElementCodes); - const unitState: UnitState = { - dataParts: { - elementCodes: JSON.stringify(this.unitStateService.unitStateElementCodes) - }, - presentationProgress: this.presentationProgress, - responseProgress: this.responseProgress, - unitStateDataType: 'iqb-standard@1.0' - }; - // eslint-disable-next-line no-console - console.log('player: unitState sendVopStateChangedNotification', unitState); - this.veronaPostService.sendVopStateChangedNotification({ unitState }); - }); - } - - ngOnDestroy(): void { - this.ngUnsubscribe.next(); - this.ngUnsubscribe.complete(); - } -}