aboutsummaryrefslogtreecommitdiffstats
path: root/vid-webpack-master/src/app/shared/components/customModal/services/modal.service.ts
diff options
context:
space:
mode:
authorYoav Schneiderman <yoav.schneiderman@intl.att.com>2020-01-08 14:46:14 +0200
committerIttay Stern <ittay.stern@att.com>2020-01-09 13:29:49 +0000
commit4ef3ee778fc944cdfe28146d4eed360ce096e5ee (patch)
treec641429928518b64f7a39acd1d241043a28978cd /vid-webpack-master/src/app/shared/components/customModal/services/modal.service.ts
parente8414b1fe839291418ead3a7e5a64bf382dc1121 (diff)
Upgrade to Angular 8
Issue-ID: VID-742 Change-Id: Ic4b3aae71d4c946e23d854847a49aa7e020c465d Signed-off-by: Yoav Schneiderman <yoav.schneiderman@intl.att.com>
Diffstat (limited to 'vid-webpack-master/src/app/shared/components/customModal/services/modal.service.ts')
-rw-r--r--vid-webpack-master/src/app/shared/components/customModal/services/modal.service.ts64
1 files changed, 64 insertions, 0 deletions
diff --git a/vid-webpack-master/src/app/shared/components/customModal/services/modal.service.ts b/vid-webpack-master/src/app/shared/components/customModal/services/modal.service.ts
new file mode 100644
index 000000000..f46ee4896
--- /dev/null
+++ b/vid-webpack-master/src/app/shared/components/customModal/services/modal.service.ts
@@ -0,0 +1,64 @@
+import {ComponentRef, Injectable, Type} from "@angular/core";
+import {CreateDynamicComponentService} from "./create-dynamic-component.service";
+import {ModalType} from "../models/modal.type";
+import {ButtonType} from "../models/button.type";
+import {ModalButtonComponent} from "onap-ui-angular/dist/modals/modal-button.component";
+import {ModalSize} from "../models/modal.size";
+import {IModalConfig} from "../models/modal.model";
+import {ModalComponent} from "../modal.component";
+
+
+@Injectable()
+export class ModalService {
+
+ constructor(private createDynamicComponentService: CreateDynamicComponentService) {
+ }
+
+ private getBaseModal = (type: ModalType | ButtonType, title: string, message: string, testId: string, buttons?: ModalButtonComponent[]): ModalComponent => {
+ const modalConfig = {
+ size: ModalSize.small,
+ title: title,
+ message: message,
+ testId: testId,
+ buttons: buttons ? buttons : [{text: 'OK', type: type, closeModal: true}],
+ type: type
+ } as IModalConfig;
+ const modalInstance: ComponentRef<ModalComponent> = this.openModal(modalConfig);
+ return modalInstance.instance;
+ };
+
+ /* Shortcut method to open basic modals with title, message, and OK button that simply closes the modal. */
+ public openInfoModal = (title: string, message: string, testId: string, buttons?: ModalButtonComponent[]): ModalComponent => {
+
+ return this.getBaseModal(ModalType.info, title, message, testId, buttons);
+ };
+
+ public openWarningModal = (title: string, message: string, testId: string, buttons?: ModalButtonComponent[]): ModalComponent => {
+ return this.getBaseModal(ModalType.warning, title, message, testId, buttons);
+ };
+
+ public openErrorModal = (title: string, message: string, testId: string, buttons?: ModalButtonComponent[]): ModalComponent => {
+ return this.getBaseModal(ModalType.error, title, message, testId, buttons);
+ };
+
+ public openSuccessModal = (title: string, message: string, testId: string, buttons?: ModalButtonComponent[]): ModalComponent => {
+ return this.getBaseModal(ModalType.success, title, message, testId, buttons);
+ };
+
+ public openCustomModal = (modalConfig: IModalConfig, dynamicComponentType: Type<any>, dynamicComponentInput?: any) => {
+ const modalInstance: ComponentRef<ModalComponent> = this.openModal(modalConfig);
+ this.createInnnerComponent(modalInstance, dynamicComponentType, dynamicComponentInput);
+ return modalInstance.instance;
+ };
+
+ public createInnnerComponent = (modalInstance: ComponentRef<ModalComponent>, dynamicComponentType: Type<any>, dynamicComponentInput?: any): void => {
+ modalInstance.instance.innerModalContent = this.createDynamicComponentService.insertComponentDynamically(dynamicComponentType, dynamicComponentInput, modalInstance.instance.dynamicContentContainer);
+ };
+
+ public openModal = (customModalData: IModalConfig): ComponentRef<ModalComponent> => {
+ let modalInstance: ComponentRef<ModalComponent> = this.createDynamicComponentService.createComponentDynamically(ModalComponent, customModalData);
+ modalInstance.instance.instanceRef = modalInstance;
+ return modalInstance;
+ }
+
+}