forked from CIT/Vmeda.Online
		
	Merge pull request #2790 from dpalou/MOBILE-3757-2
MOBILE-3757 course: Always display manual completion for some URLs
This commit is contained in:
		
						commit
						970b5220ee
					
				@ -74,7 +74,7 @@ export class AddonModLabelModuleHandlerService implements CoreCourseModuleHandle
 | 
			
		||||
    /**
 | 
			
		||||
     * @inheritdoc
 | 
			
		||||
     */
 | 
			
		||||
    manualCompletionAlwaysShown(): boolean {
 | 
			
		||||
    async manualCompletionAlwaysShown(): Promise<boolean> {
 | 
			
		||||
        return true;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -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<void> {
 | 
			
		||||
            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<boolean> {
 | 
			
		||||
        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<boolean> {
 | 
			
		||||
        return this.shouldOpenLink(module, module.course!);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
export const AddonModUrlModuleHandler = makeSingleton(AddonModUrlModuleHandlerService);
 | 
			
		||||
 | 
			
		||||
@ -1,5 +0,0 @@
 | 
			
		||||
:host {
 | 
			
		||||
    ion-button {
 | 
			
		||||
        text-transform: none;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@ -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 {
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -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<void> {
 | 
			
		||||
        this.showManualCompletion = this.showCompletionConditions ||
 | 
			
		||||
            await CoreCourseModuleDelegate.manualCompletionAlwaysShown(this.module);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Function called when the module is clicked.
 | 
			
		||||
     *
 | 
			
		||||
 | 
			
		||||
@ -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<boolean>;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
@ -380,10 +380,12 @@ export class CoreCourseModuleDelegateService extends CoreDelegate<CoreCourseModu
 | 
			
		||||
     * 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 {
 | 
			
		||||
        return !!this.executeFunctionOnEnabled<boolean>(module.modname, 'manualCompletionAlwaysShown', [module]);
 | 
			
		||||
    async manualCompletionAlwaysShown(module: CoreCourseModule): Promise<boolean> {
 | 
			
		||||
        const result = await this.executeFunctionOnEnabled<boolean>(module.modname, 'manualCompletionAlwaysShown', [module]);
 | 
			
		||||
 | 
			
		||||
        return !!result;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -192,7 +192,7 @@ export class CoreSitePluginsModuleHandler extends CoreSitePluginsBaseHandler imp
 | 
			
		||||
    /**
 | 
			
		||||
     * @inheritdoc
 | 
			
		||||
     */
 | 
			
		||||
    manualCompletionAlwaysShown(module: CoreCourseModule): boolean {
 | 
			
		||||
    async manualCompletionAlwaysShown(module: CoreCourseModule): Promise<boolean> {
 | 
			
		||||
        if (this.handlerSchema.manualcompletionalwaysshown !== undefined) {
 | 
			
		||||
            return this.handlerSchema.manualcompletionalwaysshown;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user