From 495c9320c4e7670338b7796ccc080da538a2a8fe Mon Sep 17 00:00:00 2001 From: Dani Palou Date: Thu, 20 Oct 2022 10:24:38 +0200 Subject: [PATCH] MOBILE-4153 scorm: Support links to player.php --- .../mod/scorm/components/index/index.ts | 41 ++++++--- src/addons/mod/scorm/pages/index/index.html | 2 +- src/addons/mod/scorm/pages/index/index.ts | 21 ++++- src/addons/mod/scorm/scorm.module.ts | 2 + .../scorm/services/handlers/player-link.ts | 84 +++++++++++++++++++ 5 files changed, 137 insertions(+), 13 deletions(-) create mode 100644 src/addons/mod/scorm/services/handlers/player-link.ts diff --git a/src/addons/mod/scorm/components/index/index.ts b/src/addons/mod/scorm/components/index/index.ts index ebf47cfa3..439689d15 100644 --- a/src/addons/mod/scorm/components/index/index.ts +++ b/src/addons/mod/scorm/components/index/index.ts @@ -13,7 +13,7 @@ // limitations under the License. import { CoreConstants } from '@/core/constants'; -import { Component, OnInit, Optional } from '@angular/core'; +import { Component, Input, OnInit, Optional } from '@angular/core'; import { CoreCourseModuleMainActivityComponent } from '@features/course/classes/main-activity-component'; import { CoreCourseContentsPage } from '@features/course/pages/contents/contents'; import { CoreCourse } from '@features/course/services/course'; @@ -53,6 +53,8 @@ import { }) export class AddonModScormIndexComponent extends CoreCourseModuleMainActivityComponent implements OnInit { + @Input() autoPlayData?: AddonModScormAutoPlayData; // Data to use to play the SCORM automatically. + component = AddonModScormProvider.COMPONENT; moduleName = 'scorm'; @@ -189,11 +191,16 @@ export class AddonModScormIndexComponent extends CoreCourseModuleMainActivityCom // Check whether to launch the SCORM immediately. if (this.skip === undefined) { - this.skip = !this.hasOffline && !this.errorMessage && - (!this.scorm.lastattemptlock || this.attemptsLeft > 0) && - this.accessInfo.canskipview && !this.accessInfo.canviewreport && - this.scorm.skipview! >= AddonModScormProvider.SKIPVIEW_FIRST && - (this.scorm.skipview == AddonModScormProvider.SKIPVIEW_ALWAYS || this.lastAttempt == 0); + this.skip = !this.hasOffline && !this.errorMessage && (!this.scorm.lastattemptlock || this.attemptsLeft > 0) && + ( + !!this.autoPlayData + || + ( + this.accessInfo.canskipview && !this.accessInfo.canviewreport && + (this.scorm.skipview ?? 0) >= AddonModScormProvider.SKIPVIEW_FIRST && + (this.scorm.skipview == AddonModScormProvider.SKIPVIEW_ALWAYS || this.lastAttempt == 0) + ) + ); } } @@ -533,7 +540,9 @@ export class AddonModScormIndexComponent extends CoreCourseModuleMainActivityCom * @param scoId SCO ID. */ protected openScorm(scoId?: number, preview: boolean = false): void { - // Display the full page when returning to the page. + const autoPlayData = this.autoPlayData; + + this.autoPlayData = undefined; this.skip = false; this.hasPlayed = true; @@ -555,11 +564,11 @@ export class AddonModScormIndexComponent extends CoreCourseModuleMainActivityCom `${AddonModScormModuleHandlerService.PAGE_NAME}/${this.courseId}/${this.module.id}/player`, { params: { - mode: preview ? AddonModScormProvider.MODEBROWSE : AddonModScormProvider.MODENORMAL, + mode: autoPlayData?.mode ?? (preview ? AddonModScormProvider.MODEBROWSE : AddonModScormProvider.MODENORMAL), moduleUrl: this.module.url, - newAttempt: !!this.startNewAttempt, - organizationId: this.currentOrganization.identifier, - scoId: scoId, + newAttempt: autoPlayData?.newAttempt ?? this.startNewAttempt, + organizationId: autoPlayData?.organizationId ?? this.currentOrganization.identifier, + scoId: autoPlayData?.scoId ?? scoId, }, }, ); @@ -621,3 +630,13 @@ export class AddonModScormIndexComponent extends CoreCourseModuleMainActivityCom export type AttemptGrade = AddonModScormAttemptGrade & { gradeFormatted?: string; }; + +/** + * Data to use to auto-play the SCORM. + */ +export type AddonModScormAutoPlayData = { + mode?: string; + newAttempt?: boolean; + organizationId?: string; + scoId?: number; +}; diff --git a/src/addons/mod/scorm/pages/index/index.html b/src/addons/mod/scorm/pages/index/index.html index 837e79cfb..54f781209 100644 --- a/src/addons/mod/scorm/pages/index/index.html +++ b/src/addons/mod/scorm/pages/index/index.html @@ -19,6 +19,6 @@ - + diff --git a/src/addons/mod/scorm/pages/index/index.ts b/src/addons/mod/scorm/pages/index/index.ts index dfaa663ba..17bc2fc61 100644 --- a/src/addons/mod/scorm/pages/index/index.ts +++ b/src/addons/mod/scorm/pages/index/index.ts @@ -14,7 +14,8 @@ import { Component, OnInit, ViewChild } from '@angular/core'; import { CoreCourseModuleMainActivityPage } from '@features/course/classes/main-activity-page'; -import { AddonModScormIndexComponent } from '../../components/index/index'; +import { CoreNavigator } from '@services/navigator'; +import { AddonModScormAutoPlayData, AddonModScormIndexComponent } from '../../components/index/index'; /** * Page that displays the scorm entry page. @@ -27,4 +28,22 @@ export class AddonModScormIndexPage extends CoreCourseModuleMainActivityPage, courseId?: number): CoreContentLinksAction[] { + + return [{ + action: async (siteId) => { + const cmId = Number(params.id); + const instanceId = Number(params.a); + courseId = Number(courseId || params.courseid || params.cid); + + if (!cmId && !instanceId) { + // Shouldn't happen, the regex should handle this. + return; + } + + const navOptions: CoreNavigationOptions = { + params: { + autoPlay: true, + mode: params.mode || undefined, + newAttempt: params.newattempt === 'on', + organizationId: params.currentorg, + scoId: Number(params.scoid) || undefined, + }, + }; + + if (cmId) { + CoreCourseHelper.navigateToModule( + cmId, + { + courseId, + modNavOptions: navOptions, + siteId, + }, + ); + } else { + CoreCourseHelper.navigateToModuleByInstance( + instanceId, + 'scorm', + { + courseId, + modNavOptions: navOptions, + siteId, + }, + ); + } + }, + }]; + } + +} + +export const AddonModScormPlayerLinkHandler = makeSingleton(AddonModScormPlayerLinkHandlerService);