Adding aliases for imports
[portal/nonrtric-controlpanel.git] / webapp-frontend / src / app / policy / ric-selector / ric-selector.component.ts
1 // -
2 //   ========================LICENSE_START=================================
3 //   O-RAN-SC
4 //   %%
5 //   Copyright (C) 2021: Nordix Foundation
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
21 import { Component, Input, OnInit, Output } from "@angular/core";
22 import {
23   AbstractControl,
24   ControlContainer,
25   FormControl,
26   FormGroup,
27   FormGroupDirective,
28   Validators,
29 } from "@angular/forms";
30 import { EventEmitter } from "@angular/core";
31 import { Rics } from "@interfaces/ric";
32 import { PolicyService } from "@services/policy/policy.service";
33 import { MatSelectChange } from "@angular/material/select";
34
35 @Component({
36   selector: "nrcp-ric-selector",
37   templateUrl: "./ric-selector.component.html",
38   styleUrls: ["./ric-selector.component.scss"],
39   viewProviders: [
40     { provide: ControlContainer, useExisting: FormGroupDirective },
41   ],
42 })
43 export class RicSelectorComponent implements OnInit {
44   @Input() policyTypeName: string = "";
45   @Output() selectedRic: EventEmitter<string> = new EventEmitter<string>();
46
47   ric: string = null;
48   instanceForm: FormGroup = new FormGroup({
49     ricSelector: new FormControl(this.ric, [Validators.required]),
50   });
51   allRics: string[] = [];
52
53   constructor(private dataService: PolicyService) {}
54
55   ngOnInit(): void {
56     this.fetchRics();
57   }
58
59   onRicChanged(newvalue: MatSelectChange): void {
60     this.selectedRic.emit(newvalue.value);
61   }
62
63   get ricSelector(): AbstractControl {
64     return this.instanceForm.get("ricSelector");
65   }
66
67   private fetchRics() {
68     console.log("fetchRics ", this.policyTypeName);
69     const self: RicSelectorComponent = this;
70     this.dataService.getRics(this.policyTypeName).subscribe({
71       next(value: Rics) {
72         value.rics.forEach((ric) => {
73           self.allRics.push(ric.ric_id);
74         });
75         console.log(value);
76       },
77     });
78   }
79 }