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