]> git.proxmox.com Git - ceph.git/blame - ceph/src/pybind/mgr/dashboard/frontend/src/app/ceph/block/iscsi-target-iqn-settings-modal/iscsi-target-iqn-settings-modal.component.ts
import 15.2.0 Octopus source
[ceph.git] / ceph / src / pybind / mgr / dashboard / frontend / src / app / ceph / block / iscsi-target-iqn-settings-modal / iscsi-target-iqn-settings-modal.component.ts
CommitLineData
11fdf7f2
TL
1import { Component, OnInit } from '@angular/core';
2import { FormControl } from '@angular/forms';
3
4import * as _ from 'lodash';
5import { BsModalRef } from 'ngx-bootstrap/modal';
6
7import { IscsiService } from '../../../shared/api/iscsi.service';
8import { CdFormGroup } from '../../../shared/forms/cd-form-group';
9
10@Component({
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']
14})
15export class IscsiTargetIqnSettingsModalComponent implements OnInit {
16 target_controls: FormControl;
17 target_default_controls: any;
eafe8130 18 target_controls_limits: any;
11fdf7f2
TL
19
20 settingsForm: CdFormGroup;
11fdf7f2
TL
21
22 constructor(public modalRef: BsModalRef, public iscsiService: IscsiService) {}
23
24 ngOnInit() {
9f95a23c 25 const fg: Record<string, FormControl> = {};
11fdf7f2
TL
26 _.forIn(this.target_default_controls, (_value, key) => {
27 fg[key] = new FormControl(this.target_controls.value[key]);
28 });
29
30 this.settingsForm = new CdFormGroup(fg);
31 }
32
33 save() {
34 const settings = {};
35 _.forIn(this.settingsForm.controls, (control, key) => {
36 if (!(control.value === '' || control.value === null)) {
37 settings[key] = control.value;
38 }
39 });
40
41 this.target_controls.setValue(settings);
42 this.modalRef.hide();
43 }
44
9f95a23c 45 getTargetControlLimits(setting: string) {
eafe8130
TL
46 if (this.target_controls_limits) {
47 return this.target_controls_limits[setting];
48 }
49 // backward compatibility
50 if (['Yes', 'No'].includes(this.target_default_controls[setting])) {
51 return { type: 'bool' };
52 }
53 return { type: 'int' };
11fdf7f2
TL
54 }
55}