8 } from "@angular/core";
9 import { TRANSFRER_FORM_ITEMS, CORE_FORM_ITEMS } from "./constants";
10 import { NzMessageService } from "ng-zorro-antd";
11 import { stringify } from "@angular/core/src/util";
12 import { Util } from "../../../../../../shared/utils/utils";
13 import { SlicingTaskServices } from "@src/app/core/services/slicingTaskServices";
16 selector: "app-subnet-params-model",
17 templateUrl: "./subnet-params-model.component.html",
18 styleUrls: ["./subnet-params-model.component.less"],
20 export class SubnetParamsModelComponent implements OnInit {
21 @Input() showModel: boolean;
22 @Input() detailData: any;
23 @Input() title: string;
24 @Output() cancel = new EventEmitter<boolean>();
25 @Output() paramsDataChange = new EventEmitter<any>();
26 @Output() noPassParaChange = new EventEmitter<any>();
28 transferFormItems: any[] = TRANSFRER_FORM_ITEMS;
29 regxpIP = /^((2[0-4]\d|25[0-5]|[01]?\d\d?)\.){3}(2[0-4]\d|25[0-5]|[01]?\d\d?)$/; // check for correct ip address
31 coreFormItems: any = [];
33 areaLevel: number = 3;
34 ANEndpointInputs: object = {};
35 CNEndpointInputs: object = {};
36 ANkeyList: string[] = [];
37 CNkeyList: string[] = [];
38 EndpointEnable: boolean = false; // Whether to enable the three parameters of Endpoint
39 keyList: string[] = []; // keys of endPoint
40 specialParaTN: string[] = [
41 "Resource Sharing Level",
46 // Parameters not passed to the back end
47 notPassPara: string[] = ["tn_connection_links"];
48 connectionLinkTable: any[] = [];
49 connectionTableHeader: string[] = [];
50 objectKeys = Object.keys;
51 // Comment: Above code
54 private message: NzMessageService,
56 private http: SlicingTaskServices
63 this.formData = JSON.parse(JSON.stringify(this.detailData));
64 if (this.title === "An" || this.title === "Cn") {
71 } else if (this.title === "Tn") {
72 this.getConnectionLinkTable();
73 this.ANkeyList = this.transferFormItems
75 return item.title === "AN Endpoint";
77 .options.map((val) => {
80 this.CNkeyList = this.transferFormItems
82 return item.title === "CN Endpoint";
84 .options.map((val) => {
87 this.keyList = this.ANkeyList.concat(this.CNkeyList);
89 typeof this.formData !== "undefined" &&
90 Object.keys(this.formData).length !== 0
92 this.EndpointEnable = this.keyList.every((item) => {
93 return this.formData.hasOwnProperty(item);
96 if (this.EndpointEnable) {
97 this.ANEndpointInputs = this.Util.pick(
101 this.CNEndpointInputs = this.Util.pick(
106 this.transferFormItems.map((item, index) => {
108 item.title === "AN Endpoint" ||
109 item.title === "CN Endpoint"
111 this.transferFormItems.splice(index, 1);
116 // If the endpoint related parameters from the back end are incomplete, delete the endpoint item
117 //-------> Comment: Above code
118 if (this.title === "An") {
119 this.AreaFormatting();
125 this.connectionLinkTable.forEach((item) => {
127 item.hasOwnProperty("linkId") &&
128 typeof this.formData["tn_connection_links"] !== "undefined" &&
129 this.formData["tn_connection_links"] !== "" &&
130 this.formData["tn_connection_links"] !== null &&
131 item["linkId"] === this.formData["tn_connection_links"]
135 item.checked = false;
140 changeResourceShare() {
145 if (Object.prototype.toString.call(val) === "[object Object]") {
152 getConnectionLinkTable(): void {
154 .getConnectionLinkTable(this.getConnetionFailed)
156 this.connectionLinkTable =
157 res.result_body.connection_links_list;
158 this.addCheckStatus(); // add init check status for connection link table
159 this.judgeTn(); // init judge
160 this.getTableHeader();
164 getTableHeader(): void {
165 // Find the common key of all data
166 let keyList: any[] = this.connectionLinkTable.map((item) => {
167 return Object.keys(item);
169 this.connectionTableHeader = this.Util.intersection(keyList).filter(
171 return item !== "checked";
174 // Filter redundant items in table data
175 this.connectionLinkTable.forEach((item) => {
176 for (let key in item) {
180 this.connectionTableHeader.indexOf(key) === -1
184 // Filter out the null values in each item
185 for (let i in item[key]) {
188 (item[key][i] === "" ||
189 item[key][i] === "null" ||
190 item[key][i] === null)
200 getConnetionFailed() {
201 console.log("failed");
206 this.formData["sliceProfile_TN_resourceSharingLevel"] ===
209 this.connectionLinkTable.forEach((item) => {
210 item.checked = false;
212 this.formData["tn_connection_links"] = null;
213 this.notPassPara = ["tn_connection_links"];
214 this.transferFormItems.forEach((item) => {
215 if (item.title === "Connection Links") {
218 item.title === "AN Endpoint" ||
219 item.title === "CN Endpoint"
221 item.required = true;
222 item.disable = false;
226 this.formData["sliceProfile_TN_resourceSharingLevel"] === "shared"
228 this.transferFormItems.forEach((item) => {
229 if (item.title === "Connection Links") {
230 item.disable = false;
232 item.title === "AN Endpoint" ||
233 item.title === "CN Endpoint"
236 typeof this.formData["tn_connection_links"] !==
238 this.formData["tn_connection_links"] !== null &&
239 this.formData["tn_connection_links"] !== ""
242 item.required = false;
243 this.notPassPara = [];
244 this.notPassPara = this.notPassPara.concat(
250 this.formData["tn_connection_links"] = "";
251 item.disable = false;
252 item.required = true;
253 this.notPassPara = [];
260 validateEndPoint(key: string, value: any, required: boolean): string {
262 if (this.Util.isEmpty(value)) {
263 return "can not be empty";
266 if (key === "ip_address") {
267 if (!this.regxpIP.test(value)) {
269 return "xxx.xxx.xxx.xxx";
276 } else if (key === "logical_link") {
277 if (!this.Util.isInteger(value)) {
279 return "integer only";
291 changeLinkCheck(id: string): void {
292 // update the selection state
293 this.connectionLinkTable.forEach((item) => {
294 if (item["linkId"] === id) {
297 item.checked = false;
300 this.formData["tn_connection_links"] = id; // get the selected id
305 let areaList = [...this.formData.an_coverage_area_ta_list];
306 this.areaList = areaList.map((item: any) => {
307 let arr = item.split(";");
308 item = arr.map((ite, index) => {
312 } else if (index === 1) {
320 obj.options = [{ name: ite, id: ite }];
327 handleCancel(): void {
328 this.showModel = false;
329 this.cancel.emit(this.showModel);
332 // special handling for address
333 areaCheckBeforeSubmit(target: object): Boolean {
334 for (const prop in target) {
335 if (target.hasOwnProperty(prop)) {
337 prop === "an_coverage_area_ta_list" ||
338 prop === "cn_coverage_area_ta_list"
340 // if the vlaue is "shanghai;shanghai;", the input is incomplete
341 return target[prop].every((item) => {
342 return this.Util.deepCheck(item.split(";"));
350 endCheckBeforeSubmit(endpoint, required): Array<any> {
351 // check params of Endpoint
352 let result: Array<any> = [true, ""];
354 endPointList = this.transferFormItems.find((item) => {
355 return item.title === "AN Endpoint";
360 for (let item of endPointList) {
361 if (item.title === "ip_address") {
363 } else if (item.title === "logical_link") {
364 logicalKey = item.key;
365 } else if (item.title === "nexthop_info") {
369 for (let prop in endpoint) {
370 if (prop === ipKey) {
372 if (endpoint[prop] === "") {
373 result = [false, "Endpoint can not be empty"];
374 } else if (!this.regxpIP.test(endpoint[prop])) {
375 result = [false, "Illegal IpAddress"];
378 !this.regxpIP.test(endpoint[prop]) &&
379 endpoint[prop] !== ""
381 result = [false, "Illegal IpAddress"];
383 } else if (prop === logicalKey) {
385 if (endpoint[prop] === "") {
386 result = [false, "logical can not be empty"];
387 } else if (!this.Util.isInteger(endpoint[prop])) {
388 result = [false, "LogicalID can only be an integer"];
391 !this.Util.isInteger(endpoint[prop]) &&
392 endpoint[prop] !== ""
394 result = [false, "LogicalID can only be an integer"];
396 } else if (prop === nextKey) {
397 if (required && endpoint[prop] === "") {
398 result = [false, "Endpoint can not be empty"];
405 inputHolder(title: string): string {
406 const titleArr = title.split(" ");
407 if (titleArr.length > 1) {
408 return titleArr.slice(0, 2).join("");
414 labelStyle(required: boolean): object {
417 style = { "margin-left": "18px", "margin-right": "-18px" };
425 // Verify that items of EndPoint is correct
426 if (this.EndpointEnable) {
427 let endCheckResult = [];
428 if (this.title === "Tn") {
429 const ANendCheckResult = this.endCheckBeforeSubmit(
430 this.ANEndpointInputs,
431 this.transferFormItems.find((item) => {
432 return item.title === "AN Endpoint";
435 const CNendCheckResult = this.endCheckBeforeSubmit(
436 this.CNEndpointInputs,
437 this.transferFormItems.find((item) => {
438 return item.title === "CN Endpoint";
441 if (ANendCheckResult[0] && CNendCheckResult[0]) {
442 endCheckResult[0] = true;
444 if (ANendCheckResult[0] === false) {
445 endCheckResult = ANendCheckResult;
447 endCheckResult = CNendCheckResult;
451 if (!endCheckResult[0]) {
452 this.message.error(endCheckResult[1].toString());
455 // replace the params about endPoint
456 for (let prop in this.formData) {
458 this.title === "Tn" &&
459 typeof this.ANEndpointInputs[prop] !== "undefined"
461 this.formData[prop] = this.ANEndpointInputs[prop];
463 this.title === "Tn" &&
464 typeof this.CNEndpointInputs[prop] !== "undefined"
466 this.formData[prop] = this.CNEndpointInputs[prop];
471 if (this.title === "An") {
472 const an_coverage_area_ta_list: string[] = [];
473 this.areaList.forEach((item) => {
474 let str: string = "";
475 item.forEach((area) => {
476 str += area.selected + ";";
478 an_coverage_area_ta_list.push(str.substring(0, str.length - 1));
480 params = { ...this.formData, an_coverage_area_ta_list };
482 params = { ...this.formData };
484 // Verify that each item exclude endpoint is not empty, include special handeling of area_list
485 let checkParams: object = params;
486 let requireKeyList: string[] = [];
487 let targetFormItems: any[] = [];
488 if (this.title === "An" || this.title === "Cn") {
489 targetFormItems = this.coreFormItems;
490 } else if ((this.title = "Tn")) {
491 targetFormItems = this.transferFormItems;
493 for (let item of targetFormItems) {
494 if (typeof item.required !== "undefined" && item.required) {
496 typeof item.type !== "undefined" &&
497 item.type !== "endpoint"
499 requireKeyList.push(item.key);
503 checkParams = this.Util.pick(params, requireKeyList);
505 this.Util.deepCheck(checkParams) &&
506 this.areaCheckBeforeSubmit(params)
508 this.paramsDataChange.emit(params);
509 this.noPassParaChange.emit(this.notPassPara);
512 this.message.error("Please complete the form");