MOBILE-2462 course: Don't refresh singleactivity when completion changes
parent
1311e8b9e2
commit
16c1538506
|
@ -113,4 +113,15 @@ export class CoreCourseFormatSingleActivityHandler implements CoreCourseFormatHa
|
|||
getCourseFormatComponent(injector: Injector, course: any): any | Promise<any> {
|
||||
return CoreCourseFormatSingleActivityComponent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether the view should be refreshed when completion changes. If your course format doesn't display
|
||||
* activity completion then you should return false.
|
||||
*
|
||||
* @param {any} course The course.
|
||||
* @return {boolean|Promise<boolean>} Whether course view should be refreshed when an activity completion changes.
|
||||
*/
|
||||
shouldRefreshWhenCompletionChanges(course: any): boolean | Promise<boolean> {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -80,9 +80,14 @@ export class CoreCourseSectionPage implements OnDestroy {
|
|||
this.displayEnableDownload = courseFormatDelegate.displayEnableDownload(this.course);
|
||||
this.downloadCourseEnabled = !this.coursesProvider.isDownloadCourseDisabledInSite();
|
||||
|
||||
this.completionObserver = eventsProvider.on(CoreEventsProvider.COMPLETION_MODULE_VIEWED, (data) => {
|
||||
if (data && data.courseId == this.course.id) {
|
||||
this.refreshAfterCompletionChange();
|
||||
// Check if the course format requires the view to be refreshed when completion changes.
|
||||
courseFormatDelegate.shouldRefreshWhenCompletionChanges(this.course).then((shouldRefresh) => {
|
||||
if (shouldRefresh) {
|
||||
this.completionObserver = eventsProvider.on(CoreEventsProvider.COMPLETION_MODULE_VIEWED, (data) => {
|
||||
if (data && data.courseId == this.course.id) {
|
||||
this.refreshAfterCompletionChange();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -157,4 +157,15 @@ export class CoreCourseFormatDefaultHandler implements CoreCourseFormatHandler {
|
|||
openCourse(navCtrl: NavController, course: any): Promise<any> {
|
||||
return navCtrl.push('CoreCourseSectionPage', { course: course });
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether the view should be refreshed when completion changes. If your course format doesn't display
|
||||
* activity completion then you should return false.
|
||||
*
|
||||
* @param {any} course The course.
|
||||
* @return {boolean|Promise<boolean>} Whether course view should be refreshed when an activity completion changes.
|
||||
*/
|
||||
shouldRefreshWhenCompletionChanges(course: any): boolean | Promise<boolean> {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -158,6 +158,15 @@ export interface CoreCourseFormatHandler extends CoreDelegateHandler {
|
|||
* @return {Promise<any>} Promise resolved when the data is invalidated.
|
||||
*/
|
||||
invalidateData?(course: any, sections: any[]): Promise<any>;
|
||||
|
||||
/**
|
||||
* Whether the view should be refreshed when completion changes. If your course format doesn't display
|
||||
* activity completion then you should return false.
|
||||
*
|
||||
* @param {any} course The course.
|
||||
* @return {boolean|Promise<boolean>} Whether course view should be refreshed when an activity completion changes.
|
||||
*/
|
||||
shouldRefreshWhenCompletionChanges?(course: any): boolean | Promise<boolean>;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -337,4 +346,15 @@ export class CoreCourseFormatDelegate extends CoreDelegate {
|
|||
openCourse(navCtrl: NavController, course: any): Promise<any> {
|
||||
return this.executeFunctionOnEnabled(course.format, 'openCourse', [navCtrl, course]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether the view should be refreshed when completion changes. If your course format doesn't display
|
||||
* activity completion then you should return false.
|
||||
*
|
||||
* @param {any} course The course.
|
||||
* @return {Promise<boolean>} Whether course view should be refreshed when an activity completion changes.
|
||||
*/
|
||||
shouldRefreshWhenCompletionChanges(course: any): Promise<boolean> {
|
||||
return Promise.resolve(this.executeFunctionOnEnabled(course.format, 'shouldRefreshWhenCompletionChanges', [course]));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue