summaryrefslogtreecommitdiffstats
path: root/usecaseui-portal/src/app/views/services/slicing-management/csmf-slicing-business-management/business-order/business-order.component.ts
blob: 2418c904c8e3509fd3d5659c33f43945cb33161a (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
import { Component, EventEmitter, Input, OnInit, Output } from "@angular/core";
import { COMMUNICATION_FORM_ITEMS,MASKTEXT } from "./constants";
import { Util } from "../../../../../shared/utils/utils";
import { SlicingTaskServices } from "../../../../../core/services/slicingTaskServices";
import { NzMessageService } from "ng-zorro-antd";

@Component({
	selector: "app-business-order",
	templateUrl: "./business-order.component.html",
	styleUrls: ["./business-order.component.less"],
})
export class BusinessOrderComponent implements OnInit {
	constructor(
		private myhttp: SlicingTaskServices,
		private message: NzMessageService,
		private Util: Util
	) {}

	ngOnInit() {}

	ngOnChanges() {
		this.AreaFormatting();
	}
    detailFn(flag){
	  COMMUNICATION_FORM_ITEMS.forEach((item, index) => {
		  if(item.key=='coverageAreaNumber'){
			item["coverflag"] = flag == true ? false:true
		  }
	  })
	}

	@Input() showModel: boolean;
	@Output() cancel = new EventEmitter<boolean>();
	comunicationFormItems = COMMUNICATION_FORM_ITEMS;
	slicing_order_info = {
		name: null,
		maxNumberofUEs: null,
		expDataRateDL: null,
		latency: null,
		expDataRateUL: null,
		resourceSharingLevel: "shared",
		uEMobilityLevel: "stationary",
		coverageArea: "",
		coverageAreaNumber: null,
	};
	areaList: any[] = [];
	validateRulesShow: any[] = [];
	rulesText: any[] = [];
	areaLevel: number = 4;
    masktext: string = MASKTEXT ;
	AreaFormatting(): void {
		let areaList = ["Beijing;Beijing;Haidian District;Wanshoulu Street"];
		this.areaList = areaList.map((item: any) => {
			let arr = item.split(";");
			item = arr.map((it, index) => {
				let key: string;
				if (!index) {
					key = "province";
				} else if (index === 1) {
					key = "city";
				} else if (index === 2) {
					key = "district";
				} else {
					key = "street";
				}
				const obj: any = {};
				obj.key = key;
				obj.selected = it;
				obj.options = [{ name: it, id: it }];
				return obj;
			});
			return item;
		});
	}

	handleCancel(): void {
		this.showModel = false;
		this.cancel.emit(this.showModel);
		this.slicing_order_info = {
			name: null,
			maxNumberofUEs: null,
			expDataRateDL: null,
			latency: null,
			expDataRateUL: null,
			resourceSharingLevel: "shared",
			uEMobilityLevel: "stationary",
			coverageArea: "",
			coverageAreaNumber: null,
		};
		this.validateRulesShow = [];
	}

	handleOk(): void {
		const coverage_list: string[] = [];
		let coverageAreas;

		COMMUNICATION_FORM_ITEMS.forEach((item, index) => {
			if (item.required && item.type === "input") {
				this.Util.validator(
					item.title,
					item.key,
					this.slicing_order_info[item.key],
					index,
					this.rulesText,
					this.validateRulesShow
				);
			}
		});
		if (this.validateRulesShow.indexOf(true) > -1) {
			return;
		}

		this.areaList.forEach((item) => {
			let str = "";
			item.forEach((area) => {
				str += area.selected + ";";
			});
			coverage_list.push(str.substring(0, str.length - 1));
		});
		if (coverage_list.length > 1) {
			coverageAreas = coverage_list.join("|");
		} else {
			coverageAreas = coverage_list.toString();
		}
		const coverageAreaNumber = this.slicing_order_info[
			"coverageAreaNumber"
		];
		if (coverageAreaNumber) {
			this.slicing_order_info.coverageArea = `${coverageAreas}-${coverageAreaNumber}`;
		} else {
			this.slicing_order_info.coverageArea = `${coverageAreas}`;
		}
		delete this.slicing_order_info.coverageAreaNumber;

		const paramsObj = {
			slicing_order_info: this.slicing_order_info,
		};
		const csmfSlicingPurchaseFailedCallback = () => {
			this.handleCancel();
		};
		this.myhttp
			.csmfSlicingPurchase(paramsObj, csmfSlicingPurchaseFailedCallback)
			.then((res) => {
				const result = res.result_header;
				if (
					result &&
					result.result_code &&
					+result.result_code === 200
				) {
					console.log(res);
				} else {
					this.message.create("error", "Network error");
				}
				this.handleCancel();
			});
	}
}