@worktile/planet 12.1.0 → 12.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.all-contributorsrc +84 -0
- package/.circleci/config.yml +17 -0
- package/.coveralls.yml +1 -0
- package/.docgeni/public/assets/favicon.ico +0 -0
- package/.docgeni/public/index.html +13 -0
- package/.docgenirc.js +35 -0
- package/.dockerignore +1 -0
- package/.editorconfig +22 -0
- package/.github/FUNDING.yml +12 -0
- package/.github/ISSUE_TEMPLATE/bug_report.md +38 -0
- package/.github/ISSUE_TEMPLATE/feature_request.md +20 -0
- package/.prettierignore +7 -0
- package/.prettierrc +28 -0
- package/.travis.yml +26 -0
- package/.wpmrc.js +11 -0
- package/CHANGELOG.md +391 -0
- package/CODE_OF_CONDUCT.md +76 -0
- package/Dockerfile +11 -0
- package/LICENSE +21 -0
- package/README.md +348 -0
- package/README.zh-CN.md +307 -0
- package/SECURITY.md +21 -0
- package/angular.json +373 -0
- package/commitlint.config.js +6 -0
- package/docs/api/defineApplication.md +46 -0
- package/docs/api/globalEventDispatcher.md +51 -0
- package/docs/api/index.md +5 -0
- package/docs/api/planet.md +117 -0
- package/docs/guides/getting-started.md +174 -0
- package/docs/guides/index.md +5 -0
- package/docs/guides/intro.md +216 -0
- package/examples/app1/browserslist +11 -0
- package/examples/app1/extra-webpack.config.js +33 -0
- package/examples/app1/karma.conf.js +31 -0
- package/examples/app1/postcss.config.js +1 -0
- package/examples/app1/src/app/app.module.ts +44 -0
- package/examples/app1/src/app/app.routing.ts +49 -0
- package/examples/app1/src/app/counter.service.ts +16 -0
- package/examples/app1/src/app/dashboard/dashboard.component.html +51 -0
- package/examples/app1/src/app/dashboard/dashboard.component.ts +70 -0
- package/examples/app1/src/app/detail/detail.component.html +8 -0
- package/examples/app1/src/app/detail/detail.component.ts +18 -0
- package/examples/app1/src/app/overlay.ts +26 -0
- package/examples/app1/src/app/projects/dialog/projects-dialog.component.html +10 -0
- package/examples/app1/src/app/projects/dialog/projects-dialog.component.ts +41 -0
- package/examples/app1/src/app/projects/projects.component.ts +33 -0
- package/examples/app1/src/app/root/root.component.css +3 -0
- package/examples/app1/src/app/root/root.component.html +16 -0
- package/examples/app1/src/app/root/root.component.ts +35 -0
- package/examples/app1/src/app/services/initialized-data.resolver.ts +15 -0
- package/examples/app1/src/app/shared.module.ts +57 -0
- package/examples/app1/src/app/user/detail/user-detail.component.html +5 -0
- package/examples/app1/src/app/user/detail/user-detail.component.ts +20 -0
- package/examples/app1/src/app/user/user-list.component.html +7 -0
- package/examples/app1/src/app/user/user-list.component.ts +20 -0
- package/examples/app1/src/app/user/user.module.ts +31 -0
- package/examples/app1/src/assets/.gitkeep +0 -0
- package/examples/app1/src/assets/github.png +0 -0
- package/examples/app1/src/assets/main.css +3 -0
- package/examples/app1/src/environments/environment.prod.ts +3 -0
- package/examples/app1/src/environments/environment.ts +16 -0
- package/examples/app1/src/favicon.ico +0 -0
- package/examples/app1/src/index.html +14 -0
- package/examples/app1/src/main.ts +35 -0
- package/examples/app1/src/polyfills.ts +84 -0
- package/examples/app1/src/styles.scss +35 -0
- package/examples/app1/src/test.ts +14 -0
- package/examples/app1/temp.js +221 -0
- package/examples/app1/tsconfig.app.json +10 -0
- package/examples/app1/tsconfig.spec.json +18 -0
- package/examples/app1/tslint.json +17 -0
- package/examples/app1/webpack.config.js +127 -0
- package/examples/app2/browserslist +11 -0
- package/examples/app2/extra-webpack.config.js +32 -0
- package/examples/app2/karma.conf.js +31 -0
- package/examples/app2/src/app/app.module.ts +90 -0
- package/examples/app2/src/app/dashboard/dashboard.component.html +21 -0
- package/examples/app2/src/app/dashboard/dashboard.component.ts +27 -0
- package/examples/app2/src/app/overlay.ts +26 -0
- package/examples/app2/src/app/projects/detail/detail.component.html +16 -0
- package/examples/app2/src/app/projects/detail/detail.component.ts +21 -0
- package/examples/app2/src/app/projects/project-list.component.html +29 -0
- package/examples/app2/src/app/projects/project-list.component.ts +58 -0
- package/examples/app2/src/app/projects/project.resolver.ts +15 -0
- package/examples/app2/src/app/projects/projects.service.ts +28 -0
- package/examples/app2/src/app/projects/tasks/tasks.component.html +10 -0
- package/examples/app2/src/app/projects/tasks/tasks.component.ts +16 -0
- package/examples/app2/src/app/projects/view/view.component.html +1 -0
- package/examples/app2/src/app/projects/view/view.component.ts +20 -0
- package/examples/app2/src/app/root/root.component.html +14 -0
- package/examples/app2/src/app/root/root.component.scss +12 -0
- package/examples/app2/src/app/root/root.component.ts +28 -0
- package/examples/app2/src/app/shared.module.ts +59 -0
- package/examples/app2/src/assets/.gitkeep +0 -0
- package/examples/app2/src/environments/environment.prod.ts +3 -0
- package/examples/app2/src/environments/environment.ts +16 -0
- package/examples/app2/src/favicon.ico +0 -0
- package/examples/app2/src/index.html +14 -0
- package/examples/app2/src/main.ts +36 -0
- package/examples/app2/src/polyfills.ts +84 -0
- package/examples/app2/src/styles.scss +28 -0
- package/examples/app2/src/test.ts +14 -0
- package/examples/app2/tsconfig.app.json +10 -0
- package/examples/app2/tsconfig.spec.json +18 -0
- package/examples/app2/tslint.json +7 -0
- package/examples/app2/webpack.config.js +92 -0
- package/examples/common/app-root-context.ts +10 -0
- package/examples/common/cache.ts +82 -0
- package/examples/common/index.ts +13 -0
- package/examples/common/module.ts +10 -0
- package/examples/common/overlay-container.service.ts +28 -0
- package/examples/common/section-card/section-card.component.html +5 -0
- package/examples/common/section-card/section-card.component.scss +15 -0
- package/examples/common/section-card/section-card.component.ts +11 -0
- package/examples/common/utils.ts +0 -0
- package/examples/portal/src/app/a-detail/a-detail.component.html +8 -0
- package/examples/portal/src/app/a-detail/a-detail.component.ts +18 -0
- package/examples/portal/src/app/about/about.component.html +27 -0
- package/examples/portal/src/app/about/about.component.scss +0 -0
- package/examples/portal/src/app/about/about.component.spec.ts +26 -0
- package/examples/portal/src/app/about/about.component.ts +26 -0
- package/examples/portal/src/app/app-routing.module.ts +57 -0
- package/examples/portal/src/app/app.component.html +73 -0
- package/examples/portal/src/app/app.component.scss +58 -0
- package/examples/portal/src/app/app.component.spec.ts +33 -0
- package/examples/portal/src/app/app.component.ts +111 -0
- package/examples/portal/src/app/app.module.ts +64 -0
- package/examples/portal/src/app/custom-settings.service.ts +44 -0
- package/examples/portal/src/app/overlay.ts +26 -0
- package/examples/portal/src/app/settings/settings.component.html +31 -0
- package/examples/portal/src/app/settings/settings.component.scss +3 -0
- package/examples/portal/src/app/settings/settings.component.ts +43 -0
- package/examples/portal/src/assets/.gitkeep +0 -0
- package/examples/portal/src/assets/apps.json +29 -0
- package/examples/portal/src/assets/icons/sprite.defs.svg +1 -0
- package/examples/portal/src/assets/images/logo.svg +16 -0
- package/examples/portal/src/assets/ngx-planet-micro-front-end.gif +0 -0
- package/examples/portal/src/browserslist +11 -0
- package/examples/portal/src/environments/environment.prod.ts +3 -0
- package/examples/portal/src/environments/environment.ts +16 -0
- package/examples/portal/src/extra-webpack.config.js +32 -0
- package/examples/portal/src/favicon.ico +0 -0
- package/examples/portal/src/index.html +14 -0
- package/examples/portal/src/karma.conf.js +31 -0
- package/examples/portal/src/main.ts +18 -0
- package/examples/portal/src/polyfills.ts +84 -0
- package/examples/portal/src/reboot.scss +14 -0
- package/examples/portal/src/styles.scss +14 -0
- package/examples/portal/src/test.ts +14 -0
- package/examples/portal/src/tsconfig.app.json +10 -0
- package/examples/portal/src/tsconfig.spec.json +9 -0
- package/examples/portal/src/tslint.json +7 -0
- package/extra-webpack.config.js +5 -0
- package/nginx.conf +17 -0
- package/package.json +121 -16
- package/packages/planet/karma.conf.js +37 -0
- package/packages/planet/ng-package.json +7 -0
- package/packages/planet/package.json +10 -0
- package/packages/planet/src/application/planet-application-loader.spec.ts +1102 -0
- package/packages/planet/src/application/planet-application-loader.ts +549 -0
- package/packages/planet/src/application/planet-application-ref.spec.ts +233 -0
- package/packages/planet/src/application/planet-application-ref.ts +131 -0
- package/packages/planet/src/application/planet-application.service.spec.ts +145 -0
- package/packages/planet/src/application/planet-application.service.ts +88 -0
- package/packages/planet/src/application/portal-application.spec.ts +53 -0
- package/packages/planet/src/application/portal-application.ts +28 -0
- package/packages/planet/src/assets-loader.spec.ts +689 -0
- package/packages/planet/src/assets-loader.ts +247 -0
- package/packages/planet/src/component/planet-component-loader.spec.ts +187 -0
- package/packages/planet/src/component/planet-component-loader.ts +173 -0
- package/packages/planet/src/component/planet-component-ref.ts +8 -0
- package/{component/plant-component.config.d.ts → packages/planet/src/component/plant-component.config.ts} +4 -4
- package/packages/planet/src/debug.spec.ts +58 -0
- package/packages/planet/src/debug.ts +66 -0
- package/packages/planet/src/empty/empty.component.spec.ts +34 -0
- package/packages/planet/src/empty/empty.component.ts +7 -0
- package/packages/planet/src/global-event-dispatcher.spec.ts +81 -0
- package/packages/planet/src/global-event-dispatcher.ts +82 -0
- package/packages/planet/src/global-planet.spec.ts +39 -0
- package/packages/planet/src/global-planet.ts +73 -0
- package/packages/planet/src/helpers.spec.ts +242 -0
- package/packages/planet/src/helpers.ts +125 -0
- package/packages/planet/src/module.spec.ts +79 -0
- package/packages/planet/src/module.ts +25 -0
- package/{planet.class.d.ts → packages/planet/src/planet.class.ts} +26 -5
- package/packages/planet/src/planet.spec.ts +226 -0
- package/packages/planet/src/planet.ts +113 -0
- package/{public-api.d.ts → packages/planet/src/public-api.ts} +4 -1
- package/packages/planet/src/sandbox/constants.ts +6 -0
- package/packages/planet/src/sandbox/exec.ts +22 -0
- package/packages/planet/src/sandbox/index.ts +24 -0
- package/packages/planet/src/sandbox/proxy/patches/document.ts +13 -0
- package/packages/planet/src/sandbox/proxy/patches/eventListener.ts +49 -0
- package/packages/planet/src/sandbox/proxy/patches/index.ts +13 -0
- package/packages/planet/src/sandbox/proxy/patches/storage.ts +53 -0
- package/packages/planet/src/sandbox/proxy/patches/timer.ts +50 -0
- package/packages/planet/src/sandbox/proxy/proxies/common.ts +137 -0
- package/packages/planet/src/sandbox/proxy/proxies/document.ts +140 -0
- package/packages/planet/src/sandbox/proxy/proxies/window.ts +176 -0
- package/packages/planet/src/sandbox/proxy/proxy-sandbox.ts +59 -0
- package/{sandbox/proxy/types.d.ts → packages/planet/src/sandbox/proxy/types.ts} +8 -2
- package/packages/planet/src/sandbox/sandbox.ts +20 -0
- package/packages/planet/src/sandbox/snapshot/snapshot-sandbox.ts +12 -0
- package/packages/planet/src/sandbox/types.ts +1 -0
- package/packages/planet/src/test.ts +16 -0
- package/packages/planet/src/testing/app1.module.ts +34 -0
- package/packages/planet/src/testing/app2.module.ts +24 -0
- package/packages/planet/src/testing/applications.ts +58 -0
- package/packages/planet/src/testing/index.ts +2 -0
- package/packages/planet/src/testing/utils.ts +31 -0
- package/packages/planet/tsconfig.lib.json +27 -0
- package/packages/planet/tsconfig.lib.prod.json +9 -0
- package/packages/planet/tsconfig.spec.json +17 -0
- package/packages/planet/tslint.json +7 -0
- package/postcss.config.js +3 -0
- package/proxy.conf.js +15 -0
- package/tsconfig.json +23 -0
- package/tslint.json +80 -0
- package/application/planet-application-loader.d.ts +0 -70
- package/application/planet-application-loader.d.ts.map +0 -1
- package/application/planet-application-loader.ngfactory.d.ts.map +0 -1
- package/application/planet-application-ref.d.ts +0 -36
- package/application/planet-application-ref.d.ts.map +0 -1
- package/application/planet-application.service.d.ts +0 -19
- package/application/planet-application.service.d.ts.map +0 -1
- package/application/planet-application.service.ngfactory.d.ts.map +0 -1
- package/application/portal-application.d.ts +0 -15
- package/application/portal-application.d.ts.map +0 -1
- package/assets-loader.d.ts +0 -33
- package/assets-loader.d.ts.map +0 -1
- package/assets-loader.ngfactory.d.ts.map +0 -1
- package/bundles/worktile-planet.umd.js +0 -2552
- package/bundles/worktile-planet.umd.js.map +0 -1
- package/component/planet-component-loader.d.ts +0 -28
- package/component/planet-component-loader.d.ts.map +0 -1
- package/component/planet-component-loader.ngfactory.d.ts.map +0 -1
- package/component/planet-component-ref.d.ts +0 -8
- package/component/planet-component-ref.d.ts.map +0 -1
- package/component/plant-component.config.d.ts.map +0 -1
- package/debug.d.ts +0 -22
- package/debug.d.ts.map +0 -1
- package/empty/empty.component.d.ts +0 -3
- package/empty/empty.component.d.ts.map +0 -1
- package/empty/empty.component.ngfactory.d.ts.map +0 -1
- package/esm2015/application/planet-application-loader.js +0 -452
- package/esm2015/application/planet-application-ref.js +0 -94
- package/esm2015/application/planet-application.service.js +0 -87
- package/esm2015/application/portal-application.js +0 -16
- package/esm2015/assets-loader.js +0 -217
- package/esm2015/component/planet-component-loader.js +0 -155
- package/esm2015/component/planet-component-ref.js +0 -3
- package/esm2015/component/plant-component.config.js +0 -7
- package/esm2015/debug.js +0 -33
- package/esm2015/empty/empty.component.js +0 -10
- package/esm2015/global-event-dispatcher.js +0 -71
- package/esm2015/global-planet.js +0 -51
- package/esm2015/helpers.js +0 -119
- package/esm2015/module.js +0 -27
- package/esm2015/planet.class.js +0 -9
- package/esm2015/planet.js +0 -90
- package/esm2015/public-api.js +0 -18
- package/esm2015/sandbox/constants.js +0 -7
- package/esm2015/sandbox/exec.js +0 -15
- package/esm2015/sandbox/index.js +0 -20
- package/esm2015/sandbox/proxy/patches/document.js +0 -12
- package/esm2015/sandbox/proxy/patches/eventListener.js +0 -41
- package/esm2015/sandbox/proxy/patches/index.js +0 -11
- package/esm2015/sandbox/proxy/patches/storage.js +0 -40
- package/esm2015/sandbox/proxy/patches/timer.js +0 -43
- package/esm2015/sandbox/proxy/proxies/common.js +0 -132
- package/esm2015/sandbox/proxy/proxies/document.js +0 -126
- package/esm2015/sandbox/proxy/proxies/window.js +0 -155
- package/esm2015/sandbox/proxy/proxy-sandbox.js +0 -49
- package/esm2015/sandbox/proxy/types.js +0 -2
- package/esm2015/sandbox/sandbox.js +0 -7
- package/esm2015/sandbox/snapshot/snapshot-sandbox.js +0 -12
- package/esm2015/sandbox/types.js +0 -2
- package/esm2015/worktile-planet.js +0 -6
- package/fesm2015/worktile-planet.js +0 -2036
- package/fesm2015/worktile-planet.js.map +0 -1
- package/global-event-dispatcher.d.ts +0 -20
- package/global-event-dispatcher.d.ts.map +0 -1
- package/global-event-dispatcher.ngfactory.d.ts.map +0 -1
- package/global-planet.d.ts +0 -23
- package/global-planet.d.ts.map +0 -1
- package/helpers.d.ts +0 -39
- package/helpers.d.ts.map +0 -1
- package/module.d.ts +0 -6
- package/module.d.ts.map +0 -1
- package/module.ngfactory.d.ts.map +0 -1
- package/planet.class.d.ts.map +0 -1
- package/planet.d.ts +0 -25
- package/planet.d.ts.map +0 -1
- package/planet.ngfactory.d.ts.map +0 -1
- package/public-api.d.ts.map +0 -1
- package/sandbox/constants.d.ts +0 -7
- package/sandbox/constants.d.ts.map +0 -1
- package/sandbox/exec.d.ts +0 -3
- package/sandbox/exec.d.ts.map +0 -1
- package/sandbox/index.d.ts +0 -7
- package/sandbox/index.d.ts.map +0 -1
- package/sandbox/proxy/patches/document.d.ts +0 -3
- package/sandbox/proxy/patches/document.d.ts.map +0 -1
- package/sandbox/proxy/patches/eventListener.d.ts +0 -3
- package/sandbox/proxy/patches/eventListener.d.ts.map +0 -1
- package/sandbox/proxy/patches/index.d.ts +0 -3
- package/sandbox/proxy/patches/index.d.ts.map +0 -1
- package/sandbox/proxy/patches/storage.d.ts +0 -15
- package/sandbox/proxy/patches/storage.d.ts.map +0 -1
- package/sandbox/proxy/patches/timer.d.ts +0 -3
- package/sandbox/proxy/patches/timer.d.ts.map +0 -1
- package/sandbox/proxy/proxies/common.d.ts +0 -13
- package/sandbox/proxy/proxies/common.d.ts.map +0 -1
- package/sandbox/proxy/proxies/document.d.ts +0 -14
- package/sandbox/proxy/proxies/document.d.ts.map +0 -1
- package/sandbox/proxy/proxies/window.d.ts +0 -13
- package/sandbox/proxy/proxies/window.d.ts.map +0 -1
- package/sandbox/proxy/proxy-sandbox.d.ts +0 -16
- package/sandbox/proxy/proxy-sandbox.d.ts.map +0 -1
- package/sandbox/proxy/types.d.ts.map +0 -1
- package/sandbox/sandbox.d.ts +0 -12
- package/sandbox/sandbox.d.ts.map +0 -1
- package/sandbox/snapshot/snapshot-sandbox.d.ts +0 -9
- package/sandbox/snapshot/snapshot-sandbox.d.ts.map +0 -1
- package/sandbox/types.d.ts +0 -2
- package/sandbox/types.d.ts.map +0 -1
- package/worktile-planet.d.ts +0 -6
- package/worktile-planet.d.ts.map +0 -1
- package/worktile-planet.metadata.json +0 -1
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
import { PlanetPortalApplication } from './portal-application';
|
|
2
|
+
import { NgModule, Compiler, Injector, Component, NgZone, Type } from '@angular/core';
|
|
3
|
+
import { Router } from '@angular/router';
|
|
4
|
+
import { TestBed, inject, tick, fakeAsync, flush } from '@angular/core/testing';
|
|
5
|
+
import { defineApplication, getPlanetApplicationRef, clearGlobalPlanet } from '../global-planet';
|
|
6
|
+
import { Subject } from 'rxjs';
|
|
7
|
+
import { PlanetApplicationRef } from './planet-application-ref';
|
|
8
|
+
import { RouterTestingModule } from '@angular/router/testing';
|
|
9
|
+
|
|
10
|
+
@Component({
|
|
11
|
+
selector: 'app-root',
|
|
12
|
+
template: `
|
|
13
|
+
<router-outlet></router-outlet>
|
|
14
|
+
`
|
|
15
|
+
})
|
|
16
|
+
class EmptyComponent {}
|
|
17
|
+
@NgModule({
|
|
18
|
+
declarations: [EmptyComponent],
|
|
19
|
+
imports: [
|
|
20
|
+
RouterTestingModule.withRoutes([
|
|
21
|
+
{
|
|
22
|
+
path: 'app1',
|
|
23
|
+
component: EmptyComponent
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
path: 'app1/test',
|
|
27
|
+
component: EmptyComponent
|
|
28
|
+
}
|
|
29
|
+
])
|
|
30
|
+
]
|
|
31
|
+
})
|
|
32
|
+
class AppModule {}
|
|
33
|
+
|
|
34
|
+
describe('PlanetApplicationRef', () => {
|
|
35
|
+
afterEach(() => {
|
|
36
|
+
clearGlobalPlanet();
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
describe('getPlanetApplicationRef', () => {
|
|
40
|
+
it('should get planet application ref success', () => {
|
|
41
|
+
defineApplication('app1', {
|
|
42
|
+
template: '<app1-root></app1-root>',
|
|
43
|
+
bootstrap: (portalApp?: PlanetPortalApplication) => {
|
|
44
|
+
return new Promise(() => {});
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
const planetAppRef = getPlanetApplicationRef('app1');
|
|
48
|
+
expect(planetAppRef).toBeTruthy();
|
|
49
|
+
expect(planetAppRef).toBe(window['planet'].apps['app1']);
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it('should not get planet appRef which has not exist', () => {
|
|
53
|
+
defineApplication('app1', {
|
|
54
|
+
template: '<app1-root></app1-root>',
|
|
55
|
+
bootstrap: (portalApp?: PlanetPortalApplication) => {
|
|
56
|
+
return new Promise(() => {});
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
const planetAppRef = getPlanetApplicationRef('app2');
|
|
60
|
+
expect(planetAppRef).toBeFalsy();
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
describe('ApplicationRef', () => {
|
|
65
|
+
let compiler: Compiler;
|
|
66
|
+
let injector: Injector;
|
|
67
|
+
|
|
68
|
+
function bootstrapApp1<T>(moduleType?: Type<T>) {
|
|
69
|
+
const portalApplication = new PlanetPortalApplication();
|
|
70
|
+
const ngModuleFactory = compiler.compileModuleSync(moduleType ? moduleType : AppModule);
|
|
71
|
+
const ngModuleRef = ngModuleFactory.create(injector);
|
|
72
|
+
const router = ngModuleRef.injector.get(Router);
|
|
73
|
+
defineApplication('app1', {
|
|
74
|
+
template: '<app1-root></app1-root>',
|
|
75
|
+
bootstrap: (portalApp?: PlanetPortalApplication) => {
|
|
76
|
+
return new Promise(resolve => {
|
|
77
|
+
expect(portalApp).toBe(portalApplication);
|
|
78
|
+
resolve(ngModuleRef);
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
const appRef = getPlanetApplicationRef('app1');
|
|
84
|
+
appRef.bootstrap(portalApplication).subscribe();
|
|
85
|
+
|
|
86
|
+
flush();
|
|
87
|
+
return {
|
|
88
|
+
router,
|
|
89
|
+
appRef
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
beforeEach(() => {
|
|
94
|
+
TestBed.configureTestingModule({});
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
beforeEach(inject([Compiler, Injector], (_compiler: Compiler, _injector: Injector) => {
|
|
98
|
+
compiler = _compiler;
|
|
99
|
+
injector = _injector;
|
|
100
|
+
}));
|
|
101
|
+
|
|
102
|
+
it(`should bootstrap application ref`, fakeAsync(() => {
|
|
103
|
+
const portalApplication = new PlanetPortalApplication();
|
|
104
|
+
const ngModuleFactory = compiler.compileModuleSync(AppModule);
|
|
105
|
+
const ngModuleRef = ngModuleFactory.create(injector);
|
|
106
|
+
defineApplication('app1', {
|
|
107
|
+
template: '<app1-root></app1-root>',
|
|
108
|
+
bootstrap: (portalApp?: PlanetPortalApplication) => {
|
|
109
|
+
return new Promise(resolve => {
|
|
110
|
+
expect(portalApp).toBe(portalApplication);
|
|
111
|
+
resolve(ngModuleRef);
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
const appRef = getPlanetApplicationRef('app1');
|
|
116
|
+
expect(appRef).toBeTruthy();
|
|
117
|
+
const bootstrapSpy = jasmine.createSpy('bootstrap spy');
|
|
118
|
+
appRef.bootstrap(portalApplication).subscribe(bootstrapSpy);
|
|
119
|
+
expect(appRef.bootstrapped).toEqual(false);
|
|
120
|
+
flush();
|
|
121
|
+
expect(appRef.bootstrapped).toEqual(true);
|
|
122
|
+
expect(appRef.appModuleRef).toEqual(ngModuleRef);
|
|
123
|
+
expect(appRef.appModuleRef.instance.appName).toEqual('app1');
|
|
124
|
+
expect(bootstrapSpy.calls.count()).toEqual(1);
|
|
125
|
+
expect(bootstrapSpy).toHaveBeenCalled();
|
|
126
|
+
expect(bootstrapSpy).toHaveBeenCalledWith(appRef);
|
|
127
|
+
}));
|
|
128
|
+
|
|
129
|
+
it(`should destroy application ref success`, fakeAsync(() => {
|
|
130
|
+
const portalApplication = new PlanetPortalApplication();
|
|
131
|
+
const ngModuleFactory = compiler.compileModuleSync(AppModule);
|
|
132
|
+
const ngModuleRef = ngModuleFactory.create(injector);
|
|
133
|
+
const router = ngModuleRef.injector.get(Router);
|
|
134
|
+
defineApplication('app1', {
|
|
135
|
+
template: '<app1-root></app1-root>',
|
|
136
|
+
bootstrap: (portalApp?: PlanetPortalApplication) => {
|
|
137
|
+
return new Promise(resolve => {
|
|
138
|
+
expect(portalApp).toBe(portalApplication);
|
|
139
|
+
resolve(ngModuleRef);
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
const appRef = getPlanetApplicationRef('app1');
|
|
145
|
+
appRef.bootstrap(portalApplication).subscribe();
|
|
146
|
+
|
|
147
|
+
flush();
|
|
148
|
+
expect(appRef.bootstrapped).toEqual(true);
|
|
149
|
+
expect(appRef.appModuleRef).toEqual(ngModuleRef);
|
|
150
|
+
|
|
151
|
+
appRef.destroy();
|
|
152
|
+
expect(appRef.bootstrapped).toEqual(false);
|
|
153
|
+
expect(appRef.appModuleRef).toEqual(undefined);
|
|
154
|
+
}));
|
|
155
|
+
|
|
156
|
+
it(`should get router success`, fakeAsync(() => {
|
|
157
|
+
const { appRef, router } = bootstrapApp1();
|
|
158
|
+
expect(appRef.getRouter()).toBeTruthy();
|
|
159
|
+
expect(appRef.getRouter()).toEqual(router);
|
|
160
|
+
}));
|
|
161
|
+
|
|
162
|
+
it(`should navigate to url success and get correct current router state url `, fakeAsync(() => {
|
|
163
|
+
const routerSpy = {
|
|
164
|
+
navigateByUrl: jasmine.createSpy('navigateByUrl syp'),
|
|
165
|
+
events: new Subject(),
|
|
166
|
+
routerState: {
|
|
167
|
+
snapshot: {
|
|
168
|
+
url: 'app1/hello'
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
};
|
|
172
|
+
@NgModule({
|
|
173
|
+
declarations: [],
|
|
174
|
+
imports: [],
|
|
175
|
+
providers: [
|
|
176
|
+
{
|
|
177
|
+
provide: Router,
|
|
178
|
+
useValue: routerSpy
|
|
179
|
+
}
|
|
180
|
+
]
|
|
181
|
+
})
|
|
182
|
+
class AppModuleWithSpyRouter {}
|
|
183
|
+
const { appRef } = bootstrapApp1(AppModuleWithSpyRouter);
|
|
184
|
+
expect(appRef.getCurrentRouterStateUrl()).toEqual('app1/hello');
|
|
185
|
+
|
|
186
|
+
expect(routerSpy.navigateByUrl).not.toHaveBeenCalled();
|
|
187
|
+
|
|
188
|
+
const toUrl = 'app2/to-url';
|
|
189
|
+
appRef.navigateByUrl('app2/to-url');
|
|
190
|
+
|
|
191
|
+
expect(routerSpy.navigateByUrl).toHaveBeenCalled();
|
|
192
|
+
expect(routerSpy.navigateByUrl).toHaveBeenCalledWith(toUrl);
|
|
193
|
+
}));
|
|
194
|
+
|
|
195
|
+
it(`should throw error when app is not defined`, () => {
|
|
196
|
+
expect(() => {
|
|
197
|
+
const appRef = new PlanetApplicationRef('app3', {} as any);
|
|
198
|
+
appRef.bootstrap(undefined);
|
|
199
|
+
}).toThrowError(`app(app3) is not defined`);
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
it(`should sync portal route change when sub app(app1) route navigate`, fakeAsync(() => {
|
|
203
|
+
const portalApplication = new PlanetPortalApplication();
|
|
204
|
+
portalApplication.router = { navigateByUrl: () => {} } as any;
|
|
205
|
+
const navigateByUrlSpy = spyOn(portalApplication.router, 'navigateByUrl');
|
|
206
|
+
const ngModuleFactory = compiler.compileModuleSync(AppModule);
|
|
207
|
+
const ngModuleRef = ngModuleFactory.create(injector);
|
|
208
|
+
defineApplication('app1', {
|
|
209
|
+
template: '<app1-root></app1-root>',
|
|
210
|
+
bootstrap: (portalApp?: PlanetPortalApplication) => {
|
|
211
|
+
return new Promise(resolve => {
|
|
212
|
+
expect(portalApp).toBe(portalApplication);
|
|
213
|
+
resolve(ngModuleRef);
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
});
|
|
217
|
+
const appRef = getPlanetApplicationRef('app1');
|
|
218
|
+
expect(appRef).toBeTruthy();
|
|
219
|
+
appRef.bootstrap(portalApplication);
|
|
220
|
+
|
|
221
|
+
const router = ngModuleRef.injector.get(Router);
|
|
222
|
+
const ngZone = ngModuleRef.injector.get(NgZone);
|
|
223
|
+
ngZone.run(() => {
|
|
224
|
+
router.navigateByUrl('/app1');
|
|
225
|
+
});
|
|
226
|
+
expect(navigateByUrlSpy).not.toHaveBeenCalled();
|
|
227
|
+
ngZone.onStable.next();
|
|
228
|
+
tick();
|
|
229
|
+
expect(navigateByUrlSpy).toHaveBeenCalled();
|
|
230
|
+
expect(navigateByUrlSpy).toHaveBeenCalledWith('/app1');
|
|
231
|
+
}));
|
|
232
|
+
});
|
|
233
|
+
});
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import { NgModuleRef, NgZone } from '@angular/core';
|
|
2
|
+
import { Router, NavigationEnd } from '@angular/router';
|
|
3
|
+
import { take } from 'rxjs/operators';
|
|
4
|
+
import { Observable, from } from 'rxjs';
|
|
5
|
+
import { PlanetPortalApplication } from './portal-application';
|
|
6
|
+
import { PlantComponentConfig } from '../component/plant-component.config';
|
|
7
|
+
import { PlanetComponentRef } from '../component/planet-component-ref';
|
|
8
|
+
import { getTagNameByTemplate } from '../helpers';
|
|
9
|
+
import { getSandboxInstance, Sandbox } from '../sandbox/';
|
|
10
|
+
|
|
11
|
+
export interface BootstrapOptions {
|
|
12
|
+
template: string;
|
|
13
|
+
bootstrap: BootstrapAppModule;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export type BootstrapAppModule = (portalApp: PlanetPortalApplication) => Promise<NgModuleRef<any> | undefined | null>;
|
|
17
|
+
|
|
18
|
+
export type PlantComponentFactory = <TData, TComp>(
|
|
19
|
+
componentName: string,
|
|
20
|
+
config: PlantComponentConfig<TData>
|
|
21
|
+
) => PlanetComponentRef<TComp>;
|
|
22
|
+
|
|
23
|
+
export class PlanetApplicationRef {
|
|
24
|
+
public appModuleRef?: NgModuleRef<any>;
|
|
25
|
+
public template?: string;
|
|
26
|
+
private innerSelector?: string;
|
|
27
|
+
private name: string;
|
|
28
|
+
private portalApp!: PlanetPortalApplication;
|
|
29
|
+
private appModuleBootstrap?: BootstrapAppModule;
|
|
30
|
+
private componentFactory?: PlantComponentFactory;
|
|
31
|
+
|
|
32
|
+
public get selector() {
|
|
33
|
+
return this.innerSelector;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
public get bootstrapped() {
|
|
37
|
+
return !!this.appModuleRef;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
public get ngZone(): NgZone | undefined {
|
|
41
|
+
return this.appModuleRef?.injector.get(NgZone);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
public get sandbox(): Sandbox {
|
|
45
|
+
return getSandboxInstance();
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
constructor(name: string, options?: BootstrapOptions) {
|
|
49
|
+
this.name = name;
|
|
50
|
+
if (options) {
|
|
51
|
+
this.template = options.template;
|
|
52
|
+
this.innerSelector = this.template ? getTagNameByTemplate(this.template) : '';
|
|
53
|
+
this.appModuleBootstrap = options.bootstrap;
|
|
54
|
+
}
|
|
55
|
+
// This is a hack, since NgZone doesn't allow you to configure the property that identifies your zone.
|
|
56
|
+
// See https://github.com/PlaceMe-SAS/single-spa-angular-cli/issues/33,
|
|
57
|
+
NgZone.isInAngularZone = () => {
|
|
58
|
+
// @ts-ignore
|
|
59
|
+
return window.Zone.current._properties[`ngx-planet-${name}`] === true;
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// 子应用路由变化后同步修改 portal 的 Route
|
|
64
|
+
private syncPortalRouteWhenNavigationEnd() {
|
|
65
|
+
const router = this.appModuleRef?.injector.get(Router);
|
|
66
|
+
if (router) {
|
|
67
|
+
router.events.subscribe(event => {
|
|
68
|
+
if (event instanceof NavigationEnd) {
|
|
69
|
+
this.ngZone?.onStable
|
|
70
|
+
.asObservable()
|
|
71
|
+
.pipe(take(1))
|
|
72
|
+
.subscribe(() => {
|
|
73
|
+
this.portalApp.router!.navigateByUrl(event.url);
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
bootstrap(app: PlanetPortalApplication): Observable<this> {
|
|
81
|
+
if (!this.appModuleBootstrap) {
|
|
82
|
+
throw new Error(`app(${this.name}) is not defined`);
|
|
83
|
+
}
|
|
84
|
+
this.portalApp = app;
|
|
85
|
+
return from(
|
|
86
|
+
this.appModuleBootstrap(app).then(appModuleRef => {
|
|
87
|
+
this.appModuleRef = appModuleRef!;
|
|
88
|
+
this.appModuleRef.instance.appName = this.name;
|
|
89
|
+
this.syncPortalRouteWhenNavigationEnd();
|
|
90
|
+
return this;
|
|
91
|
+
})
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
getRouter() {
|
|
96
|
+
return this.appModuleRef?.injector.get(Router);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
getCurrentRouterStateUrl() {
|
|
100
|
+
return this.getRouter()?.routerState.snapshot.url;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
navigateByUrl(url: string): void {
|
|
104
|
+
const router = this.getRouter();
|
|
105
|
+
this.ngZone?.run(() => {
|
|
106
|
+
router?.navigateByUrl(url);
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
getComponentFactory() {
|
|
111
|
+
return this.componentFactory;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
registerComponentFactory(componentFactory: PlantComponentFactory) {
|
|
115
|
+
this.componentFactory = componentFactory;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
destroy(): void {
|
|
119
|
+
if (this.appModuleRef) {
|
|
120
|
+
const router = this.appModuleRef.injector.get(Router);
|
|
121
|
+
if (router) {
|
|
122
|
+
router.dispose();
|
|
123
|
+
}
|
|
124
|
+
if (this.sandbox) {
|
|
125
|
+
this.sandbox.destroy();
|
|
126
|
+
}
|
|
127
|
+
this.appModuleRef.destroy();
|
|
128
|
+
this.appModuleRef = undefined;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import { TestBed } from '@angular/core/testing';
|
|
2
|
+
import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing';
|
|
3
|
+
import { PlanetApplicationService } from './planet-application.service';
|
|
4
|
+
import { SwitchModes } from '../planet.class';
|
|
5
|
+
import { HttpClient } from '@angular/common/http';
|
|
6
|
+
import { app1, app2, app2WithPreload } from '../testing/applications';
|
|
7
|
+
import { AssetsLoader } from 'ngx-planet/assets-loader';
|
|
8
|
+
import { Planet } from 'ngx-planet/planet';
|
|
9
|
+
|
|
10
|
+
describe('PlanetApplicationService', () => {
|
|
11
|
+
let planetApplicationService: PlanetApplicationService;
|
|
12
|
+
beforeEach(() => {
|
|
13
|
+
TestBed.configureTestingModule({
|
|
14
|
+
imports: [HttpClientTestingModule],
|
|
15
|
+
providers: []
|
|
16
|
+
});
|
|
17
|
+
planetApplicationService = TestBed.inject(PlanetApplicationService);
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
it(`should throw error when repeat PlanetApplicationService injection`, () => {
|
|
21
|
+
window['planet'].applicationService = TestBed.inject(PlanetApplicationService);
|
|
22
|
+
expect(() => {
|
|
23
|
+
return new PlanetApplicationService(TestBed.inject(HttpClient), TestBed.inject(AssetsLoader));
|
|
24
|
+
}).toThrowError('PlanetApplicationService has been injected in the portal, repeated injection is not allowed');
|
|
25
|
+
window['planet'].applicationService = null;
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
describe('register', () => {
|
|
29
|
+
it('should register signal app1 success', () => {
|
|
30
|
+
planetApplicationService.register(app1);
|
|
31
|
+
expect(planetApplicationService.getApps()).toEqual([app1]);
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it('should throw error when register exist app1 ', () => {
|
|
35
|
+
planetApplicationService.register(app1);
|
|
36
|
+
expect(() => {
|
|
37
|
+
planetApplicationService.register(app1);
|
|
38
|
+
}).toThrowError('app1 has be registered.');
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it('should register multiple apps contains app1 and app2 success', () => {
|
|
42
|
+
planetApplicationService.register([app1, app2]);
|
|
43
|
+
expect(planetApplicationService.getApps()).toEqual([app1, app2]);
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
describe('registerByUrl', () => {
|
|
47
|
+
let httpClient: HttpClient;
|
|
48
|
+
let httpTestingController: HttpTestingController;
|
|
49
|
+
beforeEach(() => {
|
|
50
|
+
httpClient = TestBed.inject(HttpClient);
|
|
51
|
+
httpTestingController = TestBed.inject(HttpTestingController);
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
afterEach(() => {
|
|
55
|
+
// After every test, assert that there are no more pending requests.
|
|
56
|
+
httpTestingController.verify();
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
it('should register multiple apps by url', () => {
|
|
60
|
+
planetApplicationService.registerByUrl('/static/apps.json');
|
|
61
|
+
const req = httpTestingController.expectOne('/static/apps.json');
|
|
62
|
+
|
|
63
|
+
// Assert that the request is a GET.
|
|
64
|
+
expect(req.request.method).toEqual('GET');
|
|
65
|
+
|
|
66
|
+
// Respond with mock data, causing Observable to resolve.
|
|
67
|
+
// Subscribe callback asserts that correct data was returned.
|
|
68
|
+
req.flush([app1, app2]);
|
|
69
|
+
|
|
70
|
+
expect(planetApplicationService.getApps()).toEqual([app1, app2]);
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
it('should register one app by url', () => {
|
|
74
|
+
planetApplicationService.registerByUrl('/static/apps.json');
|
|
75
|
+
const req = httpTestingController.expectOne('/static/apps.json');
|
|
76
|
+
expect(req.request.method).toEqual('GET');
|
|
77
|
+
req.flush(app1);
|
|
78
|
+
expect(planetApplicationService.getApps()).toEqual([app1]);
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
describe('unregister', () => {
|
|
84
|
+
it('should unregister app1 success', () => {
|
|
85
|
+
planetApplicationService.register(app1);
|
|
86
|
+
expect(planetApplicationService.getApps()).toEqual([app1]);
|
|
87
|
+
planetApplicationService.unregister(app1.name);
|
|
88
|
+
expect(planetApplicationService.getApps()).toEqual([]);
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
describe('getAppsByMatchedUrl', () => {
|
|
93
|
+
it('should get matched apps(app1) by url app1/dashboard', () => {
|
|
94
|
+
planetApplicationService.register(app1);
|
|
95
|
+
planetApplicationService.register(app2);
|
|
96
|
+
const apps = planetApplicationService.getAppsByMatchedUrl('/app1/dashboard');
|
|
97
|
+
expect(apps).toEqual([app1]);
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
it('should get matched apps by url when apps has same routerPathPrefix', () => {
|
|
101
|
+
planetApplicationService.register(app1);
|
|
102
|
+
const app2SameApp1 = { ...app2, routerPathPrefix: '/app1' };
|
|
103
|
+
planetApplicationService.register(app2SameApp1);
|
|
104
|
+
const apps = planetApplicationService.getAppsByMatchedUrl('/app1/dashboard');
|
|
105
|
+
expect(apps).toEqual([app1, app2SameApp1]);
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
it('should get empty apps by url __/dashboard/app1 without start with app1', () => {
|
|
109
|
+
planetApplicationService.register(app1);
|
|
110
|
+
planetApplicationService.register(app2);
|
|
111
|
+
const apps = planetApplicationService.getAppsByMatchedUrl('/__/dashboard/app1');
|
|
112
|
+
expect(apps).toEqual([]);
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
it('should get matched apps which rule is RegExp("(a\\wp3)|app4") by url app3/dashboard', () => {
|
|
116
|
+
planetApplicationService.register(app1);
|
|
117
|
+
planetApplicationService.register(app2);
|
|
118
|
+
const app3 = {
|
|
119
|
+
...app1,
|
|
120
|
+
name: 'app3',
|
|
121
|
+
routerPathPrefix: new RegExp('(a\\wp3)|app4')
|
|
122
|
+
};
|
|
123
|
+
planetApplicationService.register(app3);
|
|
124
|
+
const apps = planetApplicationService.getAppsByMatchedUrl('/app3/dashboard');
|
|
125
|
+
expect(apps).toBeTruthy('app is not found');
|
|
126
|
+
expect(apps[0]).toBe(app3);
|
|
127
|
+
});
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
describe('getAppsToPreload', () => {
|
|
131
|
+
it('should get correct preload apps', () => {
|
|
132
|
+
planetApplicationService.register(app1);
|
|
133
|
+
planetApplicationService.register(app2WithPreload);
|
|
134
|
+
const appsToPreload = planetApplicationService.getAppsToPreload();
|
|
135
|
+
expect(appsToPreload).toEqual([app2WithPreload]);
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
it('should get correct preload apps exclude app names', () => {
|
|
139
|
+
planetApplicationService.register(app1);
|
|
140
|
+
planetApplicationService.register(app2WithPreload);
|
|
141
|
+
const appsToPreload = planetApplicationService.getAppsToPreload(['app2']);
|
|
142
|
+
expect(appsToPreload).toEqual([]);
|
|
143
|
+
});
|
|
144
|
+
});
|
|
145
|
+
});
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { PlanetApplication } from '../planet.class';
|
|
2
|
+
import { Injectable } from '@angular/core';
|
|
3
|
+
import { HttpClient } from '@angular/common/http';
|
|
4
|
+
import { shareReplay, map } from 'rxjs/operators';
|
|
5
|
+
import { coerceArray } from '../helpers';
|
|
6
|
+
import { Observable } from 'rxjs';
|
|
7
|
+
import { AssetsLoader } from '../assets-loader';
|
|
8
|
+
import { getApplicationService } from '../global-planet';
|
|
9
|
+
|
|
10
|
+
@Injectable({
|
|
11
|
+
providedIn: 'root'
|
|
12
|
+
})
|
|
13
|
+
export class PlanetApplicationService {
|
|
14
|
+
private apps: PlanetApplication[] = [];
|
|
15
|
+
|
|
16
|
+
private appsMap: { [key: string]: PlanetApplication } = {};
|
|
17
|
+
|
|
18
|
+
constructor(private http: HttpClient, private assetsLoader: AssetsLoader) {
|
|
19
|
+
if (getApplicationService()) {
|
|
20
|
+
throw new Error(
|
|
21
|
+
'PlanetApplicationService has been injected in the portal, repeated injection is not allowed'
|
|
22
|
+
);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
register<TExtra>(appOrApps: PlanetApplication<TExtra> | PlanetApplication<TExtra>[]) {
|
|
27
|
+
const apps = coerceArray(appOrApps);
|
|
28
|
+
apps.forEach(app => {
|
|
29
|
+
if (this.appsMap[app.name]) {
|
|
30
|
+
throw new Error(`${app.name} has be registered.`);
|
|
31
|
+
}
|
|
32
|
+
this.apps.push(app);
|
|
33
|
+
this.appsMap[app.name] = app;
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
registerByUrl(url: string): Observable<void> {
|
|
38
|
+
const result = this.http.get(`${url}`).pipe(
|
|
39
|
+
map(apps => {
|
|
40
|
+
if (apps && Array.isArray(apps)) {
|
|
41
|
+
this.register(apps);
|
|
42
|
+
} else {
|
|
43
|
+
this.register(apps as PlanetApplication);
|
|
44
|
+
}
|
|
45
|
+
}),
|
|
46
|
+
shareReplay()
|
|
47
|
+
);
|
|
48
|
+
result.subscribe();
|
|
49
|
+
return result;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
unregister(name: string) {
|
|
53
|
+
if (this.appsMap[name]) {
|
|
54
|
+
delete this.appsMap[name];
|
|
55
|
+
this.apps = this.apps.filter(app => {
|
|
56
|
+
return app.name !== name;
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
getAppsByMatchedUrl<TExtra = unknown>(url: string): PlanetApplication<TExtra>[] {
|
|
62
|
+
return this.getApps().filter(app => {
|
|
63
|
+
if (app.routerPathPrefix instanceof RegExp) {
|
|
64
|
+
return app.routerPathPrefix.test(url);
|
|
65
|
+
} else {
|
|
66
|
+
return url.startsWith(app.routerPathPrefix);
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
getAppByName(name: string) {
|
|
72
|
+
return this.appsMap[name];
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
getAppsToPreload(excludeAppNames?: string[]) {
|
|
76
|
+
return this.getApps().filter(app => {
|
|
77
|
+
if (excludeAppNames) {
|
|
78
|
+
return app.preload && !excludeAppNames.includes(app.name);
|
|
79
|
+
} else {
|
|
80
|
+
return app.preload;
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
getApps() {
|
|
86
|
+
return this.apps;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { TestBed } from '@angular/core/testing';
|
|
2
|
+
import { Router } from '@angular/router';
|
|
3
|
+
import { PlanetPortalApplication } from './portal-application';
|
|
4
|
+
import { NgZone, ApplicationRef } from '@angular/core';
|
|
5
|
+
import { RouterTestingModule } from '@angular/router/testing';
|
|
6
|
+
|
|
7
|
+
describe('PlanetPortalApplication', () => {
|
|
8
|
+
let router: Router;
|
|
9
|
+
let planetPortalApplication: PlanetPortalApplication;
|
|
10
|
+
beforeEach(() => {
|
|
11
|
+
TestBed.configureTestingModule({
|
|
12
|
+
imports: [RouterTestingModule.withRoutes([])]
|
|
13
|
+
});
|
|
14
|
+
router = TestBed.inject(Router);
|
|
15
|
+
planetPortalApplication = new PlanetPortalApplication();
|
|
16
|
+
planetPortalApplication.ngZone = TestBed.inject(NgZone);
|
|
17
|
+
planetPortalApplication.applicationRef = TestBed.inject(ApplicationRef);
|
|
18
|
+
planetPortalApplication.router = TestBed.inject(Router);
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
it(`should create PlanetPortalApplication`, () => {
|
|
22
|
+
expect(planetPortalApplication).toBeTruthy();
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
it(`should run function`, () => {
|
|
26
|
+
const spy = jasmine.createSpy('spy');
|
|
27
|
+
expect(spy).not.toHaveBeenCalled();
|
|
28
|
+
planetPortalApplication.run(spy);
|
|
29
|
+
expect(spy).toHaveBeenCalled();
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it(`should run function in ngZone`, () => {
|
|
33
|
+
const ngZoneRunSpy = spyOn(planetPortalApplication.ngZone, 'run');
|
|
34
|
+
expect(ngZoneRunSpy).not.toHaveBeenCalled();
|
|
35
|
+
planetPortalApplication.run(() => {});
|
|
36
|
+
expect(ngZoneRunSpy).toHaveBeenCalled();
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it(`should run tick`, () => {
|
|
40
|
+
const tickSpy = spyOn(planetPortalApplication.applicationRef, 'tick');
|
|
41
|
+
expect(tickSpy).not.toHaveBeenCalled();
|
|
42
|
+
planetPortalApplication.tick();
|
|
43
|
+
expect(tickSpy).toHaveBeenCalled();
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it(`should run navigateByUrl`, () => {
|
|
47
|
+
const navigateByUrlSpy = spyOn(planetPortalApplication.router, 'navigateByUrl');
|
|
48
|
+
expect(navigateByUrlSpy).not.toHaveBeenCalled();
|
|
49
|
+
planetPortalApplication.navigateByUrl('/app1/dashboard', { skipLocationChange: true });
|
|
50
|
+
expect(navigateByUrlSpy).toHaveBeenCalled();
|
|
51
|
+
expect(navigateByUrlSpy).toHaveBeenCalledWith('/app1/dashboard', { skipLocationChange: true });
|
|
52
|
+
});
|
|
53
|
+
});
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { Router, UrlTree, NavigationExtras } from '@angular/router';
|
|
2
|
+
import { NgZone, Injector, ApplicationRef } from '@angular/core';
|
|
3
|
+
import { GlobalEventDispatcher } from '../global-event-dispatcher';
|
|
4
|
+
|
|
5
|
+
export class PlanetPortalApplication<TData = any> {
|
|
6
|
+
applicationRef?: ApplicationRef;
|
|
7
|
+
injector?: Injector;
|
|
8
|
+
router?: Router;
|
|
9
|
+
ngZone?: NgZone;
|
|
10
|
+
globalEventDispatcher?: GlobalEventDispatcher;
|
|
11
|
+
data?: TData;
|
|
12
|
+
|
|
13
|
+
navigateByUrl(url: string | UrlTree, extras?: NavigationExtras): Promise<boolean> {
|
|
14
|
+
return this.ngZone!.run(() => {
|
|
15
|
+
return this.router!.navigateByUrl(url, extras);
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
run<T>(fn: (...args: any[]) => T): T {
|
|
20
|
+
return this.ngZone!.run<T>(() => {
|
|
21
|
+
return fn();
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
tick() {
|
|
26
|
+
this.applicationRef!.tick();
|
|
27
|
+
}
|
|
28
|
+
}
|