2857f55d83910f49fbd117dab33cff281c6c1b7a
[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 import { modelGroupProvider } from '@angular/forms/src/directives/ng_model_group';
27
28 @Component({
29     selector: 'app-ncr-edit-dialog',
30     templateUrl: './anr-edit-ncr-dialog.component.html',
31     styleUrls: ['./anr-edit-ncr-dialog.component.scss']
32 })
33
34 export class ANREditNCRDialogComponent implements OnInit {
35
36     private ncrDialogForm: FormGroup;
37
38     constructor(
39         private dialogRef: MatDialogRef<ANREditNCRDialogComponent>,
40         private dataService: ANRXappService, private errorService: ErrorDialogService,
41         @Inject(MAT_DIALOG_DATA) private data: ANRNeighborCellRelation) {
42         console.log('constructed with data ' + data);
43     }
44
45     ngOnInit() {
46         const namePattern = /^([A-Z])+([0-9])+$/;
47         this.ncrDialogForm = new FormGroup({
48             servingCellNrcgi: new FormControl(this.data.servingCellNrcgi), // readonly
49             neighborCellNrpci: new FormControl(this.data.neighborCellNrpci), // readonly
50             neighborCellNrcgi: new FormControl(this.data.neighborCellNrcgi, [Validators.required, Validators.pattern(namePattern)]),
51             flagNoHo: new FormControl(this.data.flagNoHo),
52             flagNoXn: new FormControl(this.data.flagNoXn),
53             flagNoRemove: new FormControl(this.data.flagNoRemove)
54         });
55     }
56
57     onCancel() {
58         this.dialogRef.close();
59     }
60
61     modifyNcr = (ncrFormValue: ANRNeighborCellRelation) => {
62       if (this.ncrDialogForm.valid) {
63         const ncrm = {} as ANRNeighborCellRelationMod;
64         // there must be a btter way
65         ncrm.neighborCellNrcgi = ncrFormValue.neighborCellNrcgi;
66         ncrm.neighborCellNrpci = ncrFormValue.neighborCellNrpci;
67         ncrm.flagNoHo = ncrFormValue.flagNoHo;
68         ncrm.flagNoXn = ncrFormValue.flagNoXn;
69         ncrm.flagNoRemove = ncrFormValue.flagNoRemove;
70         this.dataService.modifyNcr(ncrFormValue.servingCellNrcgi, ncrFormValue.neighborCellNrpci, ncrm).subscribe((val: any[]) => {},
71             (error => {
72                 this.errorService.displayError('NCR update failed: ' + error.message);
73             })
74         );
75         this.dialogRef.close();
76       }
77     }
78
79     public hasError(controlName: string, errorName: string) {
80         if (this.ncrDialogForm.controls[controlName].hasError(errorName)) {
81           return true;
82         }
83         return false;
84     }
85
86     public validateControl(controlName: string) {
87         if (this.ncrDialogForm.controls[controlName].invalid && this.ncrDialogForm.controls[controlName].touched) {
88             return true;
89         }
90         return false;
91     }
92
93 }