1 import { Component, OnInit } from '@angular/core';
2 import { AbstractControl, FormControl } from '@angular/forms';
4 import * as _ from 'lodash';
5 import { BsModalRef } from 'ngx-bootstrap/modal';
7 import { IscsiService } from '../../../shared/api/iscsi.service';
8 import { CdFormGroup } from '../../../shared/forms/cd-form-group';
11 selector: 'cd-iscsi-target-image-settings-modal',
12 templateUrl: './iscsi-target-image-settings-modal.component.html',
13 styleUrls: ['./iscsi-target-image-settings-modal.component.scss']
15 export class IscsiTargetImageSettingsModalComponent implements OnInit {
19 disk_default_controls: any;
20 disk_controls_limits: any;
22 control: AbstractControl;
24 settingsForm: CdFormGroup;
26 constructor(public modalRef: BsModalRef, public iscsiService: IscsiService) {}
30 backstore: new FormControl(this.imagesSettings[this.image]['backstore']),
31 lun: new FormControl(this.imagesSettings[this.image]['lun']),
32 wwn: new FormControl(this.imagesSettings[this.image]['wwn'])
34 _.forEach(this.backstores, (backstore) => {
35 const model = this.imagesSettings[this.image][backstore] || {};
36 _.forIn(this.disk_default_controls[backstore], (_value, key) => {
37 fg[key] = new FormControl(model[key]);
41 this.settingsForm = new CdFormGroup(fg);
44 getDiskControlLimits(backstore, setting) {
45 return this.disk_controls_limits[backstore][setting];
49 const backstore = this.settingsForm.controls['backstore'].value;
50 const lun = this.settingsForm.controls['lun'].value;
51 const wwn = this.settingsForm.controls['wwn'].value;
53 _.forIn(this.settingsForm.controls, (control, key) => {
55 !(control.value === '' || control.value === null) &&
56 key in this.disk_default_controls[this.settingsForm.value['backstore']]
58 settings[key] = control.value;
59 // If one setting belongs to multiple backstores, we have to update it in all backstores
60 _.forEach(this.backstores, (currentBackstore) => {
61 if (currentBackstore !== backstore) {
62 const model = this.imagesSettings[this.image][currentBackstore] || {};
64 this.imagesSettings[this.image][currentBackstore][key] = control.value;
70 this.imagesSettings[this.image]['backstore'] = backstore;
71 this.imagesSettings[this.image]['lun'] = lun;
72 this.imagesSettings[this.image]['wwn'] = wwn;
73 this.imagesSettings[this.image][backstore] = settings;
74 this.imagesSettings = { ...this.imagesSettings };
75 this.control.updateValueAndValidity({ emitEvent: false });