Skip to content

Commit

Permalink
fix: initialise SCORM API wrapper before iframe loads
Browse files Browse the repository at this point in the history
  • Loading branch information
satikaj committed Apr 30, 2024
1 parent bb9b660 commit e8dab06
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions src/app/common/numbas-component/numbas-component.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog';
import { DomSanitizer, SafeResourceUrl } from '@angular/platform-browser';
import { Task } from 'src/app/api/models/task';
import { NumbasLmsService } from 'src/app/api/services/numbas-lms.service';
import { UserService } from 'src/app/api/services/user.service';
import { AppInjector } from 'src/app/app-injector';
import { DoubtfireConstants } from 'src/app/config/constants/doubtfire-constants';

Expand All @@ -25,19 +24,13 @@ export class NumbasComponent implements OnInit {
private dialogRef: MatDialogRef<NumbasComponent>,
@Inject(MAT_DIALOG_DATA) public data: { task: Task, mode: 'attempt' | 'review' },
private lmsService: NumbasLmsService,
private userService: UserService,
private sanitizer: DomSanitizer
) {}

ngOnInit(): void {
this.task = this.data.task;
this.lmsService.setTask(this.task);

this.currentMode = this.data.mode;

const user = this.userService.currentUser;
this.iframeSrc = this.sanitizer.bypassSecurityTrustResourceUrl(`${AppInjector.get(DoubtfireConstants).API_URL}/numbas_api/${this.task.taskDefId}/${user.authenticationToken}/${user.username}/index.html`);

window.API_1484_11 = {
Initialize: () => this.lmsService.Initialize(this.currentMode),
Terminate: () => this.lmsService.Terminate(),
Expand All @@ -48,6 +41,10 @@ export class NumbasComponent implements OnInit {
GetErrorString: (errorCode: string) => this.lmsService.GetErrorString(errorCode),
GetDiagnostic: (errorCode: string) => this.lmsService.GetDiagnostic(errorCode)
};

this.currentMode = this.data.mode;

this.iframeSrc = this.sanitizer.bypassSecurityTrustResourceUrl(`${AppInjector.get(DoubtfireConstants).API_URL}/numbas_api/${this.task.taskDefId}/index.html`);
}

removeNumbasTest(): void {
Expand Down

0 comments on commit e8dab06

Please sign in to comment.