Skip to content
Snippets Groups Projects
Commit af5598cc authored by rhenck's avatar rhenck
Browse files

Add player event handling for button's navigation events

parent 5c1fa1c5
No related branches found
No related tags found
No related merge requests found
Pipeline #41634 failed
import {
Component, EventEmitter, Input, Output
} from '@angular/core';
import { ElementComponent } from '../../directives/element-component.directive';
import { ButtonElement } from 'common/models/elements/button/button';
import { NavigationEvent } from 'common/models/elements/element';
import { ElementComponent } from '../../directives/element-component.directive';
@Component({
selector: 'aspect-button',
......@@ -68,8 +69,5 @@ import { ButtonElement } from 'common/models/elements/button/button';
})
export class ButtonComponent extends ElementComponent {
@Input() elementModel!: ButtonElement;
@Output() navigateTo = new EventEmitter<{
action: 'unitNav' | 'pageNav';
param: 'previous' | 'next' | 'first' | 'last' | 'end' | number
}>();
@Output() navigateTo = new EventEmitter<NavigationEvent>();
}
......@@ -205,6 +205,11 @@ export interface ValueChangeElement {
value: InputElementValue;
}
export interface NavigationEvent {
action: 'unitNav' | 'pageNav';
param: 'previous' | 'next' | 'first' | 'last' | 'end' | number;
}
export interface OptionElement extends UIElement {
getNewOptionLabel(optionText: string): Label;
}
......
......@@ -10,6 +10,9 @@ import {
import { ClozeElement } from 'common/models/elements/compound-elements/cloze/cloze';
import { LikertElement } from 'common/models/elements/compound-elements/likert/likert';
import { CompoundElement, InputElement } from 'common/models/elements/element';
import { ButtonComponent } from 'common/components/button/button.component';
import { VeronaPostService } from 'player/modules/verona/services/verona-post.service';
import { NavigationService } from 'player/src/app/services/navigation.service';
import { UnitStateService } from '../../../services/unit-state.service';
import { ElementModelElementCodeMappingService } from '../../../services/element-model-element-code-mapping.service';
import { ValidationService } from '../../../services/validation.service';
......@@ -39,6 +42,8 @@ export class CompoundGroupElementComponent extends ElementFormGroupDirective imp
public translateService: TranslateService,
public messageService: MessageService,
public veronaSubscriptionService: VeronaSubscriptionService,
private veronaPostService: VeronaPostService,
private navigationService: NavigationService,
public validationService: ValidationService
) {
super();
......@@ -60,6 +65,9 @@ export class CompoundGroupElementComponent extends ElementFormGroupDirective imp
this.manageKeyInputToggling(child as TextFieldSimpleComponent, childModel);
this.manageHardwareKeyBoardDetection(child as TextFieldSimpleComponent);
}
if (childModel.type === 'button') {
this.addNavigationEventListener(child as ButtonComponent);
}
});
}
......@@ -98,4 +106,17 @@ export class CompoundGroupElementComponent extends ElementFormGroupDirective imp
this.deviceService.hasHardwareKeyboard = true;
this.keyboardService.close();
}
private addNavigationEventListener(button: ButtonComponent) {
button.navigateTo
.pipe(takeUntil(this.ngUnsubscribe))
.subscribe(navigationEvent => {
if (navigationEvent.action === 'unitNav') {
this.veronaPostService.sendVopUnitNavigationRequestedNotification(
(navigationEvent.param as 'previous' | 'next' | 'first' | 'last' | 'end'));
} else {
this.navigationService.setPage(navigationEvent.param as number);
}
});
}
}
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