4d3c79724aee27a418ab2155df9733447ec55caf
[usecase-ui.git] /
1 import { Component, EventEmitter, Input, OnInit, Output } from "@angular/core";
2 import { COMMUNICATION_FORM_ITEMS } from "./constants";
3 import { Util } from "../../../../../shared/utils/utils";
4 import { SlicingTaskServices } from "../../../../../core/services/slicingTaskServices";
5 import { NzMessageService } from "ng-zorro-antd";
6
7 @Component({
8         selector: "app-business-order",
9         templateUrl: "./business-order.component.html",
10         styleUrls: ["./business-order.component.less"],
11 })
12 export class BusinessOrderComponent implements OnInit {
13         constructor(
14                 private myhttp: SlicingTaskServices,
15                 private message: NzMessageService,
16                 private Util: Util
17         ) {}
18
19         ngOnInit() {}
20
21         ngOnChanges() {
22                 this.AreaFormatting();
23         }
24
25         @Input() showModel: boolean;
26         @Output() cancel = new EventEmitter<boolean>();
27         comunicationFormItems = COMMUNICATION_FORM_ITEMS;
28         slicing_order_info = {
29                 name: null,
30                 maxNumberofUEs: null,
31                 expDataRateDL: null,
32                 latency: null,
33                 expDataRateUL: null,
34                 resourceSharingLevel: "shared",
35                 uEMobilityLevel: "stationary",
36                 coverageArea: "",
37                 coverageAreaNumber: null,
38         };
39         areaList: any[] = [];
40         validateRulesShow: any[] = [];
41         rulesText: any[] = [];
42         areaLevel: number = 4;
43
44         AreaFormatting(): void {
45                 let areaList = ["Beijing;Beijing;Haidian District;Wanshoulu Street"];
46                 this.areaList = areaList.map((item: any) => {
47                         let arr = item.split(";");
48                         item = arr.map((it, index) => {
49                                 let key: string;
50                                 if (!index) {
51                                         key = "province";
52                                 } else if (index === 1) {
53                                         key = "city";
54                                 } else if (index === 2) {
55                                         key = "district";
56                                 } else {
57                                         key = "street";
58                                 }
59                                 const obj: any = {};
60                                 obj.key = key;
61                                 obj.selected = it;
62                                 obj.options = [{ name: it, id: it }];
63                                 return obj;
64                         });
65                         return item;
66                 });
67         }
68
69         handleCancel(): void {
70                 this.showModel = false;
71                 this.cancel.emit(this.showModel);
72                 this.slicing_order_info = {
73                         name: null,
74                         maxNumberofUEs: null,
75                         expDataRateDL: null,
76                         latency: null,
77                         expDataRateUL: null,
78                         resourceSharingLevel: "shared",
79                         uEMobilityLevel: "stationary",
80                         coverageArea: "",
81                         coverageAreaNumber: null,
82                 };
83                 this.validateRulesShow = [];
84         }
85
86         handleOk(): void {
87                 const coverage_list: string[] = [];
88                 let coverageAreas;
89
90                 COMMUNICATION_FORM_ITEMS.forEach((item, index) => {
91                         if (item.required && item.type === "input") {
92                                 this.Util.validator(
93                                         item.title,
94                                         item.key,
95                                         this.slicing_order_info[item.key],
96                                         index,
97                                         this.rulesText,
98                                         this.validateRulesShow
99                                 );
100                         }
101                 });
102                 if (this.validateRulesShow.indexOf(true) > -1) {
103                         return;
104                 }
105
106                 this.areaList.forEach((item) => {
107                         let str = "";
108                         item.forEach((area) => {
109                                 str += area.selected + ";";
110                         });
111                         coverage_list.push(str.substring(0, str.length - 1));
112                 });
113                 if (coverage_list.length > 1) {
114                         coverageAreas = coverage_list.join("|");
115                 } else {
116                         coverageAreas = coverage_list.toString();
117                 }
118                 const coverageAreaNumber = this.slicing_order_info[
119                         "coverageAreaNumber"
120                 ];
121                 if (coverageAreaNumber) {
122                         this.slicing_order_info.coverageArea = `${coverageAreas}-${coverageAreaNumber}`;
123                 } else {
124                         this.slicing_order_info.coverageArea = `${coverageAreas}`;
125                 }
126                 delete this.slicing_order_info.coverageAreaNumber;
127
128                 const paramsObj = {
129                         slicing_order_info: this.slicing_order_info,
130                 };
131                 const csmfSlicingPurchaseFailedCallback = () => {
132                         this.handleCancel();
133                 };
134                 this.myhttp
135                         .csmfSlicingPurchase(paramsObj, csmfSlicingPurchaseFailedCallback)
136                         .then((res) => {
137                                 const result = res.result_header;
138                                 if (
139                                         result &&
140                                         result.result_code &&
141                                         +result.result_code === 200
142                                 ) {
143                                         console.log(res);
144                                 } else {
145                                         this.message.create("error", "Network error");
146                                 }
147                                 this.handleCancel();
148                         });
149         }
150 }