Skip to content

Commit

Permalink
refactor: change url params for test attempts
Browse files Browse the repository at this point in the history
  • Loading branch information
satikaj committed Jun 1, 2024
1 parent 8a80ae2 commit 0771468
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 29 deletions.
3 changes: 2 additions & 1 deletion src/app/api/models/scorm-player-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ export class ScormPlayerContext {
return CMIErrorCodes[value];
}

taskId: number;
projectId: number;
taskDefId: number;
user: User;

attemptNumber: number;
Expand Down
39 changes: 19 additions & 20 deletions src/app/api/services/scorm-adapter.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {ScormDataModel, ScormPlayerContext} from 'src/app/api/models/doubtfire-m
providedIn: 'root',
})
export class ScormAdapterService {
private readonly apiBaseUrl = `${API_URL}/test_attempts`;
private dataModel: ScormDataModel;
private context: ScormPlayerContext;
private xhr: XMLHttpRequest;
Expand All @@ -18,8 +17,12 @@ export class ScormAdapterService {
this.xhr = new XMLHttpRequest();
}

set taskId(taskId: number) {
this.context.taskId = taskId;
set projectId(projectId: number) {
this.context.projectId = projectId;
}

set taskDefId(taskDefId: number) {
this.context.taskDefId = taskDefId;
}

set mode(mode: 'browse' | 'normal' | 'review') {
Expand Down Expand Up @@ -51,7 +54,11 @@ export class ScormAdapterService {
}

// TODO: move this part into the player component
this.xhr.open('GET', `${this.apiBaseUrl}/${this.context.taskId}/latest`, false);
this.xhr.open(
'GET',
`${API_URL}/projects/${this.context.projectId}/task_def_id/${this.context.taskDefId}/test_attempts/latest`,
false,
);

let noTestFound = false;
let startNewTest = false;
Expand Down Expand Up @@ -82,11 +89,7 @@ export class ScormAdapterService {
}

if (!startNewTest) {
this.xhr.open(
'PATCH',
`${this.apiBaseUrl}/${this.context.taskId}/session/${this.context.attemptId}`,
false,
);
this.xhr.open('PATCH', `${API_URL}/test_attempts/${this.context.attemptId}`, false);
this.xhr.send();
console.log(this.xhr.responseText);

Expand All @@ -96,7 +99,11 @@ export class ScormAdapterService {
this.dataModel.restore(currentSession.cmi_datamodel);
console.log(this.dataModel.dump());
} else {
this.xhr.open('POST', `${this.apiBaseUrl}/${this.context.taskId}/session`, false);
this.xhr.open(
'POST',
`${API_URL}/projects/${this.context.projectId}/task_def_id/${this.context.taskDefId}/test_attempts`,
false,
);
this.xhr.send();
console.log(this.xhr.responseText);

Expand Down Expand Up @@ -126,11 +133,7 @@ export class ScormAdapterService {
break;
}

this.xhr.open(
'PATCH',
`${this.apiBaseUrl}/${this.context.taskId}/session/${this.context.attemptId}`,
false,
);
this.xhr.open('PATCH', `${API_URL}/test_attempts/${this.context.attemptId}`, false);
this.xhr.setRequestHeader('Content-Type', 'application/json');
const requestData = {
cmi_datamodel: JSON.stringify(this.dataModel.dump()),
Expand Down Expand Up @@ -202,11 +205,7 @@ export class ScormAdapterService {
}

const xhr = new XMLHttpRequest();
xhr.open(
'PATCH',
`${this.apiBaseUrl}/${this.context.taskId}/session/${this.context.attemptId}`,
true,
);
xhr.open('PATCH', `${API_URL}/test_attempts/${this.context.attemptId}`, true);
xhr.setRequestHeader('Content-Type', 'application/json');
const requestData = {
cmi_datamodel: JSON.stringify(this.dataModel.dump()),
Expand Down
5 changes: 3 additions & 2 deletions src/app/common/scorm-player/scorm-player.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export class ScormPlayerComponent implements OnInit {
context: ScormPlayerContext;

@Input()
taskId: number;
projectId: number;

@Input()
taskDefId: number;
Expand All @@ -41,7 +41,8 @@ export class ScormPlayerComponent implements OnInit {
this.globalState.setView(ViewType.OTHER);
this.globalState.hideHeader();

this.scormAdapter.taskId = this.taskId;
this.scormAdapter.projectId = this.projectId;
this.scormAdapter.taskDefId = this.taskDefId;
this.scormAdapter.mode = this.mode;

window.API_1484_11 = {
Expand Down
8 changes: 4 additions & 4 deletions src/app/doubtfire.states.ts
Original file line number Diff line number Diff line change
Expand Up @@ -298,13 +298,13 @@ const ViewAllUnits: NgHybridStateDeclaration = {
*/
const ScormPlayerState: NgHybridStateDeclaration = {
name: 'scorm-player',
url: '/task_def/:task_def_id/task/:task_id/scorm-player/:mode',
url: '/projects/:project_id/task_def_id/:task_definition_id/scorm-player/:mode',
resolve: {
taskId: function ($stateParams) {
return $stateParams.task_id;
projectId: function ($stateParams) {
return $stateParams.project_id;
},
taskDefId: function ($stateParams) {
return $stateParams.task_def_id;
return $stateParams.task_definition_id;
},
mode: function ($stateParams) {
return $stateParams.mode;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ export class TaskScormCardComponent implements OnInit {
}

launchScormPlayer(): void {
window.open(`#/task_def/${this.task.taskDefId}/task/${this.task.id}/scorm-player/normal`, '_blank');
window.open(
`#/projects/${this.task.project.id}/task_def_id/${this.task.taskDefId}/scorm-player/normal`,
'_blank',
);
}

requestMoreAttempts(): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ export class ScormCommentComponent implements OnInit {
ngOnInit() {}

reviewScormTest() {
window.open(`#/task_def/${this.task.taskDefId}/task/${this.task.id}/scorm-player/review`, '_blank');
window.open(
`#/projects/${this.task.project.id}/task_def_id/${this.task.taskDefId}/scorm-player/review`,
'_blank',
);
}
}

0 comments on commit 0771468

Please sign in to comment.