diff --git a/src/atlasViewer/atlasViewer.component.ts b/src/atlasViewer/atlasViewer.component.ts index 7aaa79bbd3be9b4a1e84aeab1f5b206326091923..a781efcb72a4905395bcb4852804bfbafc9765f7 100644 --- a/src/atlasViewer/atlasViewer.component.ts +++ b/src/atlasViewer/atlasViewer.component.ts @@ -8,18 +8,15 @@ import { WidgetServices } from "./widgetUnit/widgetService.service"; import { LayoutMainSide } from "../layouts/mainside/mainside.component"; import { Chart } from 'chart.js' import { AtlasViewerConstantsServices, SUPPORT_LIBRARY_MAP } from "./atlasViewer.constantService.service"; -import { BsModalService, BsModalRef } from "ngx-bootstrap/modal"; +import { BsModalService } from "ngx-bootstrap/modal"; import { ModalUnit } from "./modalUnit/modalUnit.component"; import { AtlasViewerURLService } from "./atlasViewer.urlService.service"; -import { ToastComponent } from "../components/toast/toast.component"; import { AtlasViewerAPIServices } from "./atlasViewer.apiService.service"; import { PluginServices } from "./atlasViewer.pluginService.service"; import '../res/css/extra_styles.css' import { NehubaContainer } from "../ui/nehubaContainer/nehubaContainer.component"; -import { ToastHandler } from "../util/pluginHandlerClasses/toastHandler"; -import { colorAnimation } from "./atlasViewer.animation"; -import { ToastService, defaultToastConfig } from "../services/toastService.service"; +import { colorAnimation } from "./atlasViewer.animation" @Component({ selector: 'atlas-viewer', @@ -50,9 +47,6 @@ export class AtlasViewer implements OnDestroy, OnInit, AfterViewInit { meetsRequirement: boolean = true - toastComponentFactory: ComponentFactory<ToastComponent> - private dedicatedViewComponentRef: ComponentRef<ToastComponent> - public sidePanelView$: Observable<string|null> private newViewer$: Observable<any> @@ -78,20 +72,16 @@ export class AtlasViewer implements OnDestroy, OnInit, AfterViewInit { } constructor( - private toastService:ToastService, private pluginService: PluginServices, private rd2: Renderer2, private store: Store<ViewerStateInterface>, public dataService: AtlasViewerDataService, - private cfr: ComponentFactoryResolver, private widgetServices: WidgetServices, private constantsService: AtlasViewerConstantsServices, public urlService: AtlasViewerURLService, public apiService: AtlasViewerAPIServices, private modalService: BsModalService ) { - this.toastComponentFactory = this.cfr.resolveComponentFactory(ToastComponent) - this.ngLayerNames$ = this.store.pipe( select('viewerState'), filter(state => isDefined(state) && isDefined(state.templateSelected)), @@ -185,57 +175,6 @@ export class AtlasViewer implements OnDestroy, OnInit, AfterViewInit { ngOnInit() { - this.toastService.showToast = (message, config) => { - const _config = Object.assign({}, defaultToastConfig, config - ? config - : {}) - const toastComponent = this.toastContainer.createComponent(this.toastComponentFactory) - if(typeof message === 'string') - toastComponent.instance.message = message - if(message instanceof TemplateRef){ - toastComponent.instance.messageContainer.createEmbeddedView(message as TemplateRef<any>) - } - - toastComponent.instance.dismissable = _config.dismissable - toastComponent.instance.timeout = _config.timeout - - let subscription - - const dismissToast = () => { - if(subscription) subscription.unsubscribe() - toastComponent.destroy() - } - - subscription = toastComponent.instance.dismissed.subscribe(dismissToast) - return dismissToast - } - - this.apiService.interactiveViewer.uiHandle.getToastHandler = () => { - const handler = new ToastHandler() - let toastComponent:ComponentRef<ToastComponent> - handler.show = () => { - toastComponent = this.toastContainer.createComponent(this.toastComponentFactory) - - toastComponent.instance.dismissable = handler.dismissable - toastComponent.instance.message = handler.message - toastComponent.instance.timeout = handler.timeout - - const _subscription = toastComponent.instance.dismissed.subscribe(userInitiated => { - _subscription.unsubscribe() - handler.hide() - }) - } - - handler.hide = () => { - if(toastComponent){ - toastComponent.destroy() - toastComponent = null - } - } - - return handler - } - this.apiService.interactiveViewer.pluginControl.loadExternalLibraries = (libraries: string[]) => new Promise((resolve, reject) => { const srcHTMLElement = libraries.map(libraryName => ({ name: libraryName, @@ -301,23 +240,6 @@ export class AtlasViewer implements OnDestroy, OnInit, AfterViewInit { ) ) - /** - * TODO dedicated view should be deprecated - */ - this.subscriptions.push( - this.dedicatedView$.subscribe(string => { - if (string === null) { - if (this.dedicatedViewComponentRef) - this.dedicatedViewComponentRef.destroy() - return - } - this.dedicatedViewComponentRef = this.toastContainer.createComponent(this.toastComponentFactory) - this.dedicatedViewComponentRef.instance.message = `hello` - this.dedicatedViewComponentRef.instance.dismissable = true - this.dedicatedViewComponentRef.instance.timeout = 1000 - }) - ) - this.subscriptions.push( this.ngLayerNames$.pipe( concatMap(data => this.constantsService.loadExportNehubaPromise.then(data)) diff --git a/src/atlasViewer/atlasViewer.template.html b/src/atlasViewer/atlasViewer.template.html index 47aec496724cdf285739bc802a118ff4a482d921..9cbaa9666527c4dedab2b2a732d08082feb3002f 100644 --- a/src/atlasViewer/atlasViewer.template.html +++ b/src/atlasViewer/atlasViewer.template.html @@ -165,8 +165,8 @@ <!-- TODO Potentially implementing plugin contextual info --> </div> <div toastContainer> - <ng-template #toastContainer> - </ng-template> + <div toastDirective> + </div> </div> </layout-floating-container> diff --git a/src/main.module.ts b/src/main.module.ts index 524ae188b285826608004d74aab832c8b1587bf2..5dfe69c06548a3f5719791c6c31b7010de945b6e 100644 --- a/src/main.module.ts +++ b/src/main.module.ts @@ -27,6 +27,7 @@ import { NewViewerDisctinctViewToLayer } from "./util/pipes/newViewerDistinctVie import { ToastService } from "./services/toastService.service"; import { AtlasWorkerService } from "./atlasViewer/atlasViewer.workerService.service"; import { HelpDirective } from "./util/directives/help.directive"; +import { ToastContainerDirective } from "./util/directives/toastContainer.directive"; @NgModule({ imports : [ @@ -62,6 +63,7 @@ import { HelpDirective } from "./util/directives/help.directive"; GlyphiconTooltipRemoveDirective, GlyphiconTooltipRemoveSignDirective, HelpDirective, + ToastContainerDirective, /* pipes */ GetNamesPipe, diff --git a/src/util/directives/toastContainer.directive.ts b/src/util/directives/toastContainer.directive.ts new file mode 100644 index 0000000000000000000000000000000000000000..befacad355e8a3e83e8e5cd44621dfdeec67a83b --- /dev/null +++ b/src/util/directives/toastContainer.directive.ts @@ -0,0 +1,72 @@ +import { Directive, ViewContainerRef, ComponentFactoryResolver, TemplateRef, ComponentRef } from '@angular/core' +import { ToastService, defaultToastConfig } from 'src/services/toastService.service'; +import { ToastComponent } from 'src/components/toast/toast.component'; +import { AtlasViewerAPIServices } from 'src/atlasViewer/atlasViewer.apiService.service'; +import { ToastHandler } from '../pluginHandlerClasses/toastHandler'; + +@Directive({ + selector: '[toastDirective]' +}) + +export class ToastContainerDirective{ + constructor( + private viewContainerRef: ViewContainerRef, + private toastService: ToastService, + private cfr: ComponentFactoryResolver, + private apiService: AtlasViewerAPIServices + ){ + const toastComponentFactory = this.cfr.resolveComponentFactory(ToastComponent) + + this.toastService.showToast = (message, config) => { + + const _config = Object.assign({}, defaultToastConfig, config + ? config + : {}) + const toastComponent = this.viewContainerRef.createComponent(toastComponentFactory) + if(typeof message === 'string') + toastComponent.instance.message = message + if(message instanceof TemplateRef){ + toastComponent.instance.messageContainer.createEmbeddedView(message as TemplateRef<any>) + } + + toastComponent.instance.dismissable = _config.dismissable + toastComponent.instance.timeout = _config.timeout + + let subscription + + const dismissToast = () => { + if(subscription) subscription.unsubscribe() + toastComponent.destroy() + } + + subscription = toastComponent.instance.dismissed.subscribe(dismissToast) + return dismissToast + } + + this.apiService.interactiveViewer.uiHandle.getToastHandler = () => { + const handler = new ToastHandler() + let toastComponent:ComponentRef<ToastComponent> + handler.show = () => { + toastComponent = this.viewContainerRef.createComponent(toastComponentFactory) + + toastComponent.instance.dismissable = handler.dismissable + toastComponent.instance.message = handler.message + toastComponent.instance.timeout = handler.timeout + + const _subscription = toastComponent.instance.dismissed.subscribe(userInitiated => { + _subscription.unsubscribe() + handler.hide() + }) + } + + handler.hide = () => { + if(toastComponent){ + toastComponent.destroy() + toastComponent = null + } + } + + return handler + } + } +} \ No newline at end of file