Commit a7a70388 authored by Konstantin Schulz's avatar Konstantin Schulz
Browse files

code review for test module

parent 1f2e44d9
......@@ -20,7 +20,7 @@
<ion-col>
<ion-label>{{ 'TEST_MODULE_GO_TO_EXERCISE' | translate}}</ion-label>
<ion-select [(ngModel)]="selectedExerciseIndex" name="selectedExerciseIndex"
(ionChange)="reviewOldExercise(+selectedExerciseIndex - 1)">
(ionChange)="showNextExercise(+selectedExerciseIndex - 1, true)">
<ion-select-option *ngFor="let number of Array.from(Array(getExerciseCount()).keys())">
{{number + 1}}
</ion-select-option>
......
......@@ -257,37 +257,6 @@ export class TestPage implements OnDestroy, OnInit {
this.ngOnInit();
}
reviewOldExercise(newIndex: number) {
this.currentExerciseIndex = newIndex;
const currentExercisePart: ExercisePart = this.currentExerciseParts[this.getCurrentExercisePartIndex()];
const maxProgress: number = currentExercisePart.exercises.length;
this.progressBarValue = (newIndex - currentExercisePart.startIndex) / maxProgress;
this.updateUI();
const currentExerciseName = this.getCurrentExerciseName();
if (currentExerciseName.startsWith(this.nonH5Pstring)) {
document.querySelector(this.h5pRowIDstring).classList.add(this.hideClassString);
// TODO: DELETE THIS
if (newIndex == this.currentExerciseParts[this.currentExerciseParts.length - 1].startIndex) {
this.analyzeResults();
H5P.externalDispatcher.off('xAPI');
this.updateUI();
}
return;
}
this.currentState = TestModuleState.showSolutions;
document.querySelector(this.h5pRowIDstring).classList.remove(this.hideClassString);
let fileName: string = currentExerciseName.split("_").slice(-1) + "_" + this.translate.currentLang + ".json";
let exerciseType = currentExerciseName.split("_").slice(0, 2).join("_");
const baseUrl: string = location.protocol.concat('//').concat(window.location.host);
window.localStorage.setItem(HelperService.config['localStorageKeyH5P'], baseUrl + "/assets/h5p/" + exerciseType + "/content/" + fileName);
if (exerciseType.startsWith(this.vocListString)) {
exerciseType = this.fillBlanksString;
}
this.initH5P(exerciseType);
}
setH5PeventHandlers() {
H5P.externalDispatcher.on('xAPI', (event: XAPIevent) => {
// results are only available when a task has been completed/answered, not in the "attempted" or "interacted" stages
......@@ -318,14 +287,16 @@ export class TestPage implements OnDestroy, OnInit {
});
}
showNextExercise(newIndex: number) {
const metaIndex: number = this.currentExerciseParts.map(x => x.startIndex).indexOf(newIndex);
if (metaIndex > -1) {
if (this.currentExerciseParts[metaIndex].durationSeconds > 0) {
this.removeTimer(false);
this.initTimer(this.currentExerciseParts[metaIndex].durationSeconds);
} else if (newIndex == this.currentExerciseParts[this.currentExerciseParts.length - 1].startIndex) {
this.removeTimer(true);
showNextExercise(newIndex: number, review: boolean = false) {
if (!review) {
const metaIndex: number = this.currentExerciseParts.map(x => x.startIndex).indexOf(newIndex);
if (metaIndex > -1) {
if (this.currentExerciseParts[metaIndex].durationSeconds > 0) {
this.removeTimer(false);
this.initTimer(this.currentExerciseParts[metaIndex].durationSeconds);
} else if (newIndex == this.currentExerciseParts[this.currentExerciseParts.length - 1].startIndex) {
this.removeTimer(true);
}
}
}
this.currentExerciseIndex = newIndex;
......@@ -336,15 +307,17 @@ export class TestPage implements OnDestroy, OnInit {
const currentExerciseName = this.getCurrentExerciseName();
if (currentExerciseName.startsWith(this.nonH5Pstring)) {
document.querySelector(this.h5pRowIDstring).classList.add(this.hideClassString);
if (newIndex == this.currentExerciseParts[this.currentExerciseParts.length - 1].startIndex) {
// uncomment this (and comment out the following line) for easier navigation during development
// if (newIndex == this.currentExerciseParts[this.currentExerciseParts.length - 1].startIndex) {
if (!review && newIndex == this.currentExerciseParts[this.currentExerciseParts.length - 1].startIndex) {
this.analyzeResults();
H5P.externalDispatcher.off('xAPI');
this.updateUI();
}
return;
}
this.currentState = review ? TestModuleState.showSolutions : TestModuleState.inProgress;
document.querySelector(this.h5pRowIDstring).classList.remove(this.hideClassString);
this.currentState = TestModuleState.inProgress;
let fileName: string = currentExerciseName.split("_").slice(-1) + "_" + this.translate.currentLang + ".json";
let exerciseType = currentExerciseName.split("_").slice(0, 2).join("_");
const baseUrl: string = location.protocol.concat('//').concat(window.location.host);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment