diff --git a/src/addon/mod/url/components/index/addon-mod-url-index.html b/src/addon/mod/url/components/index/addon-mod-url-index.html index 8bfe7d722..422095419 100644 --- a/src/addon/mod/url/components/index/addon-mod-url-index.html +++ b/src/addon/mod/url/components/index/addon-mod-url-index.html @@ -12,20 +12,20 @@ -
- - - - +
+
- - - + + + + + +

{{ 'addon.mod_url.pointingtourl' | translate }}

{{ url }}

diff --git a/src/addon/mod/url/components/index/index.ts b/src/addon/mod/url/components/index/index.ts index 3b5c581ba..589de7cbf 100644 --- a/src/addon/mod/url/components/index/index.ts +++ b/src/addon/mod/url/components/index/index.ts @@ -39,6 +39,7 @@ export class AddonModUrlIndexComponent extends CoreCourseModuleMainResourceCompo isImage = false; isAudio = false; isVideo = false; + isOther = false; mimetype: string; displayDescription = true; @@ -148,6 +149,7 @@ export class AddonModUrlIndexComponent extends CoreCourseModuleMainResourceCompo this.isImage = this.mimeUtils.isExtensionInGroup(extension, ['web_image']); this.isAudio = this.mimeUtils.isExtensionInGroup(extension, ['web_audio']); this.isVideo = this.mimeUtils.isExtensionInGroup(extension, ['web_video']); + this.isOther = !this.isImage && !this.isAudio && !this.isVideo; } if (this.shouldIframe || (this.shouldEmbed && !this.isImage && !this.isAudio && !this.isVideo)) { diff --git a/src/addon/mod/url/providers/module-handler.ts b/src/addon/mod/url/providers/module-handler.ts index 54ccb6ead..e182343fb 100644 --- a/src/addon/mod/url/providers/module-handler.ts +++ b/src/addon/mod/url/providers/module-handler.ts @@ -18,6 +18,7 @@ import { CoreDomUtilsProvider } from '@providers/utils/dom'; import { AddonModUrlIndexComponent } from '../components/index/index'; import { CoreCourseModuleHandler, CoreCourseModuleHandlerData } from '@core/course/providers/module-delegate'; import { CoreCourseProvider } from '@core/course/providers/course'; +import { CoreContentLinksHelperProvider } from '@core/contentlinks/providers/helper'; import { AddonModUrlProvider } from './url'; import { AddonModUrlHelperProvider } from './helper'; import { CoreConstants } from '@core/constants'; @@ -31,7 +32,8 @@ export class AddonModUrlModuleHandler implements CoreCourseModuleHandler { modName = 'url'; constructor(private courseProvider: CoreCourseProvider, private urlProvider: AddonModUrlProvider, - private urlHelper: AddonModUrlHelperProvider, private domUtils: CoreDomUtilsProvider) { } + private urlHelper: AddonModUrlHelperProvider, private domUtils: CoreDomUtilsProvider, + private contentLinksHelper: CoreContentLinksHelperProvider) { } /** * Check if the handler is enabled on a site level. @@ -59,32 +61,37 @@ export class AddonModUrlModuleHandler implements CoreCourseModuleHandler { class: 'addon-mod_url-handler', showDownloadButton: false, action(event: Event, navCtrl: NavController, module: any, courseId: number, options: NavOptions): void { - // Check if we need to open the URL directly. - let promise; + const modal = handler.domUtils.showModalLoading(); - if (handler.urlProvider.isGetUrlWSAvailable()) { - const modal = handler.domUtils.showModalLoading(); + // First of all, check if the URL can be handled by the app. If so, always open it directly. + handler.contentLinksHelper.canHandleLink(module.contents[0].fileurl, courseId).then((canHandle) => { + if (canHandle) { + // URL handled by the app, open it directly. + return true; + } - promise = handler.urlProvider.getUrl(courseId, module.id).catch(() => { - // Ignore errors. - }).then((url) => { - modal.dismiss(); + // Not handled by the app, check the display type. + if (handler.urlProvider.isGetUrlWSAvailable()) { + return handler.urlProvider.getUrl(courseId, module.id).catch(() => { + // Ignore errors. + }).then((url) => { + const displayType = handler.urlProvider.getFinalDisplayType(url); - const displayType = handler.urlProvider.getFinalDisplayType(url); + return displayType == CoreConstants.RESOURCELIB_DISPLAY_OPEN || + displayType == CoreConstants.RESOURCELIB_DISPLAY_POPUP; + }); + } else { + return false; + } - return displayType == CoreConstants.RESOURCELIB_DISPLAY_OPEN || - displayType == CoreConstants.RESOURCELIB_DISPLAY_POPUP; - }); - } else { - promise = Promise.resolve(false); - } - - return promise.then((shouldOpen) => { + }).then((shouldOpen) => { if (shouldOpen) { handler.openUrl(module, courseId); } else { navCtrl.push('AddonModUrlIndexPage', {module: module, courseId: courseId}, options); } + }).finally(() => { + modal.dismiss(); }); }, buttons: [ { @@ -120,24 +127,7 @@ export class AddonModUrlModuleHandler implements CoreCourseModuleHandler { protected hideLinkButton(module: any, courseId: number): Promise { return this.courseProvider.loadModuleContents(module, courseId, undefined, false, false, undefined, this.modName) .then(() => { - - if (!module.contents || !module.contents[0] || !module.contents[0].fileurl) { - // No module contents, hide the button. - return true; - } - - if (!this.urlProvider.isGetUrlWSAvailable()) { - return false; - } - - // Get the URL data. - return this.urlProvider.getUrl(courseId, module.id).then((url) => { - const displayType = this.urlProvider.getFinalDisplayType(url); - - // Don't display the button if the URL should be embedded. - return displayType == CoreConstants.RESOURCELIB_DISPLAY_EMBED || - displayType == CoreConstants.RESOURCELIB_DISPLAY_FRAME; - }); + return !(module.contents && module.contents[0] && module.contents[0].fileurl); }); } diff --git a/src/core/contentlinks/providers/helper.ts b/src/core/contentlinks/providers/helper.ts index 8cd2660d8..ad3d9b6f5 100644 --- a/src/core/contentlinks/providers/helper.ts +++ b/src/core/contentlinks/providers/helper.ts @@ -47,6 +47,22 @@ export class CoreContentLinksHelperProvider { eventsProvider.on(CoreEventsProvider.APP_LAUNCHED_URL, this.handleCustomUrl.bind(this)); } + /** + * Check whether a link can be handled by the app. + * + * @param {string} url URL to handle. + * @param {number} [courseId] Course ID related to the URL. Optional but recommended. + * @param {string} [username] Username to use to filter sites. + * @return {Promise} Promise resolved with a boolean: whether the URL can be handled. + */ + canHandleLink(url: string, courseId?: number, username?: string): Promise { + return this.contentLinksDelegate.getActionsFor(url, undefined, username).then((actions) => { + return !!this.getFirstValidAction(actions); + }).catch(() => { + return false; + }); + } + /** * Get the first valid action in a list of actions. *