aboutsummaryrefslogtreecommitdiffstats
path: root/vid-webpack-master/src/app/shared/components/genericFormPopup/generic-form-popup.component.ts
diff options
context:
space:
mode:
authorIttay Stern <ittay.stern@att.com>2018-08-29 17:01:32 +0300
committerIttay Stern <ittay.stern@att.com>2019-02-18 18:35:30 +0200
commit6f900cc45d7dd7f97430812b86b5c1d1693c8ae3 (patch)
tree936005c364dc5a7264d6304d4777c3d83494db22 /vid-webpack-master/src/app/shared/components/genericFormPopup/generic-form-popup.component.ts
parent67d99f816cc583643c35193197594cf78d8ce60a (diff)
merge from ecomp a88f0072 - Modern UI
Issue-ID: VID-378 Change-Id: Ibcb23dd27f550cf32ce2fe0239f0f496ae014ff6 Signed-off-by: Ittay Stern <ittay.stern@att.com>
Diffstat (limited to 'vid-webpack-master/src/app/shared/components/genericFormPopup/generic-form-popup.component.ts')
-rw-r--r--vid-webpack-master/src/app/shared/components/genericFormPopup/generic-form-popup.component.ts145
1 files changed, 145 insertions, 0 deletions
diff --git a/vid-webpack-master/src/app/shared/components/genericFormPopup/generic-form-popup.component.ts b/vid-webpack-master/src/app/shared/components/genericFormPopup/generic-form-popup.component.ts
new file mode 100644
index 000000000..2b6417e33
--- /dev/null
+++ b/vid-webpack-master/src/app/shared/components/genericFormPopup/generic-form-popup.component.ts
@@ -0,0 +1,145 @@
+import {Component, OnChanges, OnDestroy, OnInit} from '@angular/core';
+import {FormPopupDetails} from "../../models/formControlModels/formPopupDetails.model";
+import {DialogComponent, DialogService} from "ng2-bootstrap-modal";
+import {FormGroup} from "@angular/forms";
+import {IframeService} from "../../utils/iframe.service";
+import {ITreeNode} from "angular-tree-component/dist/defs/api";
+import * as _ from "lodash";
+import {NgRedux} from "@angular-redux/store";
+import {AppState} from "../../store/reducers";
+import {ServicePopupService} from "./genericFormServices/service/service.popup.service";
+import {ActivatedRoute} from "@angular/router";
+import {AaiService} from "../../services/aaiService/aai.service";
+import {GenericFormPopupService} from "./generic-form-popup.service";
+import {FormControlModel} from "../../models/formControlModels/formControl.model";
+import {FormGeneralErrorsService} from "../formGeneralErrors/formGeneralErrors.service";
+
+
+export interface PopupModel {
+ type : PopupType;
+ uuidData : UUIDData;
+ node : ITreeNode;
+ isUpdateMode : boolean;
+}
+
+export enum PopupType{
+ SERVICE = 'service',
+ VNF = 'vnf',
+ NETWORK = 'network',
+ VF_MODULE = 'vf_module',
+ VNF_GROUP = 'vnf_group'
+}
+
+
+@Component({
+ selector : 'generic-form-popup',
+ templateUrl : 'generic-form-popup.component.html',
+ styleUrls : ['generic-form-popup.component.scss']
+})
+
+export class GenericFormPopupComponent extends DialogComponent<PopupModel, boolean> implements OnInit, OnDestroy{
+ formPopupDetails : FormPopupDetails = null;
+ dynamicForm : FormGroup;
+ type : PopupType;
+ uuidData : UUIDData;
+ isUpdateMode : boolean;
+ node : ITreeNode = null;
+ hasGeneralApiError : boolean = false;
+ parentElementClassName = 'content';
+ errorMsg = 'Page contains errors. Please see details next to the relevant fields.';
+
+ servicesQty = 1;
+ quantityOptions = _.range(1, 51)
+ constructor(dialogService: DialogService ,
+ private _iframeService : IframeService,
+ private _store: NgRedux<AppState>,
+ private _servicePopupService : ServicePopupService,
+ private _activatedRoute : ActivatedRoute,
+ private _aaiService : AaiService,
+ private _route: ActivatedRoute,
+ private _genericFormPopupService : GenericFormPopupService){
+ super(dialogService);
+ }
+
+ closeDialog(that) : void{
+ this._iframeService.removeClassCloseModal(that.parentElementClassName);
+ this.dialogService.removeDialog(this);
+ setTimeout(() => {
+ window.parent.postMessage("closeIframe", "*");
+ }, 15);
+ }
+
+ shouldShowNotification() : boolean {
+ return this.formPopupDetails && this.formPopupDetails.UUIDData['bulkSize'] > 1
+ }
+
+ ngOnInit(): void {
+ this._route
+ .queryParams
+ .subscribe(params => {
+ console.log('changed');
+ if(params['serviceModelId'] && params['isCreate']=="true"){
+ this._genericFormPopupService.initReduxOnCreateNewService().then((serviceModelId : string)=>{
+ this.uuidData = <any>{
+ bulkSize : 1,
+ isMacro : this._store.getState().service.serviceHierarchy[serviceModelId].service.instantiationType === 'Macro',
+ type : PopupType.SERVICE,
+ serviceId: serviceModelId,
+ popupService: this._servicePopupService,
+ };
+
+ this.uuidData.popupService.closeDialogEvent.subscribe((that)=>{
+ this.closeDialog(that);
+ });
+
+ this.formPopupDetails = this.uuidData.popupService.getGenericFormPopupDetails(
+ this.uuidData['serviceId'],
+ null,
+ null,
+ this.node,
+ this.uuidData,
+ false
+ );
+ });
+ }
+ });
+
+ FormGeneralErrorsService.checkForErrorTrigger.subscribe(()=>{
+ this.hasSomeError(this.formPopupDetails, this.dynamicForm);
+ });
+
+ if(!_.isNil(this.uuidData)){
+ this.uuidData.popupService.closeDialogEvent.subscribe((that)=>{
+ this.closeDialog(that);
+ });
+
+ this.uuidData['isMacro'] = this._store.getState().service.serviceHierarchy[this.uuidData['serviceId']].service.instantiationType === 'Macro';
+ this.formPopupDetails = this._genericFormPopupService.getGenericFormDetails(this.uuidData, this.node, this.isUpdateMode);
+ }
+ }
+
+ hasSomeError(formPopupDetails : FormPopupDetails, form : FormGroup) : boolean{
+ if(_.isNil(formPopupDetails)) return false;
+ else {
+ for(let controlName in form.controls){
+ if(form.controls[controlName].errors){
+ let error: string[] = Object.keys(form.controls[controlName].errors);
+ if(error.length === 1 && error[0] === 'required'){
+ continue;
+ }else if(Object.keys(form.controls[controlName].errors).length > 0 ){
+ return true;
+ }
+ }
+ }
+ }
+
+ return formPopupDetails.formControlList.filter((item : FormControlModel) =>item.type === 'DROPDOWN' && item['hasEmptyOptions']).length > 0
+ }
+}
+
+
+export class UUIDData extends Object{
+ type : string;
+ popupService : any;
+}
+