SUPPORT-9430: fixes

This commit is contained in:
adel.ka 2025-09-29 14:34:12 +03:00
parent eba3720c6f
commit 6e8c63337e
3 changed files with 60 additions and 18 deletions

View file

@ -1,6 +1,5 @@
import {platformBrowserDynamic} from "@angular/platform-browser-dynamic";
import {MfeConfigurationProvider} from "./modules/mfe/provider/mfe-configuration.provider"; import {MfeConfigurationProvider} from "./modules/mfe/provider/mfe-configuration.provider";
import {NgModuleRef} from "@angular/core"; import {NgModuleRef, PlatformRef} from "@angular/core";
let childEventHandlerFromContainer = null; let childEventHandlerFromContainer = null;
@ -25,6 +24,8 @@ export function fireMfeEventToContainer(eventType: ChildEventType, eventData: an
} }
export function bootstrapMfeApp(createApp: () => Promise<NgModuleRef<unknown> | void>) { export function bootstrapMfeApp(createApp: () => Promise<NgModuleRef<unknown> | void>) {
let platformRef: PlatformRef = null;
function mount( function mount(
element: HTMLElement, element: HTMLElement,
settings: { settings: {
@ -44,17 +45,23 @@ export function bootstrapMfeApp(createApp: () => Promise<NgModuleRef<unknown> |
let startUrl = settings.startUrl || ''; // ресурс хост-приложения let startUrl = settings.startUrl || ''; // ресурс хост-приложения
MfeConfigurationProvider.setPageBaseUrl(joinPath(containerBaseUrl, startUrl)); MfeConfigurationProvider.setPageBaseUrl(joinPath(containerBaseUrl, startUrl));
element.appendChild(createContainerForBootstrap()) element.appendChild(createContainerForBootstrap());
childEventHandlerFromContainer = settings.childEventHandler; childEventHandlerFromContainer = settings.childEventHandler;
createApp(); createApp().then(ref => {
if (ref) {
platformRef = ref.injector.get(PlatformRef);
}
});
return { return {
parentEventHandler(eventType: ParentEventType, url: string) { parentEventHandler(eventType: ParentEventType, url: string) {
}, },
unmount() { unmount() {
console.log("Unmounting account-applications application"); if (platformRef) {
platformBrowserDynamic().destroy(); platformRef.destroy();
platformRef = null;
}
}, },
} }
} }

View file

@ -1,4 +1,4 @@
import {Component, ViewEncapsulation} from "@angular/core"; import {Component, OnDestroy, ViewEncapsulation} from "@angular/core";
import { import {
Event, Event,
NavigationCancel, NavigationCancel,
@ -8,6 +8,7 @@ import {
Router Router
} from "@angular/router"; } from "@angular/router";
import {ProgressIndicationService} from "@webbpm/base-package"; import {ProgressIndicationService} from "@webbpm/base-package";
import {Subscription} from "rxjs";
@Component({ @Component({
@ -17,21 +18,32 @@ import {ProgressIndicationService} from "@webbpm/base-package";
templateUrl: './../../../../../src/resources/template/webbpm/mfe-webbpm.html', templateUrl: './../../../../../src/resources/template/webbpm/mfe-webbpm.html',
styleUrls: ['./../../../../../src/resources/css/style.css'], styleUrls: ['./../../../../../src/resources/css/style.css'],
}) })
export class MfeWebbpmComponent { export class MfeWebbpmComponent implements OnDestroy{
public headerVisible: boolean = true; public headerVisible: boolean = true;
public footerVisible: boolean = true; public footerVisible: boolean = true;
private subscription: Subscription;
constructor(private router: Router, constructor(private router: Router,
private progressIndicationService: ProgressIndicationService) { private progressIndicationService: ProgressIndicationService) {
router.events.subscribe((event: Event) => { this.subscription = router.events.subscribe((event: Event) => {
if (event instanceof NavigationStart) { this.handleRouterEvent(event);
progressIndicationService.showProgressBar();
}
else if (event instanceof NavigationEnd
|| event instanceof NavigationError
|| event instanceof NavigationCancel) {
progressIndicationService.hideProgressBar();
}
}) })
} }
private handleRouterEvent(event: Event): void {
if (event instanceof NavigationStart) {
this.progressIndicationService.showProgressBar();
}
else if (
event instanceof NavigationEnd
|| event instanceof NavigationError
|| event instanceof NavigationCancel
) {
this.progressIndicationService.hideProgressBar();
}
}
ngOnDestroy() {
this.subscription.unsubscribe();
}
} }

View file

@ -0,0 +1,23 @@
import {PathLocationStrategy} from "@angular/common";
import {Injectable, OnDestroy} from "@angular/core";
@Injectable()
export class MfeScopedLocationStrategy extends PathLocationStrategy implements OnDestroy {
private isDestroyed: boolean = false;
replaceState(state: any, title: string, url: string, queryParams: string) {
if (!this.isDestroyed) {
super.replaceState(state, title, url, queryParams);
}
}
pushState(state: any, title: string, url: string, queryParams: string) {
if (!this.isDestroyed) {
super.pushState(state, title, url, queryParams);
}
}
ngOnDestroy(): void {
this.isDestroyed = true;
}
}