本文整理匯總了TypeScript中@providers/sites.CoreSitesProvider類的典型用法代碼示例。如果您正苦於以下問題:TypeScript CoreSitesProvider類的具體用法?TypeScript CoreSitesProvider怎麽用?TypeScript CoreSitesProvider使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了CoreSitesProvider類的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: constructor
constructor(mainMenuDelegate: CoreMainMenuDelegate, gradesMenuHandler: CoreGradesMainMenuHandler,
courseOptionHandler: CoreGradesCourseOptionHandler, courseOptionsDelegate: CoreCourseOptionsDelegate,
contentLinksDelegate: CoreContentLinksDelegate, userLinkHandler: CoreGradesUserLinkHandler,
overviewLinkHandler: CoreGradesOverviewLinkHandler, userHandler: CoreGradesUserHandler,
userDelegate: CoreUserDelegate, eventsProvider: CoreEventsProvider, sitesProvider: CoreSitesProvider) {
// Register handlers.
mainMenuDelegate.registerHandler(gradesMenuHandler);
courseOptionsDelegate.registerHandler(courseOptionHandler);
contentLinksDelegate.registerHandler(userLinkHandler);
contentLinksDelegate.registerHandler(overviewLinkHandler);
userDelegate.registerHandler(userHandler);
// Clear user profile handler cache.
eventsProvider.on(CoreUserProvider.PROFILE_REFRESHED, (data) => {
userHandler.clearViewGradesCache(data.courseId, data.userId);
}, sitesProvider.getCurrentSiteId());
eventsProvider.on(CoreEventsProvider.LOGOUT, () => {
userHandler.clearViewGradesCache();
}, sitesProvider.getCurrentSiteId());
}
示例2: getProfile
/**
* Convenient helper to get the user profile image.
*
* @param {number} userId User Id
* @return {Promise<any>} User profile Image URL or true if default icon.
*/
getProfile(userId: number): Promise<any> {
if (!userId || userId == this.sitesProvider.getCurrentSiteUserId()) {
return Promise.resolve(false);
}
// Get the user profile to retrieve the user image.
return this.userProvider.getProfile(userId, null, true).then((user) => {
user.profileimageurl = user.profileimageurl || true;
return user;
});
}
示例3:
messagesProvider.isMessagingEnabledForSite(notification.site).then(() => {
sitesProvider.isFeatureDisabled('CoreMainMenuDelegate_AddonMessages', notification.site).then((disabled) => {
if (disabled) {
// Messages are disabled, stop.
return;
}
messagesProvider.invalidateDiscussionsCache(notification.site).finally(() => {
linkHelper.goInSite(undefined, 'AddonMessagesIndexPage', undefined, notification.site);
});
});
});
示例4: loadPage
/**
* Load the right page.
*
* @return {Promise<any>} Promise resolved when done.
*/
protected loadPage(): Promise<any> {
if (this.sitesProvider.isLoggedIn()) {
if (!this.loginHelper.isSiteLoggedOut()) {
// User is logged in, go to site initial page.
return this.loginHelper.goToSiteInitialPage();
} else {
// The site is marked as logged out. Logout and try again.
return this.sitesProvider.logout().then(() => {
return this.loadPage();
});
}
} else {
return this.sitesProvider.hasSites().then((hasSites) => {
if (hasSites) {
return this.navCtrl.setRoot('CoreLoginSitesPage');
} else {
return this.loginHelper.goToAddSite(true);
}
});
}
}
示例5: getEditDataFromForm
/**
* Retrieve the entered data in the edit form.
* We don't use ng-model because it doesn't detect changes done by JavaScript.
*
* @param {any} inputData Array with the entered form values.
* @param {Array} fields Fields that defines every content in the entry.
* @param {number} [dataId] Database Id. If set, files will be uploaded and itemId set.
* @param {number} entryId Entry Id.
* @param {any} entryContents Original entry contents indexed by field id.
* @param {boolean} offline True to prepare the data for an offline uploading, false otherwise.
* @param {string} [siteId] Site ID. If not defined, current site.
* @return {Promise<any>} That contains object with the answers.
*/
getEditDataFromForm(inputData: any, fields: any, dataId: number, entryId: number, entryContents: any, offline: boolean = false,
siteId?: string): Promise<any> {
if (!inputData) {
return Promise.resolve({});
}
siteId = siteId || this.sitesProvider.getCurrentSiteId();
// Filter and translate fields to each field plugin.
const edit = [],
promises = [];
fields.forEach((field) => {
promises.push(Promise.resolve(this.fieldsDelegate.getFieldEditData(field, inputData, entryContents[field.id]))
.then((fieldData) => {
if (fieldData) {
const proms = [];
fieldData.forEach((data) => {
let dataProm;
// Upload Files if asked.
if (dataId && data.files) {
dataProm = this.uploadOrStoreFiles(dataId, 0, entryId, data.fieldid, data.files, offline, siteId)
.then((filesResult) => {
delete data.files;
data.value = filesResult;
});
} else {
dataProm = Promise.resolve();
}
proms.push(dataProm.then(() => {
if (data.value) {
data.value = JSON.stringify(data.value);
}
if (typeof data.subfield == 'undefined') {
data.subfield = '';
}
// WS wants values in Json format.
edit.push(data);
}));
});
return Promise.all(proms);
}
}));
});
return Promise.all(promises).then(() => {
return edit;
});
}
示例6:
const notificationClicked = (notification: any): void => {
sitesProvider.isFeatureDisabled('CoreMainMenuDelegate_AddonNotifications', notification.site).then((disabled) => {
if (disabled) {
// Notifications are disabled, stop.
return;
}
notificationsProvider.invalidateNotificationsList().finally(() => {
linkHelper.goInSite(undefined, 'AddonNotificationsListPage', undefined, notification.site);
});
});
};
示例7: ngOnInit
ngOnInit(): void {
this.selectedSite = this.initialSite || this.sitesProvider.getCurrentSiteId();
// Load the sites.
this.sitesProvider.getSites().then((sites) => {
const promises = [];
sites.forEach((site: any) => {
// Format the site name.
promises.push(this.textUtils.formatText(site.siteName, true, true).catch(() => {
return site.siteName;
}).then((formatted) => {
site.fullNameAndSiteName = this.translate.instant('core.fullnameandsitename',
{ fullname: site.fullName, sitename: formatted });
}));
});
return Promise.all(promises).then(() => {
this.sites = sites;
});
});
}
示例8: login
/**
* Tries to authenticate the user.
*
* @param {Event} e Event.
*/
login(e: Event): void {
e.preventDefault();
e.stopPropagation();
this.appProvider.closeKeyboard();
// Get input data.
const siteUrl = this.siteUrl,
username = this.username,
password = this.credForm.value.password;
if (!password) {
this.domUtils.showErrorModal('core.login.passwordrequired', true);
return;
}
if (!this.appProvider.isOnline()) {
this.domUtils.showErrorModal('core.networkerrormsg', true);
return;
}
const modal = this.domUtils.showModalLoading();
// Start the authentication process.
this.sitesProvider.getUserToken(siteUrl, username, password).then((data) => {
return this.sitesProvider.updateSiteToken(this.infoSiteUrl, username, data.token, data.privateToken).then(() => {
// Update site info too because functions might have changed (e.g. unisntall local_mobile).
return this.sitesProvider.updateSiteInfoByUrl(this.infoSiteUrl, username).then(() => {
// Reset fields so the data is not in the view anymore.
this.credForm.controls['password'].reset();
if (this.pageName) {
// Page defined, go to that page instead of site initial page.
return this.navCtrl.setRoot(this.pageName, this.pageParams);
} else {
return this.loginHelper.goToSiteInitialPage();
}
}).catch((error) => {
// Error, go back to login page.
this.domUtils.showErrorModalDefault(error, 'core.login.errorupdatesite', true);
this.cancel();
});
});
}).catch((error) => {
this.loginHelper.treatUserTokenError(siteUrl, error, username, password);
}).finally(() => {
modal.dismiss();
});
}
示例9:
return this.sitesProvider.updateSiteToken(this.infoSiteUrl, username, data.token, data.privateToken).then(() => {
// Update site info too because functions might have changed (e.g. unisntall local_mobile).
return this.sitesProvider.updateSiteInfoByUrl(this.infoSiteUrl, username).then(() => {
// Reset fields so the data is not in the view anymore.
this.credForm.controls['password'].reset();
// Go to the site initial page.
return this.loginHelper.goToSiteInitialPage(this.navCtrl, this.pageName, this.pageParams);
}).catch((error) => {
// Error, go back to login page.
this.domUtils.showErrorModalDefault(error, 'core.login.errorupdatesite', true);
this.cancel();
});
});
示例10: ngOnInit
/**
* Component being initialized.
*/
ngOnInit(): void {
super.ngOnInit();
this.hasOffline = false;
this.syncIcon = 'spinner';
this.siteId = this.sitesProvider.getCurrentSiteId();
this.moduleName = this.courseProvider.translateModuleName(this.moduleName);
if (this.syncEventName) {
// Refresh data if this discussion is synchronized automatically.
this.syncObserver = this.eventsProvider.on(this.syncEventName, (data) => {
this.autoSyncEventReceived(data);
}, this.siteId);
}
}