Skip to content

Commit

Permalink
Merge pull request #3954 from NoelDeMartin/MOBILE-4470
Browse files Browse the repository at this point in the history
MOBILE-4470: Improve lazy loading and fix tests
  • Loading branch information
dpalou authored Mar 5, 2024
2 parents 5936cda + fee90d4 commit 4677ce5
Show file tree
Hide file tree
Showing 16 changed files with 45 additions and 79 deletions.
1 change: 1 addition & 0 deletions src/addons/mod/chat/tests/behat/basic_usage.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down
1 change: 1 addition & 0 deletions src/addons/mod/chat/tests/behat/navigation.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down
1 change: 1 addition & 0 deletions src/addons/mod/survey/tests/behat/basic_usage.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,6 @@ export class AddonModWorkshopAssessmentStrategyAccumulativeHandlerLazyService
extends AddonModWorkshopAssessmentStrategyAccumulativeHandlerService
implements AddonWorkshopAssessmentStrategyHandler {

/**
* @inheritdoc
*/
async isEnabled(): Promise<boolean> {
return true;
}

/**
* @inheritdoc
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

}

/**
Expand All @@ -44,7 +52,6 @@ export function getAssessmentStrategyHandlerInstance(): AddonWorkshopAssessmentS

lazyHandler.setEagerInstance(new AddonModWorkshopAssessmentStrategyAccumulativeHandlerService());
lazyHandler.setLazyInstanceMethods([
'isEnabled',
'getComponent',
'getOriginalValues',
'hasDataChanged',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,6 @@ export class AddonModWorkshopAssessmentStrategyCommentsHandlerLazyService
extends AddonModWorkshopAssessmentStrategyCommentsHandlerService
implements AddonWorkshopAssessmentStrategyHandler {

/**
* @inheritdoc
*/
async isEnabled(): Promise<boolean> {
return true;
}

/**
* @inheritdoc
*/
Expand Down
11 changes: 9 additions & 2 deletions src/addons/mod/workshop/assessment/comments/services/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

}

/**
Expand All @@ -44,7 +52,6 @@ export function getAssessmentStrategyHandlerInstance(): AddonWorkshopAssessmentS

lazyHandler.setEagerInstance(new AddonModWorkshopAssessmentStrategyCommentsHandlerService());
lazyHandler.setLazyInstanceMethods([
'isEnabled',
'getComponent',
'getOriginalValues',
'hasDataChanged',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,6 @@ export class AddonModWorkshopAssessmentStrategyNumErrorsHandlerLazyService
extends AddonModWorkshopAssessmentStrategyNumErrorsHandlerService
implements AddonWorkshopAssessmentStrategyHandler {

/**
* @inheritdoc
*/
async isEnabled(): Promise<boolean> {
return true;
}

/**
* @inheritdoc
*/
Expand Down
11 changes: 9 additions & 2 deletions src/addons/mod/workshop/assessment/numerrors/services/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

}

/**
Expand All @@ -44,7 +52,6 @@ export function getAssessmentStrategyHandlerInstance(): AddonWorkshopAssessmentS

lazyHandler.setEagerInstance(new AddonModWorkshopAssessmentStrategyNumErrorsHandlerService());
lazyHandler.setLazyInstanceMethods([
'isEnabled',
'getComponent',
'getOriginalValues',
'hasDataChanged',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,6 @@ export class AddonModWorkshopAssessmentStrategyRubricHandlerLazyService
extends AddonModWorkshopAssessmentStrategyRubricHandlerService
implements AddonWorkshopAssessmentStrategyHandler {

/**
* @inheritdoc
*/
async isEnabled(): Promise<boolean> {
return true;
}

/**
* @inheritdoc
*/
Expand Down
11 changes: 9 additions & 2 deletions src/addons/mod/workshop/assessment/rubric/services/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

}

/**
Expand All @@ -44,7 +52,6 @@ export function getAssessmentStrategyHandlerInstance(): AddonWorkshopAssessmentS

lazyHandler.setEagerInstance(new AddonModWorkshopAssessmentStrategyRubricHandlerService());
lazyHandler.setLazyInstanceMethods([
'isEnabled',
'getComponent',
'getOriginalValues',
'hasDataChanged',
Expand Down
3 changes: 1 addition & 2 deletions src/app/app-routing.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

import { InjectionToken, Injector, ModuleWithProviders, NgModule, Type } from '@angular/core';
import {
PreloadAllModules,
RouterModule,
Route,
Routes,
Expand Down Expand Up @@ -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] },
Expand Down
4 changes: 3 additions & 1 deletion src/core/features/course/tests/behat/basic_usage.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down Expand Up @@ -345,7 +347,7 @@ Feature: Test basic usage of one course in app
Scenario: Navigation between sections using the bottom arrows
When I entered the course "Course 1" as "student1" in the app
Then the header should be "Course 1" in the app
And I should find "Test forum name" in the app
And I should find "Test forum name" in the app
And I should find "Test wiki name" in the app
And I should find "Choice course 1" in the app
And I should find "assignment" in the app
Expand Down
42 changes: 2 additions & 40 deletions src/core/features/mainmenu/mainmenu-tab-routing.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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()
Expand Down

0 comments on commit 4677ce5

Please sign in to comment.