1 import {Component, OnDestroy, OnInit} from '@angular/core';
2 import {FormPopupDetails} from "../../models/formControlModels/formPopupDetails.model";
3 import {DialogComponent, DialogService} from "ng2-bootstrap-modal";
4 import {FormGroup} from "@angular/forms";
5 import {IframeService} from "../../utils/iframe.service";
6 import {ITreeNode} from "angular-tree-component/dist/defs/api";
7 import * as _ from "lodash";
8 import {NgRedux} from "@angular-redux/store";
9 import {AppState} from "../../store/reducers";
10 import {ServicePopupService} from "./genericFormServices/service/service.popup.service";
11 import {ActivatedRoute, Router} from "@angular/router";
12 import {AaiService} from "../../services/aaiService/aai.service";
13 import {GenericFormPopupService} from "./generic-form-popup.service";
14 import {FormControlModel} from "../../models/formControlModels/formControl.model";
15 import {FormGeneralErrorsService} from "../formGeneralErrors/formGeneralErrors.service";
16 import {FeatureFlagsService, Features} from "../../services/featureFlag/feature-flags.service";
17 import {InstantiationTemplatesModalComponent} from "./instantiationTemplatesModal/instantiation.templates.modal.component";
18 import {updateCurrentModalModeAction} from "../../storeUtil/utils/global/global.actions";
21 export interface PopupModel {
25 isUpdateMode: boolean;
28 export enum PopupType {
32 VF_MODULE = 'vf_module',
33 VF_MODULE_UPGRADE = 'vf_module_upgrade',
34 VNF_GROUP = 'vnf_group'
39 selector: 'generic-form-popup',
40 templateUrl: 'generic-form-popup.component.html',
41 styleUrls: ['generic-form-popup.component.scss']
44 export class GenericFormPopupComponent extends DialogComponent<PopupModel, boolean> implements OnInit, OnDestroy {
45 formPopupDetails: FormPopupDetails = null;
46 dynamicForm: FormGroup;
49 showTemplateBtn: boolean = false;
50 isShowPreviousInstantiationBtn: boolean = false;
51 isUpdateMode: boolean;
52 node: ITreeNode = null;
53 hasGeneralApiError: boolean = false;
54 parentElementClassName = 'content';
55 errorMsg = 'Page contains errors. Please see details next to the relevant fields.';
56 serviceModelId : string;
58 quantityOptions = _.range(1, 51)
60 constructor(dialogService: DialogService,
61 private _iframeService: IframeService,
62 private _store: NgRedux<AppState>,
63 private _servicePopupService: ServicePopupService,
64 private _activatedRoute: ActivatedRoute,
65 private _aaiService: AaiService,
66 private _dialogService: DialogService,
67 private _route: ActivatedRoute,
68 private _router : Router,
69 private _genericFormPopupService: GenericFormPopupService) {
73 closeDialog(that): void {
74 this._iframeService.closeIframe(this.dialogService, this);
77 shouldShowNotification(): boolean {
78 return this.formPopupDetails && this.formPopupDetails.UUIDData['bulkSize'] > 1
81 clearModalIsUpdateMode() : void {
82 this._store.dispatch(updateCurrentModalModeAction(null));
86 this._store.dispatch(updateCurrentModalModeAction(this.isUpdateMode));
89 .subscribe(params => {
90 this.serviceModelId = params['serviceModelId'];
91 if (this.serviceModelId && params['isCreate'] == "true") {
92 this.onInitForCreateNewServicePopup(params['isInstantiationTemplateExists']);
96 FormGeneralErrorsService.checkForErrorTrigger.subscribe(() => {
97 this.hasSomeError(this.formPopupDetails, this.dynamicForm);
100 if (!_.isNil(this.uuidData)) {
101 this.uuidData.popupService.closeDialogEvent.subscribe((that) => {
102 this.closeDialog(that);
105 this.uuidData['isMacro'] = this._store.getState().service.serviceHierarchy[this.uuidData['serviceId']].service.vidNotions.instantiationType === 'Macro';
106 this.formPopupDetails = this._genericFormPopupService.getGenericFormDetails(this.uuidData, this.node, this.isUpdateMode);
110 private onInitForCreateNewServicePopup(isInstantiationTemplateExists : boolean) {
111 this._genericFormPopupService.initReduxOnCreateNewService().then((serviceModelId: string) => {
112 this.uuidData = <any>{
114 isMacro: this._store.getState().service.serviceHierarchy[serviceModelId].service.vidNotions.instantiationType === 'Macro',
115 type: PopupType.SERVICE,
116 serviceId: serviceModelId,
117 popupService: this._servicePopupService,
120 this.showTemplateBtn = this._genericFormPopupService.shouldShowTemplateBtn(isInstantiationTemplateExists);
121 this.isShowPreviousInstantiationBtn = !!this._store.getState().global.flags["FLAG_2004_TEMP_BUTTON_TO_INSTANTIATION_STATUS_FILTER"];
123 this.uuidData.popupService.closeDialogEvent.subscribe((that) => {
124 this.closeDialog(that);
127 this.formPopupDetails = this.uuidData.popupService.getGenericFormPopupDetails(
128 this.uuidData['serviceId'],
138 hasSomeError(formPopupDetails: FormPopupDetails, form: FormGroup): boolean {
139 if (_.isNil(formPopupDetails)) return false;
141 for (let controlName in form.controls) {
142 if (form.controls[controlName].errors) {
143 let error: string[] = Object.keys(form.controls[controlName].errors);
144 if (error.length === 1 && error[0] === 'required') {
146 } else if (Object.keys(form.controls[controlName].errors).length > 0) {
153 return formPopupDetails.formControlList.filter((item: FormControlModel) => item.type === 'DROPDOWN' && item['hasEmptyOptions'] && item.isRequired()).length > 0
157 openTemplateModal = (): void => {
158 this._router.navigate(['/instantiationTemplatesPopup'], { queryParams: { serviceModelId: this.serviceModelId}, queryParamsHandling: 'merge' });
164 export class UUIDData extends Object {