From efa25b857cc0a2c7bc70a7ec31e614a2a2f25a9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pau=20Ferrer=20Oca=C3=B1a?= Date: Tue, 17 Dec 2019 13:26:34 +0100 Subject: [PATCH] MOBILE-3213 courses: Check download courses on all related blocks --- .../addon-block-recentlyaccessedcourses.html | 4 ++-- .../recentlyaccessedcourses.ts | 15 +++++++++++++++ .../addon-block-starredcourses.html | 4 ++-- .../components/starredcourses/starredcourses.ts | 15 +++++++++++++++ 4 files changed, 34 insertions(+), 4 deletions(-) diff --git a/src/addon/block/recentlyaccessedcourses/components/recentlyaccessedcourses/addon-block-recentlyaccessedcourses.html b/src/addon/block/recentlyaccessedcourses/components/recentlyaccessedcourses/addon-block-recentlyaccessedcourses.html index 7aadba0cb..aede44831 100644 --- a/src/addon/block/recentlyaccessedcourses/components/recentlyaccessedcourses/addon-block-recentlyaccessedcourses.html +++ b/src/addon/block/recentlyaccessedcourses/components/recentlyaccessedcourses/addon-block-recentlyaccessedcourses.html @@ -1,6 +1,6 @@

{{ 'addon.block_recentlyaccessedcourses.pluginname' | translate }}

-
+
@@ -13,7 +13,7 @@
- +
diff --git a/src/addon/block/recentlyaccessedcourses/components/recentlyaccessedcourses/recentlyaccessedcourses.ts b/src/addon/block/recentlyaccessedcourses/components/recentlyaccessedcourses/recentlyaccessedcourses.ts index aa7dbdd02..4b61bfeb1 100644 --- a/src/addon/block/recentlyaccessedcourses/components/recentlyaccessedcourses/recentlyaccessedcourses.ts +++ b/src/addon/block/recentlyaccessedcourses/components/recentlyaccessedcourses/recentlyaccessedcourses.ts @@ -37,10 +37,13 @@ export class AddonBlockRecentlyAccessedCoursesComponent extends CoreBlockBaseCom icon: '', badge: '' }; + downloadCourseEnabled: boolean; + downloadCoursesEnabled: boolean; protected prefetchIconsInitialized = false; protected isDestroyed; protected coursesObserver; + protected updateSiteObserver; protected courseIds = []; protected fetchContentDefaultError = 'Error getting recent courses data.'; @@ -58,6 +61,17 @@ export class AddonBlockRecentlyAccessedCoursesComponent extends CoreBlockBaseCom */ ngOnInit(): void { + // Refresh the enabled flags if enabled. + this.downloadCourseEnabled = !this.coursesProvider.isDownloadCourseDisabledInSite(); + this.downloadCoursesEnabled = !this.coursesProvider.isDownloadCoursesDisabledInSite(); + + // Refresh the enabled flags if site is updated. + this.updateSiteObserver = this.eventsProvider.on(CoreEventsProvider.SITE_UPDATED, () => { + this.downloadCourseEnabled = !this.coursesProvider.isDownloadCourseDisabledInSite(); + this.downloadCoursesEnabled = !this.coursesProvider.isDownloadCoursesDisabledInSite(); + + }, this.sitesProvider.getCurrentSiteId()); + this.coursesObserver = this.eventsProvider.on(CoreCoursesProvider.EVENT_MY_COURSES_UPDATED, () => { this.refreshContent(); }, this.sitesProvider.getCurrentSiteId()); @@ -154,5 +168,6 @@ export class AddonBlockRecentlyAccessedCoursesComponent extends CoreBlockBaseCom ngOnDestroy(): void { this.isDestroyed = true; this.coursesObserver && this.coursesObserver.off(); + this.updateSiteObserver && this.updateSiteObserver.off(); } } diff --git a/src/addon/block/starredcourses/components/starredcourses/addon-block-starredcourses.html b/src/addon/block/starredcourses/components/starredcourses/addon-block-starredcourses.html index a6b1d49b7..af38133a9 100644 --- a/src/addon/block/starredcourses/components/starredcourses/addon-block-starredcourses.html +++ b/src/addon/block/starredcourses/components/starredcourses/addon-block-starredcourses.html @@ -1,6 +1,6 @@

{{ 'addon.block_starredcourses.pluginname' | translate }}

-
+
@@ -13,7 +13,7 @@
- +
diff --git a/src/addon/block/starredcourses/components/starredcourses/starredcourses.ts b/src/addon/block/starredcourses/components/starredcourses/starredcourses.ts index e5cabc99c..8acddb2a2 100644 --- a/src/addon/block/starredcourses/components/starredcourses/starredcourses.ts +++ b/src/addon/block/starredcourses/components/starredcourses/starredcourses.ts @@ -37,10 +37,13 @@ export class AddonBlockStarredCoursesComponent extends CoreBlockBaseComponent im icon: '', badge: '' }; + downloadCourseEnabled: boolean; + downloadCoursesEnabled: boolean; protected prefetchIconsInitialized = false; protected isDestroyed; protected coursesObserver; + protected updateSiteObserver; protected courseIds = []; protected fetchContentDefaultError = 'Error getting starred courses data.'; @@ -58,6 +61,17 @@ export class AddonBlockStarredCoursesComponent extends CoreBlockBaseComponent im */ ngOnInit(): void { + // Refresh the enabled flags if enabled. + this.downloadCourseEnabled = !this.coursesProvider.isDownloadCourseDisabledInSite(); + this.downloadCoursesEnabled = !this.coursesProvider.isDownloadCoursesDisabledInSite(); + + // Refresh the enabled flags if site is updated. + this.updateSiteObserver = this.eventsProvider.on(CoreEventsProvider.SITE_UPDATED, () => { + this.downloadCourseEnabled = !this.coursesProvider.isDownloadCourseDisabledInSite(); + this.downloadCoursesEnabled = !this.coursesProvider.isDownloadCoursesDisabledInSite(); + + }, this.sitesProvider.getCurrentSiteId()); + this.coursesObserver = this.eventsProvider.on(CoreCoursesProvider.EVENT_MY_COURSES_UPDATED, () => { this.refreshContent(); }, this.sitesProvider.getCurrentSiteId()); @@ -154,5 +168,6 @@ export class AddonBlockStarredCoursesComponent extends CoreBlockBaseComponent im ngOnDestroy(): void { this.isDestroyed = true; this.coursesObserver && this.coursesObserver.off(); + this.updateSiteObserver && this.updateSiteObserver.off(); } }