Drop Nokia from file header copyright line
[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
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: 'rd-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         this.ncrDialogForm = new FormGroup({
45             servingCellNrcgi: new FormControl(this.data.servingCellNrcgi), // readonly
46             neighborCellNrpci: new FormControl(this.data.neighborCellNrpci), // readonly
47             neighborCellNrcgi: new FormControl(this.data.neighborCellNrcgi, [Validators.required]),
48             flagNoHo: new FormControl(this.data.flagNoHo),
49             flagNoXn: new FormControl(this.data.flagNoXn),
50             flagNoRemove: new FormControl(this.data.flagNoRemove)
51         });
52     }
53
54     onCancel() {
55         this.dialogRef.close();
56     }
57
58     modifyNcr = (ncrFormValue: ANRNeighborCellRelation) => {
59         if (this.ncrDialogForm.valid) {
60             const ncrm = {} as ANRNeighborCellRelationMod;
61             // there must be a better way to build the struct
62             ncrm.neighborCellNrcgi = ncrFormValue.neighborCellNrcgi;
63             ncrm.neighborCellNrpci = ncrFormValue.neighborCellNrpci;
64             ncrm.flagNoHo = ncrFormValue.flagNoHo;
65             ncrm.flagNoXn = ncrFormValue.flagNoXn;
66             ncrm.flagNoRemove = ncrFormValue.flagNoRemove;
67             this.dataService.modifyNcr(ncrFormValue.servingCellNrcgi, ncrFormValue.neighborCellNrpci, ncrm).subscribe(
68                 (val: any[]) => {
69                     // Success
70                 },
71                 (error => {
72                     this.errorService.displayError('NCR update failed: ' + error.message);
73                 })
74             );
75             this.dialogRef.close();
76         }
77     }
78
79     hasError(controlName: string, errorName: string) {
80         if (this.ncrDialogForm.controls[controlName].hasError(errorName)) {
81             return true;
82         }
83         return false;
84     }
85
86     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 }