1 import { Component, OnInit } from '@angular/core';
2 import { FormControl } from '@angular/forms';
4 import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
5 import _ from 'lodash';
7 import { IscsiService } from '~/app/shared/api/iscsi.service';
8 import { ActionLabelsI18n } from '~/app/shared/constants/app.constants';
9 import { CdFormGroup } from '~/app/shared/forms/cd-form-group';
12 selector: 'cd-iscsi-target-iqn-settings-modal',
13 templateUrl: './iscsi-target-iqn-settings-modal.component.html',
14 styleUrls: ['./iscsi-target-iqn-settings-modal.component.scss']
16 export class IscsiTargetIqnSettingsModalComponent implements OnInit {
17 target_controls: FormControl;
18 target_default_controls: any;
19 target_controls_limits: any;
21 settingsForm: CdFormGroup;
24 public activeModal: NgbActiveModal,
25 public iscsiService: IscsiService,
26 public actionLabels: ActionLabelsI18n
30 const fg: Record<string, FormControl> = {};
31 _.forIn(this.target_default_controls, (_value, key) => {
32 fg[key] = new FormControl(this.target_controls.value[key]);
35 this.settingsForm = new CdFormGroup(fg);
40 _.forIn(this.settingsForm.controls, (control, key) => {
41 if (!(control.value === '' || control.value === null)) {
42 settings[key] = control.value;
46 this.target_controls.setValue(settings);
47 this.activeModal.close();
50 getTargetControlLimits(setting: string) {
51 if (this.target_controls_limits) {
52 return this.target_controls_limits[setting];
54 // backward compatibility
55 if (['Yes', 'No'].includes(this.target_default_controls[setting])) {
56 return { type: 'bool' };
58 return { type: 'int' };