Clean up and add license headings
[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 } from '@angular/core';
22 import { AbstractControl, ControlContainer, FormBuilder, FormControl, FormGroup, FormGroupDirective, Validators } from '@angular/forms';
23 import { Rics } from 'src/app/interfaces/ric';
24 import { PolicyService } from 'src/app/services/policy/policy.service';
25
26 @Component({
27   selector: 'nrcp-ric-selector',
28   templateUrl: './ric-selector.component.html',
29   styleUrls: ['./ric-selector.component.scss'],
30   viewProviders: [{ provide: ControlContainer, useExisting: FormGroupDirective }]
31
32 })
33 export class RicSelectorComponent implements OnInit {
34
35   @Input() instanceForm: FormGroup;
36   @Input() policyTypeName: string = '';
37   ric: string;
38   allRics: string[] = [];
39
40   constructor(
41     private dataService: PolicyService,
42     private formBuilder: FormBuilder) {
43   }
44
45   ngOnInit(): void {
46     this.instanceForm.addControl(
47       'ricSelector', new FormControl(this.ric, [
48         Validators.required
49       ]));
50
51     console.log('Ric:', this.ric);
52     this.fetchRics();
53   }
54
55   get selectedRic(): string { return this.ric; }
56
57   get ricSelector(): AbstractControl {
58     return this.instanceForm.get('ricSelector');
59   }
60
61   private fetchRics() {
62     console.log('fetchRics ', this.policyTypeName);
63     const self: RicSelectorComponent = this;
64     this.dataService.getRics(this.policyTypeName).subscribe(
65       {
66         next(value: Rics) {
67           value.rics.forEach(ric => {
68             self.allRics.push(ric.ric_id)
69           });
70           console.log(value);
71         }
72       });
73   }
74 }