diff options
Diffstat (limited to 'catalog-ui/src/app/ng2')
-rw-r--r-- | catalog-ui/src/app/ng2/app.module.ts | 5 | ||||
-rw-r--r-- | catalog-ui/src/app/ng2/services/event-bus.service.ts | 39 |
2 files changed, 42 insertions, 2 deletions
diff --git a/catalog-ui/src/app/ng2/app.module.ts b/catalog-ui/src/app/ng2/app.module.ts index a5a2fed18b..0346b10915 100644 --- a/catalog-ui/src/app/ng2/app.module.ts +++ b/catalog-ui/src/app/ng2/app.module.ts @@ -48,6 +48,7 @@ import { TranslateModule } from "./shared/translator/translate.module"; import { TranslationServiceConfig } from "./config/translation.service.config"; import {PluginFrameModule} from "./components/ui/plugin/plugin-frame.module"; import {PluginsService} from "./services/plugins.service"; +import {EventBusService} from "./services/event-bus.service"; export const upgradeAdapter = new UpgradeAdapter(forwardRef(() => AppModule)); @@ -99,6 +100,7 @@ export function configServiceFactory(config:ConfigService) { ComponentInstanceServiceNg2, TranslationServiceConfig, PluginsService, + EventBusService, { provide: APP_INITIALIZER, useFactory: configServiceFactory, @@ -112,7 +114,6 @@ export function configServiceFactory(config:ConfigService) { export class AppModule { - constructor(public upgrade:UpgradeModule) { - + constructor(public upgrade:UpgradeModule, eventBusService:EventBusService) { } } diff --git a/catalog-ui/src/app/ng2/services/event-bus.service.ts b/catalog-ui/src/app/ng2/services/event-bus.service.ts new file mode 100644 index 0000000000..7730a77f41 --- /dev/null +++ b/catalog-ui/src/app/ng2/services/event-bus.service.ts @@ -0,0 +1,39 @@ +import { Injectable } from '@angular/core'; +import {BasePubSub, IPubSubEvent} from "../../models/base-pubsub"; + +@Injectable() +export class EventBusService extends BasePubSub { + + constructor() { + super("sdc-hub"); + } + + protected handlePluginRegistration(eventData: IPubSubEvent, event: any) { + if (eventData.type === 'PLUGIN_REGISTER') { + this.register(eventData.data.pluginId, event.source, event.origin); + } else if (eventData.type === 'PLUGIN_UNREGISTER') { + this.unregister(eventData.data.pluginId); + } + } + + public unregister(pluginId: string) { + const unregisterData = { + pluginId: pluginId + }; + + this.notify('PLUGIN_CLOSE', unregisterData); + super.unregister(pluginId); + } + + protected onMessage(event: any) { + if (event.data.type === 'PLUGIN_REGISTER') { + this.handlePluginRegistration(event.data, event); + } + + super.onMessage(event); + + if (event.data.type === 'PLUGIN_UNREGISTER') { + this.handlePluginRegistration(event.data, event); + } + } +} |