]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/blob
eef5276cb73dabb41e921fd0149136284569d76b
[ceph-ci.git] /
1 import { Component, OnInit } from '@angular/core';
2 import { FormControl } from '@angular/forms';
3
4 import * as _ from 'lodash';
5 import { BsModalRef } from 'ngx-bootstrap/modal';
6
7 import { IscsiService } from '../../../shared/api/iscsi.service';
8 import { 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 })
15 export class IscsiTargetIqnSettingsModalComponent implements OnInit {
16   target_controls: FormControl;
17   target_default_controls: any;
18
19   settingsForm: CdFormGroup;
20   helpText: any;
21
22   constructor(public modalRef: BsModalRef, public iscsiService: IscsiService) {}
23
24   ngOnInit() {
25     const fg = {};
26     this.helpText = this.iscsiService.targetAdvancedSettings;
27
28     _.forIn(this.target_default_controls, (_value, key) => {
29       fg[key] = new FormControl(this.target_controls.value[key]);
30     });
31
32     this.settingsForm = new CdFormGroup(fg);
33   }
34
35   save() {
36     const settings = {};
37     _.forIn(this.settingsForm.controls, (control, key) => {
38       if (!(control.value === '' || control.value === null)) {
39         settings[key] = control.value;
40       }
41     });
42
43     this.target_controls.setValue(settings);
44     this.modalRef.hide();
45   }
46
47   isRadio(control) {
48     return ['Yes', 'No'].indexOf(this.target_default_controls[control]) !== -1;
49   }
50 }