MOBILE-2688 courses: Invalidate course list when updated

main
Pau Ferrer Ocaña 2018-11-08 12:29:43 +01:00
parent ed9dd1bba0
commit 0c0c01b8ce
4 changed files with 16 additions and 4 deletions

View File

@ -1188,6 +1188,7 @@
"core.courses.errorselfenrol": "local_moodlemobileapp",
"core.courses.filtermycourses": "local_moodlemobileapp",
"core.courses.frontpage": "admin",
"core.courses.hidecourse": "block_myoverview",
"core.courses.mycourses": "moodle",
"core.courses.mymoodle": "admin",
"core.courses.nocourses": "my",
@ -1203,6 +1204,7 @@
"core.courses.searchcoursesadvice": "local_moodlemobileapp",
"core.courses.selfenrolment": "local_moodlemobileapp",
"core.courses.sendpaymentbutton": "enrol_paypal",
"core.courses.show": "block_myoverview",
"core.courses.totalcoursesearchresults": "local_moodlemobileapp",
"core.currentdevice": "local_moodlemobileapp",
"core.datastoredoffline": "local_moodlemobileapp",

View File

@ -15,6 +15,7 @@
import { Component, OnInit, OnDestroy, Injector } from '@angular/core';
import { CoreEventsProvider } from '@providers/events';
import { CoreUtilsProvider } from '@providers/utils/utils';
import { CoreSitesProvider } from '@providers/sites';
import { CoreCoursesProvider } from '@core/courses/providers/courses';
import { CoreCoursesHelperProvider } from '@core/courses/providers/helper';
import { CoreCourseHelperProvider } from '@core/course/providers/helper';
@ -40,13 +41,15 @@ export class AddonBlockRecentlyAccessedCoursesComponent extends CoreBlockBaseCom
protected prefetchIconsInitialized = false;
protected isDestroyed;
protected updateSiteObserver;
protected coursesObserver;
protected courseIds = [];
protected fetchContentDefaultError = 'Error getting recent courses data.';
constructor(injector: Injector, private coursesProvider: CoreCoursesProvider,
private courseCompletionProvider: AddonCourseCompletionProvider, private eventsProvider: CoreEventsProvider,
private courseHelper: CoreCourseHelperProvider, private utils: CoreUtilsProvider,
private courseOptionsDelegate: CoreCourseOptionsDelegate, private coursesHelper: CoreCoursesHelperProvider) {
private courseOptionsDelegate: CoreCourseOptionsDelegate, private coursesHelper: CoreCoursesHelperProvider,
private sitesProvider: CoreSitesProvider) {
super(injector, 'AddonBlockRecentlyAccessedCoursesComponent');
}
@ -67,7 +70,11 @@ export class AddonBlockRecentlyAccessedCoursesComponent extends CoreBlockBaseCom
// Download all courses is enabled now, initialize it.
this.initPrefetchCoursesIcons();
}
});
}, this.sitesProvider.getCurrentSiteId());
this.coursesObserver = this.eventsProvider.on(CoreCoursesProvider.EVENT_MY_COURSES_UPDATED, () => {
this.refreshContent();
}, this.sitesProvider.getCurrentSiteId());
super.ngOnInit();
}
@ -147,6 +154,7 @@ export class AddonBlockRecentlyAccessedCoursesComponent extends CoreBlockBaseCom
*/
ngOnDestroy(): void {
this.isDestroyed = true;
this.coursesObserver && this.coursesObserver.off();
this.updateSiteObserver && this.updateSiteObserver.off();
}
}

View File

@ -68,6 +68,7 @@ export class CoreCoursesCourseProgressComponent implements OnInit, OnDestroy {
this.initPrefetchCourse();
}
// This field is only available from 3.6 onwards.
this.courseOptionMenuEnabled = typeof this.course.isfavourite != 'undefined';
// Refresh the enabled flag if site is updated.
@ -203,7 +204,8 @@ export class CoreCoursesCourseProgressComponent implements OnInit, OnDestroy {
protected setCourseHidden(hide: boolean): void {
this.showSpinner = true;
this.userProvider.updateUserPreference('block_myoverview_hidden_course_' + this.course.id, hide ? 1 : false).then(() => {
// We should use null to unset the preference.
this.userProvider.updateUserPreference('block_myoverview_hidden_course_' + this.course.id, hide ? 1 : null).then(() => {
this.course.hidden = hide;
this.eventsProvider.trigger(
CoreCoursesProvider.EVENT_MY_COURSES_UPDATED, {course: this.course}, this.sitesProvider.getCurrentSiteId());

View File

@ -69,7 +69,7 @@ export class CoreCoursesDashboardPage implements OnDestroy {
this.updateSiteObserver = this.eventsProvider.on(CoreEventsProvider.SITE_UPDATED, () => {
this.searchEnabled = !this.coursesProvider.isSearchCoursesDisabledInSite();
this.loadSiteName();
});
}, this.sitesProvider.getCurrentSiteId());
const promises = [];