Upgrade ANR client to API spec version 0.0.8
[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         this.ncrDialogForm = new FormGroup({
47             servingCellNrcgi: new FormControl(this.data.servingCellNrcgi), // readonly
48             neighborCellNrpci: new FormControl(this.data.neighborCellNrpci), // readonly
49             neighborCellNrcgi: new FormControl(this.data.neighborCellNrcgi, [Validators.required]),
50             flagNoHo: new FormControl(this.data.flagNoHo),
51             flagNoXn: new FormControl(this.data.flagNoXn),
52             flagNoRemove: new FormControl(this.data.flagNoRemove)
53         });
54     }
55
56     onCancel() {
57         this.dialogRef.close();
58     }
59
60     modifyNcr = (ncrFormValue: ANRNeighborCellRelation) => {
61       if (this.ncrDialogForm.valid) {
62         const ncrm = {} as ANRNeighborCellRelationMod;
63         // there must be a btter way
64         ncrm.neighborCellNrcgi = ncrFormValue.neighborCellNrcgi;
65         ncrm.neighborCellNrpci = ncrFormValue.neighborCellNrpci;
66         ncrm.flagNoHo = ncrFormValue.flagNoHo;
67         ncrm.flagNoXn = ncrFormValue.flagNoXn;
68         ncrm.flagNoRemove = ncrFormValue.flagNoRemove;
69         this.dataService.modifyNcr(ncrFormValue.servingCellNrcgi, ncrFormValue.neighborCellNrpci, ncrm).subscribe((val: any[]) => {},
70             (error => {
71                 this.errorService.displayError('NCR update failed: ' + error.message);
72             })
73         );
74         this.dialogRef.close();
75       }
76     }
77
78     public hasError(controlName: string, errorName: string) {
79         if (this.ncrDialogForm.controls[controlName].hasError(errorName)) {
80           return true;
81         }
82         return false;
83     }
84
85     public validateControl(controlName: string) {
86         if (this.ncrDialogForm.controls[controlName].invalid && this.ncrDialogForm.controls[controlName].touched) {
87             return true;
88         }
89         return false;
90     }
91
92 }