From 3ef367db762365f3d884506ae1c2dacf95dcf3cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pau=20Ferrer=20Oca=C3=B1a?= Date: Thu, 28 Dec 2017 13:25:09 +0100 Subject: [PATCH] MOBILE-2308 events: Adapt events to new functions --- src/classes/site.ts | 10 +++++----- .../pages/course-preview/course-preview.ts | 2 +- src/core/courses/pages/my-courses/my-courses.ts | 16 ++++++---------- src/core/login/pages/credentials/credentials.ts | 9 ++------- src/core/login/providers/helper.ts | 3 +-- src/core/mainmenu/pages/more/more.ts | 8 ++------ src/providers/filepool.ts | 3 +-- src/providers/sites.ts | 12 ++++++------ 8 files changed, 24 insertions(+), 39 deletions(-) diff --git a/src/classes/site.ts b/src/classes/site.ts index fea101fa3..553a1cf19 100644 --- a/src/classes/site.ts +++ b/src/classes/site.ts @@ -504,27 +504,27 @@ export class CoreSite { } // Session expired, trigger event. - this.eventsProvider.trigger(CoreEventsProvider.SESSION_EXPIRED, {siteId: this.id}); + this.eventsProvider.trigger(CoreEventsProvider.SESSION_EXPIRED, {}, this.id); // Change error message. We'll try to get data from cache. error.message = this.translate.instant('core.lostconnection'); } else if (error.errorcode === 'userdeleted') { // User deleted, trigger event. - this.eventsProvider.trigger(CoreEventsProvider.USER_DELETED, {siteId: this.id, params: data}); + this.eventsProvider.trigger(CoreEventsProvider.USER_DELETED, {params: data}, this.id); error.message = this.translate.instant('core.userdeleted'); return Promise.reject(error); } else if (error.errorcode === 'forcepasswordchangenotice') { // Password Change Forced, trigger event. - this.eventsProvider.trigger(CoreEventsProvider.PASSWORD_CHANGE_FORCED, {siteId: this.id}); + this.eventsProvider.trigger(CoreEventsProvider.PASSWORD_CHANGE_FORCED, {}, this.id); error.message = this.translate.instant('core.forcepasswordchangenotice'); return Promise.reject(error); } else if (error.errorcode === 'usernotfullysetup') { // User not fully setup, trigger event. - this.eventsProvider.trigger(CoreEventsProvider.USER_NOT_FULLY_SETUP, {siteId: this.id}); + this.eventsProvider.trigger(CoreEventsProvider.USER_NOT_FULLY_SETUP, {}, this.id); error.message = this.translate.instant('core.usernotfullysetup'); return Promise.reject(error); } else if (error.errorcode === 'sitepolicynotagreed') { // Site policy not agreed, trigger event. - this.eventsProvider.trigger(CoreEventsProvider.SITE_POLICY_NOT_AGREED, {siteId: this.id}); + this.eventsProvider.trigger(CoreEventsProvider.SITE_POLICY_NOT_AGREED, {}, this.id); error.message = this.translate.instant('core.sitepolicynotagreederror'); return Promise.reject(error); } else if (error.errorcode === 'dmlwriteexception' && this.textUtils.hasUnicodeData(data)) { diff --git a/src/core/courses/pages/course-preview/course-preview.ts b/src/core/courses/pages/course-preview/course-preview.ts index 1076440cd..0789790c9 100644 --- a/src/core/courses/pages/course-preview/course-preview.ts +++ b/src/core/courses/pages/course-preview/course-preview.ts @@ -307,7 +307,7 @@ export class CoreCoursesCoursePreviewPage implements OnDestroy { this.refreshData().finally(() => { // My courses have been updated, trigger event. this.eventsProvider.trigger( - CoreCoursesProvider.EVENT_MY_COURSES_UPDATED, {siteId: this.sitesProvider.getCurrentSiteId()}); + CoreCoursesProvider.EVENT_MY_COURSES_UPDATED, {}, this.sitesProvider.getCurrentSiteId()); }); }); }).catch((error) => { diff --git a/src/core/courses/pages/my-courses/my-courses.ts b/src/core/courses/pages/my-courses/my-courses.ts index ea3941f05..3259c9d47 100644 --- a/src/core/courses/pages/my-courses/my-courses.ts +++ b/src/core/courses/pages/my-courses/my-courses.ts @@ -53,17 +53,13 @@ export class CoreCoursesMyCoursesPage implements OnDestroy { this.coursesLoaded = true; }); - this.myCoursesObserver = this.eventsProvider.on(CoreCoursesProvider.EVENT_MY_COURSES_UPDATED, (data) => { - if (data.siteId == this.sitesProvider.getCurrentSiteId()) { - this.fetchCourses(); - } - }); + this.myCoursesObserver = this.eventsProvider.on(CoreCoursesProvider.EVENT_MY_COURSES_UPDATED, () => { + this.fetchCourses(); + }, this.sitesProvider.getCurrentSiteId()); - this.siteUpdatedObserver = this.eventsProvider.on(CoreEventsProvider.SITE_UPDATED, (data) => { - if (data.siteId == this.sitesProvider.getCurrentSiteId()) { - this.searchEnabled = !this.coursesProvider.isSearchCoursesDisabledInSite(); - } - }); + this.siteUpdatedObserver = this.eventsProvider.on(CoreEventsProvider.SITE_UPDATED, () => { + this.searchEnabled = !this.coursesProvider.isSearchCoursesDisabledInSite(); + }, this.sitesProvider.getCurrentSiteId()); } /** diff --git a/src/core/login/pages/credentials/credentials.ts b/src/core/login/pages/credentials/credentials.ts index 8d0dc4138..ceb996031 100644 --- a/src/core/login/pages/credentials/credentials.ts +++ b/src/core/login/pages/credentials/credentials.ts @@ -84,10 +84,7 @@ export class CoreLoginCredentialsPage { */ ionViewDidLeave() { this.viewLeft = true; - this.eventsProvider.trigger(CoreEventsProvider.LOGIN_SITE_UNCHECKED, { - siteId: this.siteId, - config: this.siteConfig - }); + this.eventsProvider.trigger(CoreEventsProvider.LOGIN_SITE_UNCHECKED, {config: this.siteConfig}, this.siteId); } /** @@ -146,9 +143,7 @@ export class CoreLoginCredentialsPage { if (!this.eventThrown && !this.viewLeft) { this.eventThrown = true; - this.eventsProvider.trigger(CoreEventsProvider.LOGIN_SITE_CHECKED, { - config: this.siteConfig - }); + this.eventsProvider.trigger(CoreEventsProvider.LOGIN_SITE_CHECKED, {config: this.siteConfig}); } } else { this.siteName = null; diff --git a/src/core/login/providers/helper.ts b/src/core/login/providers/helper.ts index 7ffc71213..08caa097c 100644 --- a/src/core/login/providers/helper.ts +++ b/src/core/login/providers/helper.ts @@ -574,10 +574,9 @@ export class CoreLoginHelperProvider { if (site.isLoggedOut()) { this.eventsProvider.trigger(CoreEventsProvider.SESSION_EXPIRED, { - siteId: site.getId(), pageName: pageName, params: params - }); + }, site.getId()); return true; } return false; diff --git a/src/core/mainmenu/pages/more/more.ts b/src/core/mainmenu/pages/more/more.ts index 0f0b95ff8..1f2fa4f28 100644 --- a/src/core/mainmenu/pages/more/more.ts +++ b/src/core/mainmenu/pages/more/more.ts @@ -45,12 +45,8 @@ export class CoreMainMenuMorePage implements OnDestroy { private navCtrl: NavController, private mainMenuProvider: CoreMainMenuProvider, eventsProvider: CoreEventsProvider) { this.langObserver = eventsProvider.on(CoreEventsProvider.LANGUAGE_CHANGED, this.loadSiteInfo.bind(this)); - this.updateSiteObserver = eventsProvider.on(CoreEventsProvider.SITE_UPDATED, (data) => { - if (sitesProvider.getCurrentSiteId() == data.siteId) { - this.loadSiteInfo(); - } - }); - + this.updateSiteObserver = eventsProvider.on(CoreEventsProvider.SITE_UPDATED, this.loadSiteInfo.bind(this), + sitesProvider.getCurrentSiteId()); this.loadSiteInfo(); } diff --git a/src/providers/filepool.ts b/src/providers/filepool.ts index 3a122ace8..a576880ee 100644 --- a/src/providers/filepool.ts +++ b/src/providers/filepool.ts @@ -2692,12 +2692,11 @@ export class CoreFilepoolProvider { */ protected triggerPackageStatusChanged(siteId: string, status: string, component: string, componentId?: string|number) : void { const data = { - siteid: siteId, component: component, componentId: this.fixComponentId(componentId), status: status } - this.eventsProvider.trigger(CoreEventsProvider.PACKAGE_STATUS_CHANGED, data); + this.eventsProvider.trigger(CoreEventsProvider.PACKAGE_STATUS_CHANGED, data, siteId); } /** diff --git a/src/providers/sites.ts b/src/providers/sites.ts index aaba7ee3d..e912ef2bf 100644 --- a/src/providers/sites.ts +++ b/src/providers/sites.ts @@ -398,7 +398,7 @@ export class CoreSitesProvider { this.sites[siteId] = candidateSite; // Store session. this.login(siteId); - this.eventsProvider.trigger(CoreEventsProvider.SITE_ADDED, siteId); + this.eventsProvider.trigger(CoreEventsProvider.SITE_ADDED, {}, siteId); if (this.siteTablesSchemas.length) { // Create tables in the site's database. @@ -558,7 +558,7 @@ export class CoreSitesProvider { // Check if local_mobile was installed to Moodle. return site.checkIfLocalMobileInstalledAndNotUsed().then(() => { // Local mobile was added. Throw invalid session to force reconnect and create a new token. - this.eventsProvider.trigger(CoreEventsProvider.SESSION_EXPIRED, {siteId: siteId}); + this.eventsProvider.trigger(CoreEventsProvider.SESSION_EXPIRED, {}, siteId); }, () => { // Update site info. We don't block the UI. this.updateSiteInfo(siteId); @@ -622,7 +622,7 @@ export class CoreSitesProvider { // DB remove shouldn't fail, but we'll go ahead even if it does. return site.deleteFolder(); }).then(() => { - this.eventsProvider.trigger(CoreEventsProvider.SITE_DELETED, site); + this.eventsProvider.trigger(CoreEventsProvider.SITE_DELETED, site, siteId); }); }); }); @@ -801,7 +801,7 @@ export class CoreSitesProvider { siteId: siteId }; return this.appDB.insertOrUpdateRecord(this.CURRENT_SITE_TABLE, entry, {id: 1}).then(() => { - this.eventsProvider.trigger(CoreEventsProvider.LOGIN, {siteId: siteId}); + this.eventsProvider.trigger(CoreEventsProvider.LOGIN, {}, siteId); }); } @@ -829,7 +829,7 @@ export class CoreSitesProvider { promises.push(this.appDB.deleteRecords(this.CURRENT_SITE_TABLE, {id: 1})); return Promise.all(promises).finally(() => { - this.eventsProvider.trigger(CoreEventsProvider.LOGOUT, {siteId: siteId}); + this.eventsProvider.trigger(CoreEventsProvider.LOGOUT, {}, siteId); }); } @@ -936,7 +936,7 @@ export class CoreSitesProvider { } return this.appDB.updateRecords(this.SITES_TABLE, newValues, {id: siteId}).finally(() => { - this.eventsProvider.trigger(CoreEventsProvider.SITE_UPDATED, {siteId: siteId}); + this.eventsProvider.trigger(CoreEventsProvider.SITE_UPDATED, {}, siteId); }); }); });