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

100% Statements 27/27
77.78% Branches 7/9
100% Functions 6/6
100% Lines 23/23

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
    514x
    4x

    4x
    4x

    4x
    4x

    4x

    3x

    6x
    6x
    6x

    6x
    18x

    6x

    4x
    1x
    1x

    1x

    1x
    1x

    4x
    36x

    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;

      settingsForm: CdFormGroup;
      helpText: any;

      constructor(public modalRef: BsModalRef, public iscsiService: IscsiService) {}

      ngOnInit() {
        const fg = {};
        this.helpText = this.iscsiService.targetAdvancedSettings;

        _.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();
      }

      isRadio(control) {
        return ['Yes', 'No'].indexOf(this.target_default_controls[control]) !== -1;
      }
    }