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[] = [];
55 objectKeys = Object.keys;
56 // Comment: Above code
59 private message: NzMessageService,
61 private http: SlicingTaskServices
67 // It is excuted every time you open it
69 this.formData = JSON.parse(JSON.stringify(this.detailData));
70 if (this.title === "An" || this.title === "Cn") {
77 } else if (this.title === "Tn") {
78 const pageNo = 1; // start from page 1
79 const pageSize = this.pageSize;
80 this.getConnectionLinkTable(pageNo, pageSize);
81 this.ANkeyList = this.transferFormItems
83 return item.title === "AN Endpoint";
85 .options.map((val) => {
88 this.CNkeyList = this.transferFormItems
90 return item.title === "CN Endpoint";
92 .options.map((val) => {
95 this.keyList = this.ANkeyList.concat(this.CNkeyList);
97 typeof this.formData !== "undefined" &&
98 Object.keys(this.formData).length !== 0
100 this.EndpointEnable = this.keyList.every((item) => {
101 return this.formData.hasOwnProperty(item);
104 if (this.EndpointEnable) {
105 this.ANEndpointInputs = this.Util.pick(
109 this.CNEndpointInputs = this.Util.pick(
114 this.transferFormItems.map((item, index) => {
116 item.title === "AN Endpoint" ||
117 item.title === "CN Endpoint"
119 this.transferFormItems.splice(index, 1);
124 // If the endpoint related parameters from the back end are incomplete, delete the endpoint item
125 //-------> Comment: Above code
126 if (this.title === "An") {
127 this.AreaFormatting();
133 if (this.connectionLinkTable && this.connectionLinkTable.length > 0) {
134 this.connectionLinkTable.forEach((item) => {
136 item.hasOwnProperty("linkId") &&
137 typeof this.formData["sliceProfile_TN_connection_links"] !==
139 this.formData["sliceProfile_TN_connection_links"] !== "" &&
140 this.formData["sliceProfile_TN_connection_links"] !==
143 this.formData["sliceProfile_TN_connection_links"]
147 item.checked = false;
153 // changeResourceShare() {
158 if (Object.prototype.toString.call(val) === "[object Object]") {
165 getConnectionLinkTable(pageNo, pageSize): void {
172 .getConnectionLinkTable(pageObj, this.getConnetionFailed)
176 this.loading = false;
177 this.connectionLinkTable =
178 res.result_body.connection_links_list;
179 this.recordNum = res.result_body.record_number;
180 // Use default value to occupy
181 // let defaultItem: object = {};
182 // if (this.connectionLinkTable.length !== 0) {
183 // defaultItem = JSON.parse(
184 // JSON.stringify(this.connectionLinkTable[0])
186 // for (let key in defaultItem) {
187 // if (!this.isObject(defaultItem[key])) {
188 // defaultItem[key] = "";
191 // // for (let i in defaultItem[key]) {
192 // // defaultItem[key][i] = "";
196 // for (let i = pageSize; i < this.recordNum; i++) {
197 // this.connectionLinkTable.push(defaultItem);
200 // this.hasPageNo = [1];
201 } else if (pageNo > 1) {
202 // delete the default page of the page and add the actual data of the page
203 // const startIndex = pageSize * (pageNo - 1);
204 // const endIndex = startIndex + pageSize - 1;
205 // this.connectionLinkTable.splice(startIndex, pageSize);
206 // const frontArr = this.connectionLinkTable.slice(
210 // const backArr = this.connectionLinkTable.slice(startIndex);
211 // this.connectionLinkTable = frontArr.concat(
212 // res.result_body.connection_links_list,
215 this.connectionLinkTable =
216 res.result_body.connection_links_list;
217 this.recordNum = res.result_body.record_number;
218 this.loading = false;
220 // this.hasPageNo.push(pageNo);
221 this.addCheckStatus(); // add init check status for connection link table
222 this.judgeTn(); // init judge
223 this.getTableHeader();
227 getTableHeader(): void {
228 // Find the common key of all data
229 if (this.connectionLinkTable && this.connectionLinkTable.length > 0) {
230 let keyList: any[] = this.connectionLinkTable.map((item) => {
231 return Object.keys(item);
233 this.connectionTableHeader = this.Util.intersection(keyList).filter(
235 return item !== "checked";
238 // Filter redundant items in table data
239 this.connectionLinkTable.forEach((item) => {
240 for (let key in item) {
244 this.connectionTableHeader.indexOf(key) === -1
248 // Filter out the null values in each item
249 for (let i in item[key]) {
252 (item[key][i] === "" ||
253 item[key][i] === "null" ||
254 item[key][i] === null)
266 // judge whether there is data of the page, if not, request it from the back end
267 // if (this.hasPageNo.indexOf(e) === -1) {
268 this.getConnectionLinkTable(e, this.pageSize);
271 getConnetionFailed() {
272 console.log("failed");
276 console.log("fprm", this.formData);
278 this.formData["sliceProfile_TN_resourceSharingLevel"] ===
280 this.formData["sliceProfile_TN_resourceSharingLevel"] == null
283 // this.connectionLinkTable.forEach((item) => {
284 // item.checked = false;
286 // this.formData["sliceProfile_TN_connection_links"] = null;
287 this.notPassPara = ["sliceProfile_TN_connection_links"];
288 this.transferFormItems.forEach((item) => {
289 if (item.title === "Connection Links") {
292 item.title === "AN Endpoint" ||
293 item.title === "CN Endpoint"
295 item.required = true;
296 item.disable = false;
300 this.formData["sliceProfile_TN_resourceSharingLevel"] === "shared"
302 this.transferFormItems.forEach((item) => {
303 if (item.title === "Connection Links") {
304 item.disable = false;
306 item.title === "AN Endpoint" ||
307 item.title === "CN Endpoint"
310 typeof this.formData[
311 "sliceProfile_TN_connection_links"
313 this.formData["sliceProfile_TN_connection_links"] !==
315 this.formData["sliceProfile_TN_connection_links"] !== ""
318 item.required = false;
319 this.notPassPara = [];
320 this.notPassPara = this.notPassPara.concat(
326 this.formData["sliceProfile_TN_connection_links"] = "";
327 item.disable = false;
328 item.required = true;
329 this.notPassPara = [];
336 validateEndPoint(key: string, value: any, required: boolean): string {
338 if (this.Util.isEmpty(value)) {
339 return "can not be empty";
342 if (key === "ip_address") {
343 if (!this.regxpIP.test(value)) {
345 return "xxx.xxx.xxx.xxx";
352 } else if (key === "logical_link") {
353 if (!this.Util.isInteger(value)) {
355 return "integer only";
367 changeLinkCheck(id: string): void {
368 // update the selection state
369 this.connectionLinkTable.forEach((item) => {
370 if (item["linkId"] === id) {
373 item.checked = false;
376 this.formData["sliceProfile_TN_connection_links"] = id; // get the selected id
381 let areaList = [...this.formData.an_coverage_area_ta_list];
382 this.areaList = areaList.map((item: any) => {
383 let arr = item.split(";");
384 item = arr.map((ite, index) => {
388 } else if (index === 1) {
396 obj.options = [{ name: ite, id: ite }];
403 handleCancel(): void {
404 this.noPassParaChange.emit(this.notPassPara);
405 this.showModel = false;
406 this.cancel.emit(this.showModel);
409 // special handling for address
410 areaCheckBeforeSubmit(target: object): Boolean {
411 for (const prop in target) {
412 if (target.hasOwnProperty(prop)) {
414 prop === "an_coverage_area_ta_list" ||
415 prop === "cn_coverage_area_ta_list"
417 // if the vlaue is "shanghai;shanghai;", the input is incomplete
418 return target[prop].every((item) => {
419 return this.Util.deepCheck(item.split(";"));
427 endCheckBeforeSubmit(endpoint, required): Array<any> {
428 // check params of Endpoint
429 let result: Array<any> = [true, ""];
431 endPointList = this.transferFormItems.find((item) => {
432 return item.title === "AN Endpoint";
437 for (let item of endPointList) {
438 if (item.title === "ip_address") {
440 } else if (item.title === "logical_link") {
441 logicalKey = item.key;
442 } else if (item.title === "nexthop_info") {
446 for (let prop in endpoint) {
447 if (prop === ipKey) {
449 if (endpoint[prop] === "") {
450 result = [false, "Endpoint can not be empty"];
451 } else if (!this.regxpIP.test(endpoint[prop])) {
452 result = [false, "Illegal IpAddress"];
455 !this.regxpIP.test(endpoint[prop]) &&
456 endpoint[prop] !== ""
458 result = [false, "Illegal IpAddress"];
460 } else if (prop === logicalKey) {
462 if (endpoint[prop] === "") {
463 result = [false, "logical can not be empty"];
464 } else if (!this.Util.isInteger(endpoint[prop])) {
465 result = [false, "LogicalID can only be an integer"];
468 !this.Util.isInteger(endpoint[prop]) &&
469 endpoint[prop] !== ""
471 result = [false, "LogicalID can only be an integer"];
473 } else if (prop === nextKey) {
474 if (required && endpoint[prop] === "") {
475 result = [false, "Endpoint can not be empty"];
482 inputHolder(title: string): string {
483 const titleArr = title.split(" ");
484 if (titleArr.length > 1) {
485 return titleArr.slice(0, 2).join("");
491 labelStyle(required: boolean): object {
494 style = { "margin-left": "18px", "margin-right": "-18px" };
502 // Verify that items of EndPoint is correct
503 if (this.EndpointEnable) {
504 let endCheckResult = [];
505 if (this.title === "Tn") {
506 const ANendCheckResult = this.endCheckBeforeSubmit(
507 this.ANEndpointInputs,
508 this.transferFormItems.find((item) => {
509 return item.title === "AN Endpoint";
512 const CNendCheckResult = this.endCheckBeforeSubmit(
513 this.CNEndpointInputs,
514 this.transferFormItems.find((item) => {
515 return item.title === "CN Endpoint";
518 if (ANendCheckResult[0] && CNendCheckResult[0]) {
519 endCheckResult[0] = true;
521 if (ANendCheckResult[0] === false) {
522 endCheckResult = ANendCheckResult;
524 endCheckResult = CNendCheckResult;
528 if (!endCheckResult[0]) {
529 this.message.error(endCheckResult[1].toString());
532 // replace the params about endPoint
533 for (let prop in this.formData) {
535 this.title === "Tn" &&
536 typeof this.ANEndpointInputs[prop] !== "undefined"
538 this.formData[prop] = this.ANEndpointInputs[prop];
540 this.title === "Tn" &&
541 typeof this.CNEndpointInputs[prop] !== "undefined"
543 this.formData[prop] = this.CNEndpointInputs[prop];
548 if (this.title === "An") {
549 const an_coverage_area_ta_list: string[] = [];
550 this.areaList.forEach((item) => {
551 let str: string = "";
552 item.forEach((area) => {
553 str += area.selected + ";";
555 an_coverage_area_ta_list.push(str.substring(0, str.length - 1));
557 params = { ...this.formData, an_coverage_area_ta_list };
559 params = { ...this.formData };
561 // Verify that each item exclude endpoint is not empty, include special handeling of area_list
562 let checkParams: object = params;
563 let requireKeyList: string[] = [];
564 let targetFormItems: any[] = [];
565 if (this.title === "An" || this.title === "Cn") {
566 targetFormItems = this.coreFormItems;
567 } else if ((this.title = "Tn")) {
568 targetFormItems = this.transferFormItems;
570 for (let item of targetFormItems) {
571 if (typeof item.required !== "undefined" && item.required) {
573 typeof item.type !== "undefined" &&
574 item.type !== "endpoint"
576 requireKeyList.push(item.key);
580 checkParams = this.Util.pick(params, requireKeyList);
582 this.Util.deepCheck(checkParams) &&
583 this.areaCheckBeforeSubmit(params)
585 this.paramsDataChange.emit(params);
586 this.noPassParaChange.emit(this.notPassPara);
589 this.message.error("Please complete the form");