MOBILE-2462 course: Don't refresh singleactivity when completion changes

main
Dani Palou 2018-07-04 11:13:42 +02:00
parent 1311e8b9e2
commit 16c1538506
4 changed files with 50 additions and 3 deletions

View File

@ -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;
}
}

View File

@ -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();
}
});
}
});

View File

@ -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;
}
}

View File

@ -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]));
}
}