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
65 // It is excuted every time you open it
67 this.formData = JSON.parse(JSON.stringify(this.detailData));
68 if (this.title === "An" || this.title === "Cn") {
75 } else if (this.title === "Tn") {
76 const pageNo = 1; // start from page 1
77 const pageSize = this.pageSize;
78 this.getConnectionLinkTable(pageNo, pageSize);
79 this.ANkeyList = this.transferFormItems
81 return item.title === "AN Endpoint";
83 .options.map((val) => {
86 this.CNkeyList = this.transferFormItems
88 return item.title === "CN Endpoint";
90 .options.map((val) => {
93 this.keyList = this.ANkeyList.concat(this.CNkeyList);
95 typeof this.formData !== "undefined" &&
96 Object.keys(this.formData).length !== 0
98 this.EndpointEnable = this.keyList.every((item) => {
99 return this.formData.hasOwnProperty(item);
102 if (this.EndpointEnable) {
103 this.ANEndpointInputs = this.Util.pick(
107 this.CNEndpointInputs = this.Util.pick(
112 this.transferFormItems.map((item, index) => {
114 item.title === "AN Endpoint" ||
115 item.title === "CN Endpoint"
117 this.transferFormItems.splice(index, 1);
122 // If the endpoint related parameters from the back end are incomplete, delete the endpoint item
123 //-------> Comment: Above code
124 if (this.title === "An") {
125 this.AreaFormatting();
131 this.connectionLinkTable.forEach((item) => {
133 item.hasOwnProperty("linkId") &&
134 typeof this.formData["tn_connection_links"] !== "undefined" &&
135 this.formData["tn_connection_links"] !== "" &&
136 this.formData["tn_connection_links"] !== null &&
137 item["linkId"] === this.formData["tn_connection_links"]
141 item.checked = false;
146 // changeResourceShare() {
151 if (Object.prototype.toString.call(val) === "[object Object]") {
158 getConnectionLinkTable(pageNo, pageSize): void {
164 .getConnectionLinkTable(pageObj, this.getConnetionFailed)
168 this.connectionLinkTable =
169 res.result_body.connection_links_list;
170 this.recordNum = res.result_body.record_number;
171 // Use default value to occupy
172 // let defaultItem: object = {};
173 // if (this.connectionLinkTable.length !== 0) {
174 // defaultItem = JSON.parse(
175 // JSON.stringify(this.connectionLinkTable[0])
177 // for (let key in defaultItem) {
178 // if (!this.isObject(defaultItem[key])) {
179 // defaultItem[key] = "";
182 // // for (let i in defaultItem[key]) {
183 // // defaultItem[key][i] = "";
187 // for (let i = pageSize; i < this.recordNum; i++) {
188 // this.connectionLinkTable.push(defaultItem);
191 this.hasPageNo = [1];
192 } else if (pageNo > 1) {
193 // delete the default page of the page and add the actual data of the page
194 // const startIndex = pageSize * (pageNo - 1);
195 // const endIndex = startIndex + pageSize - 1;
196 // this.connectionLinkTable.splice(startIndex, pageSize);
197 // const frontArr = this.connectionLinkTable.slice(
201 // const backArr = this.connectionLinkTable.slice(startIndex);
202 // this.connectionLinkTable = frontArr.concat(
203 // res.result_body.connection_links_list,
206 this.connectionLinkTable =
207 res.result_body.connection_links_list;
208 this.recordNum = res.result_body.record_number;
210 this.hasPageNo.push(pageNo);
211 this.addCheckStatus(); // add init check status for connection link table
212 this.judgeTn(); // init judge
213 this.getTableHeader();
217 getTableHeader(): void {
218 // Find the common key of all data
219 let keyList: any[] = this.connectionLinkTable.map((item) => {
220 return Object.keys(item);
222 this.connectionTableHeader = this.Util.intersection(keyList).filter(
224 return item !== "checked";
227 // Filter redundant items in table data
228 this.connectionLinkTable.forEach((item) => {
229 for (let key in item) {
233 this.connectionTableHeader.indexOf(key) === -1
237 // Filter out the null values in each item
238 for (let i in item[key]) {
241 (item[key][i] === "" ||
242 item[key][i] === "null" ||
243 item[key][i] === null)
254 // judge whether there is data of the page, if not, request it from the back end
255 // if (this.hasPageNo.indexOf(e) === -1) {
256 this.getConnectionLinkTable(e, this.pageSize);
259 getConnetionFailed() {
260 console.log("failed");
265 this.formData["sliceProfile_TN_resourceSharingLevel"] ===
269 // this.connectionLinkTable.forEach((item) => {
270 // item.checked = false;
272 // this.formData["tn_connection_links"] = null;
273 this.notPassPara = ["tn_connection_links"];
274 this.transferFormItems.forEach((item) => {
275 if (item.title === "Connection Links") {
278 item.title === "AN Endpoint" ||
279 item.title === "CN Endpoint"
281 item.required = true;
282 item.disable = false;
286 this.formData["sliceProfile_TN_resourceSharingLevel"] === "shared"
288 this.transferFormItems.forEach((item) => {
289 if (item.title === "Connection Links") {
290 item.disable = false;
292 item.title === "AN Endpoint" ||
293 item.title === "CN Endpoint"
296 typeof this.formData["tn_connection_links"] !==
298 this.formData["tn_connection_links"] !== null &&
299 this.formData["tn_connection_links"] !== ""
302 item.required = false;
303 this.notPassPara = [];
304 this.notPassPara = this.notPassPara.concat(
310 this.formData["tn_connection_links"] = "";
311 item.disable = false;
312 item.required = true;
313 this.notPassPara = [];
320 validateEndPoint(key: string, value: any, required: boolean): string {
322 if (this.Util.isEmpty(value)) {
323 return "can not be empty";
326 if (key === "ip_address") {
327 if (!this.regxpIP.test(value)) {
329 return "xxx.xxx.xxx.xxx";
336 } else if (key === "logical_link") {
337 if (!this.Util.isInteger(value)) {
339 return "integer only";
351 changeLinkCheck(id: string): void {
352 // update the selection state
353 this.connectionLinkTable.forEach((item) => {
354 if (item["linkId"] === id) {
357 item.checked = false;
360 this.formData["tn_connection_links"] = id; // get the selected id
365 let areaList = [...this.formData.an_coverage_area_ta_list];
366 this.areaList = areaList.map((item: any) => {
367 let arr = item.split(";");
368 item = arr.map((ite, index) => {
372 } else if (index === 1) {
380 obj.options = [{ name: ite, id: ite }];
387 handleCancel(): void {
388 this.noPassParaChange.emit(this.notPassPara);
389 this.showModel = false;
390 this.cancel.emit(this.showModel);
393 // special handling for address
394 areaCheckBeforeSubmit(target: object): Boolean {
395 for (const prop in target) {
396 if (target.hasOwnProperty(prop)) {
398 prop === "an_coverage_area_ta_list" ||
399 prop === "cn_coverage_area_ta_list"
401 // if the vlaue is "shanghai;shanghai;", the input is incomplete
402 return target[prop].every((item) => {
403 return this.Util.deepCheck(item.split(";"));
411 endCheckBeforeSubmit(endpoint, required): Array<any> {
412 // check params of Endpoint
413 let result: Array<any> = [true, ""];
415 endPointList = this.transferFormItems.find((item) => {
416 return item.title === "AN Endpoint";
421 for (let item of endPointList) {
422 if (item.title === "ip_address") {
424 } else if (item.title === "logical_link") {
425 logicalKey = item.key;
426 } else if (item.title === "nexthop_info") {
430 for (let prop in endpoint) {
431 if (prop === ipKey) {
433 if (endpoint[prop] === "") {
434 result = [false, "Endpoint can not be empty"];
435 } else if (!this.regxpIP.test(endpoint[prop])) {
436 result = [false, "Illegal IpAddress"];
439 !this.regxpIP.test(endpoint[prop]) &&
440 endpoint[prop] !== ""
442 result = [false, "Illegal IpAddress"];
444 } else if (prop === logicalKey) {
446 if (endpoint[prop] === "") {
447 result = [false, "logical can not be empty"];
448 } else if (!this.Util.isInteger(endpoint[prop])) {
449 result = [false, "LogicalID can only be an integer"];
452 !this.Util.isInteger(endpoint[prop]) &&
453 endpoint[prop] !== ""
455 result = [false, "LogicalID can only be an integer"];
457 } else if (prop === nextKey) {
458 if (required && endpoint[prop] === "") {
459 result = [false, "Endpoint can not be empty"];
466 inputHolder(title: string): string {
467 const titleArr = title.split(" ");
468 if (titleArr.length > 1) {
469 return titleArr.slice(0, 2).join("");
475 labelStyle(required: boolean): object {
478 style = { "margin-left": "18px", "margin-right": "-18px" };
486 // Verify that items of EndPoint is correct
487 if (this.EndpointEnable) {
488 let endCheckResult = [];
489 if (this.title === "Tn") {
490 const ANendCheckResult = this.endCheckBeforeSubmit(
491 this.ANEndpointInputs,
492 this.transferFormItems.find((item) => {
493 return item.title === "AN Endpoint";
496 const CNendCheckResult = this.endCheckBeforeSubmit(
497 this.CNEndpointInputs,
498 this.transferFormItems.find((item) => {
499 return item.title === "CN Endpoint";
502 if (ANendCheckResult[0] && CNendCheckResult[0]) {
503 endCheckResult[0] = true;
505 if (ANendCheckResult[0] === false) {
506 endCheckResult = ANendCheckResult;
508 endCheckResult = CNendCheckResult;
512 if (!endCheckResult[0]) {
513 this.message.error(endCheckResult[1].toString());
516 // replace the params about endPoint
517 for (let prop in this.formData) {
519 this.title === "Tn" &&
520 typeof this.ANEndpointInputs[prop] !== "undefined"
522 this.formData[prop] = this.ANEndpointInputs[prop];
524 this.title === "Tn" &&
525 typeof this.CNEndpointInputs[prop] !== "undefined"
527 this.formData[prop] = this.CNEndpointInputs[prop];
532 if (this.title === "An") {
533 const an_coverage_area_ta_list: string[] = [];
534 this.areaList.forEach((item) => {
535 let str: string = "";
536 item.forEach((area) => {
537 str += area.selected + ";";
539 an_coverage_area_ta_list.push(str.substring(0, str.length - 1));
541 params = { ...this.formData, an_coverage_area_ta_list };
543 params = { ...this.formData };
545 // Verify that each item exclude endpoint is not empty, include special handeling of area_list
546 let checkParams: object = params;
547 let requireKeyList: string[] = [];
548 let targetFormItems: any[] = [];
549 if (this.title === "An" || this.title === "Cn") {
550 targetFormItems = this.coreFormItems;
551 } else if ((this.title = "Tn")) {
552 targetFormItems = this.transferFormItems;
554 for (let item of targetFormItems) {
555 if (typeof item.required !== "undefined" && item.required) {
557 typeof item.type !== "undefined" &&
558 item.type !== "endpoint"
560 requireKeyList.push(item.key);
564 checkParams = this.Util.pick(params, requireKeyList);
566 this.Util.deepCheck(checkParams) &&
567 this.areaCheckBeforeSubmit(params)
569 this.paramsDataChange.emit(params);
570 this.noPassParaChange.emit(this.notPassPara);
573 this.message.error("Please complete the form");