]> git.apps.os.sepia.ceph.com Git - ceph.git/blob
622beb4619e4c25f1bcd4a04f1eab6c6e044e69e
[ceph.git] /
1 import { Component, OnInit } from '@angular/core';
2 import { FormControl, Validators } 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   target_controls_limits: any;
19
20   settingsForm: CdFormGroup;
21   helpText: any;
22
23   constructor(public modalRef: BsModalRef, public iscsiService: IscsiService) {}
24
25   ngOnInit() {
26     const fg = {};
27     this.helpText = this.iscsiService.targetAdvancedSettings;
28
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']));
34         }
35         if ('max' in this.target_controls_limits[key]) {
36           validators.push(Validators.max(this.target_controls_limits[key]['max']));
37         }
38       }
39       fg[key] = new FormControl(this.target_controls.value[key], { validators: validators });
40     });
41
42     this.settingsForm = new CdFormGroup(fg);
43   }
44
45   save() {
46     const settings = {};
47     _.forIn(this.settingsForm.controls, (control, key) => {
48       if (!(control.value === '' || control.value === null)) {
49         settings[key] = control.value;
50       }
51     });
52
53     this.target_controls.setValue(settings);
54     this.modalRef.hide();
55   }
56
57   isRadio(control) {
58     return ['Yes', 'No'].indexOf(this.target_default_controls[control]) !== -1;
59   }
60 }