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=bfa9d9799311c1ab323d7b125b43a367817b32a1;hb=ae54b92e9c8d621d9e3907bbe7c0b56b2c778d8d;hp=583f02af1da3dffa7d7d52474a0d6360b8156742;hpb=23f01d834cb151beb27ce2da0fe7f7b42b3b3a4d;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 583f02a..bfa9d97 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 @@ -1,54 +1,79 @@ -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'; +// - +// ========================LICENSE_START================================= +// O-RAN-SC +// %% +// Copyright (C) 2021: Nordix Foundation +// %% +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ========================LICENSE_END=================================== +// / -@Component({ - selector: 'nrcp-ric-selector', - templateUrl: './ric-selector.component.html', - styleUrls: ['./ric-selector.component.scss'], - viewProviders: [{ provide: ControlContainer, useExisting: FormGroupDirective }] +import { Component, Input, OnInit, Output } from "@angular/core"; +import { + AbstractControl, + ControlContainer, + FormControl, + FormGroup, + FormGroupDirective, + Validators, +} from "@angular/forms"; +import { EventEmitter } from "@angular/core"; +import { Rics } from "@interfaces/ric"; +import { PolicyService } from "@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 }, + ], }) 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) { - } + constructor(private dataService: PolicyService) {} ngOnInit(): void { - this.instanceForm.addControl( - 'ricSelector', new FormControl(this.ric, [ - Validators.required - ])); - - 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); + }, + }); } }