Fix get rics for no type
[portal/nonrtric-controlpanel.git] / webapp-frontend / src / app / policy / ric-selector / ric-selector.component.ts
index 996d9a0..6b502c6 100644 (file)
 //   ========================LICENSE_END===================================
 //  /
 
-import { Component, Input, OnInit } from "@angular/core";
+import { Component, Input, OnInit, Output } from "@angular/core";
 import {
   AbstractControl,
   ControlContainer,
-  FormBuilder,
   FormControl,
   FormGroup,
   FormGroupDirective,
   Validators,
 } from "@angular/forms";
-import { Rics } from "src/app/interfaces/ric";
-import { PolicyService } from "src/app/services/policy/policy.service";
+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",
@@ -40,28 +41,23 @@ import { PolicyService } from "src/app/services/policy/policy.service";
   ],
 })
 export class RicSelectorComponent implements OnInit {
-  @Input() instanceForm: FormGroup;
   @Input() policyTypeName: string = "";
-  ric: string;
+  @Output() selectedRic: EventEmitter<string> = new EventEmitter<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 {
@@ -69,6 +65,7 @@ export class RicSelectorComponent implements OnInit {
   }
 
   private fetchRics() {
+    if (!this.policyTypeName) this.policyTypeName = "";
     console.log("fetchRics ", this.policyTypeName);
     const self: RicSelectorComponent = this;
     this.dataService.getRics(this.policyTypeName).subscribe({