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 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 | 4x 4x 4x 4x 4x 4x 4x 3x 6x 6x 6x 12x 12x 18x 6x 4x 12x 12x 4x 1x 1x 1x 1x 1x 6x 1x 1x 2x 1x 1x 1x 1x 1x 1x 1x 1x 1x 4x | import { Component, OnInit } from '@angular/core';
import { AbstractControl, 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-image-settings-modal',
template: require('./iscsi-target-image-settings-modal.component.html'),
styles: []
})
export class IscsiTargetImageSettingsModalComponent implements OnInit {
image: string;
imagesSettings: any;
api_version: number;
disk_default_controls: any;
disk_controls_limits: any;
backstores: any;
control: AbstractControl;
settingsForm: CdFormGroup;
constructor(public modalRef: BsModalRef, public iscsiService: IscsiService) {}
ngOnInit() {
const fg = {
backstore: new FormControl(this.imagesSettings[this.image]['backstore']),
lun: new FormControl(this.imagesSettings[this.image]['lun']),
wwn: new FormControl(this.imagesSettings[this.image]['wwn'])
};
_.forEach(this.backstores, (backstore) => {
const model = this.imagesSettings[this.image][backstore] || {};
_.forIn(this.disk_default_controls[backstore], (_value, key) => {
fg[key] = new FormControl(model[key]);
});
});
this.settingsForm = new CdFormGroup(fg);
}
getDiskControlLimits(backstore, setting) {
Eif (this.disk_controls_limits) {
return this.disk_controls_limits[backstore][setting];
}
// backward compatibility
return { type: 'int' };
}
save() {
const backstore = this.settingsForm.controls['backstore'].value;
const lun = this.settingsForm.controls['lun'].value;
const wwn = this.settingsForm.controls['wwn'].value;
const settings = {};
_.forIn(this.settingsForm.controls, (control, key) => {
if (
!(control.value === '' || control.value === null) &&
key in this.disk_default_controls[this.settingsForm.value['backstore']]
) {
settings[key] = control.value;
// If one setting belongs to multiple backstores, we have to update it in all backstores
_.forEach(this.backstores, (currentBackstore) => {
if (currentBackstore !== backstore) {
const model = this.imagesSettings[this.image][currentBackstore] || {};
Iif (key in model) {
this.imagesSettings[this.image][currentBackstore][key] = control.value;
}
}
});
}
});
this.imagesSettings[this.image]['backstore'] = backstore;
this.imagesSettings[this.image]['lun'] = lun;
this.imagesSettings[this.image]['wwn'] = wwn;
this.imagesSettings[this.image][backstore] = settings;
this.imagesSettings = { ...this.imagesSettings };
this.control.updateValueAndValidity({ emitEvent: false });
this.modalRef.hide();
}
}
|