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,
205 this.connectionLinkTable =
206 res.result_body.connection_links_list;
207 this.recordNum = res.result_body.record_number;
209 this.hasPageNo.push(pageNo);
210 this.addCheckStatus(); // add init check status for connection link table
211 this.judgeTn(); // init judge
212 this.getTableHeader();
216 getTableHeader(): void {
217 // Find the common key of all data
218 let keyList: any[] = this.connectionLinkTable.map((item) => {
219 return Object.keys(item);
221 this.connectionTableHeader = this.Util.intersection(keyList).filter(
223 return item !== "checked";
226 // Filter redundant items in table data
227 this.connectionLinkTable.forEach((item) => {
228 for (let key in item) {
232 this.connectionTableHeader.indexOf(key) === -1
236 // Filter out the null values in each item
237 for (let i in item[key]) {
240 (item[key][i] === "" ||
241 item[key][i] === "null" ||
242 item[key][i] === null)
253 // judge whether there is data of the page, if not, request it from the back end
254 // if (this.hasPageNo.indexOf(e) === -1) {
255 this.getConnectionLinkTable(e, this.pageSize);
258 getConnetionFailed() {
259 console.log("failed");
264 this.formData["sliceProfile_TN_resourceSharingLevel"] ===
268 // this.connectionLinkTable.forEach((item) => {
269 // item.checked = false;
271 // this.formData["tn_connection_links"] = null;
272 this.notPassPara = ["tn_connection_links"];
273 this.transferFormItems.forEach((item) => {
274 if (item.title === "Connection Links") {
277 item.title === "AN Endpoint" ||
278 item.title === "CN Endpoint"
280 item.required = true;
281 item.disable = false;
285 this.formData["sliceProfile_TN_resourceSharingLevel"] === "shared"
287 this.transferFormItems.forEach((item) => {
288 if (item.title === "Connection Links") {
289 item.disable = false;
291 item.title === "AN Endpoint" ||
292 item.title === "CN Endpoint"
295 typeof this.formData["tn_connection_links"] !==
297 this.formData["tn_connection_links"] !== null &&
298 this.formData["tn_connection_links"] !== ""
301 item.required = false;
302 this.notPassPara = [];
303 this.notPassPara = this.notPassPara.concat(
309 this.formData["tn_connection_links"] = "";
310 item.disable = false;
311 item.required = true;
312 this.notPassPara = [];
319 validateEndPoint(key: string, value: any, required: boolean): string {
321 if (this.Util.isEmpty(value)) {
322 return "can not be empty";
325 if (key === "ip_address") {
326 if (!this.regxpIP.test(value)) {
328 return "xxx.xxx.xxx.xxx";
335 } else if (key === "logical_link") {
336 if (!this.Util.isInteger(value)) {
338 return "integer only";
350 changeLinkCheck(id: string): void {
351 // update the selection state
352 this.connectionLinkTable.forEach((item) => {
353 if (item["linkId"] === id) {
356 item.checked = false;
359 this.formData["tn_connection_links"] = id; // get the selected id
364 let areaList = [...this.formData.an_coverage_area_ta_list];
365 this.areaList = areaList.map((item: any) => {
366 let arr = item.split(";");
367 item = arr.map((ite, index) => {
371 } else if (index === 1) {
379 obj.options = [{ name: ite, id: ite }];
386 handleCancel(): void {
387 this.showModel = false;
388 this.cancel.emit(this.showModel);
391 // special handling for address
392 areaCheckBeforeSubmit(target: object): Boolean {
393 for (const prop in target) {
394 if (target.hasOwnProperty(prop)) {
396 prop === "an_coverage_area_ta_list" ||
397 prop === "cn_coverage_area_ta_list"
399 // if the vlaue is "shanghai;shanghai;", the input is incomplete
400 return target[prop].every((item) => {
401 return this.Util.deepCheck(item.split(";"));
409 endCheckBeforeSubmit(endpoint, required): Array<any> {
410 // check params of Endpoint
411 let result: Array<any> = [true, ""];
413 endPointList = this.transferFormItems.find((item) => {
414 return item.title === "AN Endpoint";
419 for (let item of endPointList) {
420 if (item.title === "ip_address") {
422 } else if (item.title === "logical_link") {
423 logicalKey = item.key;
424 } else if (item.title === "nexthop_info") {
428 for (let prop in endpoint) {
429 if (prop === ipKey) {
431 if (endpoint[prop] === "") {
432 result = [false, "Endpoint can not be empty"];
433 } else if (!this.regxpIP.test(endpoint[prop])) {
434 result = [false, "Illegal IpAddress"];
437 !this.regxpIP.test(endpoint[prop]) &&
438 endpoint[prop] !== ""
440 result = [false, "Illegal IpAddress"];
442 } else if (prop === logicalKey) {
444 if (endpoint[prop] === "") {
445 result = [false, "logical can not be empty"];
446 } else if (!this.Util.isInteger(endpoint[prop])) {
447 result = [false, "LogicalID can only be an integer"];
450 !this.Util.isInteger(endpoint[prop]) &&
451 endpoint[prop] !== ""
453 result = [false, "LogicalID can only be an integer"];
455 } else if (prop === nextKey) {
456 if (required && endpoint[prop] === "") {
457 result = [false, "Endpoint can not be empty"];
464 inputHolder(title: string): string {
465 const titleArr = title.split(" ");
466 if (titleArr.length > 1) {
467 return titleArr.slice(0, 2).join("");
473 labelStyle(required: boolean): object {
476 style = { "margin-left": "18px", "margin-right": "-18px" };
484 // Verify that items of EndPoint is correct
485 if (this.EndpointEnable) {
486 let endCheckResult = [];
487 if (this.title === "Tn") {
488 const ANendCheckResult = this.endCheckBeforeSubmit(
489 this.ANEndpointInputs,
490 this.transferFormItems.find((item) => {
491 return item.title === "AN Endpoint";
494 const CNendCheckResult = this.endCheckBeforeSubmit(
495 this.CNEndpointInputs,
496 this.transferFormItems.find((item) => {
497 return item.title === "CN Endpoint";
500 if (ANendCheckResult[0] && CNendCheckResult[0]) {
501 endCheckResult[0] = true;
503 if (ANendCheckResult[0] === false) {
504 endCheckResult = ANendCheckResult;
506 endCheckResult = CNendCheckResult;
510 if (!endCheckResult[0]) {
511 this.message.error(endCheckResult[1].toString());
514 // replace the params about endPoint
515 for (let prop in this.formData) {
517 this.title === "Tn" &&
518 typeof this.ANEndpointInputs[prop] !== "undefined"
520 this.formData[prop] = this.ANEndpointInputs[prop];
522 this.title === "Tn" &&
523 typeof this.CNEndpointInputs[prop] !== "undefined"
525 this.formData[prop] = this.CNEndpointInputs[prop];
530 if (this.title === "An") {
531 const an_coverage_area_ta_list: string[] = [];
532 this.areaList.forEach((item) => {
533 let str: string = "";
534 item.forEach((area) => {
535 str += area.selected + ";";
537 an_coverage_area_ta_list.push(str.substring(0, str.length - 1));
539 params = { ...this.formData, an_coverage_area_ta_list };
541 params = { ...this.formData };
543 // Verify that each item exclude endpoint is not empty, include special handeling of area_list
544 let checkParams: object = params;
545 let requireKeyList: string[] = [];
546 let targetFormItems: any[] = [];
547 if (this.title === "An" || this.title === "Cn") {
548 targetFormItems = this.coreFormItems;
549 } else if ((this.title = "Tn")) {
550 targetFormItems = this.transferFormItems;
552 for (let item of targetFormItems) {
553 if (typeof item.required !== "undefined" && item.required) {
555 typeof item.type !== "undefined" &&
556 item.type !== "endpoint"
558 requireKeyList.push(item.key);
562 checkParams = this.Util.pick(params, requireKeyList);
564 this.Util.deepCheck(checkParams) &&
565 this.areaCheckBeforeSubmit(params)
567 this.paramsDataChange.emit(params);
568 this.noPassParaChange.emit(this.notPassPara);
571 this.message.error("Please complete the form");