scorm-again 1.7.1 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.babelrc +18 -7
- package/.github/dependabot.yml +5 -0
- package/.github/workflows/main.yml +79 -0
- package/.github/workflows/stale.yml +14 -0
- package/.jsdoc.json +4 -5
- package/.mocharc.json +8 -0
- package/.run/{Mocha Unit Tests.run.xml → Mocha Unit Tests (watch).run.xml } +6 -3
- package/.run/Template Mocha.run.xml +17 -0
- package/CONTRIBUTING.md +1 -1
- package/README.md +183 -71
- package/dist/aicc.js +3822 -7030
- package/dist/aicc.js.map +1 -1
- package/dist/aicc.min.js +2 -40
- package/dist/aicc.min.js.map +1 -0
- package/dist/scorm-again.js +5965 -10498
- package/dist/scorm-again.js.map +1 -1
- package/dist/scorm-again.min.js +2 -52
- package/dist/scorm-again.min.js.map +1 -0
- package/dist/scorm12.js +3028 -5373
- package/dist/scorm12.js.map +1 -1
- package/dist/scorm12.min.js +2 -34
- package/dist/scorm12.min.js.map +1 -0
- package/dist/scorm2004.js +4054 -6693
- package/dist/scorm2004.js.map +1 -1
- package/dist/scorm2004.min.js +2 -40
- package/dist/scorm2004.min.js.map +1 -0
- package/eslint.config.js +21 -0
- package/package.json +76 -34
- package/results.json +34254 -0
- package/src/AICC.ts +72 -0
- package/src/BaseAPI.ts +1300 -0
- package/src/Scorm12API.ts +387 -0
- package/src/Scorm2004API.ts +688 -0
- package/src/cmi/aicc/attempts.ts +94 -0
- package/src/cmi/aicc/cmi.ts +100 -0
- package/src/cmi/aicc/core.ts +360 -0
- package/src/cmi/aicc/evaluation.ts +157 -0
- package/src/cmi/aicc/paths.ts +180 -0
- package/src/cmi/aicc/student_data.ts +86 -0
- package/src/cmi/aicc/student_demographics.ts +367 -0
- package/src/cmi/aicc/student_preferences.ts +176 -0
- package/src/cmi/aicc/tries.ts +116 -0
- package/src/cmi/aicc/validation.ts +25 -0
- package/src/cmi/common/array.ts +77 -0
- package/src/cmi/common/base_cmi.ts +46 -0
- package/src/cmi/common/score.ts +203 -0
- package/src/cmi/common/validation.ts +60 -0
- package/src/cmi/scorm12/cmi.ts +224 -0
- package/src/cmi/scorm12/interactions.ts +368 -0
- package/src/cmi/scorm12/nav.ts +54 -0
- package/src/cmi/scorm12/objectives.ts +112 -0
- package/src/cmi/scorm12/student_data.ts +130 -0
- package/src/cmi/scorm12/student_preference.ts +158 -0
- package/src/cmi/scorm12/validation.ts +48 -0
- package/src/cmi/scorm2004/adl.ts +272 -0
- package/src/cmi/scorm2004/cmi.ts +599 -0
- package/src/cmi/scorm2004/comments.ts +163 -0
- package/src/cmi/scorm2004/interactions.ts +466 -0
- package/src/cmi/scorm2004/learner_preference.ts +152 -0
- package/src/cmi/scorm2004/objectives.ts +212 -0
- package/src/cmi/scorm2004/score.ts +78 -0
- package/src/cmi/scorm2004/validation.ts +42 -0
- package/src/constants/api_constants.ts +318 -0
- package/src/constants/default_settings.ts +81 -0
- package/src/constants/enums.ts +5 -0
- package/src/constants/error_codes.ts +88 -0
- package/src/constants/language_constants.ts +394 -0
- package/src/constants/regex.ts +97 -0
- package/src/constants/{response_constants.js → response_constants.ts} +69 -62
- package/src/exceptions.ts +154 -0
- package/src/exports/aicc.js +1 -1
- package/src/exports/scorm-again.js +3 -3
- package/src/exports/scorm12.js +1 -1
- package/src/exports/scorm2004.js +1 -1
- package/src/helpers/scheduled_commit.ts +42 -0
- package/src/interfaces/IBaseAPI.ts +35 -0
- package/src/types/api_types.ts +32 -0
- package/src/utilities/debounce.ts +31 -0
- package/src/utilities.ts +338 -0
- package/tea.yaml +6 -0
- package/test/{AICC.spec.js → AICC.spec.ts} +79 -71
- package/test/Scorm12API.spec.ts +833 -0
- package/test/Scorm2004API.spec.ts +1298 -0
- package/test/api_helpers.ts +176 -0
- package/test/cmi/aicc_cmi.spec.ts +845 -0
- package/test/cmi/{scorm12_cmi.spec.js → scorm12_cmi.spec.ts} +253 -271
- package/test/cmi/scorm2004_cmi.spec.ts +1031 -0
- package/test/cmi_helpers.ts +207 -0
- package/test/exceptions.spec.ts +79 -0
- package/test/field_values.ts +202 -0
- package/test/types/api_types.spec.ts +126 -0
- package/test/utilities/debounce.spec.ts +56 -0
- package/test/utilities.spec.ts +322 -0
- package/tsconfig.json +18 -0
- package/webpack.config.js +65 -0
- package/.circleci/config.yml +0 -99
- package/.codeclimate.yml +0 -7
- package/.eslintrc.js +0 -36
- package/src/.flowconfig +0 -11
- package/src/AICC.js +0 -68
- package/src/BaseAPI.js +0 -1275
- package/src/Scorm12API.js +0 -308
- package/src/Scorm2004API.js +0 -572
- package/src/cmi/aicc_cmi.js +0 -1141
- package/src/cmi/common.js +0 -328
- package/src/cmi/scorm12_cmi.js +0 -1312
- package/src/cmi/scorm2004_cmi.js +0 -1692
- package/src/constants/api_constants.js +0 -218
- package/src/constants/error_codes.js +0 -87
- package/src/constants/language_constants.js +0 -76
- package/src/constants/regex.js +0 -84
- package/src/exceptions.js +0 -104
- package/src/utilities.js +0 -242
- package/test/Scorm12API.spec.js +0 -528
- package/test/Scorm2004API.spec.js +0 -775
- package/test/abstract_classes.spec.js +0 -17
- package/test/api_helpers.js +0 -128
- package/test/cmi/aicc_cmi.spec.js +0 -684
- package/test/cmi/scorm2004_cmi.spec.js +0 -1066
- package/test/cmi_helpers.js +0 -161
- package/test/exceptions.spec.js +0 -71
- package/test/field_values.js +0 -353
- package/test/utilities.spec.js +0 -339
- package/webpack.js +0 -78
|
@@ -0,0 +1,599 @@
|
|
|
1
|
+
import APIConstants from "../../constants/api_constants";
|
|
2
|
+
import Regex from "../../constants/regex";
|
|
3
|
+
import ErrorCodes from "../../constants/error_codes";
|
|
4
|
+
import { Scorm2004ValidationError } from "../../exceptions";
|
|
5
|
+
import * as Util from "../../utilities";
|
|
6
|
+
import { BaseRootCMI } from "../common/base_cmi";
|
|
7
|
+
import { check2004ValidFormat, check2004ValidRange } from "./validation";
|
|
8
|
+
import { CMILearnerPreference } from "./learner_preference";
|
|
9
|
+
import { CMIInteractions } from "./interactions";
|
|
10
|
+
import { Scorm2004CMIScore } from "./score";
|
|
11
|
+
import { CMICommentsFromLearner, CMICommentsFromLMS } from "./comments";
|
|
12
|
+
import { CMIObjectives } from "./objectives";
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Class representing cmi object for SCORM 2004
|
|
16
|
+
*/
|
|
17
|
+
export class CMI extends BaseRootCMI {
|
|
18
|
+
/**
|
|
19
|
+
* Constructor for the SCORM 2004 cmi object
|
|
20
|
+
* @param {boolean} initialized
|
|
21
|
+
*/
|
|
22
|
+
constructor(initialized: boolean = false) {
|
|
23
|
+
super();
|
|
24
|
+
this.learner_preference = new CMILearnerPreference();
|
|
25
|
+
this.score = new Scorm2004CMIScore();
|
|
26
|
+
this.comments_from_learner = new CMICommentsFromLearner();
|
|
27
|
+
this.comments_from_lms = new CMICommentsFromLMS();
|
|
28
|
+
this.interactions = new CMIInteractions();
|
|
29
|
+
this.objectives = new CMIObjectives();
|
|
30
|
+
if (initialized) this.initialize();
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
public learner_preference: CMILearnerPreference;
|
|
34
|
+
public score: Scorm2004CMIScore;
|
|
35
|
+
public comments_from_learner: CMICommentsFromLearner;
|
|
36
|
+
public comments_from_lms: CMICommentsFromLMS;
|
|
37
|
+
public interactions: CMIInteractions;
|
|
38
|
+
public objectives: CMIObjectives;
|
|
39
|
+
|
|
40
|
+
private __version = "1.0";
|
|
41
|
+
private __children = APIConstants.scorm2004.cmi_children;
|
|
42
|
+
private _completion_status = "unknown";
|
|
43
|
+
private _completion_threshold = "";
|
|
44
|
+
private _credit = "credit";
|
|
45
|
+
private _entry = "";
|
|
46
|
+
private _exit = "";
|
|
47
|
+
private _launch_data = "";
|
|
48
|
+
private _learner_id = "";
|
|
49
|
+
private _learner_name = "";
|
|
50
|
+
private _location = "";
|
|
51
|
+
private _max_time_allowed = "";
|
|
52
|
+
private _mode = "normal";
|
|
53
|
+
private _progress_measure = "";
|
|
54
|
+
private _scaled_passing_score = "";
|
|
55
|
+
private _session_time = "PT0H0M0S";
|
|
56
|
+
private _success_status = "unknown";
|
|
57
|
+
private _suspend_data = "";
|
|
58
|
+
private _time_limit_action = "continue,no message";
|
|
59
|
+
private _total_time = "";
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Called when the API has been initialized after the CMI has been created
|
|
63
|
+
*/
|
|
64
|
+
initialize() {
|
|
65
|
+
super.initialize();
|
|
66
|
+
this.learner_preference?.initialize();
|
|
67
|
+
this.score?.initialize();
|
|
68
|
+
this.comments_from_learner?.initialize();
|
|
69
|
+
this.comments_from_lms?.initialize();
|
|
70
|
+
this.interactions?.initialize();
|
|
71
|
+
this.objectives?.initialize();
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Getter for __version
|
|
76
|
+
* @return {string}
|
|
77
|
+
* @private
|
|
78
|
+
*/
|
|
79
|
+
get _version(): string {
|
|
80
|
+
return this.__version;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Setter for __version. Just throws an error.
|
|
85
|
+
* @param {string} _version
|
|
86
|
+
* @private
|
|
87
|
+
*/
|
|
88
|
+
set _version(_version: string) {
|
|
89
|
+
throw new Scorm2004ValidationError(ErrorCodes.scorm2004.READ_ONLY_ELEMENT);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Getter for __children
|
|
94
|
+
* @return {string}
|
|
95
|
+
* @private
|
|
96
|
+
*/
|
|
97
|
+
get _children(): string {
|
|
98
|
+
return this.__children;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Setter for __children. Just throws an error.
|
|
103
|
+
* @param {number} _children
|
|
104
|
+
* @private
|
|
105
|
+
*/
|
|
106
|
+
set _children(_children: number) {
|
|
107
|
+
throw new Scorm2004ValidationError(ErrorCodes.scorm2004.READ_ONLY_ELEMENT);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Getter for _completion_status
|
|
112
|
+
* @return {string}
|
|
113
|
+
*/
|
|
114
|
+
get completion_status(): string {
|
|
115
|
+
return this._completion_status;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Setter for _completion_status
|
|
120
|
+
* @param {string} completion_status
|
|
121
|
+
*/
|
|
122
|
+
set completion_status(completion_status: string) {
|
|
123
|
+
if (check2004ValidFormat(completion_status, Regex.scorm2004.CMICStatus)) {
|
|
124
|
+
this._completion_status = completion_status;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Getter for _completion_threshold
|
|
130
|
+
* @return {string}
|
|
131
|
+
*/
|
|
132
|
+
get completion_threshold(): string {
|
|
133
|
+
return this._completion_threshold;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Setter for _completion_threshold. Can only be called before initialization.
|
|
138
|
+
* @param {string} completion_threshold
|
|
139
|
+
*/
|
|
140
|
+
set completion_threshold(completion_threshold: string) {
|
|
141
|
+
if (this.initialized) {
|
|
142
|
+
throw new Scorm2004ValidationError(
|
|
143
|
+
ErrorCodes.scorm2004.READ_ONLY_ELEMENT,
|
|
144
|
+
);
|
|
145
|
+
} else {
|
|
146
|
+
this._completion_threshold = completion_threshold;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Setter for _credit
|
|
152
|
+
* @return {string}
|
|
153
|
+
*/
|
|
154
|
+
get credit(): string {
|
|
155
|
+
return this._credit;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* Setter for _credit. Can only be called before initialization.
|
|
160
|
+
* @param {string} credit
|
|
161
|
+
*/
|
|
162
|
+
set credit(credit: string) {
|
|
163
|
+
if (this.initialized) {
|
|
164
|
+
throw new Scorm2004ValidationError(
|
|
165
|
+
ErrorCodes.scorm2004.READ_ONLY_ELEMENT,
|
|
166
|
+
);
|
|
167
|
+
} else {
|
|
168
|
+
this._credit = credit;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* Getter for _entry
|
|
174
|
+
* @return {string}
|
|
175
|
+
*/
|
|
176
|
+
get entry(): string {
|
|
177
|
+
return this._entry;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* Setter for _entry. Can only be called before initialization.
|
|
182
|
+
* @param {string} entry
|
|
183
|
+
*/
|
|
184
|
+
set entry(entry: string) {
|
|
185
|
+
if (this.initialized) {
|
|
186
|
+
throw new Scorm2004ValidationError(
|
|
187
|
+
ErrorCodes.scorm2004.READ_ONLY_ELEMENT,
|
|
188
|
+
);
|
|
189
|
+
} else {
|
|
190
|
+
this._entry = entry;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* Getter for _exit. Should only be called during JSON export.
|
|
196
|
+
* @return {string}
|
|
197
|
+
*/
|
|
198
|
+
get exit(): string {
|
|
199
|
+
if (!this.jsonString) {
|
|
200
|
+
throw new Scorm2004ValidationError(
|
|
201
|
+
ErrorCodes.scorm2004.WRITE_ONLY_ELEMENT,
|
|
202
|
+
);
|
|
203
|
+
}
|
|
204
|
+
return this._exit;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* Getter for _exit
|
|
209
|
+
* @param {string} exit
|
|
210
|
+
*/
|
|
211
|
+
set exit(exit: string) {
|
|
212
|
+
if (check2004ValidFormat(exit, Regex.scorm2004.CMIExit, true)) {
|
|
213
|
+
this._exit = exit;
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* Getter for _launch_data
|
|
219
|
+
* @return {string}
|
|
220
|
+
*/
|
|
221
|
+
get launch_data(): string {
|
|
222
|
+
return this._launch_data;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
/**
|
|
226
|
+
* Setter for _launch_data. Can only be called before initialization.
|
|
227
|
+
* @param {string} launch_data
|
|
228
|
+
*/
|
|
229
|
+
set launch_data(launch_data: string) {
|
|
230
|
+
if (this.initialized) {
|
|
231
|
+
throw new Scorm2004ValidationError(
|
|
232
|
+
ErrorCodes.scorm2004.READ_ONLY_ELEMENT,
|
|
233
|
+
);
|
|
234
|
+
} else {
|
|
235
|
+
this._launch_data = launch_data;
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
/**
|
|
240
|
+
* Getter for _learner_id
|
|
241
|
+
* @return {string}
|
|
242
|
+
*/
|
|
243
|
+
get learner_id(): string {
|
|
244
|
+
return this._learner_id;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
/**
|
|
248
|
+
* Setter for _learner_id. Can only be called before initialization.
|
|
249
|
+
* @param {string} learner_id
|
|
250
|
+
*/
|
|
251
|
+
set learner_id(learner_id: string) {
|
|
252
|
+
if (this.initialized) {
|
|
253
|
+
throw new Scorm2004ValidationError(
|
|
254
|
+
ErrorCodes.scorm2004.READ_ONLY_ELEMENT,
|
|
255
|
+
);
|
|
256
|
+
} else {
|
|
257
|
+
this._learner_id = learner_id;
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
/**
|
|
262
|
+
* Getter for _learner_name
|
|
263
|
+
* @return {string}
|
|
264
|
+
*/
|
|
265
|
+
get learner_name(): string {
|
|
266
|
+
return this._learner_name;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
/**
|
|
270
|
+
* Setter for _learner_name. Can only be called before initialization.
|
|
271
|
+
* @param {string} learner_name
|
|
272
|
+
*/
|
|
273
|
+
set learner_name(learner_name: string) {
|
|
274
|
+
if (this.initialized) {
|
|
275
|
+
throw new Scorm2004ValidationError(
|
|
276
|
+
ErrorCodes.scorm2004.READ_ONLY_ELEMENT,
|
|
277
|
+
);
|
|
278
|
+
} else {
|
|
279
|
+
this._learner_name = learner_name;
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
/**
|
|
284
|
+
* Getter for _location
|
|
285
|
+
* @return {string}
|
|
286
|
+
*/
|
|
287
|
+
get location(): string {
|
|
288
|
+
return this._location;
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
/**
|
|
292
|
+
* Setter for _location
|
|
293
|
+
* @param {string} location
|
|
294
|
+
*/
|
|
295
|
+
set location(location: string) {
|
|
296
|
+
if (check2004ValidFormat(location, Regex.scorm2004.CMIString1000)) {
|
|
297
|
+
this._location = location;
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
/**
|
|
302
|
+
* Getter for _max_time_allowed
|
|
303
|
+
* @return {string}
|
|
304
|
+
*/
|
|
305
|
+
get max_time_allowed(): string {
|
|
306
|
+
return this._max_time_allowed;
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
/**
|
|
310
|
+
* Setter for _max_time_allowed. Can only be called before initialization.
|
|
311
|
+
* @param {string} max_time_allowed
|
|
312
|
+
*/
|
|
313
|
+
set max_time_allowed(max_time_allowed: string) {
|
|
314
|
+
if (this.initialized) {
|
|
315
|
+
throw new Scorm2004ValidationError(
|
|
316
|
+
ErrorCodes.scorm2004.READ_ONLY_ELEMENT,
|
|
317
|
+
);
|
|
318
|
+
} else {
|
|
319
|
+
this._max_time_allowed = max_time_allowed;
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
/**
|
|
324
|
+
* Getter for _mode
|
|
325
|
+
* @return {string}
|
|
326
|
+
*/
|
|
327
|
+
get mode(): string {
|
|
328
|
+
return this._mode;
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
/**
|
|
332
|
+
* Setter for _mode. Can only be called before initialization.
|
|
333
|
+
* @param {string} mode
|
|
334
|
+
*/
|
|
335
|
+
set mode(mode: string) {
|
|
336
|
+
if (this.initialized) {
|
|
337
|
+
throw new Scorm2004ValidationError(
|
|
338
|
+
ErrorCodes.scorm2004.READ_ONLY_ELEMENT,
|
|
339
|
+
);
|
|
340
|
+
} else {
|
|
341
|
+
this._mode = mode;
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
/**
|
|
346
|
+
* Getter for _progress_measure
|
|
347
|
+
* @return {string}
|
|
348
|
+
*/
|
|
349
|
+
get progress_measure(): string {
|
|
350
|
+
return this._progress_measure;
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
/**
|
|
354
|
+
* Setter for _progress_measure
|
|
355
|
+
* @param {string} progress_measure
|
|
356
|
+
*/
|
|
357
|
+
set progress_measure(progress_measure: string) {
|
|
358
|
+
if (
|
|
359
|
+
check2004ValidFormat(progress_measure, Regex.scorm2004.CMIDecimal) &&
|
|
360
|
+
check2004ValidRange(progress_measure, Regex.scorm2004.progress_range)
|
|
361
|
+
) {
|
|
362
|
+
this._progress_measure = progress_measure;
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
/**
|
|
367
|
+
* Getter for _scaled_passing_score
|
|
368
|
+
* @return {string}
|
|
369
|
+
*/
|
|
370
|
+
get scaled_passing_score(): string {
|
|
371
|
+
return this._scaled_passing_score;
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
/**
|
|
375
|
+
* Setter for _scaled_passing_score. Can only be called before initialization.
|
|
376
|
+
* @param {string} scaled_passing_score
|
|
377
|
+
*/
|
|
378
|
+
set scaled_passing_score(scaled_passing_score: string) {
|
|
379
|
+
if (this.initialized) {
|
|
380
|
+
throw new Scorm2004ValidationError(
|
|
381
|
+
ErrorCodes.scorm2004.READ_ONLY_ELEMENT,
|
|
382
|
+
);
|
|
383
|
+
} else {
|
|
384
|
+
this._scaled_passing_score = scaled_passing_score;
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
/**
|
|
389
|
+
* Getter for _session_time. Should only be called during JSON export.
|
|
390
|
+
* @return {string}
|
|
391
|
+
*/
|
|
392
|
+
get session_time(): string {
|
|
393
|
+
if (!this.jsonString) {
|
|
394
|
+
throw new Scorm2004ValidationError(
|
|
395
|
+
ErrorCodes.scorm2004.WRITE_ONLY_ELEMENT,
|
|
396
|
+
);
|
|
397
|
+
}
|
|
398
|
+
return this._session_time;
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
/**
|
|
402
|
+
* Setter for _session_time
|
|
403
|
+
* @param {string} session_time
|
|
404
|
+
*/
|
|
405
|
+
set session_time(session_time: string) {
|
|
406
|
+
if (check2004ValidFormat(session_time, Regex.scorm2004.CMITimespan)) {
|
|
407
|
+
this._session_time = session_time;
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
/**
|
|
412
|
+
* Getter for _success_status
|
|
413
|
+
* @return {string}
|
|
414
|
+
*/
|
|
415
|
+
get success_status(): string {
|
|
416
|
+
return this._success_status;
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
/**
|
|
420
|
+
* Setter for _success_status
|
|
421
|
+
* @param {string} success_status
|
|
422
|
+
*/
|
|
423
|
+
set success_status(success_status: string) {
|
|
424
|
+
if (check2004ValidFormat(success_status, Regex.scorm2004.CMISStatus)) {
|
|
425
|
+
this._success_status = success_status;
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
/**
|
|
430
|
+
* Getter for _suspend_data
|
|
431
|
+
* @return {string}
|
|
432
|
+
*/
|
|
433
|
+
get suspend_data(): string {
|
|
434
|
+
return this._suspend_data;
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
/**
|
|
438
|
+
* Setter for _suspend_data
|
|
439
|
+
* @param {string} suspend_data
|
|
440
|
+
*/
|
|
441
|
+
set suspend_data(suspend_data: string) {
|
|
442
|
+
if (
|
|
443
|
+
check2004ValidFormat(suspend_data, Regex.scorm2004.CMIString64000, true)
|
|
444
|
+
) {
|
|
445
|
+
this._suspend_data = suspend_data;
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
/**
|
|
450
|
+
* Getter for _time_limit_action
|
|
451
|
+
* @return {string}
|
|
452
|
+
*/
|
|
453
|
+
get time_limit_action(): string {
|
|
454
|
+
return this._time_limit_action;
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
/**
|
|
458
|
+
* Setter for _time_limit_action. Can only be called before initialization.
|
|
459
|
+
* @param {string} time_limit_action
|
|
460
|
+
*/
|
|
461
|
+
set time_limit_action(time_limit_action: string) {
|
|
462
|
+
if (this.initialized) {
|
|
463
|
+
throw new Scorm2004ValidationError(
|
|
464
|
+
ErrorCodes.scorm2004.READ_ONLY_ELEMENT,
|
|
465
|
+
);
|
|
466
|
+
} else {
|
|
467
|
+
this._time_limit_action = time_limit_action;
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
/**
|
|
472
|
+
* Getter for _total_time
|
|
473
|
+
* @return {string}
|
|
474
|
+
*/
|
|
475
|
+
get total_time(): string {
|
|
476
|
+
return this._total_time;
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
/**
|
|
480
|
+
* Setter for _total_time. Can only be called before initialization.
|
|
481
|
+
* @param {string} total_time
|
|
482
|
+
*/
|
|
483
|
+
set total_time(total_time: string) {
|
|
484
|
+
if (this.initialized) {
|
|
485
|
+
throw new Scorm2004ValidationError(
|
|
486
|
+
ErrorCodes.scorm2004.READ_ONLY_ELEMENT,
|
|
487
|
+
);
|
|
488
|
+
} else {
|
|
489
|
+
this._total_time = total_time;
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
/**
|
|
494
|
+
* Adds the current session time to the existing total time.
|
|
495
|
+
*
|
|
496
|
+
* @return {string} ISO8601 Duration
|
|
497
|
+
*/
|
|
498
|
+
getCurrentTotalTime(): string {
|
|
499
|
+
let sessionTime = this._session_time;
|
|
500
|
+
const startTime = this.start_time;
|
|
501
|
+
|
|
502
|
+
if (typeof startTime !== "undefined" && startTime !== null) {
|
|
503
|
+
const seconds = new Date().getTime() - startTime;
|
|
504
|
+
sessionTime = Util.getSecondsAsISODuration(seconds / 1000);
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
return Util.addTwoDurations(
|
|
508
|
+
this._total_time,
|
|
509
|
+
sessionTime,
|
|
510
|
+
Regex.scorm2004.CMITimespan,
|
|
511
|
+
);
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
/**
|
|
515
|
+
* toJSON for cmi
|
|
516
|
+
*
|
|
517
|
+
* @return {
|
|
518
|
+
* {
|
|
519
|
+
* comments_from_learner: CMICommentsFromLearner,
|
|
520
|
+
* comments_from_lms: CMICommentsFromLMS,
|
|
521
|
+
* completion_status: string,
|
|
522
|
+
* completion_threshold: string,
|
|
523
|
+
* credit: string,
|
|
524
|
+
* entry: string,
|
|
525
|
+
* exit: string,
|
|
526
|
+
* interactions: CMIInteractions,
|
|
527
|
+
* launch_data: string,
|
|
528
|
+
* learner_id: string,
|
|
529
|
+
* learner_name: string,
|
|
530
|
+
* learner_preference: CMILearnerPreference,
|
|
531
|
+
* location: string,
|
|
532
|
+
* max_time_allowed: string,
|
|
533
|
+
* mode: string,
|
|
534
|
+
* objectives: CMIObjectives,
|
|
535
|
+
* progress_measure: string,
|
|
536
|
+
* scaled_passing_score: string,
|
|
537
|
+
* score: Scorm2004CMIScore,
|
|
538
|
+
* session_time: string,
|
|
539
|
+
* success_status: string,
|
|
540
|
+
* suspend_data: string,
|
|
541
|
+
* time_limit_action: string
|
|
542
|
+
* }
|
|
543
|
+
* }
|
|
544
|
+
*/
|
|
545
|
+
toJSON(): {
|
|
546
|
+
comments_from_learner: CMICommentsFromLearner;
|
|
547
|
+
comments_from_lms: CMICommentsFromLMS;
|
|
548
|
+
completion_status: string;
|
|
549
|
+
completion_threshold: string;
|
|
550
|
+
credit: string;
|
|
551
|
+
entry: string;
|
|
552
|
+
exit: string;
|
|
553
|
+
interactions: CMIInteractions;
|
|
554
|
+
launch_data: string;
|
|
555
|
+
learner_id: string;
|
|
556
|
+
learner_name: string;
|
|
557
|
+
learner_preference: CMILearnerPreference;
|
|
558
|
+
location: string;
|
|
559
|
+
max_time_allowed: string;
|
|
560
|
+
mode: string;
|
|
561
|
+
objectives: CMIObjectives;
|
|
562
|
+
progress_measure: string;
|
|
563
|
+
scaled_passing_score: string;
|
|
564
|
+
score: Scorm2004CMIScore;
|
|
565
|
+
session_time: string;
|
|
566
|
+
success_status: string;
|
|
567
|
+
suspend_data: string;
|
|
568
|
+
time_limit_action: string;
|
|
569
|
+
} {
|
|
570
|
+
this.jsonString = true;
|
|
571
|
+
const result = {
|
|
572
|
+
comments_from_learner: this.comments_from_learner,
|
|
573
|
+
comments_from_lms: this.comments_from_lms,
|
|
574
|
+
completion_status: this.completion_status,
|
|
575
|
+
completion_threshold: this.completion_threshold,
|
|
576
|
+
credit: this.credit,
|
|
577
|
+
entry: this.entry,
|
|
578
|
+
exit: this.exit,
|
|
579
|
+
interactions: this.interactions,
|
|
580
|
+
launch_data: this.launch_data,
|
|
581
|
+
learner_id: this.learner_id,
|
|
582
|
+
learner_name: this.learner_name,
|
|
583
|
+
learner_preference: this.learner_preference,
|
|
584
|
+
location: this.location,
|
|
585
|
+
max_time_allowed: this.max_time_allowed,
|
|
586
|
+
mode: this.mode,
|
|
587
|
+
objectives: this.objectives,
|
|
588
|
+
progress_measure: this.progress_measure,
|
|
589
|
+
scaled_passing_score: this.scaled_passing_score,
|
|
590
|
+
score: this.score,
|
|
591
|
+
session_time: this.session_time,
|
|
592
|
+
success_status: this.success_status,
|
|
593
|
+
suspend_data: this.suspend_data,
|
|
594
|
+
time_limit_action: this.time_limit_action,
|
|
595
|
+
};
|
|
596
|
+
delete this.jsonString;
|
|
597
|
+
return result;
|
|
598
|
+
}
|
|
599
|
+
}
|