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[] = [];
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["sliceProfile_TN_connection_links"] !==
136 this.formData["sliceProfile_TN_connection_links"] !== "" &&
137 this.formData["sliceProfile_TN_connection_links"] !== null &&
139 this.formData["sliceProfile_TN_connection_links"]
143 item.checked = false;
148 // changeResourceShare() {
153 if (Object.prototype.toString.call(val) === "[object Object]") {
160 getConnectionLinkTable(pageNo, pageSize): void {
166 .getConnectionLinkTable(pageObj, this.getConnetionFailed)
170 this.connectionLinkTable =
171 res.result_body.connection_links_list;
172 this.recordNum = res.result_body.record_number;
173 // Use default value to occupy
174 // let defaultItem: object = {};
175 // if (this.connectionLinkTable.length !== 0) {
176 // defaultItem = JSON.parse(
177 // JSON.stringify(this.connectionLinkTable[0])
179 // for (let key in defaultItem) {
180 // if (!this.isObject(defaultItem[key])) {
181 // defaultItem[key] = "";
184 // // for (let i in defaultItem[key]) {
185 // // defaultItem[key][i] = "";
189 // for (let i = pageSize; i < this.recordNum; i++) {
190 // this.connectionLinkTable.push(defaultItem);
193 this.hasPageNo = [1];
194 } else if (pageNo > 1) {
195 // delete the default page of the page and add the actual data of the page
196 // const startIndex = pageSize * (pageNo - 1);
197 // const endIndex = startIndex + pageSize - 1;
198 // this.connectionLinkTable.splice(startIndex, pageSize);
199 // const frontArr = this.connectionLinkTable.slice(
203 // const backArr = this.connectionLinkTable.slice(startIndex);
204 // this.connectionLinkTable = frontArr.concat(
205 // res.result_body.connection_links_list,
208 this.connectionLinkTable =
209 res.result_body.connection_links_list;
210 this.recordNum = res.result_body.record_number;
212 this.hasPageNo.push(pageNo);
213 this.addCheckStatus(); // add init check status for connection link table
214 this.judgeTn(); // init judge
215 this.getTableHeader();
219 getTableHeader(): void {
220 // Find the common key of all data
221 let keyList: any[] = this.connectionLinkTable.map((item) => {
222 return Object.keys(item);
224 this.connectionTableHeader = this.Util.intersection(keyList).filter(
226 return item !== "checked";
229 // Filter redundant items in table data
230 this.connectionLinkTable.forEach((item) => {
231 for (let key in item) {
235 this.connectionTableHeader.indexOf(key) === -1
239 // Filter out the null values in each item
240 for (let i in item[key]) {
243 (item[key][i] === "" ||
244 item[key][i] === "null" ||
245 item[key][i] === null)
256 // judge whether there is data of the page, if not, request it from the back end
257 // if (this.hasPageNo.indexOf(e) === -1) {
258 this.getConnectionLinkTable(e, this.pageSize);
261 getConnetionFailed() {
262 console.log("failed");
267 this.formData["sliceProfile_TN_resourceSharingLevel"] ===
271 // this.connectionLinkTable.forEach((item) => {
272 // item.checked = false;
274 // this.formData["sliceProfile_TN_connection_links"] = null;
275 this.notPassPara = ["sliceProfile_TN_connection_links"];
276 this.transferFormItems.forEach((item) => {
277 if (item.title === "Connection Links") {
280 item.title === "AN Endpoint" ||
281 item.title === "CN Endpoint"
283 item.required = true;
284 item.disable = false;
288 this.formData["sliceProfile_TN_resourceSharingLevel"] === "shared"
290 this.transferFormItems.forEach((item) => {
291 if (item.title === "Connection Links") {
292 item.disable = false;
294 item.title === "AN Endpoint" ||
295 item.title === "CN Endpoint"
298 typeof this.formData[
299 "sliceProfile_TN_connection_links"
301 this.formData["sliceProfile_TN_connection_links"] !==
303 this.formData["sliceProfile_TN_connection_links"] !== ""
306 item.required = false;
307 this.notPassPara = [];
308 this.notPassPara = this.notPassPara.concat(
314 this.formData["sliceProfile_TN_connection_links"] = "";
315 item.disable = false;
316 item.required = true;
317 this.notPassPara = [];
324 validateEndPoint(key: string, value: any, required: boolean): string {
326 if (this.Util.isEmpty(value)) {
327 return "can not be empty";
330 if (key === "ip_address") {
331 if (!this.regxpIP.test(value)) {
333 return "xxx.xxx.xxx.xxx";
340 } else if (key === "logical_link") {
341 if (!this.Util.isInteger(value)) {
343 return "integer only";
355 changeLinkCheck(id: string): void {
356 // update the selection state
357 this.connectionLinkTable.forEach((item) => {
358 if (item["linkId"] === id) {
361 item.checked = false;
364 this.formData["sliceProfile_TN_connection_links"] = id; // get the selected id
369 let areaList = [...this.formData.an_coverage_area_ta_list];
370 this.areaList = areaList.map((item: any) => {
371 let arr = item.split(";");
372 item = arr.map((ite, index) => {
376 } else if (index === 1) {
384 obj.options = [{ name: ite, id: ite }];
391 handleCancel(): void {
392 this.noPassParaChange.emit(this.notPassPara);
393 this.showModel = false;
394 this.cancel.emit(this.showModel);
397 // special handling for address
398 areaCheckBeforeSubmit(target: object): Boolean {
399 for (const prop in target) {
400 if (target.hasOwnProperty(prop)) {
402 prop === "an_coverage_area_ta_list" ||
403 prop === "cn_coverage_area_ta_list"
405 // if the vlaue is "shanghai;shanghai;", the input is incomplete
406 return target[prop].every((item) => {
407 return this.Util.deepCheck(item.split(";"));
415 endCheckBeforeSubmit(endpoint, required): Array<any> {
416 // check params of Endpoint
417 let result: Array<any> = [true, ""];
419 endPointList = this.transferFormItems.find((item) => {
420 return item.title === "AN Endpoint";
425 for (let item of endPointList) {
426 if (item.title === "ip_address") {
428 } else if (item.title === "logical_link") {
429 logicalKey = item.key;
430 } else if (item.title === "nexthop_info") {
434 for (let prop in endpoint) {
435 if (prop === ipKey) {
437 if (endpoint[prop] === "") {
438 result = [false, "Endpoint can not be empty"];
439 } else if (!this.regxpIP.test(endpoint[prop])) {
440 result = [false, "Illegal IpAddress"];
443 !this.regxpIP.test(endpoint[prop]) &&
444 endpoint[prop] !== ""
446 result = [false, "Illegal IpAddress"];
448 } else if (prop === logicalKey) {
450 if (endpoint[prop] === "") {
451 result = [false, "logical can not be empty"];
452 } else if (!this.Util.isInteger(endpoint[prop])) {
453 result = [false, "LogicalID can only be an integer"];
456 !this.Util.isInteger(endpoint[prop]) &&
457 endpoint[prop] !== ""
459 result = [false, "LogicalID can only be an integer"];
461 } else if (prop === nextKey) {
462 if (required && endpoint[prop] === "") {
463 result = [false, "Endpoint can not be empty"];
470 inputHolder(title: string): string {
471 const titleArr = title.split(" ");
472 if (titleArr.length > 1) {
473 return titleArr.slice(0, 2).join("");
479 labelStyle(required: boolean): object {
482 style = { "margin-left": "18px", "margin-right": "-18px" };
490 // Verify that items of EndPoint is correct
491 if (this.EndpointEnable) {
492 let endCheckResult = [];
493 if (this.title === "Tn") {
494 const ANendCheckResult = this.endCheckBeforeSubmit(
495 this.ANEndpointInputs,
496 this.transferFormItems.find((item) => {
497 return item.title === "AN Endpoint";
500 const CNendCheckResult = this.endCheckBeforeSubmit(
501 this.CNEndpointInputs,
502 this.transferFormItems.find((item) => {
503 return item.title === "CN Endpoint";
506 if (ANendCheckResult[0] && CNendCheckResult[0]) {
507 endCheckResult[0] = true;
509 if (ANendCheckResult[0] === false) {
510 endCheckResult = ANendCheckResult;
512 endCheckResult = CNendCheckResult;
516 if (!endCheckResult[0]) {
517 this.message.error(endCheckResult[1].toString());
520 // replace the params about endPoint
521 for (let prop in this.formData) {
523 this.title === "Tn" &&
524 typeof this.ANEndpointInputs[prop] !== "undefined"
526 this.formData[prop] = this.ANEndpointInputs[prop];
528 this.title === "Tn" &&
529 typeof this.CNEndpointInputs[prop] !== "undefined"
531 this.formData[prop] = this.CNEndpointInputs[prop];
536 if (this.title === "An") {
537 const an_coverage_area_ta_list: string[] = [];
538 this.areaList.forEach((item) => {
539 let str: string = "";
540 item.forEach((area) => {
541 str += area.selected + ";";
543 an_coverage_area_ta_list.push(str.substring(0, str.length - 1));
545 params = { ...this.formData, an_coverage_area_ta_list };
547 params = { ...this.formData };
549 // Verify that each item exclude endpoint is not empty, include special handeling of area_list
550 let checkParams: object = params;
551 let requireKeyList: string[] = [];
552 let targetFormItems: any[] = [];
553 if (this.title === "An" || this.title === "Cn") {
554 targetFormItems = this.coreFormItems;
555 } else if ((this.title = "Tn")) {
556 targetFormItems = this.transferFormItems;
558 for (let item of targetFormItems) {
559 if (typeof item.required !== "undefined" && item.required) {
561 typeof item.type !== "undefined" &&
562 item.type !== "endpoint"
564 requireKeyList.push(item.key);
568 checkParams = this.Util.pick(params, requireKeyList);
570 this.Util.deepCheck(checkParams) &&
571 this.areaCheckBeforeSubmit(params)
573 this.paramsDataChange.emit(params);
574 this.noPassParaChange.emit(this.notPassPara);
577 this.message.error("Please complete the form");