Merge pull request #3954 from NoelDeMartin/MOBILE-4470

MOBILE-4470: Improve lazy loading and fix tests
main
Dani Palou 2024-03-05 13:54:27 +01:00 committed by GitHub
commit 4677ce5c3f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
16 changed files with 45 additions and 79 deletions

View File

@ -15,6 +15,7 @@ Feature: Test basic usage of chat in app
| user | course | role |
| student1 | C1 | student |
| student2 | C1 | student |
And I enable "chat" "mod" plugin
And the following "activities" exist:
| activity | name | intro | course | idnumber | groupmode |
| chat | Test chat name | Test chat | C1 | chat | 0 |

View File

@ -13,6 +13,7 @@ Feature: Test chat navigation
| user | course | role |
| student1 | C1 | student |
| student2 | C1 | student |
And I enable "chat" "mod" plugin
And the following "activities" exist:
| activity | name | intro | course | idnumber | groupmode |
| chat | Test chat name | Test chat | C1 | chat | 0 |

View File

@ -16,6 +16,7 @@ Feature: Test basic usage of survey activity in app
| user | course | role |
| student1 | C1 | student |
| teacher1 | C1 | editingteacher |
And I enable "survey" "mod" plugin
And the following "activities" exist:
| activity | name | intro | course | idnumber | groupmode |
| survey | Test survey name | Test survey | C1 | survey | 0 |

View File

@ -35,13 +35,6 @@ export class AddonModWorkshopAssessmentStrategyAccumulativeHandlerLazyService
extends AddonModWorkshopAssessmentStrategyAccumulativeHandlerService
implements AddonWorkshopAssessmentStrategyHandler {
/**
* @inheritdoc
*/
async isEnabled(): Promise<boolean> {
return true;
}
/**
* @inheritdoc
*/

View File

@ -20,11 +20,19 @@ import {
} from '@addons/mod/workshop/assessment/constants';
import type { AddonModWorkshopAssessmentStrategyAccumulativeHandlerLazyService } from './handler-lazy';
export class AddonModWorkshopAssessmentStrategyAccumulativeHandlerService {
export class AddonModWorkshopAssessmentStrategyAccumulativeHandlerService
implements Partial<AddonWorkshopAssessmentStrategyHandler> {
name = ADDON_MOD_WORKSHOP_ASSESSMENT_STRATEGY_ACCUMULATIVE_NAME;
strategyName = ADDON_MOD_WORKSHOP_ASSESSMENT_STRATEGY_ACCUMULATIVE_STRATEGY_NAME;
/**
* @inheritdoc
*/
async isEnabled(): Promise<boolean> {
return true;
}
}
/**
@ -44,7 +52,6 @@ export function getAssessmentStrategyHandlerInstance(): AddonWorkshopAssessmentS
lazyHandler.setEagerInstance(new AddonModWorkshopAssessmentStrategyAccumulativeHandlerService());
lazyHandler.setLazyInstanceMethods([
'isEnabled',
'getComponent',
'getOriginalValues',
'hasDataChanged',

View File

@ -34,13 +34,6 @@ export class AddonModWorkshopAssessmentStrategyCommentsHandlerLazyService
extends AddonModWorkshopAssessmentStrategyCommentsHandlerService
implements AddonWorkshopAssessmentStrategyHandler {
/**
* @inheritdoc
*/
async isEnabled(): Promise<boolean> {
return true;
}
/**
* @inheritdoc
*/

View File

@ -20,11 +20,19 @@ import {
} from '@addons/mod/workshop/assessment/constants';
import type { AddonModWorkshopAssessmentStrategyCommentsHandlerLazyService } from './handler-lazy';
export class AddonModWorkshopAssessmentStrategyCommentsHandlerService {
export class AddonModWorkshopAssessmentStrategyCommentsHandlerService
implements Partial<AddonWorkshopAssessmentStrategyHandler> {
name = ADDON_MOD_WORKSHOP_ASSESSMENT_STRATEGY_COMMENTS_NAME;
strategyName = ADDON_MOD_WORKSHOP_ASSESSMENT_STRATEGY_COMMENTS_STRATEGY_NAME;
/**
* @inheritdoc
*/
async isEnabled(): Promise<boolean> {
return true;
}
}
/**
@ -44,7 +52,6 @@ export function getAssessmentStrategyHandlerInstance(): AddonWorkshopAssessmentS
lazyHandler.setEagerInstance(new AddonModWorkshopAssessmentStrategyCommentsHandlerService());
lazyHandler.setLazyInstanceMethods([
'isEnabled',
'getComponent',
'getOriginalValues',
'hasDataChanged',

View File

@ -34,13 +34,6 @@ export class AddonModWorkshopAssessmentStrategyNumErrorsHandlerLazyService
extends AddonModWorkshopAssessmentStrategyNumErrorsHandlerService
implements AddonWorkshopAssessmentStrategyHandler {
/**
* @inheritdoc
*/
async isEnabled(): Promise<boolean> {
return true;
}
/**
* @inheritdoc
*/

View File

@ -20,11 +20,19 @@ import {
} from '@addons/mod/workshop/assessment/constants';
import type { AddonModWorkshopAssessmentStrategyNumErrorsHandlerLazyService } from './handler-lazy';
export class AddonModWorkshopAssessmentStrategyNumErrorsHandlerService {
export class AddonModWorkshopAssessmentStrategyNumErrorsHandlerService
implements Partial<AddonWorkshopAssessmentStrategyHandler> {
name = ADDON_MOD_WORKSHOP_ASSESSMENT_STRATEGY_NUMERRORS_NAME;
strategyName = ADDON_MOD_WORKSHOP_ASSESSMENT_STRATEGY_NUMERRORS_STRATEGY_NAME;
/**
* @inheritdoc
*/
async isEnabled(): Promise<boolean> {
return true;
}
}
/**
@ -44,7 +52,6 @@ export function getAssessmentStrategyHandlerInstance(): AddonWorkshopAssessmentS
lazyHandler.setEagerInstance(new AddonModWorkshopAssessmentStrategyNumErrorsHandlerService());
lazyHandler.setLazyInstanceMethods([
'isEnabled',
'getComponent',
'getOriginalValues',
'hasDataChanged',

View File

@ -34,13 +34,6 @@ export class AddonModWorkshopAssessmentStrategyRubricHandlerLazyService
extends AddonModWorkshopAssessmentStrategyRubricHandlerService
implements AddonWorkshopAssessmentStrategyHandler {
/**
* @inheritdoc
*/
async isEnabled(): Promise<boolean> {
return true;
}
/**
* @inheritdoc
*/

View File

@ -20,11 +20,19 @@ import {
} from '@addons/mod/workshop/assessment/constants';
import type { AddonModWorkshopAssessmentStrategyRubricHandlerLazyService } from './handler-lazy';
export class AddonModWorkshopAssessmentStrategyRubricHandlerService {
export class AddonModWorkshopAssessmentStrategyRubricHandlerService
implements Partial<AddonWorkshopAssessmentStrategyHandler> {
name = ADDON_MOD_WORKSHOP_ASSESSMENT_STRATEGY_RUBRIC_NAME;
strategyName = ADDON_MOD_WORKSHOP_ASSESSMENT_STRATEGY_RUBRIC_STRATEGY_NAME;
/**
* @inheritdoc
*/
async isEnabled(): Promise<boolean> {
return true;
}
}
/**
@ -44,7 +52,6 @@ export function getAssessmentStrategyHandlerInstance(): AddonWorkshopAssessmentS
lazyHandler.setEagerInstance(new AddonModWorkshopAssessmentStrategyRubricHandlerService());
lazyHandler.setLazyInstanceMethods([
'isEnabled',
'getComponent',
'getOriginalValues',
'hasDataChanged',

View File

@ -14,7 +14,6 @@
import { InjectionToken, Injector, ModuleWithProviders, NgModule, Type } from '@angular/core';
import {
PreloadAllModules,
RouterModule,
Route,
Routes,
@ -224,7 +223,7 @@ export const APP_ROUTES = new InjectionToken('APP_ROUTES');
@NgModule({
imports: [
RouterModule.forRoot([], { preloadingStrategy: PreloadAllModules }),
RouterModule.forRoot([]),
],
providers: [
{ provide: ROUTES, multi: true, useFactory: buildAppRoutes, deps: [Injector] },

View File

@ -17,6 +17,8 @@ Feature: Test basic usage of one course in app
| user | course | role |
| teacher1 | C1 | editingteacher |
| student1 | C1 | student |
And I enable "chat" "mod" plugin
And I enable "survey" "mod" plugin
And the following "activities" exist:
| activity | name | intro | course | idnumber | option | section |
| choice | Choice course 1 | Test choice description | C1 | choice1 | Option 1, Option 2, Option 3 | 1 |

View File

@ -18,39 +18,6 @@ import { Route, Routes } from '@angular/router';
import { ModuleRoutesConfig, isEmptyRoute, resolveModuleRoutes } from '@/app/app-routing.module';
const MAIN_MENU_TAB_ROUTES = new InjectionToken('MAIN_MENU_TAB_ROUTES');
const modulesPaths: Record<string, Set<string>> = {};
/**
* Get the name of the module the injector belongs to.
*
* @param injector Injector.
* @returns Injector module name.
*/
function getInjectorModule(injector: Injector): string | null {
if (!('source' in injector) || typeof injector.source !== 'string') {
return null;
}
// Get module name from R3Injector source.
// See https://github.com/angular/angular/blob/16.2.0/packages/core/src/di/r3_injector.ts#L161C8
return injector.source;
}
/**
* Get module paths.
*
* @param injector Injector.
* @returns Module paths.
*/
function getModulePaths(injector: Injector): Set<string> | null {
const module = getInjectorModule(injector);
if (!module) {
return null;
}
return modulesPaths[module] ??= new Set();
}
/**
* Build module routes.
@ -61,23 +28,18 @@ function getModulePaths(injector: Injector): Set<string> | null {
*/
export function buildTabMainRoutes(injector: Injector, mainRoute: Route): Routes {
const path = mainRoute.path ?? '';
const modulePaths = getModulePaths(injector);
const isRootRoute = modulePaths && !modulePaths.has(path);
const routes = resolveModuleRoutes(injector, MAIN_MENU_TAB_ROUTES);
mainRoute.path = path;
modulePaths?.add(path);
if (isRootRoute && !('redirectTo' in mainRoute)) {
if (!('redirectTo' in mainRoute)) {
mainRoute.children = mainRoute.children || [];
mainRoute.children = mainRoute.children.concat(routes.children);
} else if (isEmptyRoute(mainRoute)) {
return [];
}
return isRootRoute
? [mainRoute, ...routes.siblings]
: [mainRoute];
return [mainRoute, ...routes.siblings];
}
@NgModule()