Commit dddbe34f1b11fe04490c1eff12c3673f531fb0c5

Authored by Igor Kulikov
1 parent bfec4ef7

Improve modules loading

@@ -14,7 +14,7 @@ @@ -14,7 +14,7 @@
14 /// limitations under the License. 14 /// limitations under the License.
15 /// 15 ///
16 16
17 -import { Inject, Injectable, Type } from '@angular/core'; 17 +import { Inject, Injectable, Optional, Type } from '@angular/core';
18 import { DynamicComponentFactoryService } from '@core/services/dynamic-component-factory.service'; 18 import { DynamicComponentFactoryService } from '@core/services/dynamic-component-factory.service';
19 import { WidgetService } from '@core/http/widget.service'; 19 import { WidgetService } from '@core/http/widget.service';
20 import { forkJoin, Observable, of, ReplaySubject, Subject, throwError } from 'rxjs'; 20 import { forkJoin, Observable, of, ReplaySubject, Subject, throwError } from 'rxjs';
@@ -41,43 +41,7 @@ import { NULL_UUID } from '@shared/models/id/has-uuid'; @@ -41,43 +41,7 @@ import { NULL_UUID } from '@shared/models/id/has-uuid';
41 import { WidgetTypeId } from '@app/shared/models/id/widget-type-id'; 41 import { WidgetTypeId } from '@app/shared/models/id/widget-type-id';
42 import { TenantId } from '@app/shared/models/id/tenant-id'; 42 import { TenantId } from '@app/shared/models/id/tenant-id';
43 import { SharedModule } from '@shared/shared.module'; 43 import { SharedModule } from '@shared/shared.module';
44 -import * as AngularCore from '@angular/core';  
45 -import * as AngularCommon from '@angular/common';  
46 -import * as AngularForms from '@angular/forms';  
47 -import * as AngularRouter from '@angular/router';  
48 -import * as AngularCdkKeycodes from '@angular/cdk/keycodes';  
49 -import * as AngularCdkCoercion from '@angular/cdk/coercion';  
50 -import * as AngularMaterialChips from '@angular/material/chips';  
51 -import * as AngularMaterialAutocomplete from '@angular/material/autocomplete';  
52 -import * as AngularMaterialDialog from '@angular/material/dialog';  
53 -import * as NgrxStore from '@ngrx/store';  
54 -import * as RxJs from 'rxjs';  
55 -import * as RxJsOperators from 'rxjs/operators';  
56 -import * as TranslateCore from '@ngx-translate/core';  
57 -import * as TbCore from '@core/public-api';  
58 -import * as TbShared from '@shared/public-api';  
59 -import * as _moment from 'moment';  
60 -  
61 -declare const SystemJS;  
62 -  
63 -const widgetResourcesModulesMap = {  
64 - '@angular/core': SystemJS.newModule(AngularCore),  
65 - '@angular/common': SystemJS.newModule(AngularCommon),  
66 - '@angular/forms': SystemJS.newModule(AngularForms),  
67 - '@angular/router': SystemJS.newModule(AngularRouter),  
68 - '@angular/cdk/keycodes': SystemJS.newModule(AngularCdkKeycodes),  
69 - '@angular/cdk/coercion': SystemJS.newModule(AngularCdkCoercion),  
70 - '@angular/material/chips': SystemJS.newModule(AngularMaterialChips),  
71 - '@angular/material/autocomplete': SystemJS.newModule(AngularMaterialAutocomplete),  
72 - '@angular/material/dialog': SystemJS.newModule(AngularMaterialDialog),  
73 - '@ngrx/store': SystemJS.newModule(NgrxStore),  
74 - rxjs: SystemJS.newModule(RxJs),  
75 - 'rxjs/operators': SystemJS.newModule(RxJsOperators),  
76 - '@ngx-translate/core': SystemJS.newModule(TranslateCore),  
77 - '@core/public-api': SystemJS.newModule(TbCore),  
78 - '@shared/public-api': SystemJS.newModule(TbShared),  
79 - moment: SystemJS.newModule(_moment)  
80 -}; 44 +import { MODULES_MAP } from '@shared/public-api';
81 45
82 // @dynamic 46 // @dynamic
83 @Injectable() 47 @Injectable()
@@ -96,6 +60,7 @@ export class WidgetComponentService { @@ -96,6 +60,7 @@ export class WidgetComponentService {
96 private editingWidgetType: WidgetType; 60 private editingWidgetType: WidgetType;
97 61
98 constructor(@Inject(WINDOW) private window: Window, 62 constructor(@Inject(WINDOW) private window: Window,
  63 + @Optional() @Inject(MODULES_MAP) private modulesMap: {[key: string]: any},
99 private dynamicComponentFactoryService: DynamicComponentFactoryService, 64 private dynamicComponentFactoryService: DynamicComponentFactoryService,
100 private widgetService: WidgetService, 65 private widgetService: WidgetService,
101 private utils: UtilsService, 66 private utils: UtilsService,
@@ -260,7 +225,7 @@ export class WidgetComponentService { @@ -260,7 +225,7 @@ export class WidgetComponentService {
260 widgetInfo.resources.filter(r => r.isModule).forEach( 225 widgetInfo.resources.filter(r => r.isModule).forEach(
261 (resource) => { 226 (resource) => {
262 modulesTasks.push( 227 modulesTasks.push(
263 - this.resources.loadModules(resource.url, widgetResourcesModulesMap).pipe( 228 + this.resources.loadModules(resource.url, this.modulesMap).pipe(
264 catchError((e: Error) => of(e?.message ? e.message : `Failed to load widget resource module: '${resource.url}'`)) 229 catchError((e: Error) => of(e?.message ? e.message : `Failed to load widget resource module: '${resource.url}'`))
265 ) 230 )
266 ); 231 );
@@ -317,7 +282,7 @@ export class WidgetComponentService { @@ -317,7 +282,7 @@ export class WidgetComponentService {
317 const errorMessage = `Failed to compile widget html. \n Error: ${details.message}`; 282 const errorMessage = `Failed to compile widget html. \n Error: ${details.message}`;
318 return of(errorMessage); 283 return of(errorMessage);
319 }) 284 })
320 - ) 285 + );
321 } 286 }
322 })) 287 }))
323 ); 288 );
@@ -29,6 +29,46 @@ import { EntityViewModule } from '@modules/home/pages/entity-view/entity-view.mo @@ -29,6 +29,46 @@ import { EntityViewModule } from '@modules/home/pages/entity-view/entity-view.mo
29 import { RuleChainModule } from '@modules/home/pages/rulechain/rulechain.module'; 29 import { RuleChainModule } from '@modules/home/pages/rulechain/rulechain.module';
30 import { WidgetLibraryModule } from '@modules/home/pages/widget/widget-library.module'; 30 import { WidgetLibraryModule } from '@modules/home/pages/widget/widget-library.module';
31 import { DashboardModule } from '@modules/home/pages/dashboard/dashboard.module'; 31 import { DashboardModule } from '@modules/home/pages/dashboard/dashboard.module';
  32 +import * as AngularCore from '@angular/core';
  33 +import * as AngularCommon from '@angular/common';
  34 +import * as AngularForms from '@angular/forms';
  35 +import * as AngularRouter from '@angular/router';
  36 +import * as AngularCdkKeycodes from '@angular/cdk/keycodes';
  37 +import * as AngularCdkCoercion from '@angular/cdk/coercion';
  38 +import * as AngularMaterialChips from '@angular/material/chips';
  39 +import * as AngularMaterialAutocomplete from '@angular/material/autocomplete';
  40 +import * as AngularMaterialDialog from '@angular/material/dialog';
  41 +import * as NgrxStore from '@ngrx/store';
  42 +import * as RxJs from 'rxjs';
  43 +import * as RxJsOperators from 'rxjs/operators';
  44 +import * as TranslateCore from '@ngx-translate/core';
  45 +import * as TbCore from '@core/public-api';
  46 +import * as TbShared from '@shared/public-api';
  47 +import * as TbHomeComponents from '@home/components/public-api';
  48 +import * as _moment from 'moment';
  49 +import { MODULES_MAP } from '@shared/public-api';
  50 +
  51 +declare const SystemJS;
  52 +
  53 +const modulesMap: {[key: string]: any} = {
  54 + '@angular/core': SystemJS.newModule(AngularCore),
  55 + '@angular/common': SystemJS.newModule(AngularCommon),
  56 + '@angular/forms': SystemJS.newModule(AngularForms),
  57 + '@angular/router': SystemJS.newModule(AngularRouter),
  58 + '@angular/cdk/keycodes': SystemJS.newModule(AngularCdkKeycodes),
  59 + '@angular/cdk/coercion': SystemJS.newModule(AngularCdkCoercion),
  60 + '@angular/material/chips': SystemJS.newModule(AngularMaterialChips),
  61 + '@angular/material/autocomplete': SystemJS.newModule(AngularMaterialAutocomplete),
  62 + '@angular/material/dialog': SystemJS.newModule(AngularMaterialDialog),
  63 + '@ngrx/store': SystemJS.newModule(NgrxStore),
  64 + rxjs: SystemJS.newModule(RxJs),
  65 + 'rxjs/operators': SystemJS.newModule(RxJsOperators),
  66 + '@ngx-translate/core': SystemJS.newModule(TranslateCore),
  67 + '@core/public-api': SystemJS.newModule(TbCore),
  68 + '@shared/public-api': SystemJS.newModule(TbShared),
  69 + '@home/components/public-api': SystemJS.newModule(TbHomeComponents),
  70 + moment: SystemJS.newModule(_moment)
  71 +};
32 72
33 @NgModule({ 73 @NgModule({
34 exports: [ 74 exports: [
@@ -45,6 +85,12 @@ import { DashboardModule } from '@modules/home/pages/dashboard/dashboard.module' @@ -45,6 +85,12 @@ import { DashboardModule } from '@modules/home/pages/dashboard/dashboard.module'
45 DashboardModule, 85 DashboardModule,
46 AuditLogModule, 86 AuditLogModule,
47 UserModule 87 UserModule
  88 + ],
  89 + providers: [
  90 + {
  91 + provide: MODULES_MAP,
  92 + useValue: modulesMap
  93 + }
48 ] 94 ]
49 }) 95 })
50 export class HomePagesModule { } 96 export class HomePagesModule { }
@@ -14,9 +14,7 @@ @@ -14,9 +14,7 @@
14 /// limitations under the License. 14 /// limitations under the License.
15 /// 15 ///
16 16
17 -import * as AngularCore from '@angular/core';  
18 -import { Injectable, NgModule } from '@angular/core';  
19 -import * as AngularRouter from '@angular/router'; 17 +import { Inject, Injectable, NgModule, Optional } from '@angular/core';
20 import { 18 import {
21 ActivatedRouteSnapshot, 19 ActivatedRouteSnapshot,
22 CanActivate, 20 CanActivate,
@@ -31,52 +29,15 @@ import { @@ -31,52 +29,15 @@ import {
31 import { EntitiesTableComponent } from '../../components/entity/entities-table.component'; 29 import { EntitiesTableComponent } from '../../components/entity/entities-table.component';
32 import { Authority } from '@shared/models/authority.enum'; 30 import { Authority } from '@shared/models/authority.enum';
33 import { RuleChainsTableConfigResolver } from '@modules/home/pages/rulechain/rulechains-table-config.resolver'; 31 import { RuleChainsTableConfigResolver } from '@modules/home/pages/rulechain/rulechains-table-config.resolver';
34 -import * as RxJs from 'rxjs';  
35 import { Observable } from 'rxjs'; 32 import { Observable } from 'rxjs';
36 -import * as RxJsOperators from 'rxjs/operators';  
37 import { BreadCrumbConfig, BreadCrumbLabelFunction } from '@shared/components/breadcrumb'; 33 import { BreadCrumbConfig, BreadCrumbLabelFunction } from '@shared/components/breadcrumb';
38 import { ResolvedRuleChainMetaData, RuleChain } from '@shared/models/rule-chain.models'; 34 import { ResolvedRuleChainMetaData, RuleChain } from '@shared/models/rule-chain.models';
39 import { RuleChainService } from '@core/http/rule-chain.service'; 35 import { RuleChainService } from '@core/http/rule-chain.service';
40 import { RuleChainPageComponent } from '@home/pages/rulechain/rulechain-page.component'; 36 import { RuleChainPageComponent } from '@home/pages/rulechain/rulechain-page.component';
41 import { RuleNodeComponentDescriptor } from '@shared/models/rule-node.models'; 37 import { RuleNodeComponentDescriptor } from '@shared/models/rule-node.models';
42 import { ConfirmOnExitGuard } from '@core/guards/confirm-on-exit.guard'; 38 import { ConfirmOnExitGuard } from '@core/guards/confirm-on-exit.guard';
43 -  
44 -import * as AngularCommon from '@angular/common';  
45 -import * as AngularForms from '@angular/forms';  
46 -import * as AngularCdkCoercion from '@angular/cdk/coercion';  
47 -import * as AngularCdkKeycodes from '@angular/cdk/keycodes';  
48 -import * as AngularMaterialChips from '@angular/material/chips';  
49 -import * as AngularMaterialAutocomplete from '@angular/material/autocomplete';  
50 -import * as AngularMaterialDialog from '@angular/material/dialog';  
51 -import * as NgrxStore from '@ngrx/store';  
52 -import * as TranslateCore from '@ngx-translate/core';  
53 -import * as TbCore from '@core/public-api';  
54 import { ItemBufferService } from '@core/public-api'; 39 import { ItemBufferService } from '@core/public-api';
55 -import * as TbShared from '@shared/public-api';  
56 -import * as TbHomeComponents from '@home/components/public-api';  
57 -import * as _moment from 'moment';  
58 -  
59 -declare const SystemJS;  
60 -  
61 -const ruleNodeConfigResourcesModulesMap = {  
62 - '@angular/core': SystemJS.newModule(AngularCore),  
63 - '@angular/common': SystemJS.newModule(AngularCommon),  
64 - '@angular/forms': SystemJS.newModule(AngularForms),  
65 - '@angular/router': SystemJS.newModule(AngularRouter),  
66 - '@angular/cdk/keycodes': SystemJS.newModule(AngularCdkKeycodes),  
67 - '@angular/cdk/coercion': SystemJS.newModule(AngularCdkCoercion),  
68 - '@angular/material/chips': SystemJS.newModule(AngularMaterialChips),  
69 - '@angular/material/autocomplete': SystemJS.newModule(AngularMaterialAutocomplete),  
70 - '@angular/material/dialog': SystemJS.newModule(AngularMaterialDialog),  
71 - '@ngrx/store': SystemJS.newModule(NgrxStore),  
72 - rxjs: SystemJS.newModule(RxJs),  
73 - 'rxjs/operators': SystemJS.newModule(RxJsOperators),  
74 - '@ngx-translate/core': SystemJS.newModule(TranslateCore),  
75 - '@core/public-api': SystemJS.newModule(TbCore),  
76 - '@shared/public-api': SystemJS.newModule(TbShared),  
77 - '@home/components/public-api': SystemJS.newModule(TbHomeComponents),  
78 - moment: SystemJS.newModule(_moment)  
79 -}; 40 +import { MODULES_MAP } from '@shared/public-api';
80 41
81 @Injectable() 42 @Injectable()
82 export class RuleChainResolver implements Resolve<RuleChain> { 43 export class RuleChainResolver implements Resolve<RuleChain> {
@@ -105,11 +66,12 @@ export class ResolvedRuleChainMetaDataResolver implements Resolve<ResolvedRuleCh @@ -105,11 +66,12 @@ export class ResolvedRuleChainMetaDataResolver implements Resolve<ResolvedRuleCh
105 @Injectable() 66 @Injectable()
106 export class RuleNodeComponentsResolver implements Resolve<Array<RuleNodeComponentDescriptor>> { 67 export class RuleNodeComponentsResolver implements Resolve<Array<RuleNodeComponentDescriptor>> {
107 68
108 - constructor(private ruleChainService: RuleChainService) { 69 + constructor(private ruleChainService: RuleChainService,
  70 + @Optional() @Inject(MODULES_MAP) private modulesMap: {[key: string]: any}) {
109 } 71 }
110 72
111 resolve(route: ActivatedRouteSnapshot): Observable<Array<RuleNodeComponentDescriptor>> { 73 resolve(route: ActivatedRouteSnapshot): Observable<Array<RuleNodeComponentDescriptor>> {
112 - return this.ruleChainService.getRuleNodeComponents(ruleNodeConfigResourcesModulesMap); 74 + return this.ruleChainService.getRuleNodeComponents(this.modulesMap);
113 } 75 }
114 } 76 }
115 77
@@ -14,6 +14,8 @@ @@ -14,6 +14,8 @@
14 /// limitations under the License. 14 /// limitations under the License.
15 /// 15 ///
16 16
  17 +import { InjectionToken } from '@angular/core';
  18 +
17 export const Constants = { 19 export const Constants = {
18 serverErrorCode: { 20 serverErrorCode: {
19 general: 2, 21 general: 2,
@@ -214,3 +216,5 @@ export const contentTypesMap = new Map<ContentType, ContentTypeData>( @@ -214,3 +216,5 @@ export const contentTypesMap = new Map<ContentType, ContentTypeData>(
214 ); 216 );
215 217
216 export const customTranslationsPrefix = 'custom.'; 218 export const customTranslationsPrefix = 'custom.';
  219 +
  220 +export const MODULES_MAP = new InjectionToken<{[key: string]: any}>('ModulesMap');