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[] = [];
51 recordNum: number = 0;
52 hasPageNo: number[] = [];
53 objectKeys = Object.keys;
54 // Comment: Above code
57 private message: NzMessageService,
59 private http: SlicingTaskServices
66 this.formData = JSON.parse(JSON.stringify(this.detailData));
67 if (this.title === "An" || this.title === "Cn") {
74 } else if (this.title === "Tn") {
75 const pageNo = 1; // start from page 1
76 const pageSize = this.pageSize;
77 this.getConnectionLinkTable(pageNo, pageSize);
78 this.ANkeyList = this.transferFormItems
80 return item.title === "AN Endpoint";
82 .options.map((val) => {
85 this.CNkeyList = this.transferFormItems
87 return item.title === "CN Endpoint";
89 .options.map((val) => {
92 this.keyList = this.ANkeyList.concat(this.CNkeyList);
94 typeof this.formData !== "undefined" &&
95 Object.keys(this.formData).length !== 0
97 this.EndpointEnable = this.keyList.every((item) => {
98 return this.formData.hasOwnProperty(item);
101 if (this.EndpointEnable) {
102 this.ANEndpointInputs = this.Util.pick(
106 this.CNEndpointInputs = this.Util.pick(
111 this.transferFormItems.map((item, index) => {
113 item.title === "AN Endpoint" ||
114 item.title === "CN Endpoint"
116 this.transferFormItems.splice(index, 1);
121 // If the endpoint related parameters from the back end are incomplete, delete the endpoint item
122 //-------> Comment: Above code
123 if (this.title === "An") {
124 this.AreaFormatting();
130 this.connectionLinkTable.forEach((item) => {
132 item.hasOwnProperty("linkId") &&
133 typeof this.formData["tn_connection_links"] !== "undefined" &&
134 this.formData["tn_connection_links"] !== "" &&
135 this.formData["tn_connection_links"] !== null &&
136 item["linkId"] === this.formData["tn_connection_links"]
140 item.checked = false;
145 changeResourceShare() {
150 if (Object.prototype.toString.call(val) === "[object Object]") {
157 getConnectionLinkTable(pageNo, pageSize): void {
163 .getConnectionLinkTable(pageObj, this.getConnetionFailed)
167 this.connectionLinkTable =
168 res.result_body.connection_links_list;
169 this.recordNum = res.result_body.record_number;
170 // Use default value to occupy
171 let defaultItem: object = {};
172 if (this.connectionLinkTable.length !== 0) {
173 defaultItem = JSON.parse(
174 JSON.stringify(this.connectionLinkTable[0])
176 for (let key in defaultItem) {
177 if (!this.isObject(defaultItem[key])) {
178 defaultItem[key] = "";
181 // for (let i in defaultItem[key]) {
182 // defaultItem[key][i] = "";
186 for (let i = pageSize; i < this.recordNum; i++) {
187 this.connectionLinkTable.push(defaultItem);
190 this.hasPageNo = [1];
191 } else if (pageNo > 1) {
192 // delete the default page of the page and add the actual data of the page
193 const startIndex = pageSize * (pageNo - 1);
194 const endIndex = startIndex + pageSize - 1;
195 this.connectionLinkTable.splice(startIndex, pageSize);
196 const frontArr = this.connectionLinkTable.slice(
200 const backArr = this.connectionLinkTable.slice(startIndex);
201 this.connectionLinkTable = frontArr.concat(
202 res.result_body.connection_links_list,
206 this.hasPageNo.push(pageNo);
207 this.addCheckStatus(); // add init check status for connection link table
208 this.judgeTn(); // init judge
209 this.getTableHeader();
213 getTableHeader(): void {
214 // Find the common key of all data
215 let keyList: any[] = this.connectionLinkTable.map((item) => {
216 return Object.keys(item);
218 this.connectionTableHeader = this.Util.intersection(keyList).filter(
220 return item !== "checked";
223 // Filter redundant items in table data
224 this.connectionLinkTable.forEach((item) => {
225 for (let key in item) {
229 this.connectionTableHeader.indexOf(key) === -1
233 // Filter out the null values in each item
234 for (let i in item[key]) {
237 (item[key][i] === "" ||
238 item[key][i] === "null" ||
239 item[key][i] === null)
250 // judge whether there is data of the page, if not, request it from the back end
251 if (this.hasPageNo.indexOf(e) === -1) {
252 this.getConnectionLinkTable(e, this.pageSize);
255 getConnetionFailed() {
256 console.log("failed");
261 this.formData["sliceProfile_TN_resourceSharingLevel"] ===
264 this.connectionLinkTable.forEach((item) => {
265 item.checked = false;
267 this.formData["tn_connection_links"] = null;
268 this.notPassPara = ["tn_connection_links"];
269 this.transferFormItems.forEach((item) => {
270 if (item.title === "Connection Links") {
273 item.title === "AN Endpoint" ||
274 item.title === "CN Endpoint"
276 item.required = true;
277 item.disable = false;
281 this.formData["sliceProfile_TN_resourceSharingLevel"] === "shared"
283 this.transferFormItems.forEach((item) => {
284 if (item.title === "Connection Links") {
285 item.disable = false;
287 item.title === "AN Endpoint" ||
288 item.title === "CN Endpoint"
291 typeof this.formData["tn_connection_links"] !==
293 this.formData["tn_connection_links"] !== null &&
294 this.formData["tn_connection_links"] !== ""
297 item.required = false;
298 this.notPassPara = [];
299 this.notPassPara = this.notPassPara.concat(
305 this.formData["tn_connection_links"] = "";
306 item.disable = false;
307 item.required = true;
308 this.notPassPara = [];
315 validateEndPoint(key: string, value: any, required: boolean): string {
317 if (this.Util.isEmpty(value)) {
318 return "can not be empty";
321 if (key === "ip_address") {
322 if (!this.regxpIP.test(value)) {
324 return "xxx.xxx.xxx.xxx";
331 } else if (key === "logical_link") {
332 if (!this.Util.isInteger(value)) {
334 return "integer only";
346 changeLinkCheck(id: string): void {
347 // update the selection state
348 this.connectionLinkTable.forEach((item) => {
349 if (item["linkId"] === id) {
352 item.checked = false;
355 this.formData["tn_connection_links"] = id; // get the selected id
360 let areaList = [...this.formData.an_coverage_area_ta_list];
361 this.areaList = areaList.map((item: any) => {
362 let arr = item.split(";");
363 item = arr.map((ite, index) => {
367 } else if (index === 1) {
375 obj.options = [{ name: ite, id: ite }];
382 handleCancel(): void {
383 this.showModel = false;
384 this.cancel.emit(this.showModel);
387 // special handling for address
388 areaCheckBeforeSubmit(target: object): Boolean {
389 for (const prop in target) {
390 if (target.hasOwnProperty(prop)) {
392 prop === "an_coverage_area_ta_list" ||
393 prop === "cn_coverage_area_ta_list"
395 // if the vlaue is "shanghai;shanghai;", the input is incomplete
396 return target[prop].every((item) => {
397 return this.Util.deepCheck(item.split(";"));
405 endCheckBeforeSubmit(endpoint, required): Array<any> {
406 // check params of Endpoint
407 let result: Array<any> = [true, ""];
409 endPointList = this.transferFormItems.find((item) => {
410 return item.title === "AN Endpoint";
415 for (let item of endPointList) {
416 if (item.title === "ip_address") {
418 } else if (item.title === "logical_link") {
419 logicalKey = item.key;
420 } else if (item.title === "nexthop_info") {
424 for (let prop in endpoint) {
425 if (prop === ipKey) {
427 if (endpoint[prop] === "") {
428 result = [false, "Endpoint can not be empty"];
429 } else if (!this.regxpIP.test(endpoint[prop])) {
430 result = [false, "Illegal IpAddress"];
433 !this.regxpIP.test(endpoint[prop]) &&
434 endpoint[prop] !== ""
436 result = [false, "Illegal IpAddress"];
438 } else if (prop === logicalKey) {
440 if (endpoint[prop] === "") {
441 result = [false, "logical can not be empty"];
442 } else if (!this.Util.isInteger(endpoint[prop])) {
443 result = [false, "LogicalID can only be an integer"];
446 !this.Util.isInteger(endpoint[prop]) &&
447 endpoint[prop] !== ""
449 result = [false, "LogicalID can only be an integer"];
451 } else if (prop === nextKey) {
452 if (required && endpoint[prop] === "") {
453 result = [false, "Endpoint can not be empty"];
460 inputHolder(title: string): string {
461 const titleArr = title.split(" ");
462 if (titleArr.length > 1) {
463 return titleArr.slice(0, 2).join("");
469 labelStyle(required: boolean): object {
472 style = { "margin-left": "18px", "margin-right": "-18px" };
480 // Verify that items of EndPoint is correct
481 if (this.EndpointEnable) {
482 let endCheckResult = [];
483 if (this.title === "Tn") {
484 const ANendCheckResult = this.endCheckBeforeSubmit(
485 this.ANEndpointInputs,
486 this.transferFormItems.find((item) => {
487 return item.title === "AN Endpoint";
490 const CNendCheckResult = this.endCheckBeforeSubmit(
491 this.CNEndpointInputs,
492 this.transferFormItems.find((item) => {
493 return item.title === "CN Endpoint";
496 if (ANendCheckResult[0] && CNendCheckResult[0]) {
497 endCheckResult[0] = true;
499 if (ANendCheckResult[0] === false) {
500 endCheckResult = ANendCheckResult;
502 endCheckResult = CNendCheckResult;
506 if (!endCheckResult[0]) {
507 this.message.error(endCheckResult[1].toString());
510 // replace the params about endPoint
511 for (let prop in this.formData) {
513 this.title === "Tn" &&
514 typeof this.ANEndpointInputs[prop] !== "undefined"
516 this.formData[prop] = this.ANEndpointInputs[prop];
518 this.title === "Tn" &&
519 typeof this.CNEndpointInputs[prop] !== "undefined"
521 this.formData[prop] = this.CNEndpointInputs[prop];
526 if (this.title === "An") {
527 const an_coverage_area_ta_list: string[] = [];
528 this.areaList.forEach((item) => {
529 let str: string = "";
530 item.forEach((area) => {
531 str += area.selected + ";";
533 an_coverage_area_ta_list.push(str.substring(0, str.length - 1));
535 params = { ...this.formData, an_coverage_area_ta_list };
537 params = { ...this.formData };
539 // Verify that each item exclude endpoint is not empty, include special handeling of area_list
540 let checkParams: object = params;
541 let requireKeyList: string[] = [];
542 let targetFormItems: any[] = [];
543 if (this.title === "An" || this.title === "Cn") {
544 targetFormItems = this.coreFormItems;
545 } else if ((this.title = "Tn")) {
546 targetFormItems = this.transferFormItems;
548 for (let item of targetFormItems) {
549 if (typeof item.required !== "undefined" && item.required) {
551 typeof item.type !== "undefined" &&
552 item.type !== "endpoint"
554 requireKeyList.push(item.key);
558 checkParams = this.Util.pick(params, requireKeyList);
560 this.Util.deepCheck(checkParams) &&
561 this.areaCheckBeforeSubmit(params)
563 this.paramsDataChange.emit(params);
564 this.noPassParaChange.emit(this.notPassPara);
567 this.message.error("Please complete the form");