Add AC xApp control screen
[portal/ric-dashboard.git] / webapp-frontend / src / app / anr-xapp / anr-edit-ncr-dialog.component.ts
1 /*-
2  * ========================LICENSE_START=================================
3  * O-RAN-SC
4  * %%
5  * Copyright (C) 2019 AT&T Intellectual Property and Nokia
6  * %%
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ========================LICENSE_END===================================
19  */
20 import { Component, OnInit, Inject } from '@angular/core';
21 import { FormGroup, FormControl, Validators } from '@angular/forms';
22 import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog';
23 import { ANRXappService } from '../services/anr-xapp/anr-xapp.service';
24 import { ErrorDialogService } from '../services/ui/error-dialog.service';
25 import { ANRNeighborCellRelation, ANRNeighborCellRelationMod } from '../interfaces/anr-xapp.types';
26
27 @Component({
28     selector: 'app-ncr-edit-dialog',
29     templateUrl: './anr-edit-ncr-dialog.component.html',
30     styleUrls: ['./anr-edit-ncr-dialog.component.scss']
31 })
32
33 export class ANREditNCRDialogComponent implements OnInit {
34
35     private ncrDialogForm: FormGroup;
36
37     constructor(
38         private dialogRef: MatDialogRef<ANREditNCRDialogComponent>,
39         private dataService: ANRXappService,
40         private errorService: ErrorDialogService,
41         @Inject(MAT_DIALOG_DATA) private data: ANRNeighborCellRelation) { }
42
43     ngOnInit() {
44         const namePattern = /^([A-Z])+([0-9])+$/;
45         this.ncrDialogForm = new FormGroup({
46             servingCellNrcgi: new FormControl(this.data.servingCellNrcgi), // readonly
47             neighborCellNrpci: new FormControl(this.data.neighborCellNrpci), // readonly
48             neighborCellNrcgi: new FormControl(this.data.neighborCellNrcgi, [Validators.required, Validators.pattern(namePattern)]),
49             flagNoHo: new FormControl(this.data.flagNoHo),
50             flagNoXn: new FormControl(this.data.flagNoXn),
51             flagNoRemove: new FormControl(this.data.flagNoRemove)
52         });
53     }
54
55     onCancel() {
56         this.dialogRef.close();
57     }
58
59     modifyNcr = (ncrFormValue: ANRNeighborCellRelation) => {
60         if (this.ncrDialogForm.valid) {
61             const ncrm = {} as ANRNeighborCellRelationMod;
62             // there must be a better way
63             ncrm.neighborCellNrcgi = ncrFormValue.neighborCellNrcgi;
64             ncrm.neighborCellNrpci = ncrFormValue.neighborCellNrpci;
65             ncrm.flagNoHo = ncrFormValue.flagNoHo;
66             ncrm.flagNoXn = ncrFormValue.flagNoXn;
67             ncrm.flagNoRemove = ncrFormValue.flagNoRemove;
68             this.dataService.modifyNcr(ncrFormValue.servingCellNrcgi, ncrFormValue.neighborCellNrpci, ncrm).subscribe((val: any[]) => { },
69                 (error => {
70                     this.errorService.displayError('NCR update failed: ' + error.message);
71                 })
72             );
73             this.dialogRef.close();
74         }
75     }
76
77     hasError(controlName: string, errorName: string) {
78         if (this.ncrDialogForm.controls[controlName].hasError(errorName)) {
79             return true;
80         }
81         return false;
82     }
83
84     validateControl(controlName: string) {
85         if (this.ncrDialogForm.controls[controlName].invalid && this.ncrDialogForm.controls[controlName].touched) {
86             return true;
87         }
88         return false;
89     }
90
91 }