MOBILE-2930 scorm: Fix no visible SCO to load

main
Dani Palou 2019-07-16 13:44:49 +02:00
parent 7619c63f70
commit b3e1e29932
2 changed files with 35 additions and 20 deletions

View File

@ -270,24 +270,31 @@ export class AddonModScormPlayerPage implements OnInit, OnDestroy {
sco.image = this.scormProvider.getScoStatusIcon(sco, this.scorm.incomplete); sco.image = this.scormProvider.getScoStatusIcon(sco, this.scorm.incomplete);
}); });
// Determine current SCO if we received an ID..
if (this.initialScoId > 0) {
// SCO set by parameter, get it from TOC.
this.currentSco = this.scormHelper.getScoFromToc(this.toc, this.initialScoId);
}
if (!this.currentSco) { if (!this.currentSco) {
// No SCO defined. Get the first valid one. if (this.newAttempt) {
return this.scormHelper.getFirstSco(this.scorm.id, this.attempt, this.toc, this.organizationId, this.offline) // Creating a new attempt, use the first SCO defined by the SCORM.
.then((sco) => { this.initialScoId = this.scorm.launch;
}
if (sco) { // Determine current SCO if we received an ID.
this.currentSco = sco; if (this.initialScoId > 0) {
} else { // SCO set by parameter, get it from TOC.
// We couldn't find a SCO to load: they're all inactive or without launch URL. this.currentSco = this.scormHelper.getScoFromToc(this.toc, this.initialScoId);
this.errorMessage = 'addon.mod_scorm.errornovalidsco'; }
}
}); if (!this.currentSco) {
// No SCO defined. Get the first valid one.
return this.scormHelper.getFirstSco(this.scorm.id, this.attempt, this.toc, this.organizationId, this.mode,
this.offline).then((sco) => {
if (sco) {
this.currentSco = sco;
} else {
// We couldn't find a SCO to load: they're all inactive or without launch URL.
this.errorMessage = 'addon.mod_scorm.errornovalidsco';
}
});
}
} }
}).finally(() => { }).finally(() => {
this.loadingToc = false; this.loadingToc = false;

View File

@ -199,12 +199,15 @@ export class AddonModScormHelperProvider {
* @param {number} attempt Attempt number. * @param {number} attempt Attempt number.
* @param {any[]} [toc] SCORM's TOC. If not provided, it will be calculated. * @param {any[]} [toc] SCORM's TOC. If not provided, it will be calculated.
* @param {string} [organization] Organization to use. * @param {string} [organization] Organization to use.
* @param {string} [mode] Mode.
* @param {boolean} [offline] Whether the attempt is offline. * @param {boolean} [offline] Whether the attempt is offline.
* @param {string} [siteId] Site ID. If not defined, current site. * @param {string} [siteId] Site ID. If not defined, current site.
* @return {Promise<any>} Promise resolved with the first SCO. * @return {Promise<any>} Promise resolved with the first SCO.
*/ */
getFirstSco(scormId: number, attempt: number, toc?: any[], organization?: string, offline?: boolean, siteId?: string) getFirstSco(scormId: number, attempt: number, toc?: any[], organization?: string, mode?: string, offline?: boolean,
: Promise<any> { siteId?: string): Promise<any> {
mode = mode || AddonModScormProvider.MODENORMAL;
let promise; let promise;
if (toc && toc.length) { if (toc && toc.length) {
@ -215,15 +218,20 @@ export class AddonModScormHelperProvider {
} }
return promise.then((scos) => { return promise.then((scos) => {
// Search the first valid SCO. // Search the first valid SCO.
for (let i = 0; i < scos.length; i++) { for (let i = 0; i < scos.length; i++) {
const sco = scos[i]; const sco = scos[i];
// Return the first valid and incomplete SCO. if (sco.isvisible && sco.launch && sco.prereq &&
if (sco.isvisible && sco.prereq && sco.launch && this.scormProvider.isStatusIncomplete(sco.status)) { (mode != AddonModScormProvider.MODENORMAL || this.scormProvider.isStatusIncomplete(sco.status))) {
// In browse/review mode return the first visible sco. In normal mode, first incomplete sco.
return sco; return sco;
} }
} }
// No "valid" SCO, load the first one. In web it loads the first child because the toc contains the organization SCO.
return scos[0];
}); });
} }