MOBILE-2399 url: Fix URL variables not used

main
Dani Palou 2018-07-30 15:26:41 +02:00
parent e6c5607463
commit b731a2f887
1 changed files with 19 additions and 9 deletions

View File

@ -63,10 +63,11 @@ export class AddonModUrlIndexComponent extends CoreCourseModuleMainResourceCompo
* @return {Promise<any>} Promise resolved when done. * @return {Promise<any>} Promise resolved when done.
*/ */
protected fetchContent(refresh?: boolean): Promise<any> { protected fetchContent(refresh?: boolean): Promise<any> {
let canGetUrl = this.canGetUrl; let canGetUrl = this.canGetUrl,
mod,
promise;
// Fetch the module data. // Fetch the module data.
let promise;
if (canGetUrl) { if (canGetUrl) {
promise = this.urlProvider.getUrl(this.courseId, this.module.id); promise = this.urlProvider.getUrl(this.courseId, this.module.id);
} else { } else {
@ -76,21 +77,30 @@ export class AddonModUrlIndexComponent extends CoreCourseModuleMainResourceCompo
return promise.catch(() => { return promise.catch(() => {
canGetUrl = false; canGetUrl = false;
// Fallback in case is not prefetch or not avalaible. // Fallback in case is not prefetched or not available.
return this.courseProvider.getModule(this.module.id, this.courseId); return this.courseProvider.getModule(this.module.id, this.courseId);
}).then((url) => { }).then((url) => {
this.description = url.intro || url.description;
this.dataRetrieved.emit(url);
if (!canGetUrl) { if (!canGetUrl) {
mod = url;
if (!url.contents.length) { if (!url.contents.length) {
// If the data was cached maybe we don't have contents. Reject. // If the data was cached maybe we don't have contents. Reject.
return Promise.reject(null); return Promise.reject(null);
} }
} else {
mod = this.module;
if (!mod.contents || !mod.contents.length) {
// Try to load module contents, it's needed to get the URL with parameters.
return this.courseProvider.loadModuleContents(mod, this.courseId);
} }
}
this.description = url.intro || url.description; }).then(() => {
this.dataRetrieved.emit(url); // Always use the URL from the module because it already includes the parameters.
this.url = mod.contents && mod.contents[0] && mod.contents[0].fileurl ? mod.contents[0].fileurl : undefined;
this.url = canGetUrl ? url.externalurl :
((url.contents[0] && url.contents[0].fileurl) ? url.contents[0].fileurl : undefined);
}); });
} }