MOBILE-2403 resource: Fix issues with embedded and open button
parent
c02e134c58
commit
07976a2a9a
|
@ -124,7 +124,7 @@ export class AddonModResourceIndexComponent extends CoreCourseModuleMainResource
|
||||||
} else if (this.resourceHelper.isDisplayedEmbedded(this.module, resource && resource.display)) {
|
} else if (this.resourceHelper.isDisplayedEmbedded(this.module, resource && resource.display)) {
|
||||||
this.mode = 'embedded';
|
this.mode = 'embedded';
|
||||||
|
|
||||||
return this.resourceHelper.getEmbeddedHtml(this.module).then((html) => {
|
return this.resourceHelper.getEmbeddedHtml(this.module, this.courseId).then((html) => {
|
||||||
this.contentText = html;
|
this.contentText = html;
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -47,10 +47,11 @@ export class AddonModResourceHelperProvider {
|
||||||
* Get the HTML to display an embedded resource.
|
* Get the HTML to display an embedded resource.
|
||||||
*
|
*
|
||||||
* @param {any} module The module object.
|
* @param {any} module The module object.
|
||||||
* @return {Promise<any>} Promise resolved with the iframe src.
|
* @param {number} courseId The course ID.
|
||||||
|
* @return {Promise<any>} Promise resolved with the HTML.
|
||||||
*/
|
*/
|
||||||
getEmbeddedHtml(module: any): Promise<any> {
|
getEmbeddedHtml(module: any, courseId: number): Promise<any> {
|
||||||
return this.courseHelper.downloadModuleWithMainFileIfNeeded(module, module.course, AddonModResourceProvider.COMPONENT,
|
return this.courseHelper.downloadModuleWithMainFileIfNeeded(module, courseId, AddonModResourceProvider.COMPONENT,
|
||||||
module.id, module.contents).then((result) => {
|
module.id, module.contents).then((result) => {
|
||||||
const file = module.contents[0],
|
const file = module.contents[0],
|
||||||
ext = this.mimetypeUtils.getFileExtension(file.filename),
|
ext = this.mimetypeUtils.getFileExtension(file.filename),
|
||||||
|
|
|
@ -39,22 +39,13 @@ export class CoreCourseModuleComponent implements OnInit, OnDestroy {
|
||||||
@Input('downloadEnabled') set enabled(value: boolean) {
|
@Input('downloadEnabled') set enabled(value: boolean) {
|
||||||
this.downloadEnabled = value;
|
this.downloadEnabled = value;
|
||||||
|
|
||||||
if (this.module.handlerData.showDownloadButton && this.downloadEnabled && !this.statusObserver) {
|
if (this.module.handlerData.showDownloadButton && this.downloadEnabled && !this.statusCalculated) {
|
||||||
// First time that the download is enabled. Initialize the data.
|
// First time that the download is enabled. Initialize the data.
|
||||||
|
this.statusCalculated = true;
|
||||||
this.spinner = true; // Show spinner while calculating the status.
|
this.spinner = true; // Show spinner while calculating the status.
|
||||||
|
|
||||||
this.prefetchHandler = this.prefetchDelegate.getPrefetchHandlerFor(this.module);
|
|
||||||
|
|
||||||
// Get current status to decide which icon should be shown.
|
// Get current status to decide which icon should be shown.
|
||||||
this.prefetchDelegate.getModuleStatus(this.module, this.courseId).then(this.showStatus.bind(this));
|
this.prefetchDelegate.getModuleStatus(this.module, this.courseId).then(this.showStatus.bind(this));
|
||||||
|
|
||||||
// Listen for changes on this module status.
|
|
||||||
this.statusObserver = this.eventsProvider.on(CoreEventsProvider.PACKAGE_STATUS_CHANGED, (data) => {
|
|
||||||
if (data.componentId === this.module.id && this.prefetchHandler &&
|
|
||||||
data.component === this.prefetchHandler.component) {
|
|
||||||
this.showStatus(data.status);
|
|
||||||
}
|
|
||||||
}, this.sitesProvider.getCurrentSiteId());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@Output() completionChanged?: EventEmitter<void>; // Will emit an event when the module completion changes.
|
@Output() completionChanged?: EventEmitter<void>; // Will emit an event when the module completion changes.
|
||||||
|
@ -66,6 +57,7 @@ export class CoreCourseModuleComponent implements OnInit, OnDestroy {
|
||||||
|
|
||||||
protected prefetchHandler: CoreCourseModulePrefetchHandler;
|
protected prefetchHandler: CoreCourseModulePrefetchHandler;
|
||||||
protected statusObserver;
|
protected statusObserver;
|
||||||
|
protected statusCalculated = false;
|
||||||
protected isDestroyed = false;
|
protected isDestroyed = false;
|
||||||
|
|
||||||
constructor(@Optional() protected navCtrl: NavController, protected prefetchDelegate: CoreCourseModulePrefetchDelegate,
|
constructor(@Optional() protected navCtrl: NavController, protected prefetchDelegate: CoreCourseModulePrefetchDelegate,
|
||||||
|
@ -82,6 +74,25 @@ export class CoreCourseModuleComponent implements OnInit, OnDestroy {
|
||||||
if (this.module && !this.module.handlerData) {
|
if (this.module && !this.module.handlerData) {
|
||||||
this.module.handlerData = {};
|
this.module.handlerData = {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (this.module.handlerData.showDownloadButton) {
|
||||||
|
// Listen for changes on this module status, even if download isn't enabled.
|
||||||
|
this.prefetchHandler = this.prefetchDelegate.getPrefetchHandlerFor(this.module);
|
||||||
|
|
||||||
|
this.statusObserver = this.eventsProvider.on(CoreEventsProvider.PACKAGE_STATUS_CHANGED, (data) => {
|
||||||
|
if (data.componentId === this.module.id && this.prefetchHandler &&
|
||||||
|
data.component === this.prefetchHandler.component) {
|
||||||
|
|
||||||
|
if (this.downloadEnabled) {
|
||||||
|
// Download is enabled, show the status.
|
||||||
|
this.showStatus(data.status);
|
||||||
|
} else if (this.module.handlerData.updateStatus) {
|
||||||
|
// Download isn't enabled but the handler defines a updateStatus function, call it anyway.
|
||||||
|
this.module.handlerData.updateStatus(data.status);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, this.sitesProvider.getCurrentSiteId());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue