// ========================LICENSE_END===================================
// /
-import { Component, Input, OnInit } 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 { 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 }]
-
+ 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<string> = new EventEmitter<string>();
- @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);
+ if (!this.policyTypeName) 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);
+ });
+ },
+ });
}
}