MOBILE-4272 workshop: Decouple services

main
Noel De Martin 2023-07-26 11:49:44 +09:00
parent a5cd697012
commit 0d6eb5cb23
4 changed files with 46 additions and 23 deletions

View File

@ -23,27 +23,35 @@ import { CoreCronDelegate } from '@services/cron';
import { CORE_SITE_SCHEMAS } from '@services/sites'; import { CORE_SITE_SCHEMAS } from '@services/sites';
import { AddonModWorkshopAssessmentStrategyModule } from './assessment/assessment.module'; import { AddonModWorkshopAssessmentStrategyModule } from './assessment/assessment.module';
import { AddonModWorkshopComponentsModule } from './components/components.module'; import { AddonModWorkshopComponentsModule } from './components/components.module';
import { AddonWorkshopAssessmentStrategyDelegateService } from './services/assessment-strategy-delegate';
import { ADDON_MOD_WORKSHOP_OFFLINE_SITE_SCHEMA } from './services/database/workshop'; import { ADDON_MOD_WORKSHOP_OFFLINE_SITE_SCHEMA } from './services/database/workshop';
import { AddonModWorkshopIndexLinkHandler } from './services/handlers/index-link'; import { AddonModWorkshopIndexLinkHandler } from './services/handlers/index-link';
import { AddonModWorkshopListLinkHandler } from './services/handlers/list-link'; import { AddonModWorkshopListLinkHandler } from './services/handlers/list-link';
import { AddonModWorkshopModuleHandler } from './services/handlers/module'; import { AddonModWorkshopModuleHandler } from './services/handlers/module';
import { AddonModWorkshopProvider } from './services/workshop';
import { AddonModWorkshopHelperProvider } from './services/workshop-helper';
import { AddonModWorkshopOfflineProvider } from './services/workshop-offline';
import { AddonModWorkshopSyncProvider } from './services/workshop-sync';
import { ADDON_MOD_WORKSHOP_COMPONENT, ADDON_MOD_WORKSHOP_PAGE_NAME } from '@addons/mod/workshop/constants'; import { ADDON_MOD_WORKSHOP_COMPONENT, ADDON_MOD_WORKSHOP_PAGE_NAME } from '@addons/mod/workshop/constants';
import { getCronHandlerInstance } from '@addons/mod/workshop/services/handlers/sync-cron'; import { getCronHandlerInstance } from '@addons/mod/workshop/services/handlers/sync-cron';
import { getPrefetchHandlerInstance } from '@addons/mod/workshop/services/handlers/prefetch'; import { getPrefetchHandlerInstance } from '@addons/mod/workshop/services/handlers/prefetch';
// List of providers (without handlers). /**
export const ADDON_MOD_WORKSHOP_SERVICES: Type<unknown>[] = [ * Get workshop services.
AddonModWorkshopProvider, *
AddonModWorkshopOfflineProvider, * @returns Workshop services.
AddonModWorkshopSyncProvider, */
AddonModWorkshopHelperProvider, export async function getWorkshopServices(): Promise<Type<unknown>[]> {
AddonWorkshopAssessmentStrategyDelegateService, const { AddonModWorkshopProvider } = await import('@addons/mod/workshop/services/workshop');
]; const { AddonModWorkshopOfflineProvider } = await import('@addons/mod/workshop/services/workshop-offline');
const { AddonModWorkshopSyncProvider } = await import('@addons/mod/workshop/services/workshop-sync');
const { AddonModWorkshopHelperProvider } = await import('@addons/mod/workshop/services/workshop-helper');
const { AddonWorkshopAssessmentStrategyDelegateService } =
await import('@addons/mod/workshop/services/assessment-strategy-delegate');
return [
AddonModWorkshopProvider,
AddonModWorkshopOfflineProvider,
AddonModWorkshopSyncProvider,
AddonModWorkshopHelperProvider,
AddonWorkshopAssessmentStrategyDelegateService,
];
}
const routes: Routes = [ const routes: Routes = [
{ {

View File

@ -126,11 +126,8 @@ export class CoreCompileHtmlComponent implements OnChanges, OnDestroy, DoCheck {
this.compiling.emit(true); this.compiling.emit(true);
try { try {
const factory = await CoreCompile.createAndCompileComponent( const componentClass = await this.getComponentClass();
this.text, const factory = await CoreCompile.createAndCompileComponent(this.text, componentClass, this.extraImports);
this.getComponentClass(),
this.extraImports,
);
// Destroy previous components. // Destroy previous components.
this.componentRef?.destroy(); this.componentRef?.destroy();
@ -166,9 +163,10 @@ export class CoreCompileHtmlComponent implements OnChanges, OnDestroy, DoCheck {
* *
* @returns The component class. * @returns The component class.
*/ */
protected getComponentClass(): Type<unknown> { protected async getComponentClass(): Promise<Type<unknown>> {
// eslint-disable-next-line @typescript-eslint/no-this-alias // eslint-disable-next-line @typescript-eslint/no-this-alias
const compileInstance = this; const compileInstance = this;
const lazyLibraries = await CoreCompile.getLazyLibraries();
// Create the component, using the text as the template. // Create the component, using the text as the template.
return class CoreCompileHtmlFakeComponent implements OnInit, AfterContentInit, AfterViewInit, OnDestroy { return class CoreCompileHtmlFakeComponent implements OnInit, AfterContentInit, AfterViewInit, OnDestroy {
@ -184,7 +182,10 @@ export class CoreCompileHtmlComponent implements OnChanges, OnDestroy, DoCheck {
this['dataArray'] = []; this['dataArray'] = [];
// Inject the libraries. // Inject the libraries.
CoreCompile.injectLibraries(this, compileInstance.extraProviders); CoreCompile.injectLibraries(this, [
...lazyLibraries,
...compileInstance.extraProviders,
]);
// Always add these elements, they could be needed on component init (componentObservable). // Always add these elements, they could be needed on component init (componentObservable).
this['ChangeDetectorRef'] = compileInstance.changeDetector; this['ChangeDetectorRef'] = compileInstance.changeDetector;

View File

@ -149,7 +149,7 @@ import { ADDON_MOD_SCORM_SERVICES } from '@addons/mod/scorm/scorm.module';
import { ADDON_MOD_SURVEY_SERVICES } from '@addons/mod/survey/survey.module'; import { ADDON_MOD_SURVEY_SERVICES } from '@addons/mod/survey/survey.module';
import { ADDON_MOD_URL_SERVICES } from '@addons/mod/url/url.module'; import { ADDON_MOD_URL_SERVICES } from '@addons/mod/url/url.module';
import { ADDON_MOD_WIKI_SERVICES } from '@addons/mod/wiki/wiki.module'; import { ADDON_MOD_WIKI_SERVICES } from '@addons/mod/wiki/wiki.module';
import { ADDON_MOD_WORKSHOP_SERVICES } from '@addons/mod/workshop/workshop.module'; import { getWorkshopServices } from '@addons/mod/workshop/workshop.module';
import { ADDON_NOTES_SERVICES } from '@addons/notes/notes.module'; import { ADDON_NOTES_SERVICES } from '@addons/notes/notes.module';
import { ADDON_NOTIFICATIONS_SERVICES } from '@addons/notifications/notifications.module'; import { ADDON_NOTIFICATIONS_SERVICES } from '@addons/notifications/notifications.module';
import { ADDON_PRIVATEFILES_SERVICES } from '@addons/privatefiles/privatefiles.module'; import { ADDON_PRIVATEFILES_SERVICES } from '@addons/privatefiles/privatefiles.module';
@ -317,7 +317,6 @@ export class CoreCompileProvider {
...ADDON_MOD_SURVEY_SERVICES, ...ADDON_MOD_SURVEY_SERVICES,
...ADDON_MOD_URL_SERVICES, ...ADDON_MOD_URL_SERVICES,
...ADDON_MOD_WIKI_SERVICES, ...ADDON_MOD_WIKI_SERVICES,
...ADDON_MOD_WORKSHOP_SERVICES,
...ADDON_NOTES_SERVICES, ...ADDON_NOTES_SERVICES,
...ADDON_NOTIFICATIONS_SERVICES, ...ADDON_NOTIFICATIONS_SERVICES,
...ADDON_PRIVATEFILES_SERVICES, ...ADDON_PRIVATEFILES_SERVICES,
@ -388,6 +387,19 @@ export class CoreCompileProvider {
}); });
} }
/**
* Get lazy libraries to inject.
*
* @returns Lazy libraries.
*/
async getLazyLibraries(): Promise<Type<unknown>[]> {
const ADDON_MOD_WORKSHOP_SERVICES = await getWorkshopServices();
return [
...ADDON_MOD_WORKSHOP_SERVICES,
];
}
/** /**
* Instantiate a dynamic component. * Instantiate a dynamic component.
* *

View File

@ -268,11 +268,13 @@ export class CoreSitePluginsHelperProvider {
} }
// Create a "fake" instance to hold all the libraries. // Create a "fake" instance to hold all the libraries.
const lazyLibraries = await CoreCompile.getLazyLibraries();
const instance = { const instance = {
// eslint-disable-next-line @typescript-eslint/naming-convention // eslint-disable-next-line @typescript-eslint/naming-convention
HANDLER_DISABLED: HANDLER_DISABLED, HANDLER_DISABLED: HANDLER_DISABLED,
}; };
CoreCompile.injectLibraries(instance);
CoreCompile.injectLibraries(instance, lazyLibraries);
// Add some data of the WS call result. // Add some data of the WS call result.
const jsData = CoreSitePlugins.createDataForJS(result); const jsData = CoreSitePlugins.createDataForJS(result);