3848ffbba04fed49f1432939c01c89231ad299c0
[usecase-ui.git] /
1 import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
2 import { Util } from '../../../shared/utils/utils';
3
4 @Component({
5   selector: 'app-input-intent-expectation',
6   templateUrl: './input-intent-expectation.component.html',
7   styleUrls: ['../intent-management.component.less']
8 })
9 export class InputIntentExpectationComponent implements OnInit {
10
11   constructor(
12     private Util: Util
13   ) { }
14
15   @Input() showModel: boolean;
16   @Output() modalOpreation = new EventEmitter();
17   @Input() editExpectationTableData;
18
19   defaultParams:Object={
20     expectationId:'',
21     expectationName:'',
22     expectationType:'DELIVERY',
23     expectationObject:{
24       objectType:'CLL_VPN',
25       objectInstance:'',
26     },
27     expectationTargets:[]
28   };
29   currentIndex:number = -1;
30
31   listOfData: any[] = [];
32
33   intentTargetShow: boolean = false;
34   editTargetTableList: Object={};
35
36   expectationTypeList: any[] = [];
37   expectationObjectTypeList: any[] = [];
38
39   ngOnInit() {
40     this.expectationTypeList = [
41       { label:'DELIVERY', value:'DELIVERY' },
42       { label:'ASSURANCE', value:'ASSURANCE' }
43     ]
44     this.expectationObjectTypeList = [
45       { label:'CLL_VPN', value:'CLL_VPN' }
46     ]
47   }
48
49   ngOnChanges() {
50     if (this.showModel) {
51       if (JSON.stringify(this.editExpectationTableData)!=='{}') {
52         this.defaultParams=this.editExpectationTableData
53         this.listOfData=this.defaultParams['expectationTargets']
54       }
55     }
56         }
57
58   handleCancel(): void {
59     this.modalOpreation.emit({ "cancel": true });
60     this.clearExpectationData()
61   }
62   handleOk(): void {
63     if(JSON.stringify(this.editExpectationTableData)==='{}'){
64       this.defaultParams['expectationId']=this.Util.getUuid()
65     }
66     this.modalOpreation.emit({ "cancel": false, "param": this.defaultParams });
67     this.clearExpectationData()
68   }
69   editTargetList(data,i): void {
70     this.editTargetTableList=JSON.parse(JSON.stringify(data))
71     this.currentIndex=i
72     this.intentTargetShow = true
73   }
74   deleteTargetList(i): void{
75     this.listOfData.splice(i,1)
76   }
77   clearExpectationData(): void{
78     this.showModel = false;
79     this.defaultParams = {
80       expectationId:'',
81       expectationName:'',
82       expectationType:'DELIVERY',
83       expectationObject:{
84         objectType:'CLL_VPN',
85         objectInstance:'',
86       },
87       expectationTargets:[]
88     };
89     this.listOfData=[]
90   }
91   inputIntentTargetShow(): void {
92     this.intentTargetShow = true;
93   }
94   inputIntentStateClose($event: any): void {
95     this.intentTargetShow = false;
96     this.editTargetTableList={}
97     if ($event.cancel) {
98         return;
99     }
100     if(this.currentIndex>-1){
101       this.listOfData[this.currentIndex]=$event.param
102       this.currentIndex=-1
103     }else{
104       this.listOfData.push($event.param)
105     }
106     this.defaultParams['expectationTargets']=this.listOfData
107   }
108
109 }