1 import { Component, OnInit } from '@angular/core';
2 import { 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 {
18 disk_default_controls: any;
19 disk_controls_limits: any;
22 settingsForm: CdFormGroup;
24 constructor(public modalRef: BsModalRef, public iscsiService: IscsiService) {}
28 backstore: new FormControl(this.imagesSettings[this.image]['backstore'])
30 _.forEach(this.backstores, (backstore) => {
31 const model = this.imagesSettings[this.image][backstore] || {};
32 _.forIn(this.disk_default_controls[backstore], (_value, key) => {
33 fg[key] = new FormControl(model[key]);
37 this.settingsForm = new CdFormGroup(fg);
40 getDiskControlLimits(backstore, setting) {
41 return this.disk_controls_limits[backstore][setting];
45 const backstore = this.settingsForm.controls['backstore'].value;
47 _.forIn(this.settingsForm.controls, (control, key) => {
49 !(control.value === '' || control.value === null) &&
50 key in this.disk_default_controls[this.settingsForm.value['backstore']]
52 settings[key] = control.value;
53 // If one setting belongs to multiple backstores, we have to update it in all backstores
54 _.forEach(this.backstores, (currentBackstore) => {
55 if (currentBackstore !== backstore) {
56 const model = this.imagesSettings[this.image][currentBackstore] || {};
58 this.imagesSettings[this.image][currentBackstore][key] = control.value;
64 this.imagesSettings[this.image]['backstore'] = backstore;
65 this.imagesSettings[this.image][backstore] = settings;
66 this.imagesSettings = { ...this.imagesSettings };