summaryrefslogtreecommitdiffstats
path: root/usecaseui-portal/src/app/views/services/sotn-management/order-service/order-service.component.ts
blob: 1cfd00fd735f1d91cb94c021ca83e5082a50e8da (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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
import { Component, OnInit, Output, EventEmitter } from '@angular/core';
import {
  FormBuilder,  
  FormGroup,
  Validators
} from '@angular/forms';
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { NzMessageService } from 'ng-zorro-antd';
import { baseUrl } from '../../../../datainterface';

@Component({
  selector: 'app-order-service',
  templateUrl: './order-service.component.html',
  styleUrls: ['./order-service.component.less']
})
export class OrderServiceComponent implements OnInit {

  validateForm: FormGroup;
  l2vpn:object = {};
  siteData:object = {};
  buttonDisabled:boolean = false;
  intervalData:any;
  baseUrl = baseUrl.baseUrl
  expandDataSet = [
    { rowIdx: 1, name: 'i18nTextDefine_serviceInformation', expand: true },
    { rowIdx: 2, name: 'i18nTextDefine_vpnInformation', expand: true },
    { rowIdx: 3, name: 'i18nTextDefine_uniInformation', expand: true }
  ];
  uni = {};
  sotnUni = [];
  
  @Output() childEvent = new EventEmitter<string>();

  constructor(private fb: FormBuilder, private http: HttpClient, private message: NzMessageService) { }

  ngOnInit() {
    this.validateForm = this.fb.group({
      name:[null, [Validators.required]],
      description:[null, [Validators.required]],
      l2vpn_name:[null, [Validators.required]],
      l2vpn_dualLink:[null, [Validators.required]],
      l2vpn_description:[null, [Validators.required]],
      l2vpn_SLS:[null, [Validators.required]],
      l2vpn_COS:[null, [Validators.required]],
      l2vpn_tenantId:[null, [Validators.required]],
      l2vpn_vpnType:[null, [Validators.required]],
      l2vpn_cbs:[null, [Validators.required]],
      l2vpn_ebs:[null, [Validators.required]],
      l2vpn_colorAware:[null, [Validators.required]],
      l2vpn_reroute:[null, [Validators.required]],
      l2vpn_couplingFlag:[null, [Validators.required]],
      l2vpn_cir:[null, [Validators.required]],
      l2vpn_eir:[null, [Validators.required]],
      l2vpn_startTime:[null, [Validators.required]],
      l2vpn_endTime:[null, [Validators.required]],
      sotnuni_cVLAN:[null, [Validators.required]],
      sotnuni_tpId:[null, [Validators.required]],
    });
  }

  
  numberOnly(event): boolean {
    const charCode = (event.which) ? event.which : event.keyCode;
    if (charCode > 31 && (charCode < 48 || charCode > 57)) {
        }
    return true;
  }

  addUNI () {
    if(this.uni['sotnuni_cVLAN'] == undefined || this.uni['sotnuni_tpId'] == undefined) {
      this.message.error("Please enter cVLAN & TPID first.");
      return;
    }
    this.sotnUni.push(this.uni);
    this.uni = {};
  }

  deletesotnUni(data) {
    for(let i = 0; i < this.sotnUni.length; i++) {
      if(data.sotnuni_tpId == this.sotnUni[i].sotnuni_tpId) {
        this.sotnUni.splice(i, 1); 
      }
    }
  }

  selectOrderSiteData(): void {
    if (!this.validateVpnAndUni() ||
      !this.validateServices() ) {
      this.message.error("Please fill all mandatory fields");
    } else {
      this.siteData["l2vpn"] = [this.l2vpn];
      this.siteData["sotnUni"] = this.sotnUni;
      this.putnewSotnSiteData()
    }
  }

  validateServices (): boolean {
    if (this.siteData["name"] == null ||
      this.siteData["description"] == null) {
        return false;
    }
    return true;
  }

  validateVpnAndUni (): boolean {
    if (this.l2vpn["l2vpn_COS"] == null ||
      this.l2vpn["l2vpn_dualLink"] == null ||
      this.l2vpn["l2vpn_description"] == null ||
      this.l2vpn["l2vpn_name"] == null ||
      this.l2vpn["l2vpn_tenantId"] == null ||
      this.l2vpn["l2vpn_vpnType"] == null ||
      this.l2vpn["l2vpn_cbs"] == null ||
      this.l2vpn["l2vpn_ebs"] == null ||
      this.l2vpn["l2vpn_colorAware"] == null ||
      this.l2vpn["l2vpn_cir"] == null ||
      this.l2vpn["l2vpn_startTime"] == null ||
      this.l2vpn["l2vpn_endTime"] == null ||
      this.l2vpn["l2vpn_eir"] == null ||
      this.l2vpn["l2vpn_SLS"] == null ||
      this.sotnUni.length == 0 ||
      this.l2vpn["l2vpn_reroute"] == null) {
        return false;
    }
    // for (const i in this.validateForm.controls) {
    //   this.validateForm.controls[i].markAsDirty();
    //   this.validateForm.controls[i].updateValueAndValidity();
    // }
    return true;
  }

  putnewSotnSiteData() {
    console.log("order service data===>", this.siteData)
    let comp = this;
    this.message.info('Instantiation In Progress');
    this.buttonDisabled = true;
    let body = JSON.stringify(this.siteData);
    const httpOptions = {
      headers: new HttpHeaders({
       'Content-Type': 'application/json',
      })
    };
    
    let url1 = this.baseUrl + '/uui-lcm/Sotnservices_unni';
    this.http.post<any>(url1, body, httpOptions).subscribe((data) => { 
      let comp = this;
      this.message.info('Instantiation In Progress');
      this.intervalData = setInterval(() => {
        const httpOptions1 = {
          headers: new HttpHeaders({
           'Content-Type': 'application/json',
          })
        };
        let url2 = this.baseUrl + "/uui-lcm/Sotnservices/serviceStatus/service-instance/" + data.service.serviceId;
        this.http.get<any>(url2, httpOptions1).subscribe((data) => {
          if (data.status == "1") {
            clearInterval(comp.intervalData);
            comp.message.success('Service Created');
            comp.goToPage();
          }
          else {
            comp.message.info('Instantiation In Progress');
          }
        }, (err) => {
          console.log(err);
        });
      }, 1000);
    }, (err) => {
      console.log(err);
    });
    setTimeout(() => {
      comp.message.success("Service Created");
      comp.goToPage.call(comp);
    }, 3000);
  }

  goToPage(): void {
    var comb = this;
    setTimeout(function () {
      comb.childEvent.emit();
    }, 1000);
  }

}