MOBILE-2333 siteplugins: Rename bootstrap to init & treat exceptions
parent
bec35e3c98
commit
28dc1232ad
|
@ -78,6 +78,12 @@ export interface CoreSiteWSPreSets {
|
|||
*/
|
||||
getEmergencyCacheUsingCacheKey?: boolean;
|
||||
|
||||
/**
|
||||
* If true, the cache entry will be deleted if the WS call returns an exception.
|
||||
* @type {boolean}
|
||||
*/
|
||||
deleteCacheIfWSError?: boolean;
|
||||
|
||||
/**
|
||||
* Whether it should only be 1 entry for this cache key (all entries with same key will be deleted).
|
||||
* @type {boolean}
|
||||
|
@ -633,6 +639,15 @@ export class CoreSite {
|
|||
return Promise.reject(error);
|
||||
}
|
||||
|
||||
if (preSets.deleteCacheIfWSError && this.utils.isWebServiceError(error)) {
|
||||
// Delete the cache entry and return the entry. Don't block the user with the delete.
|
||||
this.deleteFromCache(method, data, preSets).catch(() => {
|
||||
// Ignore errors.
|
||||
});
|
||||
|
||||
return Promise.reject(error);
|
||||
}
|
||||
|
||||
this.logger.debug(`WS call '${method}' failed. Trying to use the emergency cache.`);
|
||||
preSets.omitExpires = true;
|
||||
preSets.getFromCache = true;
|
||||
|
|
|
@ -25,7 +25,7 @@ export class CoreSitePluginsCourseOptionHandler extends CoreSitePluginsBaseHandl
|
|||
priority: number;
|
||||
|
||||
constructor(name: string, protected title: string, protected plugin: any, protected handlerSchema: any,
|
||||
protected bootstrapResult: any, protected sitePluginsProvider: CoreSitePluginsProvider) {
|
||||
protected initResult: any, protected sitePluginsProvider: CoreSitePluginsProvider) {
|
||||
super(name);
|
||||
|
||||
this.priority = handlerSchema.priority;
|
||||
|
@ -42,7 +42,7 @@ export class CoreSitePluginsCourseOptionHandler extends CoreSitePluginsBaseHandl
|
|||
*/
|
||||
isEnabledForCourse(courseId: number, accessData: any, navOptions?: any, admOptions?: any): boolean | Promise<boolean> {
|
||||
return this.sitePluginsProvider.isHandlerEnabledForCourse(
|
||||
courseId, this.handlerSchema.restricttoenrolledcourses, this.bootstrapResult.restrict);
|
||||
courseId, this.handlerSchema.restricttoenrolledcourses, this.initResult.restrict);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -22,7 +22,7 @@ export class CoreSitePluginsMainMenuHandler extends CoreSitePluginsBaseHandler i
|
|||
priority: number;
|
||||
|
||||
constructor(name: string, protected title: string, protected plugin: any, protected handlerSchema: any,
|
||||
protected bootstrapResult: any) {
|
||||
protected initResult: any) {
|
||||
super(name);
|
||||
|
||||
this.priority = handlerSchema.priority;
|
||||
|
@ -43,7 +43,7 @@ export class CoreSitePluginsMainMenuHandler extends CoreSitePluginsBaseHandler i
|
|||
title: this.title,
|
||||
component: this.plugin.component,
|
||||
method: this.handlerSchema.method,
|
||||
bootstrapResult: this.bootstrapResult
|
||||
initResult: this.initResult
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -38,7 +38,7 @@ export class CoreSitePluginsUserProfileHandler extends CoreSitePluginsBaseHandle
|
|||
type: string;
|
||||
|
||||
constructor(name: string, protected title: string, protected plugin: any, protected handlerSchema: any,
|
||||
protected bootstrapResult: any, protected sitePluginsProvider: CoreSitePluginsProvider) {
|
||||
protected initResult: any, protected sitePluginsProvider: CoreSitePluginsProvider) {
|
||||
super(name);
|
||||
|
||||
this.priority = handlerSchema.priority;
|
||||
|
@ -59,14 +59,14 @@ export class CoreSitePluginsUserProfileHandler extends CoreSitePluginsBaseHandle
|
|||
isEnabledForUser(user: any, courseId: number, navOptions?: any, admOptions?: any): boolean | Promise<boolean> {
|
||||
// First check if it's enabled for the user.
|
||||
const enabledForUser = this.sitePluginsProvider.isHandlerEnabledForUser(user.id, this.handlerSchema.restricttocurrentuser,
|
||||
this.bootstrapResult.restrict);
|
||||
this.initResult.restrict);
|
||||
if (!enabledForUser) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Enabled for user, check if it's enabled for the course.
|
||||
return this.sitePluginsProvider.isHandlerEnabledForCourse(
|
||||
courseId, this.handlerSchema.restricttoenrolledcourses, this.bootstrapResult.restrict);
|
||||
courseId, this.handlerSchema.restricttoenrolledcourses, this.initResult.restrict);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -92,7 +92,7 @@ export class CoreSitePluginsUserProfileHandler extends CoreSitePluginsBaseHandle
|
|||
courseid: courseId,
|
||||
userid: user.id
|
||||
},
|
||||
bootstrapResult: this.bootstrapResult
|
||||
initResult: this.initResult
|
||||
});
|
||||
}
|
||||
};
|
||||
|
|
|
@ -1 +1 @@
|
|||
<core-site-plugins-plugin-content *ngIf="component && method" [component]="component" [method]="method" [args]="args" [bootstrapResult]="bootstrapResult"></core-site-plugins-plugin-content>
|
||||
<core-site-plugins-plugin-content *ngIf="component && method" [component]="component" [method]="method" [args]="args" [initResult]="initResult"></core-site-plugins-plugin-content>
|
|
@ -33,7 +33,7 @@ export class CoreSitePluginsCourseFormatComponent implements OnInit {
|
|||
component: string;
|
||||
method: string;
|
||||
args: any;
|
||||
bootstrapResult: any;
|
||||
initResult: any;
|
||||
|
||||
constructor(protected sitePluginsProvider: CoreSitePluginsProvider) { }
|
||||
|
||||
|
@ -50,7 +50,7 @@ export class CoreSitePluginsCourseFormatComponent implements OnInit {
|
|||
courseid: this.course.id,
|
||||
downloadenabled: this.downloadEnabled
|
||||
};
|
||||
this.bootstrapResult = handler.bootstrapResult;
|
||||
this.initResult = handler.initResult;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,5 +2,5 @@
|
|||
<ion-refresher [enabled]="content && content.dataLoaded" (ionRefresh)="refreshData($event)">
|
||||
<ion-refresher-content pullingText="{{ 'core.pulltorefresh' | translate }}"></ion-refresher-content>
|
||||
</ion-refresher>
|
||||
<core-site-plugins-plugin-content *ngIf="component && method" [component]="component" [method]="method" [args]="args" [bootstrapResult]="bootstrapResult"></core-site-plugins-plugin-content>
|
||||
<core-site-plugins-plugin-content *ngIf="component && method" [component]="component" [method]="method" [args]="args" [initResult]="initResult"></core-site-plugins-plugin-content>
|
||||
</ion-content>
|
|
@ -32,7 +32,7 @@ export class CoreSitePluginsCourseOptionComponent implements OnInit {
|
|||
component: string;
|
||||
method: string;
|
||||
args: any;
|
||||
bootstrapResult: any;
|
||||
initResult: any;
|
||||
|
||||
constructor(protected sitePluginsProvider: CoreSitePluginsProvider) { }
|
||||
|
||||
|
@ -48,7 +48,7 @@ export class CoreSitePluginsCourseOptionComponent implements OnInit {
|
|||
this.args = {
|
||||
courseid: this.courseId,
|
||||
};
|
||||
this.bootstrapResult = handler.bootstrapResult;
|
||||
this.initResult = handler.initResult;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,4 +9,4 @@
|
|||
</core-context-menu>
|
||||
</core-navbar-buttons>
|
||||
|
||||
<core-site-plugins-plugin-content *ngIf="component && method" [component]="component" [method]="method" [args]="args" [bootstrapResult]="bootstrapResult" (onContentLoaded)="contentLoaded($event)" (onLoadingContent)="contentLoading($event)"></core-site-plugins-plugin-content>
|
||||
<core-site-plugins-plugin-content *ngIf="component && method" [component]="component" [method]="method" [args]="args" [initResult]="initResult" (onContentLoaded)="contentLoaded($event)" (onLoadingContent)="contentLoading($event)"></core-site-plugins-plugin-content>
|
||||
|
|
|
@ -37,7 +37,7 @@ export class CoreSitePluginsModuleIndexComponent implements OnInit, OnDestroy, C
|
|||
component: string;
|
||||
method: string;
|
||||
args: any;
|
||||
bootstrapResult: any;
|
||||
initResult: any;
|
||||
|
||||
// Data for context menu.
|
||||
externalUrl: string;
|
||||
|
@ -69,7 +69,7 @@ export class CoreSitePluginsModuleIndexComponent implements OnInit, OnDestroy, C
|
|||
courseid: this.courseId,
|
||||
cmid: this.module.id
|
||||
};
|
||||
this.bootstrapResult = handler.bootstrapResult;
|
||||
this.initResult = handler.initResult;
|
||||
}
|
||||
|
||||
// Get the data for the context menu.
|
||||
|
|
|
@ -28,7 +28,7 @@ export class CoreSitePluginsPluginContentComponent implements OnInit {
|
|||
@Input() component: string;
|
||||
@Input() method: string;
|
||||
@Input() args: any;
|
||||
@Input() bootstrapResult: any; // Result of the bootstrap WS call of the handler.
|
||||
@Input() initResult: any; // Result of the init WS call of the handler.
|
||||
@Output() onContentLoaded?: EventEmitter<boolean>; // Emits an event when the content is loaded.
|
||||
@Output() onLoadingContent?: EventEmitter<boolean>; // Emits an event when starts to load the content.
|
||||
|
||||
|
@ -65,7 +65,7 @@ export class CoreSitePluginsPluginContentComponent implements OnInit {
|
|||
this.content = result.templates.length ? result.templates[0].html : ''; // Load first template.
|
||||
this.javascript = result.javascript;
|
||||
this.otherData = result.otherdata;
|
||||
this.jsData = this.sitePluginsProvider.createDataForJS(this.bootstrapResult, result);
|
||||
this.jsData = this.sitePluginsProvider.createDataForJS(this.initResult, result);
|
||||
|
||||
this.onContentLoaded.emit(refresh);
|
||||
}).catch((error) => {
|
||||
|
|
|
@ -92,7 +92,7 @@ export class CoreSitePluginsCallWSNewContentDirective extends CoreSitePluginsCal
|
|||
component: this.component,
|
||||
method: this.method,
|
||||
args: args,
|
||||
bootstrapResult: this.parentContent && this.parentContent.bootstrapResult
|
||||
initResult: this.parentContent && this.parentContent.initResult
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -89,7 +89,7 @@ export class CoreSitePluginsNewContentDirective implements OnInit {
|
|||
component: this.component,
|
||||
method: this.method,
|
||||
args: args,
|
||||
bootstrapResult: this.parentContent && this.parentContent.bootstrapResult
|
||||
initResult: this.parentContent && this.parentContent.initResult
|
||||
});
|
||||
}
|
||||
});
|
||||
|
|
|
@ -11,5 +11,5 @@
|
|||
<ion-refresher [enabled]="content && content.dataLoaded" (ionRefresh)="refreshData($event)">
|
||||
<ion-refresher-content pullingText="{{ 'core.pulltorefresh' | translate }}"></ion-refresher-content>
|
||||
</ion-refresher>
|
||||
<core-site-plugins-plugin-content [component]="component" [method]="method" [args]="args" [bootstrapResult]="bootstrapResult"></core-site-plugins-plugin-content>
|
||||
<core-site-plugins-plugin-content [component]="component" [method]="method" [args]="args" [initResult]="initResult"></core-site-plugins-plugin-content>
|
||||
</ion-content>
|
||||
|
|
|
@ -32,14 +32,14 @@ export class CoreSitePluginsPluginPage {
|
|||
component: string;
|
||||
method: string;
|
||||
args: any;
|
||||
bootstrapResult: any;
|
||||
initResult: any;
|
||||
|
||||
constructor(params: NavParams) {
|
||||
this.title = params.get('title');
|
||||
this.component = params.get('component');
|
||||
this.method = params.get('method');
|
||||
this.args = params.get('args');
|
||||
this.bootstrapResult = params.get('bootstrapResult');
|
||||
this.initResult = params.get('initResult');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -89,19 +89,19 @@ export class CoreSitePluginsHelperProvider {
|
|||
}
|
||||
|
||||
/**
|
||||
* Bootstrap a handler if it has some bootstrap method.
|
||||
* Execute a handler's init method if it has any.
|
||||
*
|
||||
* @param {any} plugin Data of the plugin.
|
||||
* @param {any} handlerSchema Data about the handler.
|
||||
* @return {Promise<any>} Promise resolved when done. It returns the results of the getContent call and the data returned by
|
||||
* the bootstrap JS (if any).
|
||||
* the init JS (if any).
|
||||
*/
|
||||
protected bootstrapHandler(plugin: any, handlerSchema: any): Promise<any> {
|
||||
if (!handlerSchema.bootstrap) {
|
||||
protected executeHandlerInit(plugin: any, handlerSchema: any): Promise<any> {
|
||||
if (!handlerSchema.init) {
|
||||
return Promise.resolve({});
|
||||
}
|
||||
|
||||
return this.executeMethodAndJS(plugin, handlerSchema.bootstrap);
|
||||
return this.executeMethodAndJS(plugin, handlerSchema.init, true);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -109,12 +109,16 @@ export class CoreSitePluginsHelperProvider {
|
|||
*
|
||||
* @param {any} plugin Data of the plugin.
|
||||
* @param {string} method The method to call.
|
||||
* @param {boolean} [isInit] Whether it's the init method.
|
||||
* @return {Promise<any>} Promise resolved when done. It returns the results of the getContent call and the data returned by
|
||||
* the JS (if any).
|
||||
*/
|
||||
protected executeMethodAndJS(plugin: any, method: string): Promise<any> {
|
||||
protected executeMethodAndJS(plugin: any, method: string, isInit?: boolean): Promise<any> {
|
||||
const siteId = this.sitesProvider.getCurrentSiteId(),
|
||||
preSets = {getFromCache: false}; // Try to ignore cache.
|
||||
preSets = {
|
||||
getFromCache: false, // Try to ignore cache.
|
||||
deleteCacheIfWSError: isInit // If the init WS call returns an exception we won't use cached data.
|
||||
};
|
||||
|
||||
return this.sitePluginsProvider.getContent(plugin.component, method, {}, preSets).then((result) => {
|
||||
if (!result.javascript || this.sitesProvider.getCurrentSiteId() != siteId) {
|
||||
|
@ -290,8 +294,8 @@ export class CoreSitePluginsHelperProvider {
|
|||
*/
|
||||
registerHandler(plugin: any, handlerName: string, handlerSchema: any): Promise<any> {
|
||||
|
||||
// Wait for the bootstrap JS to be executed.
|
||||
return this.bootstrapHandler(plugin, handlerSchema).then((result) => {
|
||||
// Wait for the init JS to be executed.
|
||||
return this.executeHandlerInit(plugin, handlerSchema).then((result) => {
|
||||
let promise;
|
||||
|
||||
switch (handlerSchema.delegate) {
|
||||
|
@ -331,12 +335,12 @@ export class CoreSitePluginsHelperProvider {
|
|||
plugin: plugin,
|
||||
handlerName: handlerName,
|
||||
handlerSchema: handlerSchema,
|
||||
bootstrapResult: result
|
||||
initResult: result
|
||||
});
|
||||
}
|
||||
});
|
||||
}).catch((err) => {
|
||||
this.logger.error('Error executing bootstrap method', handlerSchema.bootstrap, err);
|
||||
this.logger.error('Error executing init method', handlerSchema.init, err);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -346,11 +350,11 @@ export class CoreSitePluginsHelperProvider {
|
|||
* @param {any} plugin Data of the plugin.
|
||||
* @param {string} handlerName Name of the handler in the plugin.
|
||||
* @param {any} handlerSchema Data about the handler.
|
||||
* @param {any} bootstrapResult Result of the bootstrap WS call.
|
||||
* @param {any} initResult Result of the init WS call.
|
||||
* @return {string} A string to identify the handler.
|
||||
*/
|
||||
protected registerCourseFormatHandler(plugin: any, handlerName: string, handlerSchema: any, bootstrapResult: any): string {
|
||||
this.logger.debug('Register site plugin in course format delegate:', plugin, handlerSchema, bootstrapResult);
|
||||
protected registerCourseFormatHandler(plugin: any, handlerName: string, handlerSchema: any, initResult: any): string {
|
||||
this.logger.debug('Register site plugin in course format delegate:', plugin, handlerSchema, initResult);
|
||||
|
||||
// Create and register the handler.
|
||||
const uniqueName = this.sitePluginsProvider.getHandlerUniqueName(plugin, handlerName),
|
||||
|
@ -366,10 +370,10 @@ export class CoreSitePluginsHelperProvider {
|
|||
* @param {any} plugin Data of the plugin.
|
||||
* @param {string} handlerName Name of the handler in the plugin.
|
||||
* @param {any} handlerSchema Data about the handler.
|
||||
* @param {any} bootstrapResult Result of the bootstrap WS call.
|
||||
* @param {any} initResult Result of the init WS call.
|
||||
* @return {string} A string to identify the handler.
|
||||
*/
|
||||
protected registerCourseOptionHandler(plugin: any, handlerName: string, handlerSchema: any, bootstrapResult: any): string {
|
||||
protected registerCourseOptionHandler(plugin: any, handlerName: string, handlerSchema: any, initResult: any): string {
|
||||
if (!handlerSchema.displaydata) {
|
||||
// Required data not provided, stop.
|
||||
this.logger.warn('Ignore site plugin because it doesn\'t provide displaydata', plugin, handlerSchema);
|
||||
|
@ -377,14 +381,14 @@ export class CoreSitePluginsHelperProvider {
|
|||
return;
|
||||
}
|
||||
|
||||
this.logger.debug('Register site plugin in course option delegate:', plugin, handlerSchema, bootstrapResult);
|
||||
this.logger.debug('Register site plugin in course option delegate:', plugin, handlerSchema, initResult);
|
||||
|
||||
// Create and register the handler.
|
||||
const uniqueName = this.sitePluginsProvider.getHandlerUniqueName(plugin, handlerName),
|
||||
prefixedTitle = this.getPrefixedString(plugin.addon, handlerSchema.displaydata.title);
|
||||
|
||||
this.courseOptionsDelegate.registerHandler(new CoreSitePluginsCourseOptionHandler(uniqueName, prefixedTitle, plugin,
|
||||
handlerSchema, bootstrapResult, this.sitePluginsProvider));
|
||||
handlerSchema, initResult, this.sitePluginsProvider));
|
||||
|
||||
return uniqueName;
|
||||
}
|
||||
|
@ -395,10 +399,10 @@ export class CoreSitePluginsHelperProvider {
|
|||
* @param {any} plugin Data of the plugin.
|
||||
* @param {string} handlerName Name of the handler in the plugin.
|
||||
* @param {any} handlerSchema Data about the handler.
|
||||
* @param {any} bootstrapResult Result of the bootstrap WS call.
|
||||
* @param {any} initResult Result of the init WS call.
|
||||
* @return {string} A string to identify the handler.
|
||||
*/
|
||||
protected registerMainMenuHandler(plugin: any, handlerName: string, handlerSchema: any, bootstrapResult: any): string {
|
||||
protected registerMainMenuHandler(plugin: any, handlerName: string, handlerSchema: any, initResult: any): string {
|
||||
if (!handlerSchema.displaydata) {
|
||||
// Required data not provided, stop.
|
||||
this.logger.warn('Ignore site plugin because it doesn\'t provide displaydata', plugin, handlerSchema);
|
||||
|
@ -406,14 +410,14 @@ export class CoreSitePluginsHelperProvider {
|
|||
return;
|
||||
}
|
||||
|
||||
this.logger.debug('Register site plugin in main menu delegate:', plugin, handlerSchema, bootstrapResult);
|
||||
this.logger.debug('Register site plugin in main menu delegate:', plugin, handlerSchema, initResult);
|
||||
|
||||
// Create and register the handler.
|
||||
const uniqueName = this.sitePluginsProvider.getHandlerUniqueName(plugin, handlerName),
|
||||
prefixedTitle = this.getPrefixedString(plugin.addon, handlerSchema.displaydata.title);
|
||||
|
||||
this.mainMenuDelegate.registerHandler(
|
||||
new CoreSitePluginsMainMenuHandler(uniqueName, prefixedTitle, plugin, handlerSchema, bootstrapResult));
|
||||
new CoreSitePluginsMainMenuHandler(uniqueName, prefixedTitle, plugin, handlerSchema, initResult));
|
||||
|
||||
return uniqueName;
|
||||
}
|
||||
|
@ -424,10 +428,10 @@ export class CoreSitePluginsHelperProvider {
|
|||
* @param {any} plugin Data of the plugin.
|
||||
* @param {string} handlerName Name of the handler in the plugin.
|
||||
* @param {any} handlerSchema Data about the handler.
|
||||
* @param {any} bootstrapResult Result of the bootstrap WS call.
|
||||
* @param {any} initResult Result of the init WS call.
|
||||
* @return {string} A string to identify the handler.
|
||||
*/
|
||||
protected registerModuleHandler(plugin: any, handlerName: string, handlerSchema: any, bootstrapResult: any): string {
|
||||
protected registerModuleHandler(plugin: any, handlerName: string, handlerSchema: any, initResult: any): string {
|
||||
if (!handlerSchema.displaydata) {
|
||||
// Required data not provided, stop.
|
||||
this.logger.warn('Ignore site plugin because it doesn\'t provide displaydata', plugin, handlerSchema);
|
||||
|
@ -435,7 +439,7 @@ export class CoreSitePluginsHelperProvider {
|
|||
return;
|
||||
}
|
||||
|
||||
this.logger.debug('Register site plugin in module delegate:', plugin, handlerSchema, bootstrapResult);
|
||||
this.logger.debug('Register site plugin in module delegate:', plugin, handlerSchema, initResult);
|
||||
|
||||
// Create and register the handler.
|
||||
const uniqueName = this.sitePluginsProvider.getHandlerUniqueName(plugin, handlerName),
|
||||
|
@ -458,10 +462,10 @@ export class CoreSitePluginsHelperProvider {
|
|||
* @param {any} plugin Data of the plugin.
|
||||
* @param {string} handlerName Name of the handler in the plugin.
|
||||
* @param {any} handlerSchema Data about the handler.
|
||||
* @param {any} bootstrapResult Result of the bootstrap WS call.
|
||||
* @param {any} initResult Result of the init WS call.
|
||||
* @return {string} A string to identify the handler.
|
||||
*/
|
||||
protected registerUserProfileHandler(plugin: any, handlerName: string, handlerSchema: any, bootstrapResult: any): string {
|
||||
protected registerUserProfileHandler(plugin: any, handlerName: string, handlerSchema: any, initResult: any): string {
|
||||
if (!handlerSchema.displaydata) {
|
||||
// Required data not provided, stop.
|
||||
this.logger.warn('Ignore site plugin because it doesn\'t provide displaydata', plugin, handlerSchema);
|
||||
|
@ -469,14 +473,14 @@ export class CoreSitePluginsHelperProvider {
|
|||
return;
|
||||
}
|
||||
|
||||
this.logger.debug('Register site plugin in user profile delegate:', plugin, handlerSchema, bootstrapResult);
|
||||
this.logger.debug('Register site plugin in user profile delegate:', plugin, handlerSchema, initResult);
|
||||
|
||||
// Create and register the handler.
|
||||
const uniqueName = this.sitePluginsProvider.getHandlerUniqueName(plugin, handlerName),
|
||||
prefixedTitle = this.getPrefixedString(plugin.addon, handlerSchema.displaydata.title);
|
||||
|
||||
this.userDelegate.registerHandler(new CoreSitePluginsUserProfileHandler(uniqueName, prefixedTitle, plugin, handlerSchema,
|
||||
bootstrapResult, this.sitePluginsProvider));
|
||||
initResult, this.sitePluginsProvider));
|
||||
|
||||
return uniqueName;
|
||||
}
|
||||
|
@ -487,10 +491,10 @@ export class CoreSitePluginsHelperProvider {
|
|||
* @param {any} plugin Data of the plugin.
|
||||
* @param {string} handlerName Name of the handler in the plugin.
|
||||
* @param {any} handlerSchema Data about the handler.
|
||||
* @param {any} bootstrapResult Result of the bootstrap WS call.
|
||||
* @param {any} initResult Result of the init WS call.
|
||||
* @return {string|Promise<string>} A string (or a promise resolved with a string) to identify the handler.
|
||||
*/
|
||||
protected registerUserProfileFieldHandler(plugin: any, handlerName: string, handlerSchema: any, bootstrapResult: any)
|
||||
protected registerUserProfileFieldHandler(plugin: any, handlerName: string, handlerSchema: any, initResult: any)
|
||||
: string | Promise<string> {
|
||||
if (!handlerSchema.method) {
|
||||
// Required data not provided, stop.
|
||||
|
@ -499,7 +503,7 @@ export class CoreSitePluginsHelperProvider {
|
|||
return;
|
||||
}
|
||||
|
||||
this.logger.debug('Register site plugin in user profile field delegate:', plugin, handlerSchema, bootstrapResult);
|
||||
this.logger.debug('Register site plugin in user profile field delegate:', plugin, handlerSchema, initResult);
|
||||
|
||||
// Execute the main method and its JS. The template returned will be used in the profile field component.
|
||||
return this.executeMethodAndJS(plugin, handlerSchema.method).then((result) => {
|
||||
|
|
|
@ -47,10 +47,10 @@ export interface CoreSitePluginsHandler {
|
|||
handlerSchema: any;
|
||||
|
||||
/**
|
||||
* Result of the bootstrap WS call.
|
||||
* Result of the init WS call.
|
||||
* @type {any}
|
||||
*/
|
||||
bootstrapResult?: any;
|
||||
initResult?: any;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -137,23 +137,23 @@ export class CoreSitePluginsProvider {
|
|||
}
|
||||
|
||||
/**
|
||||
* Given the result of a bootstrap get_content and, optionally, the result of another get_content,
|
||||
* Given the result of a init get_content and, optionally, the result of another get_content,
|
||||
* build an object with the data to pass to the JS of the get_content.
|
||||
*
|
||||
* @param {any} bootstrapResult Result of the bootstrap WS call.
|
||||
* @param {any} initResult Result of the init WS call.
|
||||
* @param {any} [contentResult] Result of the content WS call (if any).
|
||||
* @return {any} An object with the data to pass to the JS.
|
||||
*/
|
||||
createDataForJS(bootstrapResult: any, contentResult?: any): any {
|
||||
// First of all, add the data returned by the bootstrap JS (if any).
|
||||
let data = this.utils.clone(bootstrapResult.jsResult || {});
|
||||
createDataForJS(initResult: any, contentResult?: any): any {
|
||||
// First of all, add the data returned by the init JS (if any).
|
||||
let data = this.utils.clone(initResult.jsResult || {});
|
||||
if (typeof data == 'boolean') {
|
||||
data = {};
|
||||
}
|
||||
|
||||
// Now add some data returned by the bootstrap WS call.
|
||||
data.BOOTSTRAP_TEMPLATES = this.utils.objectToKeyValueMap(bootstrapResult.templates, 'id', 'html');
|
||||
data.BOOTSTRAP_OTHERDATA = bootstrapResult.otherdata;
|
||||
// Now add some data returned by the init WS call.
|
||||
data.INIT_TEMPLATES = this.utils.objectToKeyValueMap(initResult.templates, 'id', 'html');
|
||||
data.INIT_OTHERDATA = initResult.otherdata;
|
||||
|
||||
if (contentResult) {
|
||||
// Now add the data returned by the content WS call.
|
||||
|
|
|
@ -626,7 +626,11 @@ export class CoreUtilsProvider {
|
|||
* @return {boolean} Whether the error was returned by the WebService.
|
||||
*/
|
||||
isWebServiceError(error: any): boolean {
|
||||
return typeof error.errorcode == 'undefined' && typeof error.warningcode == 'undefined';
|
||||
return typeof error.warningcode != 'undefined' || (typeof error.errorcode != 'undefined' &&
|
||||
error.errorcode != 'invalidtoken' && error.errorcode != 'userdeleted' && error.errorcode != 'upgraderunning' &&
|
||||
error.errorcode != 'forcepasswordchangenotice' && error.errorcode != 'usernotfullysetup' &&
|
||||
error.errorcode != 'sitepolicynotagreed' && error.errorcode != 'sitemaintenance' &&
|
||||
(error.errorcode != 'accessexception' || error.message.indexOf('Invalid token - token expired') == -1));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue