1 import {Component, OnChanges, 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} 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";
18 export interface PopupModel {
22 isUpdateMode : boolean;
25 export enum PopupType{
29 VF_MODULE = 'vf_module',
30 VNF_GROUP = 'vnf_group'
35 selector : 'generic-form-popup',
36 templateUrl : 'generic-form-popup.component.html',
37 styleUrls : ['generic-form-popup.component.scss']
40 export class GenericFormPopupComponent extends DialogComponent<PopupModel, boolean> implements OnInit, OnDestroy{
41 formPopupDetails : FormPopupDetails = null;
42 dynamicForm : FormGroup;
45 isUpdateMode : boolean;
46 node : ITreeNode = null;
47 hasGeneralApiError : boolean = false;
48 parentElementClassName = 'content';
49 errorMsg = 'Page contains errors. Please see details next to the relevant fields.';
52 quantityOptions = _.range(1, 51)
53 constructor(dialogService: DialogService ,
54 private _iframeService : IframeService,
55 private _store: NgRedux<AppState>,
56 private _servicePopupService : ServicePopupService,
57 private _activatedRoute : ActivatedRoute,
58 private _aaiService : AaiService,
59 private _route: ActivatedRoute,
60 private _genericFormPopupService : GenericFormPopupService){
64 closeDialog(that) : void{
65 this._iframeService.removeClassCloseModal(that.parentElementClassName);
66 this.dialogService.removeDialog(this);
68 window.parent.postMessage("closeIframe", "*");
72 shouldShowNotification() : boolean {
73 return this.formPopupDetails && this.formPopupDetails.UUIDData['bulkSize'] > 1
79 .subscribe(params => {
80 console.log('changed');
81 if(params['serviceModelId'] && params['isCreate']=="true"){
82 this._genericFormPopupService.initReduxOnCreateNewService().then((serviceModelId : string)=>{
83 this.uuidData = <any>{
85 isMacro : this._store.getState().service.serviceHierarchy[serviceModelId].service.instantiationType === 'Macro',
86 type : PopupType.SERVICE,
87 serviceId: serviceModelId,
88 popupService: this._servicePopupService,
91 this.uuidData.popupService.closeDialogEvent.subscribe((that)=>{
92 this.closeDialog(that);
95 this.formPopupDetails = this.uuidData.popupService.getGenericFormPopupDetails(
96 this.uuidData['serviceId'],
107 FormGeneralErrorsService.checkForErrorTrigger.subscribe(()=>{
108 this.hasSomeError(this.formPopupDetails, this.dynamicForm);
111 if(!_.isNil(this.uuidData)){
112 this.uuidData.popupService.closeDialogEvent.subscribe((that)=>{
113 this.closeDialog(that);
116 this.uuidData['isMacro'] = this._store.getState().service.serviceHierarchy[this.uuidData['serviceId']].service.instantiationType === 'Macro';
117 this.formPopupDetails = this._genericFormPopupService.getGenericFormDetails(this.uuidData, this.node, this.isUpdateMode);
121 hasSomeError(formPopupDetails : FormPopupDetails, form : FormGroup) : boolean{
122 if(_.isNil(formPopupDetails)) return false;
124 for(let controlName in form.controls){
125 if(form.controls[controlName].errors){
126 let error: string[] = Object.keys(form.controls[controlName].errors);
127 if(error.length === 1 && error[0] === 'required'){
129 }else if(Object.keys(form.controls[controlName].errors).length > 0 ){
136 return formPopupDetails.formControlList.filter((item : FormControlModel) =>item.type === 'DROPDOWN' && item['hasEmptyOptions']).length > 0
141 export class UUIDData extends Object{