MOBILE-4099 scorm: Remove some non-null assertions

main
Dani Palou 2022-06-21 08:20:57 +02:00
parent 7b5a5bed8f
commit fad887aa65
6 changed files with 20 additions and 18 deletions

View File

@ -510,8 +510,9 @@ export class AddonModScormDataModel12 {
// Load default values. // Load default values.
for (const element in this.dataModel[scoId]) { for (const element in this.dataModel[scoId]) {
if (element.match(/\.n\./) === null) { if (element.match(/\.n\./) === null) {
if (this.dataModel[scoId][element].defaultvalue !== undefined) { const defaultValue = this.dataModel[scoId][element].defaultvalue;
this.currentUserData[scoId].userdata[element] = this.dataModel[scoId][element].defaultvalue!; if (defaultValue !== undefined) {
this.currentUserData[scoId].userdata[element] = defaultValue;
} }
} }
} }
@ -519,8 +520,9 @@ export class AddonModScormDataModel12 {
// Load initial user data for current SCO. // Load initial user data for current SCO.
for (const element in this.def[scoId]) { for (const element in this.def[scoId]) {
if (element.match(/\.n\./) === null) { if (element.match(/\.n\./) === null) {
if (this.dataModel[scoId][element].defaultvalue !== undefined) { const defaultValue = this.dataModel[scoId][element].defaultvalue;
this.currentUserData[scoId].userdata[element] = this.dataModel[scoId][element].defaultvalue!; if (defaultValue !== undefined) {
this.currentUserData[scoId].userdata[element] = defaultValue;
} else if (this.defExtra[scoId][element] !== undefined) { } else if (this.defExtra[scoId][element] !== undefined) {
// Check in user data values. // Check in user data values.
this.currentUserData[scoId].userdata[element] = this.defExtra[scoId][element]; this.currentUserData[scoId].userdata[element] = this.defExtra[scoId][element];
@ -808,7 +810,7 @@ export class AddonModScormDataModel12 {
if (this.dataModel[this.scoId][elementModel] !== undefined) { if (this.dataModel[this.scoId][elementModel] !== undefined) {
if (this.dataModel[this.scoId][elementModel].mod != 'r') { if (this.dataModel[this.scoId][elementModel].mod != 'r') {
expression = new RegExp(this.dataModel[this.scoId][elementModel].format!); expression = new RegExp(this.dataModel[this.scoId][elementModel].format ?? '');
value = value + ''; value = value + '';
const matches = value.match(expression); const matches = value.match(expression);

View File

@ -415,7 +415,7 @@ export class AddonModScormPlayerPage implements OnInit, OnDestroy {
this.scorm, this.scorm,
sco.id, sco.id,
this.attempt, this.attempt,
this.userData!, this.userData ?? {},
this.mode, this.mode,
this.offline, this.offline,
this.canSaveTracks, this.canSaveTracks,

View File

@ -89,7 +89,7 @@ export class AddonModScormPrefetchHandlerService extends CoreCourseActivityPrefe
]); ]);
// Success, return the hash. // Success, return the hash.
return scorm.sha1hash!; return scorm.sha1hash ?? '';
} }
/** /**
@ -112,7 +112,7 @@ export class AddonModScormPrefetchHandlerService extends CoreCourseActivityPrefe
const packageUrl = AddonModScorm.getPackageUrl(scorm); const packageUrl = AddonModScorm.getPackageUrl(scorm);
// Get the folder where the unzipped files will be. // Get the folder where the unzipped files will be.
const dirPath = await AddonModScorm.getScormFolder(scorm.moduleurl!); const dirPath = await AddonModScorm.getScormFolder(scorm.moduleurl ?? '');
// Notify that the download is starting. // Notify that the download is starting.
onProgress && onProgress({ message: 'core.downloading' }); onProgress && onProgress({ message: 'core.downloading' });
@ -282,7 +282,7 @@ export class AddonModScormPrefetchHandlerService extends CoreCourseActivityPrefe
const scorm = await this.getScorm(module, courseId); const scorm = await this.getScorm(module, courseId);
// Get the folder where SCORM should be unzipped. // Get the folder where SCORM should be unzipped.
const path = await AddonModScorm.getScormFolder(scorm.moduleurl!); const path = await AddonModScorm.getScormFolder(scorm.moduleurl ?? '');
return CoreFile.getDirectorySize(path); return CoreFile.getDirectorySize(path);
} }
@ -388,7 +388,7 @@ export class AddonModScormPrefetchHandlerService extends CoreCourseActivityPrefe
const scorm = await this.getScorm(module, courseId, siteId); const scorm = await this.getScorm(module, courseId, siteId);
// Get the folder where SCORM should be unzipped. // Get the folder where SCORM should be unzipped.
const path = await AddonModScorm.getScormFolder(scorm.moduleurl!); const path = await AddonModScorm.getScormFolder(scorm.moduleurl ?? '');
const promises: Promise<unknown>[] = []; const promises: Promise<unknown>[] = [];

View File

@ -484,7 +484,7 @@ export class AddonModScormOfflineProvider {
response[scoId] = { response[scoId] = {
scoid: scoId, scoid: scoId,
userdata: { userdata: {
userid: userId!, userid: userId ?? site.getUserId(),
scoid: scoId, scoid: scoId,
timemodified: 0, timemodified: 0,
}, },
@ -492,7 +492,7 @@ export class AddonModScormOfflineProvider {
}; };
} }
response[scoId].userdata[entry.element] = entry.value!; response[scoId].userdata[entry.element] = entry.value ?? '';
if (entry.timemodified > Number(response[scoId].userdata.timemodified)) { if (entry.timemodified > Number(response[scoId].userdata.timemodified)) {
response[scoId].userdata.timemodified = entry.timemodified; response[scoId].userdata.timemodified = entry.timemodified;
} }

View File

@ -777,7 +777,7 @@ export class AddonModScormSyncProvider extends CoreCourseActivitySyncBaseProvide
lastOffline, lastOffline,
newAttemptsSameOrder, newAttemptsSameOrder,
newAttemptsAtEnd, newAttemptsAtEnd,
lastOfflineData.timecreated!, lastOfflineData.timecreated ?? 0,
lastOfflineData.incomplete, lastOfflineData.incomplete,
warnings, warnings,
siteId, siteId,
@ -812,7 +812,7 @@ export class AddonModScormSyncProvider extends CoreCourseActivitySyncBaseProvide
lastOffline, lastOffline,
newAttemptsSameOrder, newAttemptsSameOrder,
newAttemptsAtEnd, newAttemptsAtEnd,
lastOfflineData.timecreated!, lastOfflineData.timecreated ?? 0,
lastOfflineData.incomplete, lastOfflineData.incomplete,
warnings, warnings,
siteId, siteId,

View File

@ -357,8 +357,8 @@ export class AddonModScormProvider {
element = '!'; element = '!';
} else if (reOther.test(element)) { } else if (reOther.test(element)) {
// Other symbols = | <> . // Other symbols = | <> .
matches = element.match(reOther)!; matches = element.match(reOther) ?? [];
element = matches[1].trim(); element = matches[1]?.trim();
if (trackData[element] !== undefined) { if (trackData[element] !== undefined) {
let value = matches[3].trim().replace(/('|")/gi, ''); let value = matches[3].trim().replace(/('|")/gi, '');
@ -968,7 +968,7 @@ export class AddonModScormProvider {
return launchUrl; return launchUrl;
} }
const dirPath = await CoreFilepool.getPackageDirUrlByUrl(siteId, scorm.moduleurl!); const dirPath = await CoreFilepool.getPackageDirUrlByUrl(siteId, scorm.moduleurl ?? '');
return CoreText.concatenatePaths(dirPath, launchUrl); return CoreText.concatenatePaths(dirPath, launchUrl);
} }
@ -1573,7 +1573,7 @@ export class AddonModScormProvider {
userData?: AddonModScormUserDataMap, userData?: AddonModScormUserDataMap,
): boolean { ): boolean {
if (offline) { if (offline) {
return AddonModScormOffline.saveTracksSync(scorm, scoId, attempt, tracks, userData!); return AddonModScormOffline.saveTracksSync(scorm, scoId, attempt, tracks, userData ?? {});
} else { } else {
const success = this.saveTracksSyncOnline(scoId, attempt, tracks); const success = this.saveTracksSyncOnline(scoId, attempt, tracks);