MOBILE-2308 events: Adapt events to new functions

main
Pau Ferrer Ocaña 2017-12-28 13:25:09 +01:00
parent 6f671fe39f
commit 3ef367db76
8 changed files with 24 additions and 39 deletions

View File

@ -504,27 +504,27 @@ export class CoreSite {
} }
// Session expired, trigger event. // 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. // Change error message. We'll try to get data from cache.
error.message = this.translate.instant('core.lostconnection'); error.message = this.translate.instant('core.lostconnection');
} else if (error.errorcode === 'userdeleted') { } else if (error.errorcode === 'userdeleted') {
// User deleted, trigger event. // 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'); error.message = this.translate.instant('core.userdeleted');
return Promise.reject(error); return Promise.reject(error);
} else if (error.errorcode === 'forcepasswordchangenotice') { } else if (error.errorcode === 'forcepasswordchangenotice') {
// Password Change Forced, trigger event. // 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'); error.message = this.translate.instant('core.forcepasswordchangenotice');
return Promise.reject(error); return Promise.reject(error);
} else if (error.errorcode === 'usernotfullysetup') { } else if (error.errorcode === 'usernotfullysetup') {
// User not fully setup, trigger event. // 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'); error.message = this.translate.instant('core.usernotfullysetup');
return Promise.reject(error); return Promise.reject(error);
} else if (error.errorcode === 'sitepolicynotagreed') { } else if (error.errorcode === 'sitepolicynotagreed') {
// Site policy not agreed, trigger event. // 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'); error.message = this.translate.instant('core.sitepolicynotagreederror');
return Promise.reject(error); return Promise.reject(error);
} else if (error.errorcode === 'dmlwriteexception' && this.textUtils.hasUnicodeData(data)) { } else if (error.errorcode === 'dmlwriteexception' && this.textUtils.hasUnicodeData(data)) {

View File

@ -307,7 +307,7 @@ export class CoreCoursesCoursePreviewPage implements OnDestroy {
this.refreshData().finally(() => { this.refreshData().finally(() => {
// My courses have been updated, trigger event. // My courses have been updated, trigger event.
this.eventsProvider.trigger( this.eventsProvider.trigger(
CoreCoursesProvider.EVENT_MY_COURSES_UPDATED, {siteId: this.sitesProvider.getCurrentSiteId()}); CoreCoursesProvider.EVENT_MY_COURSES_UPDATED, {}, this.sitesProvider.getCurrentSiteId());
}); });
}); });
}).catch((error) => { }).catch((error) => {

View File

@ -53,17 +53,13 @@ export class CoreCoursesMyCoursesPage implements OnDestroy {
this.coursesLoaded = true; this.coursesLoaded = true;
}); });
this.myCoursesObserver = this.eventsProvider.on(CoreCoursesProvider.EVENT_MY_COURSES_UPDATED, (data) => { this.myCoursesObserver = this.eventsProvider.on(CoreCoursesProvider.EVENT_MY_COURSES_UPDATED, () => {
if (data.siteId == this.sitesProvider.getCurrentSiteId()) { this.fetchCourses();
this.fetchCourses(); }, this.sitesProvider.getCurrentSiteId());
}
});
this.siteUpdatedObserver = this.eventsProvider.on(CoreEventsProvider.SITE_UPDATED, (data) => { this.siteUpdatedObserver = this.eventsProvider.on(CoreEventsProvider.SITE_UPDATED, () => {
if (data.siteId == this.sitesProvider.getCurrentSiteId()) { this.searchEnabled = !this.coursesProvider.isSearchCoursesDisabledInSite();
this.searchEnabled = !this.coursesProvider.isSearchCoursesDisabledInSite(); }, this.sitesProvider.getCurrentSiteId());
}
});
} }
/** /**

View File

@ -84,10 +84,7 @@ export class CoreLoginCredentialsPage {
*/ */
ionViewDidLeave() { ionViewDidLeave() {
this.viewLeft = true; this.viewLeft = true;
this.eventsProvider.trigger(CoreEventsProvider.LOGIN_SITE_UNCHECKED, { this.eventsProvider.trigger(CoreEventsProvider.LOGIN_SITE_UNCHECKED, {config: this.siteConfig}, this.siteId);
siteId: this.siteId,
config: this.siteConfig
});
} }
/** /**
@ -146,9 +143,7 @@ export class CoreLoginCredentialsPage {
if (!this.eventThrown && !this.viewLeft) { if (!this.eventThrown && !this.viewLeft) {
this.eventThrown = true; this.eventThrown = true;
this.eventsProvider.trigger(CoreEventsProvider.LOGIN_SITE_CHECKED, { this.eventsProvider.trigger(CoreEventsProvider.LOGIN_SITE_CHECKED, {config: this.siteConfig});
config: this.siteConfig
});
} }
} else { } else {
this.siteName = null; this.siteName = null;

View File

@ -574,10 +574,9 @@ export class CoreLoginHelperProvider {
if (site.isLoggedOut()) { if (site.isLoggedOut()) {
this.eventsProvider.trigger(CoreEventsProvider.SESSION_EXPIRED, { this.eventsProvider.trigger(CoreEventsProvider.SESSION_EXPIRED, {
siteId: site.getId(),
pageName: pageName, pageName: pageName,
params: params params: params
}); }, site.getId());
return true; return true;
} }
return false; return false;

View File

@ -45,12 +45,8 @@ export class CoreMainMenuMorePage implements OnDestroy {
private navCtrl: NavController, private mainMenuProvider: CoreMainMenuProvider, eventsProvider: CoreEventsProvider) { private navCtrl: NavController, private mainMenuProvider: CoreMainMenuProvider, eventsProvider: CoreEventsProvider) {
this.langObserver = eventsProvider.on(CoreEventsProvider.LANGUAGE_CHANGED, this.loadSiteInfo.bind(this)); this.langObserver = eventsProvider.on(CoreEventsProvider.LANGUAGE_CHANGED, this.loadSiteInfo.bind(this));
this.updateSiteObserver = eventsProvider.on(CoreEventsProvider.SITE_UPDATED, (data) => { this.updateSiteObserver = eventsProvider.on(CoreEventsProvider.SITE_UPDATED, this.loadSiteInfo.bind(this),
if (sitesProvider.getCurrentSiteId() == data.siteId) { sitesProvider.getCurrentSiteId());
this.loadSiteInfo();
}
});
this.loadSiteInfo(); this.loadSiteInfo();
} }

View File

@ -2692,12 +2692,11 @@ export class CoreFilepoolProvider {
*/ */
protected triggerPackageStatusChanged(siteId: string, status: string, component: string, componentId?: string|number) : void { protected triggerPackageStatusChanged(siteId: string, status: string, component: string, componentId?: string|number) : void {
const data = { const data = {
siteid: siteId,
component: component, component: component,
componentId: this.fixComponentId(componentId), componentId: this.fixComponentId(componentId),
status: status status: status
} }
this.eventsProvider.trigger(CoreEventsProvider.PACKAGE_STATUS_CHANGED, data); this.eventsProvider.trigger(CoreEventsProvider.PACKAGE_STATUS_CHANGED, data, siteId);
} }
/** /**

View File

@ -398,7 +398,7 @@ export class CoreSitesProvider {
this.sites[siteId] = candidateSite; this.sites[siteId] = candidateSite;
// Store session. // Store session.
this.login(siteId); this.login(siteId);
this.eventsProvider.trigger(CoreEventsProvider.SITE_ADDED, siteId); this.eventsProvider.trigger(CoreEventsProvider.SITE_ADDED, {}, siteId);
if (this.siteTablesSchemas.length) { if (this.siteTablesSchemas.length) {
// Create tables in the site's database. // Create tables in the site's database.
@ -558,7 +558,7 @@ export class CoreSitesProvider {
// Check if local_mobile was installed to Moodle. // Check if local_mobile was installed to Moodle.
return site.checkIfLocalMobileInstalledAndNotUsed().then(() => { return site.checkIfLocalMobileInstalledAndNotUsed().then(() => {
// Local mobile was added. Throw invalid session to force reconnect and create a new token. // 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. // Update site info. We don't block the UI.
this.updateSiteInfo(siteId); this.updateSiteInfo(siteId);
@ -622,7 +622,7 @@ export class CoreSitesProvider {
// DB remove shouldn't fail, but we'll go ahead even if it does. // DB remove shouldn't fail, but we'll go ahead even if it does.
return site.deleteFolder(); return site.deleteFolder();
}).then(() => { }).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 siteId: siteId
}; };
return this.appDB.insertOrUpdateRecord(this.CURRENT_SITE_TABLE, entry, {id: 1}).then(() => { 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})); promises.push(this.appDB.deleteRecords(this.CURRENT_SITE_TABLE, {id: 1}));
return Promise.all(promises).finally(() => { 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(() => { 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);
}); });
}); });
}); });