1 import { Component, OnInit } from '@angular/core';
2 import { FormControl } from '@angular/forms';
4 import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
5 import * as _ from 'lodash';
7 import { IscsiService } from '../../../shared/api/iscsi.service';
8 import { CdFormGroup } from '../../../shared/forms/cd-form-group';
11 selector: 'cd-iscsi-target-iqn-settings-modal',
12 templateUrl: './iscsi-target-iqn-settings-modal.component.html',
13 styleUrls: ['./iscsi-target-iqn-settings-modal.component.scss']
15 export class IscsiTargetIqnSettingsModalComponent implements OnInit {
16 target_controls: FormControl;
17 target_default_controls: any;
18 target_controls_limits: any;
20 settingsForm: CdFormGroup;
22 constructor(public activeModal: NgbActiveModal, public iscsiService: IscsiService) {}
25 const fg: Record<string, FormControl> = {};
26 _.forIn(this.target_default_controls, (_value, key) => {
27 fg[key] = new FormControl(this.target_controls.value[key]);
30 this.settingsForm = new CdFormGroup(fg);
35 _.forIn(this.settingsForm.controls, (control, key) => {
36 if (!(control.value === '' || control.value === null)) {
37 settings[key] = control.value;
41 this.target_controls.setValue(settings);
42 this.activeModal.close();
45 getTargetControlLimits(setting: string) {
46 if (this.target_controls_limits) {
47 return this.target_controls_limits[setting];
49 // backward compatibility
50 if (['Yes', 'No'].includes(this.target_default_controls[setting])) {
51 return { type: 'bool' };
53 return { type: 'int' };