Commit 57a15c03 authored by Konstantin Schulz's avatar Konstantin Schulz

added a new curated exercise by Potsdam University

parent 7de52892
Pipeline #14594 passed with stages
in 2 minutes and 52 seconds
...@@ -358,7 +358,7 @@ class McTestCase(unittest.TestCase): ...@@ -358,7 +358,7 @@ class McTestCase(unittest.TestCase):
DatabaseService.commit() DatabaseService.commit()
response = Mocks.app_dict[self.class_name].client.post( response = Mocks.app_dict[self.class_name].client.post(
TestingConfig.SERVER_URI_H5P, headers=Mocks.headers_form_data, data=hf.to_dict()) TestingConfig.SERVER_URI_H5P, headers=Mocks.headers_form_data, data=hf.to_dict())
self.assertEqual(len(response.get_data()), 1940145) self.assertEqual(len(response.get_data()), 1963607)
with patch.object(mcserver.app.api.h5pAPI, "get_text_field_content", return_value=""): with patch.object(mcserver.app.api.h5pAPI, "get_text_field_content", return_value=""):
response = Mocks.app_dict[self.class_name].client.post( response = Mocks.app_dict[self.class_name].client.post(
TestingConfig.SERVER_URI_H5P, headers=Mocks.headers_form_data, data=hf.to_dict()) TestingConfig.SERVER_URI_H5P, headers=Mocks.headers_form_data, data=hf.to_dict())
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
1. Clone the repo: `git clone https://scm.cms.hu-berlin.de/callidus/machina-callida.git` 1. Clone the repo: `git clone https://scm.cms.hu-berlin.de/callidus/machina-callida.git`
2. Move to the newly created folder: `cd machina-callida/mc_frontend` 2. Move to the newly created folder: `cd machina-callida/mc_frontend`
3. Run `npm install` 3. Run `npm install`
4. Run `npm install -g @angular/cli` (you may need `sudo`). 4. Run `npm install -g @angular/cli` (you may need `sudo`). Optional: Install the Ionic CLI for additional command-line utilities: `npm i -g @ionic/cli`.
5. Check that the Angular command line interface is installed by running `ng --version`. It should print the version of the Angular CLI. 5. Check that the Angular command line interface is installed by running `ng --version`. It should print the version of the Angular CLI.
6. Run `npm start`. 6. Run `npm start`.
If you already ran `npm install` and the CLI still complains about missing dependencies, install them one by one using `npm install DEPENDENCY_NAME`. If you already ran `npm install` and the CLI still complains about missing dependencies, install them one by one using `npm install DEPENDENCY_NAME`.
......
...@@ -30,6 +30,10 @@ export const routes: Routes = [ ...@@ -30,6 +30,10 @@ export const routes: Routes = [
path: 'embed', path: 'embed',
loadChildren: () => import('./embed/embed.module').then( m => m.EmbedPageModule) loadChildren: () => import('./embed/embed.module').then( m => m.EmbedPageModule)
}, },
{
path: 'sequences',
loadChildren: () => import('./sequences/sequences.module').then( m => m.SequencesPageModule)
},
......
...@@ -25,6 +25,7 @@ import {LoadChildrenCallback, Route} from '@angular/router'; ...@@ -25,6 +25,7 @@ import {LoadChildrenCallback, Route} from '@angular/router';
import configMC from '../configMC'; import configMC from '../configMC';
import {SemanticsPageModule} from './semantics/semantics.module'; import {SemanticsPageModule} from './semantics/semantics.module';
import {EmbedPageModule} from './embed/embed.module'; import {EmbedPageModule} from './embed/embed.module';
import {SequencesPageModule} from './sequences/sequences.module';
describe('AppComponent', () => { describe('AppComponent', () => {
let statusBarSpy, splashScreenSpy, platformReadySpy, fixture: ComponentFixture<AppComponent>, let statusBarSpy, splashScreenSpy, platformReadySpy, fixture: ComponentFixture<AppComponent>,
...@@ -105,8 +106,9 @@ describe('AppComponent', () => { ...@@ -105,8 +106,9 @@ describe('AppComponent', () => {
}); });
it('should test routing', (done) => { it('should test routing', (done) => {
const urls: string[] = [configMC.pageUrlEmbed.slice(1), configMC.pageUrlSemantics.slice(1)]; const urls: string[] = [configMC.pageUrlEmbed.slice(1), configMC.pageUrlSemantics.slice(1),
const modules: any[] = [EmbedPageModule, SemanticsPageModule]; configMC.pageUrlSequences.slice(1)];
const modules: any[] = [EmbedPageModule, SemanticsPageModule, SequencesPageModule];
let doneCount = 0; let doneCount = 0;
new Promise(resolve => { new Promise(resolve => {
urls.forEach((url, index) => { urls.forEach((url, index) => {
......
...@@ -74,7 +74,7 @@ describe('CorpusService', () => { ...@@ -74,7 +74,7 @@ describe('CorpusService', () => {
corpusService.checkAnnisResponse().then(() => { corpusService.checkAnnisResponse().then(() => {
}, () => { }, () => {
expect(corpusService.annisResponse).toBeFalsy(); expect(corpusService.annisResponse).toBeFalsy();
helperService.applicationState.next(new ApplicationState()); helperService.applicationState.next(new ApplicationState({mostRecentSetup: new TextData()}));
corpusService.checkAnnisResponse().then(() => { corpusService.checkAnnisResponse().then(() => {
}, () => { }, () => {
expect(corpusService.annisResponse).toBeFalsy(); expect(corpusService.annisResponse).toBeFalsy();
......
...@@ -122,15 +122,11 @@ export class CorpusService { ...@@ -122,15 +122,11 @@ export class CorpusService {
return resolve(); return resolve();
} }
this.helperService.applicationState.pipe(take(1)).subscribe((state: ApplicationState) => { this.helperService.applicationState.pipe(take(1)).subscribe((state: ApplicationState) => {
if (state.mostRecentSetup) { this.annisResponse = state.mostRecentSetup.annisResponse;
this.annisResponse = state.mostRecentSetup.annisResponse; this.currentAuthor = state.mostRecentSetup.currentAuthor;
this.currentAuthor = state.mostRecentSetup.currentAuthor; this.currentUrn = state.mostRecentSetup.currentUrn;
this.currentUrn = state.mostRecentSetup.currentUrn; this.currentCorpusCache = state.mostRecentSetup.currentCorpus;
this.currentCorpusCache = state.mostRecentSetup.currentCorpus; return this.annisResponse ? resolve() : reject();
return resolve();
} else {
return reject();
}
}, () => { }, () => {
return reject(); return reject();
}); });
......
...@@ -31,7 +31,7 @@ describe('EmbedPage', () => { ...@@ -31,7 +31,7 @@ describe('EmbedPage', () => {
beforeEach(() => { beforeEach(() => {
fixture = TestBed.createComponent(EmbedPage); fixture = TestBed.createComponent(EmbedPage);
embedPage = fixture.componentInstance; embedPage = fixture.componentInstance;
loadExerciseSpy = spyOn(embedPage, 'loadExercise').and.returnValue(Promise.resolve()); loadExerciseSpy = spyOn(embedPage.exerciseService, 'loadExerciseFromQueryParams').and.returnValue(Promise.resolve());
fixture.detectChanges(); fixture.detectChanges();
}); });
...@@ -46,10 +46,12 @@ describe('EmbedPage', () => { ...@@ -46,10 +46,12 @@ describe('EmbedPage', () => {
it('should load an exercise', (done) => { it('should load an exercise', (done) => {
loadExerciseSpy.and.callThrough(); loadExerciseSpy.and.callThrough();
const loadH5Pspy: Spy = spyOn(embedPage.exerciseService, 'loadH5P').and.returnValue(Promise.resolve()); const loadH5Pspy: Spy = spyOn(embedPage.exerciseService, 'loadExercise').and.returnValue(Promise.resolve());
embedPage.loadExercise().then(() => { embedPage.exerciseService.loadExerciseFromQueryParams(embedPage.activatedRoute).then(() => {
expect(loadH5Pspy).toHaveBeenCalledTimes(1);
loadH5Pspy.and.callFake(() => Promise.reject()); loadH5Pspy.and.callFake(() => Promise.reject());
embedPage.loadExercise().then(() => {}, () => { embedPage.exerciseService.loadExerciseFromQueryParams(embedPage.activatedRoute).then(() => {
}, () => {
expect(loadH5Pspy).toHaveBeenCalledTimes(2); expect(loadH5Pspy).toHaveBeenCalledTimes(2);
done(); done();
}); });
......
import {Component, OnInit} from '@angular/core'; import {Component, OnInit} from '@angular/core';
import {ActivatedRoute} from '@angular/router'; import {ActivatedRoute} from '@angular/router';
import {ExerciseService} from '../exercise.service'; import {ExerciseService} from '../exercise.service';
import {ExerciseParams} from '../models/exerciseParams';
@Component({ @Component({
selector: 'app-embed', selector: 'app-embed',
...@@ -14,21 +13,9 @@ export class EmbedPage implements OnInit { ...@@ -14,21 +13,9 @@ export class EmbedPage implements OnInit {
public exerciseService: ExerciseService) { public exerciseService: ExerciseService) {
} }
loadExercise(): Promise<void> {
return new Promise<void>((resolve, reject) => {
this.activatedRoute.queryParams.subscribe((params: ExerciseParams) => {
this.exerciseService.loadH5P(params.eid).then(() => {
return resolve();
}, () => {
return reject();
});
});
});
}
ngOnInit(): Promise<void> { ngOnInit(): Promise<void> {
return new Promise<void>((resolve, reject) => { return new Promise<void>((resolve, reject) => {
this.loadExercise().then(() => { this.exerciseService.loadExerciseFromQueryParams(this.activatedRoute).then(() => {
return resolve(); return resolve();
}, () => { }, () => {
return reject(); return reject();
......
...@@ -8,11 +8,13 @@ import {TranslateTestingModule} from './translate-testing/translate-testing.modu ...@@ -8,11 +8,13 @@ import {TranslateTestingModule} from './translate-testing/translate-testing.modu
import {ExercisePart} from './models/exercisePart'; import {ExercisePart} from './models/exercisePart';
import MockMC from './models/mockMC'; import MockMC from './models/mockMC';
import {ApplicationState} from './models/applicationState'; import {ApplicationState} from './models/applicationState';
import {AnnisResponse, ExerciseTypePath} from '../../openapi'; import {AnnisResponse, ExerciseTypePath, Solution} from '../../openapi';
import {ExerciseType, MoodleExerciseType} from './models/enum'; import {ExerciseType, LanguageShortcut, MoodleExerciseType} from './models/enum';
import {ExerciseParams} from './models/exerciseParams'; import {ExerciseParams} from './models/exerciseParams';
import configMC from '../configMC'; import configMC from '../configMC';
import Spy = jasmine.Spy; import Spy = jasmine.Spy;
import {ActivatedRoute} from '@angular/router';
import {of} from 'rxjs';
declare var H5PStandalone: any; declare var H5PStandalone: any;
...@@ -76,21 +78,26 @@ describe('ExerciseService', () => { ...@@ -76,21 +78,26 @@ describe('ExerciseService', () => {
const postSpy: Spy = spyOn(exerciseService.helperService, 'makePostRequest').and.callFake(() => Promise.resolve(new Blob())); const postSpy: Spy = spyOn(exerciseService.helperService, 'makePostRequest').and.callFake(() => Promise.resolve(new Blob()));
const downloadSpy: Spy = spyOn(exerciseService, 'downloadBlobAsFile'); const downloadSpy: Spy = spyOn(exerciseService, 'downloadBlobAsFile');
exerciseService.corpusService.annisResponse = {exercise_id: ''}; exerciseService.corpusService.annisResponse = {exercise_id: ''};
exerciseService.corpusService.currentSolutions = exerciseService.corpusService.annisResponse.solutions = [{
target: {
token_id: 1,
sentence_id: 1
}
}];
exerciseService.corpusService.exercise.type = ExerciseType.markWords; exerciseService.corpusService.exercise.type = ExerciseType.markWords;
exerciseService.currentExerciseLanguage = LanguageShortcut.English;
exerciseService.downloadH5Pexercise().then(() => { exerciseService.downloadH5Pexercise().then(() => {
expect(downloadSpy).toHaveBeenCalledTimes(1); expect(downloadSpy).toHaveBeenCalledTimes(1);
postSpy.and.callFake(() => Promise.reject()); exerciseService.corpusService.currentSolutions =
exerciseService.corpusService.exercise.type = ExerciseType.cloze; exerciseService.corpusService.annisResponse.solutions = [{
target: {
token_id: 1,
sentence_id: 1
}
}];
exerciseService.downloadH5Pexercise().then(() => { exerciseService.downloadH5Pexercise().then(() => {
}, () => { expect(downloadSpy).toHaveBeenCalledTimes(2);
expect(downloadSpy).toHaveBeenCalledTimes(1); postSpy.and.callFake(() => Promise.reject());
done(); exerciseService.corpusService.exercise.type = ExerciseType.cloze;
exerciseService.downloadH5Pexercise().then(() => {
}, () => {
expect(downloadSpy).toHaveBeenCalledTimes(2);
done();
});
}); });
}); });
}); });
...@@ -107,49 +114,77 @@ describe('ExerciseService', () => { ...@@ -107,49 +114,77 @@ describe('ExerciseService', () => {
expect(nodeList.length).toBe(1); expect(nodeList.length).toBe(1);
}); });
it('should get solution indices', () => {
const solution: Solution = {target: {sentence_id: 1, token_id: 1}};
exerciseService.corpusService.annisResponse = {solutions: [solution]};
const result: string = exerciseService.getSolutionIndices([solution]);
expect(result).toContain('0');
});
it('should initialize H5P', (done) => { it('should initialize H5P', (done) => {
let h5pCalled = false; let h5pCalled = false;
spyOn(exerciseService, 'createH5Pstandalone').and.callFake(() => new Promise(resolve => { spyOn(exerciseService, 'createH5Pstandalone').and.callFake(() => new Promise(resolve => {
h5pCalled = true; h5pCalled = true;
return resolve(); return resolve();
})); }));
exerciseService.initH5P('', false).then(() => { exerciseService.initH5P('', '', false).then(() => {
expect(h5pCalled).toBe(true); expect(h5pCalled).toBe(true);
done(); done();
}); });
}); });
it('should load an exercise', (done) => { it('should load an exercise', (done) => {
const ar: AnnisResponse = {exercise_type: MoodleExerciseType.cloze.toString()};
const getSpy: Spy = spyOn(exerciseService.helperService, 'makeGetRequest').and.returnValue(Promise.resolve(ar));
const initSpy: Spy = spyOn(exerciseService, 'initH5P').and.returnValue(Promise.resolve()); const initSpy: Spy = spyOn(exerciseService, 'initH5P').and.returnValue(Promise.resolve());
exerciseService.helperService.applicationState.next( exerciseService.loadExercise({}).then(() => {
exerciseService.helperService.deepCopy(MockMC.applicationState) as ApplicationState); }, () => {
let ep: ExerciseParams = {eid: 'eid'}; expect(initSpy).toHaveBeenCalledTimes(0);
exerciseService.loadExercise(ep).then(() => { const ar: AnnisResponse = {exercise_type: MoodleExerciseType.cloze.toString()};
expect(initSpy).toHaveBeenCalledTimes(1); const getSpy: Spy = spyOn(exerciseService.helperService, 'makeGetRequest').and.returnValue(Promise.resolve(ar));
getSpy.and.callFake(() => Promise.reject()); exerciseService.helperService.applicationState.next(
exerciseService.helperService.deepCopy(MockMC.applicationState) as ApplicationState);
let ep: ExerciseParams = {eid: 'eid'};
exerciseService.loadExercise(ep).then(() => { exerciseService.loadExercise(ep).then(() => {
}, () => {
expect(initSpy).toHaveBeenCalledTimes(1); expect(initSpy).toHaveBeenCalledTimes(1);
ep = {file: '', type: ''}; getSpy.and.callFake(() => Promise.reject());
exerciseService.loadExercise(ep).then(() => { exerciseService.loadExercise(ep).then(() => {
ep = {file: '', type: ExerciseTypePath.VocList}; }, () => {
expect(initSpy).toHaveBeenCalledTimes(1);
ep = {file: '', type: '', language: LanguageShortcut.English, showActions: true};
exerciseService.loadExercise(ep).then(() => { exerciseService.loadExercise(ep).then(() => {
expect(initSpy).toHaveBeenCalledTimes(3); ep = {file: '', type: ExerciseTypePath.VocList};
done(); exerciseService.loadExercise(ep).then(() => {
expect(initSpy).toHaveBeenCalledTimes(3);
done();
});
}); });
}); });
}); });
}); });
}); });
it('should load an exercise from query params', (done) => {
const loadSpy: Spy = spyOn(exerciseService, 'loadExercise').and.returnValue(Promise.resolve());
const activatedRoute: ActivatedRoute = {queryParams: of({})} as ActivatedRoute;
exerciseService.loadExerciseFromQueryParams(activatedRoute).then(() => {
loadSpy.and.callFake(() => Promise.reject());
exerciseService.loadExerciseFromQueryParams(activatedRoute).then(() => {}, () => {
expect(loadSpy).toHaveBeenCalledTimes(2);
done();
});
});
});
it('should load H5P', (done) => { it('should load H5P', (done) => {
const initSpy: Spy = spyOn(exerciseService, 'initH5P').and.returnValue(Promise.resolve()); const initSpy: Spy = spyOn(exerciseService, 'initH5P').and.returnValue(Promise.resolve());
exerciseService.corpusService.exercise.type = ExerciseType.markWords; exerciseService.corpusService.exercise.type = ExerciseType.markWords;
exerciseService.loadH5P('').then(() => { exerciseService.loadH5P('').then(() => {
expect(initSpy).toHaveBeenCalledTimes(1); expect(initSpy).toHaveBeenCalledTimes(1);
done(); exerciseService.excludeOOV = true;
exerciseService.corpusService.currentSolutions = [];
exerciseService.loadH5P('').then(() => {
expect(initSpy).toHaveBeenCalledTimes(2);
done();
});
}); });
}); });
...@@ -214,6 +249,12 @@ describe('ExerciseService', () => { ...@@ -214,6 +249,12 @@ describe('ExerciseService', () => {
.withArgs(exerciseService.embedTextAreaString).and.returnValue(textarea); .withArgs(exerciseService.embedTextAreaString).and.returnValue(textarea);
getSpy.withArgs(exerciseService.embedSizeInputString, true).and.returnValue(inputs); getSpy.withArgs(exerciseService.embedSizeInputString, true).and.returnValue(inputs);
exerciseService.corpusService.annisResponse = {exercise_type: MoodleExerciseType.cloze.toString()}; exerciseService.corpusService.annisResponse = {exercise_type: MoodleExerciseType.cloze.toString()};
exerciseService.currentExerciseParams = {eid: ''};
exerciseService.updateEmbedUrl();
expect(textarea.innerHTML).toBeTruthy();
textarea.innerHTML = '';
expect(textarea.innerHTML).toBeFalsy();
exerciseService.currentExerciseParams = {eid: 'eid'};
exerciseService.updateEmbedUrl(); exerciseService.updateEmbedUrl();
expect(textarea.innerHTML).toBeTruthy(); expect(textarea.innerHTML).toBeTruthy();
}); });
......
...@@ -3,9 +3,9 @@ import {Injectable} from '@angular/core'; ...@@ -3,9 +3,9 @@ import {Injectable} from '@angular/core';
import configMC from '../configMC'; import configMC from '../configMC';
import {HelperService} from './helper.service'; import {HelperService} from './helper.service';
import {ExercisePart} from './models/exercisePart'; import {ExercisePart} from './models/exercisePart';
import {EventMC, ExerciseType, MoodleExerciseType} from './models/enum'; import {EventMC, ExerciseType, LanguageShortcut, MoodleExerciseType} from './models/enum';
import {HttpClient, HttpParams} from '@angular/common/http'; import {HttpClient, HttpParams} from '@angular/common/http';
import {AnnisResponse, ExerciseTypePath, H5PForm} from '../../openapi'; import {AnnisResponse, ExerciseTypePath, H5PForm, Solution} from '../../openapi';
import {take} from 'rxjs/operators'; import {take} from 'rxjs/operators';
import {ApplicationState} from './models/applicationState'; import {ApplicationState} from './models/applicationState';
import {ToastController} from '@ionic/angular'; import {ToastController} from '@ionic/angular';
...@@ -14,6 +14,7 @@ import {TranslateService} from '@ngx-translate/core'; ...@@ -14,6 +14,7 @@ import {TranslateService} from '@ngx-translate/core';
import {Storage} from '@ionic/storage'; import {Storage} from '@ionic/storage';
import {ExerciseParams} from './models/exerciseParams'; import {ExerciseParams} from './models/exerciseParams';
import {DisplayOptions, Options} from './models/h5pStandalone'; import {DisplayOptions, Options} from './models/h5pStandalone';
import {ActivatedRoute} from '@angular/router';
declare var H5PStandalone: any; declare var H5PStandalone: any;
...@@ -38,9 +39,12 @@ export class ExerciseService { ...@@ -38,9 +39,12 @@ export class ExerciseService {
''; '';
} }
public currentExerciseLanguage: string | LanguageShortcut;
public currentExerciseName: string; public currentExerciseName: string;
public currentExerciseParams: ExerciseParams;
public currentExercisePartIndex: number; public currentExercisePartIndex: number;
public currentExerciseParts: ExercisePart[] = []; public currentExerciseParts: ExercisePart[] = [];
public currentExerciseTypePath: ExerciseTypePath;
public displayOptions: DisplayOptions = { // Customise the look of the H5P public displayOptions: DisplayOptions = { // Customise the look of the H5P
frame: true, frame: true,
copyright: true, copyright: true,
...@@ -56,7 +60,9 @@ export class ExerciseService { ...@@ -56,7 +60,9 @@ export class ExerciseService {
public excludeOOV = false; public excludeOOV = false;
public h5pContainerString = '.h5p-container'; public h5pContainerString = '.h5p-container';
public h5pIframeString = '.h5p-iframe'; public h5pIframeString = '.h5p-iframe';
public h5pPathLocal = 'assets/h5p';
public kwicGraphs: string; public kwicGraphs: string;
public nonH5Pstring = 'nonH5P';
public options: Options = { public options: Options = {
frameCss: 'assets/h5p-standalone-master/dist/styles/h5p.css', frameCss: 'assets/h5p-standalone-master/dist/styles/h5p.css',
frameJs: 'assets/h5p-standalone-master/dist/frame.bundle.js', frameJs: 'assets/h5p-standalone-master/dist/frame.bundle.js',
...@@ -108,15 +114,12 @@ export class ExerciseService { ...@@ -108,15 +114,12 @@ export class ExerciseService {
downloadH5Pexercise(): Promise<void> { downloadH5Pexercise(): Promise<void> {
return new Promise<void>((resolve, reject) => { return new Promise<void>((resolve, reject) => {
const url = `${configMC.backendBaseUrl}${configMC.backendApiH5pPath}`; const url = `${configMC.backendBaseUrl}${configMC.backendApiH5pPath}`;
const indices: number[] = this.corpusService.currentSolutions.map( const indices: number[] = this.corpusService.currentSolutions ? this.corpusService.currentSolutions.map(
x => this.corpusService.annisResponse.solutions.indexOf(x)); x => this.corpusService.annisResponse.solutions.indexOf(x)) : [];
const exerciseTypePath: ExerciseTypePath =
this.corpusService.exercise.type === ExerciseType.markWords ?
ExerciseTypePath.MarkWords : ExerciseTypePath.DragText;
const h5pForm: H5PForm = { const h5pForm: H5PForm = {
eid: this.corpusService.annisResponse.exercise_id, eid: this.corpusService.annisResponse.exercise_id,
exercise_type_path: exerciseTypePath, exercise_type_path: this.currentExerciseTypePath,
lang: this.translateService.currentLang, lang: this.currentExerciseLanguage.toString(),
solution_indices: indices solution_indices: indices
}; };
const formData: FormData = new FormData(); const formData: FormData = new FormData();
...@@ -125,7 +128,7 @@ export class ExerciseService { ...@@ -125,7 +128,7 @@ export class ExerciseService {
const errorMsg: string = HelperService.generalErrorAlertMessage; const errorMsg: string = HelperService.generalErrorAlertMessage;
this.helperService.makePostRequest(this.http, this.toastCtrl, url, formData, errorMsg, options) this.helperService.makePostRequest(this.http, this.toastCtrl, url, formData, errorMsg, options)
.then((result: Blob) => { .then((result: Blob) => {
const fileName = exerciseTypePath + '.h5p'; const fileName = this.currentExerciseTypePath + '.h5p';
this.downloadBlobAsFile(result, fileName); this.downloadBlobAsFile(result, fileName);
return resolve(); return resolve();
}, () => { }, () => {
...@@ -147,10 +150,18 @@ export class ExerciseService { ...@@ -147,10 +150,18 @@ export class ExerciseService {
return document.querySelector(this.h5pIframeString); return document.querySelector(this.h5pIframeString);
} }
initH5P(exerciseTypePath: string, showActions: boolean = true): Promise<void> { getSolutionIndices(solutions: Solution[]): string {
const indices: string[] =
solutions.map(x => this.corpusService.annisResponse.solutions.indexOf(x).toString());
return '&solution_indices=' + indices.join(',');
}
initH5P(exerciseTypePath: ExerciseTypePath | string, url: string, showActions: boolean = true): Promise<void> {
return new Promise((resolve) => { return new Promise((resolve) => {
this.setH5Purl(url);
this.currentExerciseTypePath = exerciseTypePath as ExerciseTypePath;
const el: HTMLDivElement = document.querySelector(this.h5pContainerString); const el: HTMLDivElement = document.querySelector(this.h5pContainerString);
const h5pLocation = 'assets/h5p/' + exerciseTypePath; const h5pLocation = this.h5pPathLocal + '/' + exerciseTypePath;
const displayOptions: DisplayOptions = this.helperService.deepCopy(this.displayOptions); const displayOptions: DisplayOptions = this.helperService.deepCopy(this.displayOptions);
if (!showActions) { if (!showActions) {
displayOptions.embed = false; displayOptions.embed = false;
...@@ -169,6 +180,12 @@ export class ExerciseService { ...@@ -169,6 +180,12 @@ export class ExerciseService {
loadExercise(params: ExerciseParams): Promise<void> { loadExercise(params: ExerciseParams): Promise<void> {
return new Promise<void>((resolve, reject) => { return new Promise<void>((resolve, reject) => {
if (!Object.keys(params).length) {
return reject();