MOBILE-3873 bbb: Allow both inapp support and site plugin support
parent
322285e9ff
commit
fd8d433f05
|
@ -17,6 +17,8 @@ import { Injectable, Type } from '@angular/core';
|
|||
import { CoreModuleHandlerBase } from '@features/course/classes/module-base-handler';
|
||||
import { CoreCourseAnyModuleData } from '@features/course/services/course';
|
||||
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 { AddonModBBBIndexComponent } from '../../components/index';
|
||||
import { AddonModBBB } from '../bigbluebuttonbn';
|
||||
|
@ -32,6 +34,7 @@ export class AddonModBBBModuleHandlerService extends CoreModuleHandlerBase imple
|
|||
name = 'AddonModBBB';
|
||||
modName = 'bigbluebuttonbn';
|
||||
protected pageName = ADDON_MOD_BBB_MAIN_MENU_PAGE_NAME;
|
||||
protected sitePluginHandler?: CoreSitePluginsModuleHandler;
|
||||
|
||||
supportedFeatures = {
|
||||
[CoreConstants.FEATURE_GROUPS]: true,
|
||||
|
@ -48,7 +51,21 @@ export class AddonModBBBModuleHandlerService extends CoreModuleHandlerBase imple
|
|||
* @inheritdoc
|
||||
*/
|
||||
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,
|
||||
forCoursePage?: boolean,
|
||||
): CoreCourseModuleHandlerData {
|
||||
if (this.sitePluginHandler) {
|
||||
return this.sitePluginHandler.getData(module, courseId, sectionId, forCoursePage);
|
||||
}
|
||||
|
||||
const data = super.getData(module, courseId, sectionId, forCoursePage);
|
||||
|
||||
data.showDownloadButton = false;
|
||||
|
@ -71,6 +92,10 @@ export class AddonModBBBModuleHandlerService extends CoreModuleHandlerBase imple
|
|||
* @inheritdoc
|
||||
*/
|
||||
async getMainComponent(): Promise<Type<unknown>> {
|
||||
if (this.sitePluginHandler) {
|
||||
return this.sitePluginHandler.getMainComponent();
|
||||
}
|
||||
|
||||
return AddonModBBBIndexComponent;
|
||||
}
|
||||
|
||||
|
|
|
@ -161,7 +161,11 @@ export class CoreSitePluginsModuleIndexComponent implements OnInit, OnDestroy, C
|
|||
* Expand the description.
|
||||
*/
|
||||
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,
|
||||
componentId: this.module.id,
|
||||
filter: true,
|
||||
|
|
|
@ -205,7 +205,7 @@ export class CoreSitePluginsHelperProvider {
|
|||
undefined,
|
||||
undefined,
|
||||
undefined,
|
||||
handlerSchema.styles!.version,
|
||||
handlerSchema.styles?.version,
|
||||
);
|
||||
|
||||
// File is downloaded, get the contents.
|
||||
|
@ -378,8 +378,9 @@ export class CoreSitePluginsHelperProvider {
|
|||
|
||||
if (plugin.parsedHandlers) {
|
||||
// Register all the handlers.
|
||||
await CoreUtils.allPromises(Object.keys(plugin.parsedHandlers).map(async (name) => {
|
||||
await this.registerHandler(plugin, name, plugin.parsedHandlers![name]);
|
||||
const parsedHandlers = plugin.parsedHandlers;
|
||||
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);
|
||||
CoreCourseModuleDelegate.registerHandler(moduleHandler);
|
||||
CoreSitePlugins.setModuleHandlerInstance(modName, moduleHandler);
|
||||
|
||||
if (handlerSchema.offlinefunctions && Object.keys(handlerSchema.offlinefunctions).length) {
|
||||
// Register the prefetch handler.
|
||||
|
|
|
@ -28,6 +28,7 @@ import { CoreWSExternalFile, CoreWSExternalWarning } from '@services/ws';
|
|||
import { makeSingleton } from '@singletons';
|
||||
import { CoreEvents } from '@singletons/events';
|
||||
import { CoreLogger } from '@singletons/logger';
|
||||
import { CoreSitePluginsModuleHandler } from '../classes/handlers/module-handler';
|
||||
|
||||
const ROOT_CACHE_KEY = 'CoreSitePlugins:';
|
||||
|
||||
|
@ -44,6 +45,8 @@ export class CoreSitePluginsProvider {
|
|||
protected sitePlugins: {[name: string]: CoreSitePluginsHandler} = {}; // Site plugins registered.
|
||||
protected sitePluginPromises: {[name: string]: Promise<void>} = {}; // Promises of loading plugins.
|
||||
protected fetchPluginsDeferred: PromiseDefer<void>;
|
||||
protected moduleHandlerInstances: Record<string, CoreSitePluginsModuleHandler> = {};
|
||||
|
||||
hasSitePluginsLoaded = false;
|
||||
sitePluginsFinishedLoading = false;
|
||||
|
||||
|
@ -262,7 +265,7 @@ export class CoreSitePluginsProvider {
|
|||
switch (paramName) {
|
||||
case 'courseids':
|
||||
// The WS needs the list of course IDs. Create the list.
|
||||
return [courseId!];
|
||||
return [courseId || 0];
|
||||
|
||||
case component + 'id':
|
||||
// The WS needs the instance id.
|
||||
|
@ -540,10 +543,13 @@ export class CoreSitePluginsProvider {
|
|||
return;
|
||||
}
|
||||
|
||||
const siteInstance = site;
|
||||
const offlineFunctions = handlerSchema.offlinefunctions;
|
||||
|
||||
await Promise.all(Object.keys(handlerSchema.offlinefunctions).map(async(method) => {
|
||||
if (site!.wsAvailable(method)) {
|
||||
if (siteInstance.wsAvailable(method)) {
|
||||
// The method is a WS.
|
||||
const paramsList = handlerSchema.offlinefunctions![method];
|
||||
const paramsList = offlineFunctions[method];
|
||||
const cacheKey = this.getCallWSCacheKey(method, args);
|
||||
let params: Record<string, unknown> = {};
|
||||
|
||||
|
@ -584,7 +590,7 @@ export class CoreSitePluginsProvider {
|
|||
// Prefetch the files in the content.
|
||||
if (result.files.length) {
|
||||
await CoreFilepool.downloadOrPrefetchFiles(
|
||||
site!.getId(),
|
||||
siteInstance.getId(),
|
||||
result.files,
|
||||
!!prefetch,
|
||||
false,
|
||||
|
@ -657,6 +663,26 @@ export class CoreSitePluginsProvider {
|
|||
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);
|
||||
|
|
Loading…
Reference in New Issue