MOBILE-1874 siteplugins: Support site plugins in activities block
parent
28e9fdc9d8
commit
187a07f8bd
|
@ -0,0 +1,26 @@
|
|||
ion-app.app-root.md addon-block-activitymodules {
|
||||
.core-module-icon {
|
||||
margin-top: $label-md-margin-top;
|
||||
margin-bottom: $label-md-margin-bottom;
|
||||
width: 24px;
|
||||
height: 24px;
|
||||
}
|
||||
}
|
||||
|
||||
ion-app.app-root.ios addon-block-activitymodules {
|
||||
.core-module-icon {
|
||||
margin-top: $label-ios-margin-top;
|
||||
margin-bottom: $label-ios-margin-bottom;
|
||||
width: 24px;
|
||||
height: 24px;
|
||||
}
|
||||
}
|
||||
|
||||
ion-app.app-root.wp addon-block-activitymodules {
|
||||
.core-module-icon {
|
||||
margin-top: $item-wp-padding-top;
|
||||
margin-bottom: $item-wp-padding-bottom;
|
||||
width: 24px;
|
||||
height: 24px;
|
||||
}
|
||||
}
|
|
@ -110,7 +110,7 @@ export class AddonBlockActivityModulesComponent extends CoreBlockBaseComponent i
|
|||
if (modName === 'resources') {
|
||||
icon = this.courseProvider.getModuleIconSrc('page');
|
||||
} else {
|
||||
icon = this.courseProvider.getModuleIconSrc(modName);
|
||||
icon = this.moduleDelegate.getModuleIconSrc(modName);
|
||||
}
|
||||
|
||||
this.entries.push({
|
||||
|
|
|
@ -94,6 +94,8 @@ ion-app.app-root.ios core-course-module {
|
|||
a.core-course-module-handler .core-module-icon {
|
||||
margin-top: $label-ios-margin-top;
|
||||
margin-bottom: $label-ios-margin-bottom;
|
||||
width: 24px;
|
||||
height: 24px;
|
||||
}
|
||||
|
||||
.core-module-title core-format-text {
|
||||
|
@ -119,6 +121,8 @@ ion-app.app-root.wp core-course-module {
|
|||
a.core-course-module-handler .core-module-icon {
|
||||
margin-top: $item-wp-padding-top;
|
||||
margin-bottom: $item-wp-padding-bottom;
|
||||
width: 24px;
|
||||
height: 24px;
|
||||
}
|
||||
|
||||
.core-module-title core-format-text {
|
||||
|
|
|
@ -71,6 +71,13 @@ export interface CoreCourseModuleHandler extends CoreDelegateHandler {
|
|||
*/
|
||||
displayRefresherInSingleActivity?(): boolean;
|
||||
|
||||
/**
|
||||
* Get the icon src for the module.
|
||||
*
|
||||
* @return {string} The icon src.
|
||||
*/
|
||||
getIconSrc?(): string;
|
||||
|
||||
/**
|
||||
* Check if this type of module supports a certain feature.
|
||||
* If this function is implemented, the supportedFeatures object will be ignored.
|
||||
|
@ -302,6 +309,16 @@ export class CoreCourseModuleDelegate extends CoreDelegate {
|
|||
return this.executeFunctionOnEnabled(modname, 'displayRefresherInSingleActivity');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the icon src for a certain type of module.
|
||||
*
|
||||
* @param {any} modname The name of the module type.
|
||||
* @return {string} The icon src.
|
||||
*/
|
||||
getModuleIconSrc(modname: string): string {
|
||||
return this.executeFunctionOnEnabled(modname, 'getIconSrc') || this.courseProvider.getModuleIconSrc(modname);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a certain type of module supports a certain feature.
|
||||
*
|
||||
|
|
|
@ -23,9 +23,18 @@ import { CoreSitePluginsModuleIndexComponent } from '../../components/module-ind
|
|||
*/
|
||||
export class CoreSitePluginsModuleHandler extends CoreSitePluginsBaseHandler implements CoreCourseModuleHandler {
|
||||
priority: number;
|
||||
supportedFeatures: {[name: string]: any};
|
||||
supportsFeature: (feature: string) => any;
|
||||
|
||||
constructor(name: string, public modName: string, protected handlerSchema: any) {
|
||||
constructor(name: string, public modName: string, protected handlerSchema: any, protected initResult: any) {
|
||||
super(name);
|
||||
|
||||
this.supportedFeatures = handlerSchema.supportedfeatures;
|
||||
|
||||
if (initResult && initResult.jsResult && initResult.jsResult.supportsFeature) {
|
||||
// The init result defines a function to check if a feature is supported, use it.
|
||||
this.supportsFeature = initResult.jsResult.supportsFeature.bind(initResult.jsResult);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -58,6 +67,15 @@ export class CoreSitePluginsModuleHandler extends CoreSitePluginsBaseHandler imp
|
|||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the icon src for the module.
|
||||
*
|
||||
* @return {string} The icon src.
|
||||
*/
|
||||
getIconSrc(): string {
|
||||
return this.handlerSchema.displaydata.icon;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the component to render the module. This is needed to support singleactivity course format.
|
||||
* The component returned must implement CoreCourseModuleMainComponent.
|
||||
|
|
|
@ -443,7 +443,7 @@ export class CoreSitePluginsHelperProvider {
|
|||
break;
|
||||
|
||||
case 'CoreCourseModuleDelegate':
|
||||
promise = Promise.resolve(this.registerModuleHandler(plugin, handlerName, handlerSchema));
|
||||
promise = Promise.resolve(this.registerModuleHandler(plugin, handlerName, handlerSchema, result));
|
||||
break;
|
||||
|
||||
case 'CoreUserDelegate':
|
||||
|
@ -720,9 +720,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} initResult Result of the init WS call.
|
||||
* @return {string} A string to identify the handler.
|
||||
*/
|
||||
protected registerModuleHandler(plugin: any, handlerName: string, handlerSchema: 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);
|
||||
|
@ -730,13 +731,13 @@ export class CoreSitePluginsHelperProvider {
|
|||
return;
|
||||
}
|
||||
|
||||
this.logger.debug('Register site plugin in module delegate:', plugin, handlerSchema);
|
||||
this.logger.debug('Register site plugin in module delegate:', plugin, handlerSchema, initResult);
|
||||
|
||||
// Create and register the handler.
|
||||
const uniqueName = this.sitePluginsProvider.getHandlerUniqueName(plugin, handlerName),
|
||||
modName = plugin.component.replace('mod_', '');
|
||||
|
||||
this.moduleDelegate.registerHandler(new CoreSitePluginsModuleHandler(uniqueName, modName, handlerSchema));
|
||||
this.moduleDelegate.registerHandler(new CoreSitePluginsModuleHandler(uniqueName, modName, handlerSchema, initResult));
|
||||
|
||||
if (handlerSchema.offlinefunctions && Object.keys(handlerSchema.offlinefunctions).length) {
|
||||
// Register the prefetch handler.
|
||||
|
|
Loading…
Reference in New Issue