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 ANEndpointInputs: object = {};
34 CNEndpointInputs: object = {};
35 ANkeyList: string[] = [];
36 CNkeyList: string[] = [];
37 EndpointEnable: boolean = false; // Whether to enable the three parameters of Endpoint
38 keyList: string[] = []; // keys of endPoint
39 specialParaTN: string[] = [
40 "Resource Sharing Level",
45 // Parameters not passed to the back end
46 notPassPara: string[] = ["tn_connection_links"];
47 connectionLinkTable: any[] = [];
48 connectionTableHeader: string[] = [];
49 objectKeys = Object.keys;
50 // Comment: Above code
53 private message: NzMessageService,
55 private http: SlicingTaskServices
62 this.formData = JSON.parse(JSON.stringify(this.detailData));
63 if (this.title === "An" || this.title === "Cn") {
70 } else if (this.title === "Tn") {
71 this.getConnectionLinkTable();
72 this.ANkeyList = this.transferFormItems
74 return item.title === "AN Endpoint";
76 .options.map((val) => {
79 this.CNkeyList = this.transferFormItems
81 return item.title === "CN Endpoint";
83 .options.map((val) => {
86 this.keyList = this.ANkeyList.concat(this.CNkeyList);
88 typeof this.formData !== "undefined" &&
89 Object.keys(this.formData).length !== 0
91 this.EndpointEnable = this.keyList.every((item) => {
92 return this.formData.hasOwnProperty(item);
95 if (this.EndpointEnable) {
96 this.ANEndpointInputs = this.Util.pick(
100 this.CNEndpointInputs = this.Util.pick(
105 this.transferFormItems.map((item, index) => {
107 item.title === "AN Endpoint" ||
108 item.title === "CN Endpoint"
110 this.transferFormItems.splice(index, 1);
115 // If the endpoint related parameters from the back end are incomplete, delete the endpoint item
116 //-------> Comment: Above code
117 if (this.title === "An") {
118 this.AreaFormatting();
124 this.connectionLinkTable.forEach((item) => {
126 item.hasOwnProperty("linkId") &&
127 typeof this.formData["tn_connection_links"] !== "undefined" &&
128 this.formData["tn_connection_links"] !== "" &&
129 this.formData["tn_connection_links"] !== null &&
130 item["linkId"] === this.formData["tn_connection_links"]
134 item.checked = false;
139 changeResourceShare() {
144 if (Object.prototype.toString.call(val) === "[object Object]") {
151 getConnectionLinkTable(): void {
153 .getConnectionLinkTable(this.getConnetionFailed)
155 this.connectionLinkTable =
156 res.result_body.connection_links_list;
157 this.addCheckStatus(); // add init check status for connection link table
158 this.judgeTn(); // init judge
159 this.getTableHeader();
163 getTableHeader(): void {
164 // Find the common key of all data
165 let keyList: any[] = this.connectionLinkTable.map((item) => {
166 return Object.keys(item);
168 this.connectionTableHeader = this.Util.intersection(keyList).filter(
170 return item !== "checked";
173 // Filter redundant items in table data
174 this.connectionLinkTable.forEach((item) => {
175 for (let key in item) {
179 this.connectionTableHeader.indexOf(key) === -1
183 // Filter out the null values in each item
184 for (let i in item[key]) {
187 (item[key][i] === "" ||
188 item[key][i] === "null" ||
189 item[key][i] === null)
199 getConnetionFailed() {
200 console.log("failed");
205 this.formData["sliceProfile_TN_resourceSharingLevel"] ===
208 this.connectionLinkTable.forEach((item) => {
209 item.checked = false;
211 this.formData["tn_connection_links"] = null;
212 this.notPassPara = ["tn_connection_links"];
213 this.transferFormItems.forEach((item) => {
214 if (item.title === "Connection Links") {
217 item.title === "AN Endpoint" ||
218 item.title === "CN Endpoint"
220 item.required = true;
221 item.disable = false;
225 this.formData["sliceProfile_TN_resourceSharingLevel"] === "shared"
227 this.transferFormItems.forEach((item) => {
228 if (item.title === "Connection Links") {
229 item.disable = false;
231 item.title === "AN Endpoint" ||
232 item.title === "CN Endpoint"
235 typeof this.formData["tn_connection_links"] !==
237 this.formData["tn_connection_links"] !== null &&
238 this.formData["tn_connection_links"] !== ""
241 item.required = false;
242 this.notPassPara = [];
243 this.notPassPara = this.notPassPara.concat(
249 this.formData["tn_connection_links"] = "";
250 item.disable = false;
251 item.required = true;
252 this.notPassPara = [];
259 validateEndPoint(key: string, value: any, required: boolean): string {
261 if (this.Util.isEmpty(value)) {
262 return "can not be empty";
265 if (key === "ip_address") {
266 if (!this.regxpIP.test(value)) {
268 return "xxx.xxx.xxx.xxx";
275 } else if (key === "logical_link") {
276 if (!this.Util.isInteger(value)) {
278 return "integer only";
290 changeLinkCheck(id: string): void {
291 // update the selection state
292 this.connectionLinkTable.forEach((item) => {
293 if (item["linkId"] === id) {
296 item.checked = false;
299 this.formData["tn_connection_links"] = id; // get the selected id
304 let areaList = [...this.formData.an_coverage_area_ta_list];
305 this.areaList = areaList.map((item: any) => {
306 let arr = item.split(";");
307 item = arr.map((ite, index) => {
311 } else if (index === 1) {
319 obj.options = [{ name: ite, id: ite }];
326 handleCancel(): void {
327 this.showModel = false;
328 this.cancel.emit(this.showModel);
331 // special handling for address
332 areaCheckBeforeSubmit(target: object): Boolean {
333 for (const prop in target) {
334 if (target.hasOwnProperty(prop)) {
336 prop === "an_coverage_area_ta_list" ||
337 prop === "cn_coverage_area_ta_list"
339 // if the vlaue is "shanghai;shanghai;", the input is incomplete
340 return target[prop].every((item) => {
341 return this.Util.deepCheck(item.split(";"));
349 endCheckBeforeSubmit(endpoint, required): Array<any> {
350 // check params of Endpoint
351 let result: Array<any> = [true, ""];
353 endPointList = this.transferFormItems.find((item) => {
354 return item.title === "AN Endpoint";
359 for (let item of endPointList) {
360 if (item.title === "ip_address") {
362 } else if (item.title === "logical_link") {
363 logicalKey = item.key;
364 } else if (item.title === "nexthop_info") {
368 for (let prop in endpoint) {
369 if (prop === ipKey) {
371 if (endpoint[prop] === "") {
372 result = [false, "Endpoint can not be empty"];
373 } else if (!this.regxpIP.test(endpoint[prop])) {
374 result = [false, "Illegal IpAddress"];
377 !this.regxpIP.test(endpoint[prop]) &&
378 endpoint[prop] !== ""
380 result = [false, "Illegal IpAddress"];
382 } else if (prop === logicalKey) {
384 if (endpoint[prop] === "") {
385 result = [false, "logical can not be empty"];
386 } else if (!this.Util.isInteger(endpoint[prop])) {
387 result = [false, "LogicalID can only be an integer"];
390 !this.Util.isInteger(endpoint[prop]) &&
391 endpoint[prop] !== ""
393 result = [false, "LogicalID can only be an integer"];
395 } else if (prop === nextKey) {
396 if (required && endpoint[prop] === "") {
397 result = [false, "Endpoint can not be empty"];
404 inputHolder(title: string): string {
405 const titleArr = title.split(" ");
406 if (titleArr.length > 1) {
407 return titleArr.slice(0, 2).join("");
413 labelStyle(required: boolean): object {
416 style = { "margin-left": "18px", "margin-right": "-18px" };
424 // Verify that items of EndPoint is correct
425 if (this.EndpointEnable) {
426 let endCheckResult = [];
427 if (this.title === "Tn") {
428 const ANendCheckResult = this.endCheckBeforeSubmit(
429 this.ANEndpointInputs,
430 this.transferFormItems.find((item) => {
431 return item.title === "AN Endpoint";
434 const CNendCheckResult = this.endCheckBeforeSubmit(
435 this.CNEndpointInputs,
436 this.transferFormItems.find((item) => {
437 return item.title === "CN Endpoint";
440 if (ANendCheckResult[0] && CNendCheckResult[0]) {
441 endCheckResult[0] = true;
443 if (ANendCheckResult[0] === false) {
444 endCheckResult = ANendCheckResult;
446 endCheckResult = CNendCheckResult;
450 if (!endCheckResult[0]) {
451 this.message.error(endCheckResult[1].toString());
454 // replace the params about endPoint
455 for (let prop in this.formData) {
457 this.title === "Tn" &&
458 typeof this.ANEndpointInputs[prop] !== "undefined"
460 this.formData[prop] = this.ANEndpointInputs[prop];
462 this.title === "Tn" &&
463 typeof this.CNEndpointInputs[prop] !== "undefined"
465 this.formData[prop] = this.CNEndpointInputs[prop];
470 if (this.title === "An") {
471 const an_coverage_area_ta_list: string[] = [];
472 this.areaList.forEach((item) => {
473 let str: string = "";
474 item.forEach((area) => {
475 str += area.selected + ";";
477 an_coverage_area_ta_list.push(str.substring(0, str.length - 1));
479 params = { ...this.formData, an_coverage_area_ta_list };
481 params = { ...this.formData };
483 // Verify that each item exclude endpoint is not empty, include special handeling of area_list
484 let checkParams: object = params;
485 let requireKeyList: string[] = [];
486 let targetFormItems: any[] = [];
487 if (this.title === "An" || this.title === "Cn") {
488 targetFormItems = this.coreFormItems;
489 } else if ((this.title = "Tn")) {
490 targetFormItems = this.transferFormItems;
492 for (let item of targetFormItems) {
493 if (typeof item.required !== "undefined" && item.required) {
495 typeof item.type !== "undefined" &&
496 item.type !== "endpoint"
498 requireKeyList.push(item.key);
502 checkParams = this.Util.pick(params, requireKeyList);
504 this.Util.deepCheck(checkParams) &&
505 this.areaCheckBeforeSubmit(params)
507 this.paramsDataChange.emit(params);
508 this.noPassParaChange.emit(this.notPassPara);
511 this.message.error("Please complete the form");