MOBILE-2376 siteplugins: Support message output handlers
parent
c02e134c58
commit
157a2882d3
|
@ -82,7 +82,7 @@ export interface AddonMessageOutputHandlerData {
|
||||||
|
|
||||||
constructor(protected loggerProvider: CoreLoggerProvider, protected sitesProvider: CoreSitesProvider,
|
constructor(protected loggerProvider: CoreLoggerProvider, protected sitesProvider: CoreSitesProvider,
|
||||||
protected eventsProvider: CoreEventsProvider) {
|
protected eventsProvider: CoreEventsProvider) {
|
||||||
super('CoreSettingsDelegate', loggerProvider, sitesProvider, eventsProvider);
|
super('AddonMessageOutputDelegate', loggerProvider, sitesProvider, eventsProvider);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -0,0 +1,47 @@
|
||||||
|
// (C) Copyright 2015 Martin Dougiamas
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
import { AddonMessageOutputHandler, AddonMessageOutputHandlerData } from '@addon/messageoutput/providers/delegate';
|
||||||
|
import { CoreSitePluginsBaseHandler } from './base-handler';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handler to display a message output settings option.
|
||||||
|
*/
|
||||||
|
export class CoreSitePluginsMessageOutputHandler extends CoreSitePluginsBaseHandler implements AddonMessageOutputHandler {
|
||||||
|
|
||||||
|
constructor(name: string, public processorName: string, protected title: string, protected plugin: any,
|
||||||
|
protected handlerSchema: any, protected initResult: any) {
|
||||||
|
super(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the data needed to render the handler.
|
||||||
|
*
|
||||||
|
* @return {AddonMessageOutputHandlerData} Data.
|
||||||
|
*/
|
||||||
|
getDisplayData(): AddonMessageOutputHandlerData {
|
||||||
|
return {
|
||||||
|
priority: this.handlerSchema.priority,
|
||||||
|
label: this.title,
|
||||||
|
icon: this.handlerSchema.displaydata.icon,
|
||||||
|
page: 'CoreSitePluginsPluginPage',
|
||||||
|
pageParams: {
|
||||||
|
title: this.title,
|
||||||
|
component: this.plugin.component,
|
||||||
|
method: this.handlerSchema.method,
|
||||||
|
initResult: this.initResult
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
|
@ -34,6 +34,7 @@ import { CoreCourseOptionsDelegate } from '@core/course/providers/options-delega
|
||||||
import { CoreCourseFormatDelegate } from '@core/course/providers/format-delegate';
|
import { CoreCourseFormatDelegate } from '@core/course/providers/format-delegate';
|
||||||
import { CoreUserDelegate } from '@core/user/providers/user-delegate';
|
import { CoreUserDelegate } from '@core/user/providers/user-delegate';
|
||||||
import { CoreUserProfileFieldDelegate } from '@core/user/providers/user-profile-field-delegate';
|
import { CoreUserProfileFieldDelegate } from '@core/user/providers/user-profile-field-delegate';
|
||||||
|
import { AddonMessageOutputDelegate } from '@addon/messageoutput/providers/delegate';
|
||||||
|
|
||||||
// Handler classes.
|
// Handler classes.
|
||||||
import { CoreSitePluginsCourseFormatHandler } from '../classes/course-format-handler';
|
import { CoreSitePluginsCourseFormatHandler } from '../classes/course-format-handler';
|
||||||
|
@ -43,6 +44,7 @@ import { CoreSitePluginsModulePrefetchHandler } from '../classes/module-prefetch
|
||||||
import { CoreSitePluginsMainMenuHandler } from '../classes/main-menu-handler';
|
import { CoreSitePluginsMainMenuHandler } from '../classes/main-menu-handler';
|
||||||
import { CoreSitePluginsUserProfileHandler } from '../classes/user-handler';
|
import { CoreSitePluginsUserProfileHandler } from '../classes/user-handler';
|
||||||
import { CoreSitePluginsUserProfileFieldHandler } from '../classes/user-profile-field-handler';
|
import { CoreSitePluginsUserProfileFieldHandler } from '../classes/user-profile-field-handler';
|
||||||
|
import { CoreSitePluginsMessageOutputHandler } from '../classes/message-output-handler';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper service to provide functionalities regarding site plugins. It basically has the features to load and register site
|
* Helper service to provide functionalities regarding site plugins. It basically has the features to load and register site
|
||||||
|
@ -64,7 +66,8 @@ export class CoreSitePluginsHelperProvider {
|
||||||
private compileProvider: CoreCompileProvider, private utils: CoreUtilsProvider, private urlUtils: CoreUrlUtilsProvider,
|
private compileProvider: CoreCompileProvider, private utils: CoreUtilsProvider, private urlUtils: CoreUrlUtilsProvider,
|
||||||
private courseOptionsDelegate: CoreCourseOptionsDelegate, eventsProvider: CoreEventsProvider,
|
private courseOptionsDelegate: CoreCourseOptionsDelegate, eventsProvider: CoreEventsProvider,
|
||||||
private courseFormatDelegate: CoreCourseFormatDelegate, private profileFieldDelegate: CoreUserProfileFieldDelegate,
|
private courseFormatDelegate: CoreCourseFormatDelegate, private profileFieldDelegate: CoreUserProfileFieldDelegate,
|
||||||
private textUtils: CoreTextUtilsProvider, private filepoolProvider: CoreFilepoolProvider) {
|
private textUtils: CoreTextUtilsProvider, private filepoolProvider: CoreFilepoolProvider,
|
||||||
|
private messageOutputDelegate: AddonMessageOutputDelegate) {
|
||||||
this.logger = logger.getInstance('CoreSitePluginsHelperProvider');
|
this.logger = logger.getInstance('CoreSitePluginsHelperProvider');
|
||||||
|
|
||||||
// Fetch the plugins on login.
|
// Fetch the plugins on login.
|
||||||
|
@ -433,6 +436,10 @@ export class CoreSitePluginsHelperProvider {
|
||||||
promise = Promise.resolve(this.registerUserProfileFieldHandler(plugin, handlerName, handlerSchema, result));
|
promise = Promise.resolve(this.registerUserProfileFieldHandler(plugin, handlerName, handlerSchema, result));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 'AddonMessageOutputHandler':
|
||||||
|
promise = Promise.resolve(this.registerMessageOutputHandler(plugin, handlerName, handlerSchema, result));
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
// Nothing to do.
|
// Nothing to do.
|
||||||
promise = Promise.resolve();
|
promise = Promise.resolve();
|
||||||
|
@ -532,6 +539,36 @@ export class CoreSitePluginsHelperProvider {
|
||||||
return uniqueName;
|
return uniqueName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Given a handler in an plugin, register it in the main menu delegate.
|
||||||
|
*
|
||||||
|
* @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} initResult Result of the init WS call.
|
||||||
|
* @return {string} A string to identify the handler.
|
||||||
|
*/
|
||||||
|
protected registerMessageOutputHandler(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);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.logger.debug('Register site plugin in message output delegate:', plugin, handlerSchema, initResult);
|
||||||
|
|
||||||
|
// Create and register the handler.
|
||||||
|
const uniqueName = this.sitePluginsProvider.getHandlerUniqueName(plugin, handlerName),
|
||||||
|
prefixedTitle = this.getPrefixedString(plugin.addon, handlerSchema.displaydata.title),
|
||||||
|
processorName = plugin.component.replace('message_', '');
|
||||||
|
|
||||||
|
this.messageOutputDelegate.registerHandler(new CoreSitePluginsMessageOutputHandler(uniqueName, processorName,
|
||||||
|
prefixedTitle, plugin, handlerSchema, initResult));
|
||||||
|
|
||||||
|
return uniqueName;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Given a handler in an plugin, register it in the module delegate.
|
* Given a handler in an plugin, register it in the module delegate.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in New Issue