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.
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)) {

View File

@ -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) => {

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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