All files / src/app/ceph/block/iscsi-target-iqn-settings-modal iscsi-target-iqn-settings-modal.component.ts

90.32% Statements 28/31
68.75% Branches 11/16
100% Functions 7/7
88.89% Lines 24/27

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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 564x 4x   4x 4x   4x 4x             4x             3x   6x 6x 6x 18x     6x     4x 1x 1x 3x 1x       1x 1x     4x 18x 18x               4x  
import { Component, OnInit } from '@angular/core';
import { FormControl } from '@angular/forms';
 
import * as _ from 'lodash';
import { BsModalRef } from 'ngx-bootstrap/modal';
 
import { IscsiService } from '../../../shared/api/iscsi.service';
import { CdFormGroup } from '../../../shared/forms/cd-form-group';
 
@Component({
  selector: 'cd-iscsi-target-iqn-settings-modal',
  template: require('./iscsi-target-iqn-settings-modal.component.html'),
  styles: []
})
export class IscsiTargetIqnSettingsModalComponent implements OnInit {
  target_controls: FormControl;
  target_default_controls: any;
  target_controls_limits: any;
 
  settingsForm: CdFormGroup;
 
  constructor(public modalRef: BsModalRef, public iscsiService: IscsiService) {}
 
  ngOnInit() {
    const fg = {};
    _.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.modalRef.hide();
  }
 
  getTargetControlLimits(setting) {
    Eif (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' };
  }
}