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[] = ["sliceProfile_TN_connection_links"];
48 connectionLinkTable: any[] = [];
49 connectionTableHeader: string[] = [];
51 recordNum: number = 0;
52 hasPageNo: number[] = [];
54 objectKeys = Object.keys;
55 // Comment: Above code
58 private message: NzMessageService,
60 private http: SlicingTaskServices
66 // It is excuted every time you open it
68 this.formData = JSON.parse(JSON.stringify(this.detailData));
69 if (this.title === "An" || this.title === "Cn") {
76 } else if (this.title === "Tn") {
77 const pageNo = 1; // start from page 1
78 const pageSize = this.pageSize;
79 this.getConnectionLinkTable(pageNo, pageSize);
80 this.ANkeyList = this.transferFormItems
82 return item.title === "AN Endpoint";
84 .options.map((val) => {
87 this.CNkeyList = this.transferFormItems
89 return item.title === "CN Endpoint";
91 .options.map((val) => {
94 this.keyList = this.ANkeyList.concat(this.CNkeyList);
96 typeof this.formData !== "undefined" &&
97 Object.keys(this.formData).length !== 0
99 this.EndpointEnable = this.keyList.every((item) => {
100 return this.formData.hasOwnProperty(item);
103 if (this.EndpointEnable) {
104 this.ANEndpointInputs = this.Util.pick(
108 this.CNEndpointInputs = this.Util.pick(
113 this.transferFormItems.map((item, index) => {
115 item.title === "AN Endpoint" ||
116 item.title === "CN Endpoint"
118 this.transferFormItems.splice(index, 1);
123 // If the endpoint related parameters from the back end are incomplete, delete the endpoint item
124 //-------> Comment: Above code
125 if (this.title === "An") {
126 this.AreaFormatting();
132 if(this.connectionLinkTable && this.connectionLinkTable.length>0){
133 this.connectionLinkTable.forEach((item) => {
135 item.hasOwnProperty("linkId") &&
136 typeof this.formData["sliceProfile_TN_connection_links"] !==
138 this.formData["sliceProfile_TN_connection_links"] !== "" &&
139 this.formData["sliceProfile_TN_connection_links"] !== null &&
141 this.formData["sliceProfile_TN_connection_links"]
145 item.checked = false;
151 // changeResourceShare() {
156 if (Object.prototype.toString.call(val) === "[object Object]") {
163 getConnectionLinkTable(pageNo, pageSize): void {
170 .getConnectionLinkTable(pageObj, this.getConnetionFailed)
175 this.connectionLinkTable =
176 res.result_body.connection_links_list;
177 this.recordNum = res.result_body.record_number;
178 // Use default value to occupy
179 // let defaultItem: object = {};
180 // if (this.connectionLinkTable.length !== 0) {
181 // defaultItem = JSON.parse(
182 // JSON.stringify(this.connectionLinkTable[0])
184 // for (let key in defaultItem) {
185 // if (!this.isObject(defaultItem[key])) {
186 // defaultItem[key] = "";
189 // // for (let i in defaultItem[key]) {
190 // // defaultItem[key][i] = "";
194 // for (let i = pageSize; i < this.recordNum; i++) {
195 // this.connectionLinkTable.push(defaultItem);
198 this.hasPageNo = [1];
199 } else if (pageNo > 1) {
200 // delete the default page of the page and add the actual data of the page
201 // const startIndex = pageSize * (pageNo - 1);
202 // const endIndex = startIndex + pageSize - 1;
203 // this.connectionLinkTable.splice(startIndex, pageSize);
204 // const frontArr = this.connectionLinkTable.slice(
208 // const backArr = this.connectionLinkTable.slice(startIndex);
209 // this.connectionLinkTable = frontArr.concat(
210 // res.result_body.connection_links_list,
213 this.connectionLinkTable =
214 res.result_body.connection_links_list;
215 this.recordNum = res.result_body.record_number;
217 this.hasPageNo.push(pageNo);
218 this.addCheckStatus(); // add init check status for connection link table
219 this.judgeTn(); // init judge
220 this.getTableHeader();
224 getTableHeader(): void {
225 // Find the common key of all data
226 if(this.connectionLinkTable && this.connectionLinkTable.length>0){
227 let keyList: any[] = this.connectionLinkTable.map((item) => {
228 return Object.keys(item);
230 this.connectionTableHeader = this.Util.intersection(keyList).filter(
232 return item !== "checked";
235 // Filter redundant items in table data
236 this.connectionLinkTable.forEach((item) => {
237 for (let key in item) {
241 this.connectionTableHeader.indexOf(key) === -1
245 // Filter out the null values in each item
246 for (let i in item[key]) {
249 (item[key][i] === "" ||
250 item[key][i] === "null" ||
251 item[key][i] === null)
263 // judge whether there is data of the page, if not, request it from the back end
264 // if (this.hasPageNo.indexOf(e) === -1) {
265 this.getConnectionLinkTable(e, this.pageSize);
268 getConnetionFailed() {
269 console.log("failed");
273 console.log('fprm',this.formData)
275 this.formData["sliceProfile_TN_resourceSharingLevel"] ===
276 "non-shared" || this.formData["sliceProfile_TN_resourceSharingLevel"]==null
279 // this.connectionLinkTable.forEach((item) => {
280 // item.checked = false;
282 // this.formData["sliceProfile_TN_connection_links"] = null;
283 this.notPassPara = ["sliceProfile_TN_connection_links"];
284 this.transferFormItems.forEach((item) => {
285 if (item.title === "Connection Links") {
288 item.title === "AN Endpoint" ||
289 item.title === "CN Endpoint"
291 item.required = true;
292 item.disable = false;
296 this.formData["sliceProfile_TN_resourceSharingLevel"] === "shared"
298 this.transferFormItems.forEach((item) => {
299 if (item.title === "Connection Links") {
300 item.disable = false;
302 item.title === "AN Endpoint" ||
303 item.title === "CN Endpoint"
306 typeof this.formData[
307 "sliceProfile_TN_connection_links"
309 this.formData["sliceProfile_TN_connection_links"] !==
311 this.formData["sliceProfile_TN_connection_links"] !== ""
314 item.required = false;
315 this.notPassPara = [];
316 this.notPassPara = this.notPassPara.concat(
322 this.formData["sliceProfile_TN_connection_links"] = "";
323 item.disable = false;
324 item.required = true;
325 this.notPassPara = [];
332 validateEndPoint(key: string, value: any, required: boolean): string {
334 if (this.Util.isEmpty(value)) {
335 return "can not be empty";
338 if (key === "ip_address") {
339 if (!this.regxpIP.test(value)) {
341 return "xxx.xxx.xxx.xxx";
348 } else if (key === "logical_link") {
349 if (!this.Util.isInteger(value)) {
351 return "integer only";
363 changeLinkCheck(id: string): void {
364 // update the selection state
365 this.connectionLinkTable.forEach((item) => {
366 if (item["linkId"] === id) {
369 item.checked = false;
372 this.formData["sliceProfile_TN_connection_links"] = id; // get the selected id
377 let areaList = [...this.formData.an_coverage_area_ta_list];
378 this.areaList = areaList.map((item: any) => {
379 let arr = item.split(";");
380 item = arr.map((ite, index) => {
384 } else if (index === 1) {
392 obj.options = [{ name: ite, id: ite }];
399 handleCancel(): void {
400 this.noPassParaChange.emit(this.notPassPara);
401 this.showModel = false;
402 this.cancel.emit(this.showModel);
405 // special handling for address
406 areaCheckBeforeSubmit(target: object): Boolean {
407 for (const prop in target) {
408 if (target.hasOwnProperty(prop)) {
410 prop === "an_coverage_area_ta_list" ||
411 prop === "cn_coverage_area_ta_list"
413 // if the vlaue is "shanghai;shanghai;", the input is incomplete
414 return target[prop].every((item) => {
415 return this.Util.deepCheck(item.split(";"));
423 endCheckBeforeSubmit(endpoint, required): Array<any> {
424 // check params of Endpoint
425 let result: Array<any> = [true, ""];
427 endPointList = this.transferFormItems.find((item) => {
428 return item.title === "AN Endpoint";
433 for (let item of endPointList) {
434 if (item.title === "ip_address") {
436 } else if (item.title === "logical_link") {
437 logicalKey = item.key;
438 } else if (item.title === "nexthop_info") {
442 for (let prop in endpoint) {
443 if (prop === ipKey) {
445 if (endpoint[prop] === "") {
446 result = [false, "Endpoint can not be empty"];
447 } else if (!this.regxpIP.test(endpoint[prop])) {
448 result = [false, "Illegal IpAddress"];
451 !this.regxpIP.test(endpoint[prop]) &&
452 endpoint[prop] !== ""
454 result = [false, "Illegal IpAddress"];
456 } else if (prop === logicalKey) {
458 if (endpoint[prop] === "") {
459 result = [false, "logical can not be empty"];
460 } else if (!this.Util.isInteger(endpoint[prop])) {
461 result = [false, "LogicalID can only be an integer"];
464 !this.Util.isInteger(endpoint[prop]) &&
465 endpoint[prop] !== ""
467 result = [false, "LogicalID can only be an integer"];
469 } else if (prop === nextKey) {
470 if (required && endpoint[prop] === "") {
471 result = [false, "Endpoint can not be empty"];
478 inputHolder(title: string): string {
479 const titleArr = title.split(" ");
480 if (titleArr.length > 1) {
481 return titleArr.slice(0, 2).join("");
487 labelStyle(required: boolean): object {
490 style = { "margin-left": "18px", "margin-right": "-18px" };
498 // Verify that items of EndPoint is correct
499 if (this.EndpointEnable) {
500 let endCheckResult = [];
501 if (this.title === "Tn") {
502 const ANendCheckResult = this.endCheckBeforeSubmit(
503 this.ANEndpointInputs,
504 this.transferFormItems.find((item) => {
505 return item.title === "AN Endpoint";
508 const CNendCheckResult = this.endCheckBeforeSubmit(
509 this.CNEndpointInputs,
510 this.transferFormItems.find((item) => {
511 return item.title === "CN Endpoint";
514 if (ANendCheckResult[0] && CNendCheckResult[0]) {
515 endCheckResult[0] = true;
517 if (ANendCheckResult[0] === false) {
518 endCheckResult = ANendCheckResult;
520 endCheckResult = CNendCheckResult;
524 if (!endCheckResult[0]) {
525 this.message.error(endCheckResult[1].toString());
528 // replace the params about endPoint
529 for (let prop in this.formData) {
531 this.title === "Tn" &&
532 typeof this.ANEndpointInputs[prop] !== "undefined"
534 this.formData[prop] = this.ANEndpointInputs[prop];
536 this.title === "Tn" &&
537 typeof this.CNEndpointInputs[prop] !== "undefined"
539 this.formData[prop] = this.CNEndpointInputs[prop];
544 if (this.title === "An") {
545 const an_coverage_area_ta_list: string[] = [];
546 this.areaList.forEach((item) => {
547 let str: string = "";
548 item.forEach((area) => {
549 str += area.selected + ";";
551 an_coverage_area_ta_list.push(str.substring(0, str.length - 1));
553 params = { ...this.formData, an_coverage_area_ta_list };
555 params = { ...this.formData };
557 // Verify that each item exclude endpoint is not empty, include special handeling of area_list
558 let checkParams: object = params;
559 let requireKeyList: string[] = [];
560 let targetFormItems: any[] = [];
561 if (this.title === "An" || this.title === "Cn") {
562 targetFormItems = this.coreFormItems;
563 } else if ((this.title = "Tn")) {
564 targetFormItems = this.transferFormItems;
566 for (let item of targetFormItems) {
567 if (typeof item.required !== "undefined" && item.required) {
569 typeof item.type !== "undefined" &&
570 item.type !== "endpoint"
572 requireKeyList.push(item.key);
576 checkParams = this.Util.pick(params, requireKeyList);
578 this.Util.deepCheck(checkParams) &&
579 this.areaCheckBeforeSubmit(params)
581 this.paramsDataChange.emit(params);
582 this.noPassParaChange.emit(this.notPassPara);
585 this.message.error("Please complete the form");