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 if(this.connectionLinkTable && this.connectionLinkTable.length>0){
132 this.connectionLinkTable.forEach((item) => {
134 item.hasOwnProperty("linkId") &&
135 typeof this.formData["sliceProfile_TN_connection_links"] !==
137 this.formData["sliceProfile_TN_connection_links"] !== "" &&
138 this.formData["sliceProfile_TN_connection_links"] !== null &&
140 this.formData["sliceProfile_TN_connection_links"]
144 item.checked = false;
150 // changeResourceShare() {
155 if (Object.prototype.toString.call(val) === "[object Object]") {
162 getConnectionLinkTable(pageNo, pageSize): void {
168 .getConnectionLinkTable(pageObj, this.getConnetionFailed)
172 this.connectionLinkTable =
173 res.result_body.connection_links_list;
174 this.recordNum = res.result_body.record_number;
175 // Use default value to occupy
176 // let defaultItem: object = {};
177 // if (this.connectionLinkTable.length !== 0) {
178 // defaultItem = JSON.parse(
179 // JSON.stringify(this.connectionLinkTable[0])
181 // for (let key in defaultItem) {
182 // if (!this.isObject(defaultItem[key])) {
183 // defaultItem[key] = "";
186 // // for (let i in defaultItem[key]) {
187 // // defaultItem[key][i] = "";
191 // for (let i = pageSize; i < this.recordNum; i++) {
192 // this.connectionLinkTable.push(defaultItem);
195 this.hasPageNo = [1];
196 } else if (pageNo > 1) {
197 // delete the default page of the page and add the actual data of the page
198 // const startIndex = pageSize * (pageNo - 1);
199 // const endIndex = startIndex + pageSize - 1;
200 // this.connectionLinkTable.splice(startIndex, pageSize);
201 // const frontArr = this.connectionLinkTable.slice(
205 // const backArr = this.connectionLinkTable.slice(startIndex);
206 // this.connectionLinkTable = frontArr.concat(
207 // res.result_body.connection_links_list,
210 this.connectionLinkTable =
211 res.result_body.connection_links_list;
212 this.recordNum = res.result_body.record_number;
214 this.hasPageNo.push(pageNo);
215 this.addCheckStatus(); // add init check status for connection link table
216 this.judgeTn(); // init judge
217 this.getTableHeader();
221 getTableHeader(): void {
222 // Find the common key of all data
223 if(this.connectionLinkTable && this.connectionLinkTable.length>0){
224 let keyList: any[] = this.connectionLinkTable.map((item) => {
225 return Object.keys(item);
227 this.connectionTableHeader = this.Util.intersection(keyList).filter(
229 return item !== "checked";
232 // Filter redundant items in table data
233 this.connectionLinkTable.forEach((item) => {
234 for (let key in item) {
238 this.connectionTableHeader.indexOf(key) === -1
242 // Filter out the null values in each item
243 for (let i in item[key]) {
246 (item[key][i] === "" ||
247 item[key][i] === "null" ||
248 item[key][i] === null)
260 // judge whether there is data of the page, if not, request it from the back end
261 // if (this.hasPageNo.indexOf(e) === -1) {
262 this.getConnectionLinkTable(e, this.pageSize);
265 getConnetionFailed() {
266 console.log("failed");
271 this.formData["sliceProfile_TN_resourceSharingLevel"] ===
275 // this.connectionLinkTable.forEach((item) => {
276 // item.checked = false;
278 // this.formData["sliceProfile_TN_connection_links"] = null;
279 this.notPassPara = ["sliceProfile_TN_connection_links"];
280 this.transferFormItems.forEach((item) => {
281 if (item.title === "Connection Links") {
284 item.title === "AN Endpoint" ||
285 item.title === "CN Endpoint"
287 item.required = true;
288 item.disable = false;
292 this.formData["sliceProfile_TN_resourceSharingLevel"] === "shared"
294 this.transferFormItems.forEach((item) => {
295 if (item.title === "Connection Links") {
296 item.disable = false;
298 item.title === "AN Endpoint" ||
299 item.title === "CN Endpoint"
302 typeof this.formData[
303 "sliceProfile_TN_connection_links"
305 this.formData["sliceProfile_TN_connection_links"] !==
307 this.formData["sliceProfile_TN_connection_links"] !== ""
310 item.required = false;
311 this.notPassPara = [];
312 this.notPassPara = this.notPassPara.concat(
318 this.formData["sliceProfile_TN_connection_links"] = "";
319 item.disable = false;
320 item.required = true;
321 this.notPassPara = [];
328 validateEndPoint(key: string, value: any, required: boolean): string {
330 if (this.Util.isEmpty(value)) {
331 return "can not be empty";
334 if (key === "ip_address") {
335 if (!this.regxpIP.test(value)) {
337 return "xxx.xxx.xxx.xxx";
344 } else if (key === "logical_link") {
345 if (!this.Util.isInteger(value)) {
347 return "integer only";
359 changeLinkCheck(id: string): void {
360 // update the selection state
361 this.connectionLinkTable.forEach((item) => {
362 if (item["linkId"] === id) {
365 item.checked = false;
368 this.formData["sliceProfile_TN_connection_links"] = id; // get the selected id
373 let areaList = [...this.formData.an_coverage_area_ta_list];
374 this.areaList = areaList.map((item: any) => {
375 let arr = item.split(";");
376 item = arr.map((ite, index) => {
380 } else if (index === 1) {
388 obj.options = [{ name: ite, id: ite }];
395 handleCancel(): void {
396 this.noPassParaChange.emit(this.notPassPara);
397 this.showModel = false;
398 this.cancel.emit(this.showModel);
401 // special handling for address
402 areaCheckBeforeSubmit(target: object): Boolean {
403 for (const prop in target) {
404 if (target.hasOwnProperty(prop)) {
406 prop === "an_coverage_area_ta_list" ||
407 prop === "cn_coverage_area_ta_list"
409 // if the vlaue is "shanghai;shanghai;", the input is incomplete
410 return target[prop].every((item) => {
411 return this.Util.deepCheck(item.split(";"));
419 endCheckBeforeSubmit(endpoint, required): Array<any> {
420 // check params of Endpoint
421 let result: Array<any> = [true, ""];
423 endPointList = this.transferFormItems.find((item) => {
424 return item.title === "AN Endpoint";
429 for (let item of endPointList) {
430 if (item.title === "ip_address") {
432 } else if (item.title === "logical_link") {
433 logicalKey = item.key;
434 } else if (item.title === "nexthop_info") {
438 for (let prop in endpoint) {
439 if (prop === ipKey) {
441 if (endpoint[prop] === "") {
442 result = [false, "Endpoint can not be empty"];
443 } else if (!this.regxpIP.test(endpoint[prop])) {
444 result = [false, "Illegal IpAddress"];
447 !this.regxpIP.test(endpoint[prop]) &&
448 endpoint[prop] !== ""
450 result = [false, "Illegal IpAddress"];
452 } else if (prop === logicalKey) {
454 if (endpoint[prop] === "") {
455 result = [false, "logical can not be empty"];
456 } else if (!this.Util.isInteger(endpoint[prop])) {
457 result = [false, "LogicalID can only be an integer"];
460 !this.Util.isInteger(endpoint[prop]) &&
461 endpoint[prop] !== ""
463 result = [false, "LogicalID can only be an integer"];
465 } else if (prop === nextKey) {
466 if (required && endpoint[prop] === "") {
467 result = [false, "Endpoint can not be empty"];
474 inputHolder(title: string): string {
475 const titleArr = title.split(" ");
476 if (titleArr.length > 1) {
477 return titleArr.slice(0, 2).join("");
483 labelStyle(required: boolean): object {
486 style = { "margin-left": "18px", "margin-right": "-18px" };
494 // Verify that items of EndPoint is correct
495 if (this.EndpointEnable) {
496 let endCheckResult = [];
497 if (this.title === "Tn") {
498 const ANendCheckResult = this.endCheckBeforeSubmit(
499 this.ANEndpointInputs,
500 this.transferFormItems.find((item) => {
501 return item.title === "AN Endpoint";
504 const CNendCheckResult = this.endCheckBeforeSubmit(
505 this.CNEndpointInputs,
506 this.transferFormItems.find((item) => {
507 return item.title === "CN Endpoint";
510 if (ANendCheckResult[0] && CNendCheckResult[0]) {
511 endCheckResult[0] = true;
513 if (ANendCheckResult[0] === false) {
514 endCheckResult = ANendCheckResult;
516 endCheckResult = CNendCheckResult;
520 if (!endCheckResult[0]) {
521 this.message.error(endCheckResult[1].toString());
524 // replace the params about endPoint
525 for (let prop in this.formData) {
527 this.title === "Tn" &&
528 typeof this.ANEndpointInputs[prop] !== "undefined"
530 this.formData[prop] = this.ANEndpointInputs[prop];
532 this.title === "Tn" &&
533 typeof this.CNEndpointInputs[prop] !== "undefined"
535 this.formData[prop] = this.CNEndpointInputs[prop];
540 if (this.title === "An") {
541 const an_coverage_area_ta_list: string[] = [];
542 this.areaList.forEach((item) => {
543 let str: string = "";
544 item.forEach((area) => {
545 str += area.selected + ";";
547 an_coverage_area_ta_list.push(str.substring(0, str.length - 1));
549 params = { ...this.formData, an_coverage_area_ta_list };
551 params = { ...this.formData };
553 // Verify that each item exclude endpoint is not empty, include special handeling of area_list
554 let checkParams: object = params;
555 let requireKeyList: string[] = [];
556 let targetFormItems: any[] = [];
557 if (this.title === "An" || this.title === "Cn") {
558 targetFormItems = this.coreFormItems;
559 } else if ((this.title = "Tn")) {
560 targetFormItems = this.transferFormItems;
562 for (let item of targetFormItems) {
563 if (typeof item.required !== "undefined" && item.required) {
565 typeof item.type !== "undefined" &&
566 item.type !== "endpoint"
568 requireKeyList.push(item.key);
572 checkParams = this.Util.pick(params, requireKeyList);
574 this.Util.deepCheck(checkParams) &&
575 this.areaCheckBeforeSubmit(params)
577 this.paramsDataChange.emit(params);
578 this.noPassParaChange.emit(this.notPassPara);
581 this.message.error("Please complete the form");