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.
Merge pull request doubtfire-lms#877 from doubtfire-lms/new/scorm
New/scorm
- Loading branch information
Showing
48 changed files
with
1,841 additions
and
55 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
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,6 @@ | ||
{ | ||
"/api": { | ||
"target": "http://localhost:3000", | ||
"secure": false | ||
} | ||
} |
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,50 @@ | ||
export class ScormDataModel { | ||
dataModel: {[key: string]: any} = {}; | ||
readonly msgPrefix = 'SCORM DataModel: '; | ||
|
||
constructor() { | ||
this.dataModel = {}; | ||
} | ||
|
||
public restore(dataModel: string) { | ||
// console.log(this.msgPrefix + 'restoring DataModel with provided data'); | ||
this.dataModel = JSON.parse(dataModel); | ||
} | ||
|
||
public get(key: string): string { | ||
// console.log(`SCORM DataModel: get ${key} ${this.dataModel[key]}`); | ||
return this.dataModel[key] ?? ''; | ||
} | ||
|
||
public dump(): {[key: string]: any} { | ||
return this.dataModel; | ||
} | ||
|
||
public set(key: string, value: any): string { | ||
// console.log(this.msgPrefix + 'set: ', key, value); | ||
this.dataModel[key] = value; | ||
if (key.match('cmi.interactions.\\d+.id')) { | ||
// cmi.interactions._count must be incremented after a new interaction is created | ||
const interactionPath = key.match('cmi.interactions.\\d+'); | ||
const objectivesCounterForInteraction = interactionPath.toString() + '.objectives._count'; | ||
// console.log('Incrementing cmi.interactions._count'); | ||
this.dataModel['cmi.interactions._count']++; | ||
// cmi.interactions.n.objectives._count must be initialized after an interaction is created | ||
// console.log(`Initializing ${objectivesCounterForInteraction}`); | ||
this.dataModel[objectivesCounterForInteraction] = 0; | ||
} | ||
if (key.match('cmi.interactions.\\d+.objectives.\\d+.id')) { | ||
const interactionPath = key.match('cmi.interactions.\\d+.objectives'); | ||
const objectivesCounterForInteraction = interactionPath.toString() + '._count'; | ||
// cmi.interactions.n.objectives._count must be incremented after objective creation | ||
// console.log(`Incrementing ${objectivesCounterForInteraction}`); | ||
this.dataModel[objectivesCounterForInteraction.toString()]++; | ||
} | ||
if (key.match('cmi.objectives.\\d+.id')) { | ||
// cmi.objectives._count must be incremented after a new objective is created | ||
// console.log('Incrementing cmi.objectives._count'); | ||
this.dataModel['cmi.objectives._count']++; | ||
} | ||
return 'true'; | ||
} | ||
} |
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,66 @@ | ||
import {User} from 'src/app/api/models/doubtfire-model'; | ||
|
||
type DataModelState = 'Uninitialized' | 'Initialized' | 'Terminated'; | ||
|
||
type DataModelError = Record<number, string>; | ||
const CMIErrorCodes: DataModelError = { | ||
0: 'No Error', | ||
101: 'General Exception', | ||
102: 'General Initialization Failure', | ||
103: 'Already Initialized', | ||
104: 'Content Instance Terminated', | ||
111: 'General Termination Failure', | ||
112: 'Termination Before Initialization', | ||
113: 'Termination After Termination', | ||
122: 'Retrieve Data Before Initialization', | ||
123: 'Retrieve Data After Termination', | ||
132: 'Store Data Before Initialization', | ||
133: 'Store Data After Termination', | ||
142: 'Commit Before Initialization', | ||
143: 'Commit After Termination', | ||
201: 'General Argument Error', | ||
301: 'General Get Failure', | ||
351: 'General Set Failure', | ||
391: 'General Commit Failure', | ||
401: 'Undefined Data Model Element', | ||
402: 'Unimplemented Data Model Element', | ||
403: 'Data Model Element Value Not Initialized', | ||
404: 'Data Model Element Is Read Only', | ||
405: 'Data Model Element Is Write Only', | ||
406: 'Data Model Element Type Mismatch', | ||
407: 'Data Model Element Value Out Of Range', | ||
408: 'Data Model Dependency Not Established', | ||
}; | ||
|
||
export class ScormPlayerContext { | ||
mode: 'browse' | 'normal' | 'review' | 'preview'; | ||
state: DataModelState; | ||
|
||
private _errorCode: number; | ||
get errorCode() { | ||
return this._errorCode; | ||
} | ||
set errorCode(value: number) { | ||
this._errorCode = value; | ||
} | ||
|
||
getErrorMessage(value: string): string { | ||
return CMIErrorCodes[value]; | ||
} | ||
|
||
projectId: number; | ||
taskDefId: number; | ||
user: User; | ||
|
||
attemptId: number; | ||
learnerName: string; | ||
learnerId: number; | ||
|
||
constructor(user: User) { | ||
this.user = user; | ||
this.learnerId = user.id; | ||
this.learnerName = user.firstName + ' ' + user.lastName; | ||
this.state = 'Uninitialized'; | ||
this.errorCode = 0; | ||
} | ||
} |
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,12 @@ | ||
import {Task, TaskComment, TestAttempt} from '../doubtfire-model'; | ||
|
||
export class ScormComment extends TaskComment { | ||
testAttempt: TestAttempt; | ||
|
||
// UI rendering data | ||
lastInScormSeries: boolean = false; | ||
|
||
constructor(task: Task) { | ||
super(task); | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
src/app/api/models/task-comment/scorm-extension-comment.ts
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,33 @@ | ||
import {Observable} from 'rxjs'; | ||
import {tap} from 'rxjs/operators'; | ||
import {AppInjector} from 'src/app/app-injector'; | ||
import {TaskCommentService} from '../../services/task-comment.service'; | ||
import {TaskComment, Task} from '../doubtfire-model'; | ||
|
||
export class ScormExtensionComment extends TaskComment { | ||
assessed: boolean; | ||
granted: boolean; | ||
dateAssessed: Date; | ||
taskScormExtensions: number; | ||
|
||
constructor(task: Task) { | ||
super(task); | ||
} | ||
|
||
private assessScormExtension(): Observable<TaskComment> { | ||
const tcs: TaskCommentService = AppInjector.get(TaskCommentService); | ||
return tcs.assessScormExtension(this).pipe( | ||
tap((tc: TaskComment) => { | ||
const scormExtension: ScormExtensionComment = tc as ScormExtensionComment; | ||
|
||
const task = tc.task; | ||
task.scormExtensions = scormExtension.taskScormExtensions; | ||
}), | ||
); | ||
} | ||
|
||
public grant(): Observable<TaskComment> { | ||
this.granted = true; | ||
return this.assessScormExtension(); | ||
} | ||
} |
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
Oops, something went wrong.