1 import { Component, OnInit } from '@angular/core';
2 import { FormControl, Validators } from '@angular/forms';
4 import * as _ from 'lodash';
5 import { BsModalRef } from 'ngx-bootstrap/modal';
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;
23 constructor(public modalRef: BsModalRef, public iscsiService: IscsiService) {}
27 this.helpText = this.iscsiService.targetAdvancedSettings;
29 _.forIn(this.target_default_controls, (_value, key) => {
30 const validators = [];
31 if (this.target_controls_limits && key in this.target_controls_limits) {
32 if ('min' in this.target_controls_limits[key]) {
33 validators.push(Validators.min(this.target_controls_limits[key]['min']));
35 if ('max' in this.target_controls_limits[key]) {
36 validators.push(Validators.max(this.target_controls_limits[key]['max']));
39 fg[key] = new FormControl(this.target_controls.value[key], { validators: validators });
42 this.settingsForm = new CdFormGroup(fg);
47 _.forIn(this.settingsForm.controls, (control, key) => {
48 if (!(control.value === '' || control.value === null)) {
49 settings[key] = control.value;
53 this.target_controls.setValue(settings);
58 return ['Yes', 'No'].indexOf(this.target_default_controls[control]) !== -1;