MOBILE-3873 bbb: Allow both inapp support and site plugin support

main
Dani Palou 2021-09-29 11:32:09 +02:00
parent 322285e9ff
commit fd8d433f05
4 changed files with 66 additions and 9 deletions

View File

@ -17,6 +17,8 @@ import { Injectable, Type } from '@angular/core';
import { CoreModuleHandlerBase } from '@features/course/classes/module-base-handler'; import { CoreModuleHandlerBase } from '@features/course/classes/module-base-handler';
import { CoreCourseAnyModuleData } from '@features/course/services/course'; import { CoreCourseAnyModuleData } from '@features/course/services/course';
import { CoreCourseModuleHandler, CoreCourseModuleHandlerData } from '@features/course/services/module-delegate'; import { CoreCourseModuleHandler, CoreCourseModuleHandlerData } from '@features/course/services/module-delegate';
import { CoreSitePluginsModuleHandler } from '@features/siteplugins/classes/handlers/module-handler';
import { CoreSitePlugins } from '@features/siteplugins/services/siteplugins';
import { makeSingleton } from '@singletons'; import { makeSingleton } from '@singletons';
import { AddonModBBBIndexComponent } from '../../components/index'; import { AddonModBBBIndexComponent } from '../../components/index';
import { AddonModBBB } from '../bigbluebuttonbn'; import { AddonModBBB } from '../bigbluebuttonbn';
@ -32,6 +34,7 @@ export class AddonModBBBModuleHandlerService extends CoreModuleHandlerBase imple
name = 'AddonModBBB'; name = 'AddonModBBB';
modName = 'bigbluebuttonbn'; modName = 'bigbluebuttonbn';
protected pageName = ADDON_MOD_BBB_MAIN_MENU_PAGE_NAME; protected pageName = ADDON_MOD_BBB_MAIN_MENU_PAGE_NAME;
protected sitePluginHandler?: CoreSitePluginsModuleHandler;
supportedFeatures = { supportedFeatures = {
[CoreConstants.FEATURE_GROUPS]: true, [CoreConstants.FEATURE_GROUPS]: true,
@ -48,7 +51,21 @@ export class AddonModBBBModuleHandlerService extends CoreModuleHandlerBase imple
* @inheritdoc * @inheritdoc
*/ */
async isEnabled(): Promise<boolean> { async isEnabled(): Promise<boolean> {
return AddonModBBB.isPluginEnabled(); const enabled = await AddonModBBB.isPluginEnabled();
if (enabled) {
delete this.sitePluginHandler;
this.name = 'AddonModBBB';
return true;
}
// Native support not available in this site. Check if it's supported by site plugin.
this.sitePluginHandler = CoreSitePlugins.getModuleHandlerInstance(this.modName);
// Change the handler name to be able to retrieve the plugin data in component.
this.name = this.sitePluginHandler?.name || this.name;
return !!this.sitePluginHandler;
} }
/** /**
@ -60,6 +77,10 @@ export class AddonModBBBModuleHandlerService extends CoreModuleHandlerBase imple
sectionId?: number, sectionId?: number,
forCoursePage?: boolean, forCoursePage?: boolean,
): CoreCourseModuleHandlerData { ): CoreCourseModuleHandlerData {
if (this.sitePluginHandler) {
return this.sitePluginHandler.getData(module, courseId, sectionId, forCoursePage);
}
const data = super.getData(module, courseId, sectionId, forCoursePage); const data = super.getData(module, courseId, sectionId, forCoursePage);
data.showDownloadButton = false; data.showDownloadButton = false;
@ -71,6 +92,10 @@ export class AddonModBBBModuleHandlerService extends CoreModuleHandlerBase imple
* @inheritdoc * @inheritdoc
*/ */
async getMainComponent(): Promise<Type<unknown>> { async getMainComponent(): Promise<Type<unknown>> {
if (this.sitePluginHandler) {
return this.sitePluginHandler.getMainComponent();
}
return AddonModBBBIndexComponent; return AddonModBBBIndexComponent;
} }

View File

@ -161,7 +161,11 @@ export class CoreSitePluginsModuleIndexComponent implements OnInit, OnDestroy, C
* Expand the description. * Expand the description.
*/ */
expandDescription(): void { expandDescription(): void {
CoreTextUtils.viewText(Translate.instant('core.description'), this.description!, { if (!this.description) {
return;
}
CoreTextUtils.viewText(Translate.instant('core.description'), this.description, {
component: this.component, component: this.component,
componentId: this.module.id, componentId: this.module.id,
filter: true, filter: true,

View File

@ -205,7 +205,7 @@ export class CoreSitePluginsHelperProvider {
undefined, undefined,
undefined, undefined,
undefined, undefined,
handlerSchema.styles!.version, handlerSchema.styles?.version,
); );
// File is downloaded, get the contents. // File is downloaded, get the contents.
@ -378,8 +378,9 @@ export class CoreSitePluginsHelperProvider {
if (plugin.parsedHandlers) { if (plugin.parsedHandlers) {
// Register all the handlers. // Register all the handlers.
await CoreUtils.allPromises(Object.keys(plugin.parsedHandlers).map(async (name) => { const parsedHandlers = plugin.parsedHandlers;
await this.registerHandler(plugin, name, plugin.parsedHandlers![name]); await CoreUtils.allPromises(Object.keys(parsedHandlers).map(async (name) => {
await this.registerHandler(plugin, name, parsedHandlers[name]);
})); }));
} }
} }
@ -891,6 +892,7 @@ export class CoreSitePluginsHelperProvider {
const moduleHandler = new CoreSitePluginsModuleHandler(uniqueName, modName, plugin, handlerSchema, initResult); const moduleHandler = new CoreSitePluginsModuleHandler(uniqueName, modName, plugin, handlerSchema, initResult);
CoreCourseModuleDelegate.registerHandler(moduleHandler); CoreCourseModuleDelegate.registerHandler(moduleHandler);
CoreSitePlugins.setModuleHandlerInstance(modName, moduleHandler);
if (handlerSchema.offlinefunctions && Object.keys(handlerSchema.offlinefunctions).length) { if (handlerSchema.offlinefunctions && Object.keys(handlerSchema.offlinefunctions).length) {
// Register the prefetch handler. // Register the prefetch handler.

View File

@ -28,6 +28,7 @@ import { CoreWSExternalFile, CoreWSExternalWarning } from '@services/ws';
import { makeSingleton } from '@singletons'; import { makeSingleton } from '@singletons';
import { CoreEvents } from '@singletons/events'; import { CoreEvents } from '@singletons/events';
import { CoreLogger } from '@singletons/logger'; import { CoreLogger } from '@singletons/logger';
import { CoreSitePluginsModuleHandler } from '../classes/handlers/module-handler';
const ROOT_CACHE_KEY = 'CoreSitePlugins:'; const ROOT_CACHE_KEY = 'CoreSitePlugins:';
@ -44,6 +45,8 @@ export class CoreSitePluginsProvider {
protected sitePlugins: {[name: string]: CoreSitePluginsHandler} = {}; // Site plugins registered. protected sitePlugins: {[name: string]: CoreSitePluginsHandler} = {}; // Site plugins registered.
protected sitePluginPromises: {[name: string]: Promise<void>} = {}; // Promises of loading plugins. protected sitePluginPromises: {[name: string]: Promise<void>} = {}; // Promises of loading plugins.
protected fetchPluginsDeferred: PromiseDefer<void>; protected fetchPluginsDeferred: PromiseDefer<void>;
protected moduleHandlerInstances: Record<string, CoreSitePluginsModuleHandler> = {};
hasSitePluginsLoaded = false; hasSitePluginsLoaded = false;
sitePluginsFinishedLoading = false; sitePluginsFinishedLoading = false;
@ -262,7 +265,7 @@ export class CoreSitePluginsProvider {
switch (paramName) { switch (paramName) {
case 'courseids': case 'courseids':
// The WS needs the list of course IDs. Create the list. // The WS needs the list of course IDs. Create the list.
return [courseId!]; return [courseId || 0];
case component + 'id': case component + 'id':
// The WS needs the instance id. // The WS needs the instance id.
@ -540,10 +543,13 @@ export class CoreSitePluginsProvider {
return; return;
} }
const siteInstance = site;
const offlineFunctions = handlerSchema.offlinefunctions;
await Promise.all(Object.keys(handlerSchema.offlinefunctions).map(async(method) => { await Promise.all(Object.keys(handlerSchema.offlinefunctions).map(async(method) => {
if (site!.wsAvailable(method)) { if (siteInstance.wsAvailable(method)) {
// The method is a WS. // The method is a WS.
const paramsList = handlerSchema.offlinefunctions![method]; const paramsList = offlineFunctions[method];
const cacheKey = this.getCallWSCacheKey(method, args); const cacheKey = this.getCallWSCacheKey(method, args);
let params: Record<string, unknown> = {}; let params: Record<string, unknown> = {};
@ -584,7 +590,7 @@ export class CoreSitePluginsProvider {
// Prefetch the files in the content. // Prefetch the files in the content.
if (result.files.length) { if (result.files.length) {
await CoreFilepool.downloadOrPrefetchFiles( await CoreFilepool.downloadOrPrefetchFiles(
site!.getId(), siteInstance.getId(),
result.files, result.files,
!!prefetch, !!prefetch,
false, false,
@ -657,6 +663,26 @@ export class CoreSitePluginsProvider {
return this.fetchPluginsDeferred.promise; return this.fetchPluginsDeferred.promise;
} }
/**
* Get a module hander instance, if present.
*
* @param modName Mod name without "mod_".
* @return Handler instance, undefined if not found.
*/
getModuleHandlerInstance(modName: string): CoreSitePluginsModuleHandler | undefined {
return this.moduleHandlerInstances[modName];
}
/**
* Set a module hander instance.
*
* @param modName Mod name.
* @param handler Handler instance.
*/
setModuleHandlerInstance(modName: string, handler: CoreSitePluginsModuleHandler): void {
this.moduleHandlerInstances[modName] = handler;
}
} }
export const CoreSitePlugins = makeSingleton(CoreSitePluginsProvider); export const CoreSitePlugins = makeSingleton(CoreSitePluginsProvider);