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[] = [];
54 objectKeys = Object.keys;
55 // Comment: Above code
58 private message: NzMessageService,
60 private http: SlicingTaskServices
66 // It is excuted every time you open it
68 this.formData = JSON.parse(JSON.stringify(this.detailData));
69 if (this.title === "An" || this.title === "Cn") {
76 } else if (this.title === "Tn") {
77 const pageNo = 1; // start from page 1
78 const pageSize = this.pageSize;
79 this.getConnectionLinkTable(pageNo, pageSize);
80 this.ANkeyList = this.transferFormItems
82 return item.title === "AN Endpoint";
84 .options.map((val) => {
87 this.CNkeyList = this.transferFormItems
89 return item.title === "CN Endpoint";
91 .options.map((val) => {
94 this.keyList = this.ANkeyList.concat(this.CNkeyList);
96 typeof this.formData !== "undefined" &&
97 Object.keys(this.formData).length !== 0
99 this.EndpointEnable = this.keyList.every((item) => {
100 return this.formData.hasOwnProperty(item);
103 if (this.EndpointEnable) {
104 this.ANEndpointInputs = this.Util.pick(
108 this.CNEndpointInputs = this.Util.pick(
113 this.transferFormItems.map((item, index) => {
115 item.title === "AN Endpoint" ||
116 item.title === "CN Endpoint"
118 this.transferFormItems.splice(index, 1);
123 // If the endpoint related parameters from the back end are incomplete, delete the endpoint item
124 //-------> Comment: Above code
125 if (this.title === "An") {
126 this.AreaFormatting();
132 if(this.connectionLinkTable && this.connectionLinkTable.length>0){
133 this.connectionLinkTable.forEach((item) => {
135 item.hasOwnProperty("linkId") &&
136 typeof this.formData["sliceProfile_TN_connection_links"] !==
138 this.formData["sliceProfile_TN_connection_links"] !== "" &&
139 this.formData["sliceProfile_TN_connection_links"] !== null &&
141 this.formData["sliceProfile_TN_connection_links"]
145 item.checked = false;
151 // changeResourceShare() {
156 if (Object.prototype.toString.call(val) === "[object Object]") {
163 getConnectionLinkTable(pageNo, pageSize): void {
170 .getConnectionLinkTable(pageObj, this.getConnetionFailed)
174 this.connectionLinkTable =
175 res.result_body.connection_links_list;
176 this.recordNum = res.result_body.record_number;
177 // Use default value to occupy
178 // let defaultItem: object = {};
179 // if (this.connectionLinkTable.length !== 0) {
180 // defaultItem = JSON.parse(
181 // JSON.stringify(this.connectionLinkTable[0])
183 // for (let key in defaultItem) {
184 // if (!this.isObject(defaultItem[key])) {
185 // defaultItem[key] = "";
188 // // for (let i in defaultItem[key]) {
189 // // defaultItem[key][i] = "";
193 // for (let i = pageSize; i < this.recordNum; i++) {
194 // this.connectionLinkTable.push(defaultItem);
197 this.hasPageNo = [1];
198 } else if (pageNo > 1) {
199 // delete the default page of the page and add the actual data of the page
200 // const startIndex = pageSize * (pageNo - 1);
201 // const endIndex = startIndex + pageSize - 1;
202 // this.connectionLinkTable.splice(startIndex, pageSize);
203 // const frontArr = this.connectionLinkTable.slice(
207 // const backArr = this.connectionLinkTable.slice(startIndex);
208 // this.connectionLinkTable = frontArr.concat(
209 // res.result_body.connection_links_list,
212 this.connectionLinkTable =
213 res.result_body.connection_links_list;
214 this.recordNum = res.result_body.record_number;
216 this.hasPageNo.push(pageNo);
217 this.addCheckStatus(); // add init check status for connection link table
218 this.judgeTn(); // init judge
219 this.getTableHeader();
223 getTableHeader(): void {
224 // Find the common key of all data
225 if(this.connectionLinkTable && this.connectionLinkTable.length>0){
226 let keyList: any[] = this.connectionLinkTable.map((item) => {
227 return Object.keys(item);
229 this.connectionTableHeader = this.Util.intersection(keyList).filter(
231 return item !== "checked";
234 // Filter redundant items in table data
235 this.connectionLinkTable.forEach((item) => {
236 for (let key in item) {
240 this.connectionTableHeader.indexOf(key) === -1
244 // Filter out the null values in each item
245 for (let i in item[key]) {
248 (item[key][i] === "" ||
249 item[key][i] === "null" ||
250 item[key][i] === null)
262 // judge whether there is data of the page, if not, request it from the back end
263 // if (this.hasPageNo.indexOf(e) === -1) {
264 this.getConnectionLinkTable(e, this.pageSize);
267 getConnetionFailed() {
268 console.log("failed");
272 console.log('fprm',this.formData)
274 this.formData["sliceProfile_TN_resourceSharingLevel"] ===
275 "non-shared" || this.formData["sliceProfile_TN_resourceSharingLevel"]==null
278 // this.connectionLinkTable.forEach((item) => {
279 // item.checked = false;
281 // this.formData["sliceProfile_TN_connection_links"] = null;
282 this.notPassPara = ["sliceProfile_TN_connection_links"];
283 this.transferFormItems.forEach((item) => {
284 if (item.title === "Connection Links") {
287 item.title === "AN Endpoint" ||
288 item.title === "CN Endpoint"
290 item.required = true;
291 item.disable = false;
295 this.formData["sliceProfile_TN_resourceSharingLevel"] === "shared"
297 this.transferFormItems.forEach((item) => {
298 if (item.title === "Connection Links") {
299 item.disable = false;
301 item.title === "AN Endpoint" ||
302 item.title === "CN Endpoint"
305 typeof this.formData[
306 "sliceProfile_TN_connection_links"
308 this.formData["sliceProfile_TN_connection_links"] !==
310 this.formData["sliceProfile_TN_connection_links"] !== ""
313 item.required = false;
314 this.notPassPara = [];
315 this.notPassPara = this.notPassPara.concat(
321 this.formData["sliceProfile_TN_connection_links"] = "";
322 item.disable = false;
323 item.required = true;
324 this.notPassPara = [];
331 validateEndPoint(key: string, value: any, required: boolean): string {
333 if (this.Util.isEmpty(value)) {
334 return "can not be empty";
337 if (key === "ip_address") {
338 if (!this.regxpIP.test(value)) {
340 return "xxx.xxx.xxx.xxx";
347 } else if (key === "logical_link") {
348 if (!this.Util.isInteger(value)) {
350 return "integer only";
362 changeLinkCheck(id: string): void {
363 // update the selection state
364 this.connectionLinkTable.forEach((item) => {
365 if (item["linkId"] === id) {
368 item.checked = false;
371 this.formData["sliceProfile_TN_connection_links"] = id; // get the selected id
376 let areaList = [...this.formData.an_coverage_area_ta_list];
377 this.areaList = areaList.map((item: any) => {
378 let arr = item.split(";");
379 item = arr.map((ite, index) => {
383 } else if (index === 1) {
391 obj.options = [{ name: ite, id: ite }];
398 handleCancel(): void {
399 this.noPassParaChange.emit(this.notPassPara);
400 this.showModel = false;
401 this.cancel.emit(this.showModel);
404 // special handling for address
405 areaCheckBeforeSubmit(target: object): Boolean {
406 for (const prop in target) {
407 if (target.hasOwnProperty(prop)) {
409 prop === "an_coverage_area_ta_list" ||
410 prop === "cn_coverage_area_ta_list"
412 // if the vlaue is "shanghai;shanghai;", the input is incomplete
413 return target[prop].every((item) => {
414 return this.Util.deepCheck(item.split(";"));
422 endCheckBeforeSubmit(endpoint, required): Array<any> {
423 // check params of Endpoint
424 let result: Array<any> = [true, ""];
426 endPointList = this.transferFormItems.find((item) => {
427 return item.title === "AN Endpoint";
432 for (let item of endPointList) {
433 if (item.title === "ip_address") {
435 } else if (item.title === "logical_link") {
436 logicalKey = item.key;
437 } else if (item.title === "nexthop_info") {
441 for (let prop in endpoint) {
442 if (prop === ipKey) {
444 if (endpoint[prop] === "") {
445 result = [false, "Endpoint can not be empty"];
446 } else if (!this.regxpIP.test(endpoint[prop])) {
447 result = [false, "Illegal IpAddress"];
450 !this.regxpIP.test(endpoint[prop]) &&
451 endpoint[prop] !== ""
453 result = [false, "Illegal IpAddress"];
455 } else if (prop === logicalKey) {
457 if (endpoint[prop] === "") {
458 result = [false, "logical can not be empty"];
459 } else if (!this.Util.isInteger(endpoint[prop])) {
460 result = [false, "LogicalID can only be an integer"];
463 !this.Util.isInteger(endpoint[prop]) &&
464 endpoint[prop] !== ""
466 result = [false, "LogicalID can only be an integer"];
468 } else if (prop === nextKey) {
469 if (required && endpoint[prop] === "") {
470 result = [false, "Endpoint can not be empty"];
477 inputHolder(title: string): string {
478 const titleArr = title.split(" ");
479 if (titleArr.length > 1) {
480 return titleArr.slice(0, 2).join("");
486 labelStyle(required: boolean): object {
489 style = { "margin-left": "18px", "margin-right": "-18px" };
497 // Verify that items of EndPoint is correct
498 if (this.EndpointEnable) {
499 let endCheckResult = [];
500 if (this.title === "Tn") {
501 const ANendCheckResult = this.endCheckBeforeSubmit(
502 this.ANEndpointInputs,
503 this.transferFormItems.find((item) => {
504 return item.title === "AN Endpoint";
507 const CNendCheckResult = this.endCheckBeforeSubmit(
508 this.CNEndpointInputs,
509 this.transferFormItems.find((item) => {
510 return item.title === "CN Endpoint";
513 if (ANendCheckResult[0] && CNendCheckResult[0]) {
514 endCheckResult[0] = true;
516 if (ANendCheckResult[0] === false) {
517 endCheckResult = ANendCheckResult;
519 endCheckResult = CNendCheckResult;
523 if (!endCheckResult[0]) {
524 this.message.error(endCheckResult[1].toString());
527 // replace the params about endPoint
528 for (let prop in this.formData) {
530 this.title === "Tn" &&
531 typeof this.ANEndpointInputs[prop] !== "undefined"
533 this.formData[prop] = this.ANEndpointInputs[prop];
535 this.title === "Tn" &&
536 typeof this.CNEndpointInputs[prop] !== "undefined"
538 this.formData[prop] = this.CNEndpointInputs[prop];
543 if (this.title === "An") {
544 const an_coverage_area_ta_list: string[] = [];
545 this.areaList.forEach((item) => {
546 let str: string = "";
547 item.forEach((area) => {
548 str += area.selected + ";";
550 an_coverage_area_ta_list.push(str.substring(0, str.length - 1));
552 params = { ...this.formData, an_coverage_area_ta_list };
554 params = { ...this.formData };
556 // Verify that each item exclude endpoint is not empty, include special handeling of area_list
557 let checkParams: object = params;
558 let requireKeyList: string[] = [];
559 let targetFormItems: any[] = [];
560 if (this.title === "An" || this.title === "Cn") {
561 targetFormItems = this.coreFormItems;
562 } else if ((this.title = "Tn")) {
563 targetFormItems = this.transferFormItems;
565 for (let item of targetFormItems) {
566 if (typeof item.required !== "undefined" && item.required) {
568 typeof item.type !== "undefined" &&
569 item.type !== "endpoint"
571 requireKeyList.push(item.key);
575 checkParams = this.Util.pick(params, requireKeyList);
577 this.Util.deepCheck(checkParams) &&
578 this.areaCheckBeforeSubmit(params)
580 this.paramsDataChange.emit(params);
581 this.noPassParaChange.emit(this.notPassPara);
584 this.message.error("Please complete the form");