Commit 794249ef authored by Konstantin Schulz's avatar Konstantin Schulz
Browse files

fixed deep links to voc_list exercises

parent 7be07669
/* tslint:disable:no-string-literal */
import {Injectable} from '@angular/core';
declare var H5P: any;
// dirty hack to prevent H5P access errors after resize events
window.onresize = () => {
/* tslint:disable:prefer-const */
/* tslint:disable:no-shadowed-variable */
let H5P: any;
/* tslint:enable:prefer-const */
/* tslint:enable:no-shadowed-variable */
};
@Injectable({
providedIn: 'root'
})
export class ExerciseService {
public excludeOOV = false;
public fillBlanksString = 'fill_blanks';
public kwicGraphs: string;
public vocListString = 'voc_list';
constructor() {
}
......@@ -21,4 +33,15 @@ export class ExerciseService {
return s4() + s4() + '-' + s4() + '-' + s4() + '-' +
s4() + '-' + s4() + s4() + s4();
}
initH5P(exerciseTypePath: string) {
// dirty hack to get H5P going without explicit button click on the new page
setTimeout(() => {
H5P.jQuery('.h5p-container').empty().h5p({
frameJs: 'assets/dist/js/h5p-standalone-frame.min.js',
frameCss: 'assets/dist/styles/h5p.css',
h5pContent: 'assets/h5p/' + exerciseTypePath
});
}, 50);
}
}
......@@ -4,16 +4,7 @@ import {HelperService} from '../helper.service';
import {NavController} from '@ionic/angular';
import {ActivatedRoute} from '@angular/router';
import {TranslateService} from '@ngx-translate/core';
declare var H5P: any;
// dirty hack to prevent H5P access errors after resize events
window.onresize = () => {
/* tslint:disable:prefer-const */
/* tslint:disable:no-shadowed-variable */
let H5P: any;
/* tslint:enable:prefer-const */
/* tslint:enable:no-shadowed-variable */
};
import {ExerciseService} from 'src/app/exercise.service';
@Component({
selector: 'app-exercise',
......@@ -26,21 +17,17 @@ export class ExercisePage implements OnInit {
constructor(public navCtrl: NavController,
public activatedRoute: ActivatedRoute,
public translateService: TranslateService) {
public translateService: TranslateService,
public exerciseService: ExerciseService) {
this.activatedRoute.queryParams.subscribe((params: object) => {
const exerciseType: string = params['type'];
const exerciseTypePath: string = exerciseType === this.exerciseService.vocListString ?
this.exerciseService.fillBlanksString : exerciseType;
const file: string = params['file'];
const lang: string = this.translateService.currentLang;
window.localStorage.setItem(HelperService.config['localStorageKeyH5P'],
HelperService.baseUrl + '/assets/h5p/' + exerciseType + '/content/' + file + '_' + lang + '.json');
// dirty hack to get H5P going without explicit button click on the new page
setTimeout(() => {
H5P.jQuery('.h5p-container').empty().h5p({
frameJs: 'assets/dist/js/h5p-standalone-frame.min.js',
frameCss: 'assets/dist/styles/h5p.css',
h5pContent: 'assets/h5p/' + exerciseType
});
}, 50);
this.exerciseService.initH5P(exerciseTypePath);
});
}
......
......@@ -11,14 +11,6 @@ import {Solution} from 'src/app/models/solution';
import {HttpClient} from '@angular/common/http';
declare var H5P: any;
// dirty hack to prevent H5P access errors after resize events
window.onresize = () => {
/* tslint:disable:prefer-const */
/* tslint:disable:no-shadowed-variable */
let H5P: any;
/* tslint:enable:prefer-const */
/* tslint:enable:no-shadowed-variable */
};
@Component({
selector: 'app-preview',
......@@ -58,14 +50,7 @@ export class PreviewPage implements OnDestroy {
+ this.corpusService.annisResponse.exercise_id + '&lang=' + this.translateService.getBrowserLang() +
solutionIndicesString;
window.localStorage.setItem(HelperService.config['localStorageKeyH5P'], url);
// dirty hack to get H5P going without explicit button click on the new page
setTimeout(() => {
H5P.jQuery('.h5p-container').empty().h5p({
frameJs: 'assets/dist/js/h5p-standalone-frame.min.js',
frameCss: 'assets/dist/styles/h5p.css',
h5pContent: 'assets/h5p/drag_text'
});
}, 50);
this.exerciseService.initH5P('drag_text');
}
this.updateFileUrl();
}
......
......@@ -13,16 +13,9 @@ import LanguageMap from 'src/app/models/xAPI/LanguageMap';
import {HttpClient, HttpErrorResponse} from '@angular/common/http';
import Context from 'src/app/models/xAPI/Context';
import {TestResultMC} from 'src/app/models/testResultMC';
import {ExerciseService} from 'src/app/exercise.service';
declare var H5P: any;
// dirty hack to prevent H5P access errors after resize events
window.onresize = () => {
/* tslint:disable:prefer-const */
/* tslint:disable:no-shadowed-variable */
let H5P: any;
/* tslint:enable:prefer-const */
/* tslint:enable:no-shadowed-variable */
};
@Component({
selector: 'app-test',
......@@ -93,7 +86,6 @@ export class TestPage implements OnDestroy, OnInit {
public dataSentSuccessMessage: string;
public didTimeRunOut = false;
public exerciseCount: number;
public fillBlanksString = 'fill_blanks';
public h5pBlanksString = 'H5P.Blanks';
public h5pCheckButtonClassString = '.h5p-question-check-answer';
public h5pDragTextString = 'H5P.DragText';
......@@ -111,7 +103,6 @@ export class TestPage implements OnDestroy, OnInit {
public testType: TestType;
public timer: any;
public timerIDstring = '#timer';
public vocListString = 'voc_list';
public wasDataSent: boolean;
constructor(public navCtrl: NavController,
......@@ -119,7 +110,8 @@ export class TestPage implements OnDestroy, OnInit {
public vocService: VocabularyService,
public popoverController: PopoverController,
public http: HttpClient,
public toastCtrl: ToastController) {
public toastCtrl: ToastController,
public exerciseService: ExerciseService) {
this.translate.get('DATA_SENT').subscribe(value => this.dataSentSuccessMessage = value);
this.translate.get('DATA_ALREADY_SENT').subscribe(value => this.dataAlreadySentMessage = value);
}
......@@ -245,17 +237,6 @@ export class TestPage implements OnDestroy, OnInit {
}
}
public initH5P(exerciseType: string) {
// dirty hack to get H5P going without explicit button click on the new page
setTimeout(() => {
H5P.jQuery('.h5p-container').empty().h5p({
frameJs: 'assets/dist/js/h5p-standalone-frame.min.js',
frameCss: 'assets/dist/styles/h5p.css',
h5pContent: 'assets/h5p/' + exerciseType
});
}, 50);
}
initTimer(durationSeconds: number) {
// add the new duration to countdown
const countDownDate = new Date(new Date().getTime() + durationSeconds * 1000).getTime(); // 15
......@@ -430,10 +411,10 @@ export class TestPage implements OnDestroy, OnInit {
let exerciseType = currentExerciseName.split('_').slice(0, 2).join('_');
window.localStorage.setItem(HelperService.config['localStorageKeyH5P'],
HelperService.baseUrl + '/assets/h5p/' + exerciseType + '/content/' + fileName);
if (exerciseType.startsWith(this.vocListString)) {
exerciseType = this.fillBlanksString;
if (exerciseType.startsWith(this.exerciseService.vocListString)) {
exerciseType = this.exerciseService.fillBlanksString;
}
this.initH5P(exerciseType);
this.exerciseService.initH5P(exerciseType);
}
triggerInputEventHandler() {
......
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