summaryrefslogtreecommitdiffstats
path: root/usecaseui-portal/src/app/views/intent-management/input-intent-state/input-intent-state.component.ts
blob: 5686b4f3d477b81d770279e03f2ca0ce3dd43b6c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
import { Component, EventEmitter, Input, OnInit, Output, ViewChild } from '@angular/core';
import { Util } from '../../../shared/utils/utils';

@Component({
  selector: 'app-input-intent-state',
  templateUrl: './input-intent-state.component.html',
  styleUrls: ['../intent-management.component.less']
})
export class InputIntentStateComponent implements OnInit {

  constructor(
    private Util: Util
  ) { }

  currentIndex:number = -1;
  listOfData: any[] = [];
  intentConditionShow: boolean = false;
  editConditionTableList: Object={};

  ngOnInit() {
    this.operatorList = [
      { label:'EQUALTO', value:'EQUALTO'},
      { label:'LARGETHAN', value:'LARGETHAN'},
      { label:'LESSTHAN', value:'LESSTHAN'}
    ]
    this.conditionType = 'value'
  }
  @Input() showModel: boolean;
  @Output() modalOpreation = new EventEmitter();
  @Input() editTargetTableData;

  defaultParams:Object={
    targetId:'',
    targetName:'',
    targetConditions:[]
  };

  operatorList: any[] = [];
  conditionType: string;

  ngOnChanges() {
    if (this.showModel) {
      if (JSON.stringify(this.editTargetTableData)!=='{}') {
        this.defaultParams=this.editTargetTableData
      }
    }
	}
  handleCancel(): void {
    this.modalOpreation.emit({ "cancel": true });
    this.clearTargetConditionData()
  }
  handleOk(): void {
    if(JSON.stringify(this.editTargetTableData)==='{}'){
      this.defaultParams['targetId']=this.Util.getUuid()
    }
    this.modalOpreation.emit({ "cancel": false, "param": this.defaultParams });
    this.clearTargetConditionData()
  }
  inputTargetConditionShow(): void {
    this.intentConditionShow = true;
  }
  inputIntentConditionClose($event: any): void {
    this.intentConditionShow = false;
    this.editConditionTableList={}
    if ($event.cancel) {
        return;
    }
    if(this.currentIndex>-1){
      this.listOfData[this.currentIndex]=$event.param
      this.currentIndex=-1
    }else{
      this.listOfData.push($event.param)
    }
    this.defaultParams['targetConditions']=this.listOfData
  }
  editConditionList(data,i): void {
    this.editConditionTableList=JSON.parse(JSON.stringify(data))
    this.currentIndex=i
    this.intentConditionShow = true
  }
  deleteConditionList(i): void{
    this.listOfData.splice(i,1)
  }
  clearTargetConditionData(): void{
    this.showModel = false;
    this.defaultParams = {
      targetId:'',
      targetName:'',
      targetConditions:[]
    };
    this.listOfData=[]
  }

}