X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=webapp-frontend%2Fsrc%2Fapp%2Fpolicy%2Fric-selector%2Fric-selector.component.ts;h=15e1a61e0339e6068a6fabffe1d6e7e600bc6917;hb=9fbfc54c9aa3669dd84d85f7c95fa57ba57ec642;hp=d4b50c0f3a25ed87d4f4d85904646fe8df931624;hpb=b3f6966f626c9d58e443280ff3ce17e44a2873e4;p=portal%2Fnonrtric-controlpanel.git diff --git a/webapp-frontend/src/app/policy/ric-selector/ric-selector.component.ts b/webapp-frontend/src/app/policy/ric-selector/ric-selector.component.ts index d4b50c0..15e1a61 100644 --- a/webapp-frontend/src/app/policy/ric-selector/ric-selector.component.ts +++ b/webapp-frontend/src/app/policy/ric-selector/ric-selector.component.ts @@ -17,59 +17,68 @@ // limitations under the License. // ========================LICENSE_END=================================== // / -// -import { Component, Input, OnInit } from '@angular/core'; -import { AbstractControl, ControlContainer, FormBuilder, FormControl, FormGroup, FormGroupDirective, Validators } from '@angular/forms'; -import { Ric, Rics } from 'src/app/interfaces/ric'; -import { PolicyService } from 'src/app/services/policy/policy.service'; +import { Component, Input, OnInit, Output } from "@angular/core"; +import { + AbstractControl, + ControlContainer, + FormBuilder, + FormControl, + FormGroup, + FormGroupDirective, + Validators, +} from "@angular/forms"; +import { EventEmitter } from "@angular/core"; +import { Rics } from "src/app/interfaces/ric"; +import { PolicyService } from "src/app/services/policy/policy.service"; +import { MatSelectChange } from "@angular/material/select"; @Component({ - selector: 'nrcp-ric-selector', - templateUrl: './ric-selector.component.html', - styleUrls: ['./ric-selector.component.scss'], - viewProviders: [{ provide: ControlContainer, useExisting: FormGroupDirective }] - + selector: "nrcp-ric-selector", + templateUrl: "./ric-selector.component.html", + styleUrls: ["./ric-selector.component.scss"], + viewProviders: [ + { provide: ControlContainer, useExisting: FormGroupDirective }, + ], }) export class RicSelectorComponent implements OnInit { + @Input() policyTypeName: string = ""; + @Output() selectedRic: EventEmitter = new EventEmitter(); - @Input() instanceForm: FormGroup; - @Input() policyTypeName: string = ''; - ric: string; + ric: string = null; + instanceForm: FormGroup = new FormGroup({ + ricSelector: new FormControl(this.ric, [Validators.required]), + }); allRics: string[] = []; constructor( private dataService: PolicyService, - private formBuilder: FormBuilder) { - } + private formBuilder: FormBuilder + ) {} ngOnInit(): void { - this.instanceForm.addControl( - 'ricSelector', new FormControl(this.ric, [ - Validators.required - ])); - - console.log('Ric:', this.ric); + console.log("Ric:", this.ric); this.fetchRics(); } - get selectedRic(): string { return this.ric; } + onRicChanged(newvalue: MatSelectChange): void { + this.selectedRic.emit(newvalue.value); + } get ricSelector(): AbstractControl { - return this.instanceForm.get('ricSelector'); + return this.instanceForm.get("ricSelector"); } private fetchRics() { - console.log('fetchRics ', this.policyTypeName); + console.log("fetchRics ", this.policyTypeName); const self: RicSelectorComponent = this; - this.dataService.getRics(this.policyTypeName).subscribe( - { - next(value: Rics) { - value.rics.forEach(ric => { - self.allRics.push(ric.ric_id) - }); - console.log(value); - } - }); + this.dataService.getRics(this.policyTypeName).subscribe({ + next(value: Rics) { + value.rics.forEach((ric) => { + self.allRics.push(ric.ric_id); + }); + console.log(value); + }, + }); } }