MOBILE-2539 url: Always show open button and don't embed internal links

main
dpalou 2018-10-04 16:42:14 +02:00
parent 6d39cd5c4f
commit 71bd461c42
4 changed files with 56 additions and 48 deletions

View File

@ -12,7 +12,12 @@
<core-course-module-description *ngIf="displayDescription" [description]="description" [component]="component" [componentId]="componentId"></core-course-module-description> <core-course-module-description *ngIf="displayDescription" [description]="description" [component]="component" [componentId]="componentId"></core-course-module-description>
<div *ngIf="shouldEmbed" class="addon-mod_url-embedded-url"> <div *ngIf="shouldIframe || (shouldEmbed && isOther)" class="addon-mod_url-embedded-url">
<core-iframe [src]="url"></core-iframe>
</div>
<ion-list *ngIf="!shouldIframe && (!shouldEmbed || !isOther)">
<ion-item *ngIf="shouldEmbed">
<img *ngIf="isImage" title="{{name}}" [src]="url"> <img *ngIf="isImage" title="{{name}}" [src]="url">
<video *ngIf="isVideo" title="{{name}}" controls> <video *ngIf="isVideo" title="{{name}}" controls>
<source [src]="url" [type]="mimetype"> <source [src]="url" [type]="mimetype">
@ -20,12 +25,7 @@
<audio *ngIf="isAudio" title="{{name}}" controls> <audio *ngIf="isAudio" title="{{name}}" controls>
<source [src]="url" [type]="mimetype"> <source [src]="url" [type]="mimetype">
</audio> </audio>
<core-iframe *ngIf="!isImage && !isVideo && !isAudio" [src]="url"></core-iframe> </ion-item>
</div>
<core-iframe *ngIf="shouldIframe" [src]="url"></core-iframe>
<ion-list *ngIf="!shouldEmbed && !shouldIframe">
<ion-item text-wrap> <ion-item text-wrap>
<h2>{{ 'addon.mod_url.pointingtourl' | translate }}</h2> <h2>{{ 'addon.mod_url.pointingtourl' | translate }}</h2>
<p>{{ url }}</p> <p>{{ url }}</p>

View File

@ -39,6 +39,7 @@ export class AddonModUrlIndexComponent extends CoreCourseModuleMainResourceCompo
isImage = false; isImage = false;
isAudio = false; isAudio = false;
isVideo = false; isVideo = false;
isOther = false;
mimetype: string; mimetype: string;
displayDescription = true; displayDescription = true;
@ -148,6 +149,7 @@ export class AddonModUrlIndexComponent extends CoreCourseModuleMainResourceCompo
this.isImage = this.mimeUtils.isExtensionInGroup(extension, ['web_image']); this.isImage = this.mimeUtils.isExtensionInGroup(extension, ['web_image']);
this.isAudio = this.mimeUtils.isExtensionInGroup(extension, ['web_audio']); this.isAudio = this.mimeUtils.isExtensionInGroup(extension, ['web_audio']);
this.isVideo = this.mimeUtils.isExtensionInGroup(extension, ['web_video']); 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)) { if (this.shouldIframe || (this.shouldEmbed && !this.isImage && !this.isAudio && !this.isVideo)) {

View File

@ -18,6 +18,7 @@ import { CoreDomUtilsProvider } from '@providers/utils/dom';
import { AddonModUrlIndexComponent } from '../components/index/index'; import { AddonModUrlIndexComponent } from '../components/index/index';
import { CoreCourseModuleHandler, CoreCourseModuleHandlerData } from '@core/course/providers/module-delegate'; import { CoreCourseModuleHandler, CoreCourseModuleHandlerData } from '@core/course/providers/module-delegate';
import { CoreCourseProvider } from '@core/course/providers/course'; import { CoreCourseProvider } from '@core/course/providers/course';
import { CoreContentLinksHelperProvider } from '@core/contentlinks/providers/helper';
import { AddonModUrlProvider } from './url'; import { AddonModUrlProvider } from './url';
import { AddonModUrlHelperProvider } from './helper'; import { AddonModUrlHelperProvider } from './helper';
import { CoreConstants } from '@core/constants'; import { CoreConstants } from '@core/constants';
@ -31,7 +32,8 @@ export class AddonModUrlModuleHandler implements CoreCourseModuleHandler {
modName = 'url'; modName = 'url';
constructor(private courseProvider: CoreCourseProvider, private urlProvider: AddonModUrlProvider, 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. * Check if the handler is enabled on a site level.
@ -59,32 +61,37 @@ export class AddonModUrlModuleHandler implements CoreCourseModuleHandler {
class: 'addon-mod_url-handler', class: 'addon-mod_url-handler',
showDownloadButton: false, showDownloadButton: false,
action(event: Event, navCtrl: NavController, module: any, courseId: number, options: NavOptions): void { action(event: Event, navCtrl: NavController, module: any, courseId: number, options: NavOptions): void {
// Check if we need to open the URL directly.
let promise;
if (handler.urlProvider.isGetUrlWSAvailable()) {
const modal = handler.domUtils.showModalLoading(); const modal = handler.domUtils.showModalLoading();
promise = handler.urlProvider.getUrl(courseId, module.id).catch(() => { // 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;
}
// Not handled by the app, check the display type.
if (handler.urlProvider.isGetUrlWSAvailable()) {
return handler.urlProvider.getUrl(courseId, module.id).catch(() => {
// Ignore errors. // Ignore errors.
}).then((url) => { }).then((url) => {
modal.dismiss();
const displayType = handler.urlProvider.getFinalDisplayType(url); const displayType = handler.urlProvider.getFinalDisplayType(url);
return displayType == CoreConstants.RESOURCELIB_DISPLAY_OPEN || return displayType == CoreConstants.RESOURCELIB_DISPLAY_OPEN ||
displayType == CoreConstants.RESOURCELIB_DISPLAY_POPUP; displayType == CoreConstants.RESOURCELIB_DISPLAY_POPUP;
}); });
} else { } else {
promise = Promise.resolve(false); return false;
} }
return promise.then((shouldOpen) => { }).then((shouldOpen) => {
if (shouldOpen) { if (shouldOpen) {
handler.openUrl(module, courseId); handler.openUrl(module, courseId);
} else { } else {
navCtrl.push('AddonModUrlIndexPage', {module: module, courseId: courseId}, options); navCtrl.push('AddonModUrlIndexPage', {module: module, courseId: courseId}, options);
} }
}).finally(() => {
modal.dismiss();
}); });
}, },
buttons: [ { buttons: [ {
@ -120,24 +127,7 @@ export class AddonModUrlModuleHandler implements CoreCourseModuleHandler {
protected hideLinkButton(module: any, courseId: number): Promise<boolean> { protected hideLinkButton(module: any, courseId: number): Promise<boolean> {
return this.courseProvider.loadModuleContents(module, courseId, undefined, false, false, undefined, this.modName) return this.courseProvider.loadModuleContents(module, courseId, undefined, false, false, undefined, this.modName)
.then(() => { .then(() => {
return !(module.contents && module.contents[0] && module.contents[0].fileurl);
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;
});
}); });
} }

View File

@ -47,6 +47,22 @@ export class CoreContentLinksHelperProvider {
eventsProvider.on(CoreEventsProvider.APP_LAUNCHED_URL, this.handleCustomUrl.bind(this)); 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<boolean>} Promise resolved with a boolean: whether the URL can be handled.
*/
canHandleLink(url: string, courseId?: number, username?: string): Promise<boolean> {
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. * Get the first valid action in a list of actions.
* *