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

100% Statements 25/25
81.82% Branches 9/11
100% Functions 5/5
100% Lines 21/21

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 474x   4x 4x   4x             4x                 3x   6x 6x   6x 6x 12x       4x 1x 1x 1x   1x     1x 1x 1x 1x   4x  
import { Component, OnInit } from '@angular/core';
 
import * as _ from 'lodash';
import { BsModalRef } from 'ngx-bootstrap/modal';
 
import { IscsiService } from '../../../shared/api/iscsi.service';
 
@Component({
  selector: 'cd-iscsi-target-image-settings-modal',
  template: require('./iscsi-target-image-settings-modal.component.html'),
  styles: []
})
export class IscsiTargetImageSettingsModalComponent implements OnInit {
  image: string;
  imagesSettings: any;
  disk_default_controls: any;
  backstores: any;
 
  model: any;
  helpText: any;
 
  constructor(public modalRef: BsModalRef, public iscsiService: IscsiService) {}
 
  ngOnInit() {
    this.helpText = this.iscsiService.imageAdvancedSettings;
 
    this.model = _.cloneDeep(this.imagesSettings[this.image]);
    _.forEach(this.backstores, (backstore) => {
      this.model[backstore] = this.model[backstore] || {};
    });
  }
 
  save() {
    const backstore = this.model.backstore;
    const settings = {};
    _.forIn(this.model[backstore], (value, key) => {
      if (!(value === '' || value === null)) {
        settings[key] = value;
      }
    });
    this.imagesSettings[this.image]['backstore'] = backstore;
    this.imagesSettings[this.image][backstore] = settings;
    this.imagesSettings = { ...this.imagesSettings };
    this.modalRef.hide();
  }
}