forked from doubtfire-lms/doubtfire-web
-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: enable reviewing, passing, deleting test attempts and add test …
…attempt model and service
- Loading branch information
Showing
12 changed files
with
259 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import {Task, TaskComment, TestAttempt} from '../doubtfire-model'; | ||
|
||
export class ScormComment extends TaskComment { | ||
testAttempt: TestAttempt; | ||
|
||
constructor(task: Task) { | ||
super(task); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import {Entity} from 'ngx-entity-service'; | ||
import {Task} from './doubtfire-model'; | ||
|
||
export class TestAttempt extends Entity { | ||
id: number; | ||
attemptNumber: number; | ||
terminated: boolean; | ||
completionStatus: boolean; | ||
successStatus: boolean; | ||
scoreScaled: number; | ||
cmiDatamodel: string; | ||
attemptedTime: Date; | ||
|
||
task: Task; | ||
|
||
constructor(task: Task) { | ||
super(); | ||
this.task = task; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
import {Injectable} from '@angular/core'; | ||
import {CachedEntityService} from 'ngx-entity-service'; | ||
import API_URL from 'src/app/config/constants/apiURL'; | ||
import {Task, TestAttempt} from 'src/app/api/models/doubtfire-model'; | ||
import {Observable} from 'rxjs'; | ||
import {AppInjector} from 'src/app/app-injector'; | ||
import {DoubtfireConstants} from 'src/app/config/constants/doubtfire-constants'; | ||
import {AlertService} from 'src/app/common/services/alert.service'; | ||
import {HttpClient} from '@angular/common/http'; | ||
|
||
@Injectable() | ||
export class TestAttemptService extends CachedEntityService<TestAttempt> { | ||
protected readonly endpointFormat = 'test_attempts/:id:'; | ||
protected readonly forTaskEndpoint = | ||
'/projects/:project_id:/task_definition_id/:task_def_id:/test_attempts'; | ||
protected readonly latestCompletedEndpoint = | ||
this.forTaskEndpoint + '/latest?completed=:completed:'; | ||
|
||
constructor(httpClient: HttpClient) { | ||
super(httpClient, API_URL); | ||
|
||
this.mapping.addKeys( | ||
'id', | ||
'attemptNumber', | ||
'terminated', | ||
'completionStatus', | ||
'successStatus', | ||
'scoreScaled', | ||
'cmiDatamodel', | ||
'attemptedTime', | ||
); | ||
} | ||
|
||
public override createInstanceFrom(_json: object, constructorParams: Task): TestAttempt { | ||
return new TestAttempt(constructorParams); | ||
} | ||
|
||
public getAttemptsForTask(task: Task): Observable<TestAttempt[]> { | ||
return this.query( | ||
{ | ||
project_id: task.project.id, | ||
task_def_id: task.taskDefId, | ||
}, | ||
{ | ||
endpointFormat: this.forTaskEndpoint, | ||
constructorParams: task, | ||
}, | ||
); | ||
} | ||
|
||
public getLatestCompletedAttempt(task: Task): Observable<TestAttempt> { | ||
return this.get( | ||
{ | ||
project_id: task.project.id, | ||
task_def_id: task.taskDefId, | ||
completed: true, | ||
}, | ||
{ | ||
endpointFormat: this.latestCompletedEndpoint, | ||
constructorParams: task, | ||
}, | ||
); | ||
} | ||
|
||
public overrideSuccessStatus(testAttemptId: number, successStatus: boolean): void { | ||
const http = AppInjector.get(HttpClient); | ||
|
||
http | ||
.patch( | ||
`${AppInjector.get(DoubtfireConstants).API_URL}/test_attempts/${testAttemptId}?success_status=${successStatus}`, | ||
{}, | ||
) | ||
.subscribe({ | ||
next: (_data) => { | ||
(AppInjector.get(AlertService) as AlertService).success( | ||
'Attempt pass status successfully overridden.', | ||
6000, | ||
); | ||
}, | ||
error: (message) => { | ||
(AppInjector.get(AlertService) as AlertService).error(message, 6000); | ||
}, | ||
}); | ||
} | ||
|
||
public deleteAttempt(testAttemptId: number): void { | ||
const http = AppInjector.get(HttpClient); | ||
|
||
http | ||
.delete(`${AppInjector.get(DoubtfireConstants).API_URL}/test_attempts/${testAttemptId}`, {}) | ||
.subscribe({ | ||
next: (_data) => { | ||
(AppInjector.get(AlertService) as AlertService).success( | ||
'Attempt successfully deleted.', | ||
6000, | ||
); | ||
}, | ||
error: (message) => { | ||
(AppInjector.get(AlertService) as AlertService).error(message, 6000); | ||
}, | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 7 additions & 4 deletions
11
src/app/tasks/task-comments-viewer/scorm-comment/scorm-comment.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.