8 } from "@angular/core";
9 import { TRANSFRER_FORM_ITEMS, CORE_FORM_ITEMS, ADDRESS } 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 creatAreaList(): void {
344 this.areaList.push(arr);
347 deleteAreaList(index: number): void {
348 this.areaList.splice(index, 1);
351 handleChange(area: any[], areaItem: any): void {
352 if (areaItem.key === "province" && areaItem.options.length <= 1) {
353 areaItem.options = ADDRESS;
354 } else if (areaItem.key === "city" && areaItem.options.length <= 1) {
355 ADDRESS.forEach((item) => {
356 if (item.name === area[0].selected) {
357 areaItem.options = item.city;
361 areaItem.key === "district" &&
362 areaItem.options.length <= 1
364 ADDRESS.forEach((item: any) => {
365 item.city.forEach((city) => {
366 if (city.name === area[1].selected) {
367 areaItem.options = city.county;
374 handleChangeSelected(area: any[], areaItem: any) {
375 if (areaItem.key === "province") {
376 area[1].selected = "";
377 area[1].options = [];
378 area[2].selected = "";
379 area[2].options = [];
380 } else if (areaItem.key === "city") {
381 area[2].selected = "";
382 area[2].options = [];
386 handleCancel(): void {
387 this.showModel = false;
388 this.cancel.emit(this.showModel);
391 // prompt text for each item of area_list
392 checkArea(area: any): string {
394 area.every((item) => {
395 return item.selected === "";
401 area.some((item) => {
402 return item.selected === "";
410 // special handling for address
411 areaCheckBeforeSubmit(target: object): Boolean {
412 for (const prop in target) {
413 if (target.hasOwnProperty(prop)) {
415 prop === "an_coverage_area_ta_list" ||
416 prop === "cn_coverage_area_ta_list"
418 // if the vlaue is "shanghai;shanghai;", the input is incomplete
419 return target[prop].every((item) => {
420 return this.Util.deepCheck(item.split(";"));
428 endCheckBeforeSubmit(endpoint, required): Array<any> {
429 // check params of Endpoint
430 let result: Array<any> = [true, ""];
432 endPointList = this.transferFormItems.find((item) => {
433 return item.title === "AN Endpoint";
438 for (let item of endPointList) {
439 if (item.title === "ip_address") {
441 } else if (item.title === "logical_link") {
442 logicalKey = item.key;
443 } else if (item.title === "nexthop_info") {
447 for (let prop in endpoint) {
448 if (prop === ipKey) {
450 if (endpoint[prop] === "") {
451 result = [false, "Endpoint can not be empty"];
452 } else if (!this.regxpIP.test(endpoint[prop])) {
453 result = [false, "Illegal IpAddress"];
456 !this.regxpIP.test(endpoint[prop]) &&
457 endpoint[prop] !== ""
459 result = [false, "Illegal IpAddress"];
461 } else if (prop === logicalKey) {
463 if (endpoint[prop] === "") {
464 result = [false, "logical can not be empty"];
465 } else if (!this.Util.isInteger(endpoint[prop])) {
466 result = [false, "LogicalID can only be an integer"];
469 !this.Util.isInteger(endpoint[prop]) &&
470 endpoint[prop] !== ""
472 result = [false, "LogicalID can only be an integer"];
474 } else if (prop === nextKey) {
475 if (required && endpoint[prop] === "") {
476 result = [false, "Endpoint can not be empty"];
483 inputHolder(title: string): string {
484 const titleArr = title.split(" ");
485 if (titleArr.length > 1) {
486 return titleArr.slice(0, 2).join("");
492 labelStyle(required: boolean): object {
495 style = { "margin-left": "18px", "margin-right": "-18px" };
503 // Verify that items of EndPoint is correct
504 if (this.EndpointEnable) {
505 let endCheckResult = [];
506 if (this.title === "Tn") {
507 const ANendCheckResult = this.endCheckBeforeSubmit(
508 this.ANEndpointInputs,
509 this.transferFormItems.find((item) => {
510 return item.title === "AN Endpoint";
513 const CNendCheckResult = this.endCheckBeforeSubmit(
514 this.CNEndpointInputs,
515 this.transferFormItems.find((item) => {
516 return item.title === "CN Endpoint";
519 if (ANendCheckResult[0] && CNendCheckResult[0]) {
520 endCheckResult[0] = true;
522 if (ANendCheckResult[0] === false) {
523 endCheckResult = ANendCheckResult;
525 endCheckResult = CNendCheckResult;
529 if (!endCheckResult[0]) {
530 this.message.error(endCheckResult[1].toString());
533 // replace the params about endPoint
534 for (let prop in this.formData) {
536 this.title === "Tn" &&
537 typeof this.ANEndpointInputs[prop] !== "undefined"
539 this.formData[prop] = this.ANEndpointInputs[prop];
541 this.title === "Tn" &&
542 typeof this.CNEndpointInputs[prop] !== "undefined"
544 this.formData[prop] = this.CNEndpointInputs[prop];
549 if (this.title === "An") {
550 const an_coverage_area_ta_list: string[] = [];
551 this.areaList.forEach((item) => {
552 let str: string = "";
553 item.forEach((area) => {
554 str += area.selected + ";";
556 an_coverage_area_ta_list.push(str.substring(0, str.length - 1));
558 params = { ...this.formData, an_coverage_area_ta_list };
560 params = { ...this.formData };
562 // Verify that each item exclude endpoint is not empty, include special handeling of area_list
563 let checkParams: object = params;
564 let requireKeyList: string[] = [];
565 let targetFormItems: any[] = [];
566 if (this.title === "An" || this.title === "Cn") {
567 targetFormItems = this.coreFormItems;
568 } else if ((this.title = "Tn")) {
569 targetFormItems = this.transferFormItems;
571 for (let item of targetFormItems) {
572 if (typeof item.required !== "undefined" && item.required) {
574 typeof item.type !== "undefined" &&
575 item.type !== "endpoint"
577 requireKeyList.push(item.key);
581 checkParams = this.Util.pick(params, requireKeyList);
583 this.Util.deepCheck(checkParams) &&
584 this.areaCheckBeforeSubmit(params)
586 this.paramsDataChange.emit(params);
587 this.noPassParaChange.emit(this.notPassPara);
590 this.message.error("Please complete the form");