From 0da8be81e7a95ba52fc4bd2da115083b357fe171 Mon Sep 17 00:00:00 2001 From: Dani Palou Date: Tue, 25 May 2021 11:13:12 +0200 Subject: [PATCH 1/2] MOBILE-3757 course: Always display manual completion for some URLs --- .../mod/label/services/handlers/module.ts | 2 +- .../mod/url/services/handlers/module.ts | 72 +++++++++++-------- .../course/components/module/module.ts | 11 ++- .../course/services/module-delegate.ts | 12 ++-- .../classes/handlers/module-handler.ts | 2 +- 5 files changed, 60 insertions(+), 39 deletions(-) diff --git a/src/addons/mod/label/services/handlers/module.ts b/src/addons/mod/label/services/handlers/module.ts index e93f13b26..46e0ad9da 100644 --- a/src/addons/mod/label/services/handlers/module.ts +++ b/src/addons/mod/label/services/handlers/module.ts @@ -74,7 +74,7 @@ export class AddonModLabelModuleHandlerService implements CoreCourseModuleHandle /** * @inheritdoc */ - manualCompletionAlwaysShown(): boolean { + async manualCompletionAlwaysShown(): Promise { return true; } diff --git a/src/addons/mod/url/services/handlers/module.ts b/src/addons/mod/url/services/handlers/module.ts index 464d876e9..9e4cd9571 100644 --- a/src/addons/mod/url/services/handlers/module.ts +++ b/src/addons/mod/url/services/handlers/module.ts @@ -85,39 +85,11 @@ export class AddonModUrlModuleHandlerService implements CoreCourseModuleHandler title: module.name, class: 'addon-mod_url-handler', showDownloadButton: false, - async action(event: Event, module: CoreCourseModule, courseId: number, options?: CoreNavigationOptions): Promise { + action: async (event: Event, module: CoreCourseModule, courseId: number, options?: CoreNavigationOptions) => { const modal = await CoreDomUtils.showModalLoading(); - // First of all, make sure module contents are loaded. try { - await CoreCourse.loadModuleContents( - module, - courseId, - undefined, - false, - false, - undefined, - this.modName, - ); - - // Check if the URL can be handled by the app. If so, always open it directly. - const canHandle = - await CoreContentLinksHelper.canHandleLink(module.contents[0].fileurl, courseId, undefined, true); - - let shouldOpen = false; - if (canHandle) { - // URL handled by the app, open it directly. - shouldOpen = true; - } else if (AddonModUrl.isGetUrlWSAvailable()) { - // Not handled by the app, check the display type. - const url = await CoreUtils.ignoreErrors(AddonModUrl.getUrl(courseId, module.id)); - const displayType = AddonModUrl.getFinalDisplayType(url); - - shouldOpen = displayType == CoreConstants.RESOURCELIB_DISPLAY_OPEN || - displayType == CoreConstants.RESOURCELIB_DISPLAY_POPUP; - } else { - shouldOpen = false; - } + const shouldOpen = this.shouldOpenLink(module, courseId); if (shouldOpen) { openUrl(module, courseId); @@ -185,5 +157,45 @@ export class AddonModUrlModuleHandlerService implements CoreCourseModuleHandler return AddonModUrlIndexComponent; } + /** + * Check whether the link should be opened directly. + * + * @param module Module. + * @param courseId Course ID. + * @return Promise resolved with boolean. + */ + protected async shouldOpenLink(module: CoreCourseModule, courseId: number): Promise { + try { + // First of all, make sure module contents are loaded. + await CoreCourse.loadModuleContents(module, courseId, undefined, false, false, undefined, this.modName); + + // Check if the URL can be handled by the app. If so, always open it directly. + const canHandle = await CoreContentLinksHelper.canHandleLink(module.contents[0].fileurl, courseId, undefined, true); + + if (canHandle) { + // URL handled by the app, open it directly. + return true; + } else if (AddonModUrl.isGetUrlWSAvailable()) { + // Not handled by the app, check the display type. + const url = await CoreUtils.ignoreErrors(AddonModUrl.getUrl(courseId, module.id)); + const displayType = AddonModUrl.getFinalDisplayType(url); + + return displayType == CoreConstants.RESOURCELIB_DISPLAY_OPEN || + displayType == CoreConstants.RESOURCELIB_DISPLAY_POPUP; + } + + return false; + } catch { + return false; + } + } + + /** + * @inheritdoc + */ + manualCompletionAlwaysShown(module: CoreCourseModule): Promise { + return this.shouldOpenLink(module, module.course!); + } + } export const AddonModUrlModuleHandler = makeSingleton(AddonModUrlModuleHandlerService); diff --git a/src/core/features/course/components/module/module.ts b/src/core/features/course/components/module/module.ts index 8c7201bd9..5bde5c98a 100644 --- a/src/core/features/course/components/module/module.ts +++ b/src/core/features/course/components/module/module.ts @@ -89,8 +89,7 @@ export class CoreCourseModuleComponent implements OnInit, OnDestroy { this.courseId = this.courseId || this.module.course; this.modNameTranslated = CoreCourse.translateModuleName(this.module.modname) || ''; this.showLegacyCompletion = !CoreSites.getCurrentSite()?.isVersionGreaterEqualThan('3.11'); - this.showManualCompletion = - this.showCompletionConditions || CoreCourseModuleDelegate.manualCompletionAlwaysShown(this.module); + this.checkShowManualCompletion(); if (!this.module.handlerData) { return; @@ -128,6 +127,14 @@ export class CoreCourseModuleComponent implements OnInit, OnDestroy { } } + /** + * Check whether manual completion should be shown. + */ + protected async checkShowManualCompletion(): Promise { + this.showManualCompletion = this.showCompletionConditions || + await CoreCourseModuleDelegate.manualCompletionAlwaysShown(this.module); + } + /** * Function called when the module is clicked. * diff --git a/src/core/features/course/services/module-delegate.ts b/src/core/features/course/services/module-delegate.ts index 0930be852..f1cfb206e 100644 --- a/src/core/features/course/services/module-delegate.ts +++ b/src/core/features/course/services/module-delegate.ts @@ -98,9 +98,9 @@ export interface CoreCourseModuleHandler extends CoreDelegateHandler { * Returns false by default. * * @param module Module. - * @return Whether the manual completion should always be displayed. + * @return Promise resolved with boolean: whether the manual completion should always be displayed. */ - manualCompletionAlwaysShown?(module: CoreCourseModule): boolean; + manualCompletionAlwaysShown?(module: CoreCourseModule): Promise; } /** @@ -380,10 +380,12 @@ export class CoreCourseModuleDelegateService extends CoreDelegate(module.modname, 'manualCompletionAlwaysShown', [module]); + async manualCompletionAlwaysShown(module: CoreCourseModule): Promise { + const result = await this.executeFunctionOnEnabled(module.modname, 'manualCompletionAlwaysShown', [module]); + + return !!result; } } diff --git a/src/core/features/siteplugins/classes/handlers/module-handler.ts b/src/core/features/siteplugins/classes/handlers/module-handler.ts index 15a08d35e..c776e722c 100644 --- a/src/core/features/siteplugins/classes/handlers/module-handler.ts +++ b/src/core/features/siteplugins/classes/handlers/module-handler.ts @@ -192,7 +192,7 @@ export class CoreSitePluginsModuleHandler extends CoreSitePluginsBaseHandler imp /** * @inheritdoc */ - manualCompletionAlwaysShown(module: CoreCourseModule): boolean { + async manualCompletionAlwaysShown(module: CoreCourseModule): Promise { if (this.handlerSchema.manualcompletionalwaysshown !== undefined) { return this.handlerSchema.manualcompletionalwaysshown; } From f85a6f570d29c71c0bec1ee06dbd34ecedc90817 Mon Sep 17 00:00:00 2001 From: Dani Palou Date: Tue, 25 May 2021 12:03:12 +0200 Subject: [PATCH 2/2] MOBILE-3757 course: Display completion button in uppercase --- .../module-manual-completion/module-manual-completion.scss | 5 ----- .../module-manual-completion/module-manual-completion.ts | 1 - 2 files changed, 6 deletions(-) delete mode 100644 src/core/features/course/components/module-manual-completion/module-manual-completion.scss diff --git a/src/core/features/course/components/module-manual-completion/module-manual-completion.scss b/src/core/features/course/components/module-manual-completion/module-manual-completion.scss deleted file mode 100644 index 0aa279fc8..000000000 --- a/src/core/features/course/components/module-manual-completion/module-manual-completion.scss +++ /dev/null @@ -1,5 +0,0 @@ -:host { - ion-button { - text-transform: none; - } -} diff --git a/src/core/features/course/components/module-manual-completion/module-manual-completion.ts b/src/core/features/course/components/module-manual-completion/module-manual-completion.ts index 68e8ff927..ede613119 100644 --- a/src/core/features/course/components/module-manual-completion/module-manual-completion.ts +++ b/src/core/features/course/components/module-manual-completion/module-manual-completion.ts @@ -25,7 +25,6 @@ import { CoreEventObserver, CoreEvents } from '@singletons/events'; @Component({ selector: 'core-course-module-manual-completion', templateUrl: 'core-course-module-manual-completion.html', - styleUrls: ['module-manual-completion.scss'], }) export class CoreCourseModuleManualCompletionComponent implements OnInit, OnChanges, OnDestroy {