From 8261a4ea8091c27b61ac581a852e2e18283b3cdd Mon Sep 17 00:00:00 2001 From: YuanHu Date: Tue, 27 Mar 2018 17:33:22 +0800 Subject: Include paletx components Include paletx components to WF Designer UI. Issue-ID: SDC-1130,SDC-1131 Change-Id: Iad06b2dde8fc98d03a0e3633e829b686d75cafd0 Signed-off-by: YuanHu --- .../src/app/paletx/plx-modal/modal-ref.ts | 109 +++++++++++++++++++++ 1 file changed, 109 insertions(+) create mode 100644 sdc-workflow-designer-ui/src/app/paletx/plx-modal/modal-ref.ts (limited to 'sdc-workflow-designer-ui/src/app/paletx/plx-modal/modal-ref.ts') diff --git a/sdc-workflow-designer-ui/src/app/paletx/plx-modal/modal-ref.ts b/sdc-workflow-designer-ui/src/app/paletx/plx-modal/modal-ref.ts new file mode 100644 index 00000000..061dc70e --- /dev/null +++ b/sdc-workflow-designer-ui/src/app/paletx/plx-modal/modal-ref.ts @@ -0,0 +1,109 @@ +import {Injectable, ComponentRef} from '@angular/core'; +import {PlxModalBackdrop} from './modal-backdrop'; +import {PlxModalWindow} from './modal-window'; +import {ContentRef} from '../util/popup'; + +/** + * A reference to an active (currently opened) modal. Instances of this class + * can be injected into components passed as modal content. + */ +@Injectable() +export class PlxActiveModal { + /** + * Can be used to close a modal, passing an optional result. + */ + public close(result?: any): void { + // TO DO + } + + /** + * Can be used to dismiss a modal, passing an optional reason. + */ + public dismiss(reason?: any): void { + // TO DO + } +} + +/** + * A reference to a newly opened modal. + */ +@Injectable() +export class PlxModalRef { + private _resolve: (result?: any) => void; + private _reject: (reason?: any) => void; + + /** + * The instance of component used as modal's content. + * Undefined when a TemplateRef is used as modal's content. + */ + get componentInstance(): any { + if (this._contentRef.componentRef) { + return this._contentRef.componentRef.instance; + } + } + + // only needed to keep TS1.8 compatibility + set componentInstance(instance: any) { + // TO DO + } + + /** + * A promise that is resolved when a modal is closed and rejected when a modal is dismissed. + */ + public result: Promise; + + constructor(private _windowCmptRef: ComponentRef, private _contentRef: ContentRef, + private _backdropCmptRef?: ComponentRef) { + _windowCmptRef.instance.dismissEvent.subscribe((reason: any) => { + this.dismiss(reason); + }); + + this.result = new Promise((resolve, reject) => { + this._resolve = resolve; + this._reject = reject; + }); + this.result.then(null, () => { + // TO DO + }); + } + + /** + * Can be used to close a modal, passing an optional result. + */ + public close(result?: any): void { + if (this._windowCmptRef) { + this._resolve(result); + this._removeModalElements(); + } + } + + /** + * Can be used to dismiss a modal, passing an optional reason. + */ + public dismiss(reason?: any): void { + if (this._windowCmptRef) { + this._reject(reason); + this._removeModalElements(); + } + } + + private _removeModalElements() { + const windowNativeEl = this._windowCmptRef.location.nativeElement; + windowNativeEl.parentNode.removeChild(windowNativeEl); + this._windowCmptRef.destroy(); + + if (this._backdropCmptRef) { + const backdropNativeEl = this._backdropCmptRef.location.nativeElement; + backdropNativeEl.parentNode.removeChild(backdropNativeEl); + this._backdropCmptRef.destroy(); + } + + if (this._contentRef && this._contentRef.viewRef) { + this._contentRef.viewRef.destroy(); + } + + this._windowCmptRef = null; + this._backdropCmptRef = null; + this._contentRef = null; + } +} -- cgit 1.2.3-korg