Code related to custom adapters rewritten

This commit is contained in:
Piotr Pekala 2019-02-27 00:14:49 -08:00
parent 296548ffd6
commit d05bdd5200
3 changed files with 61 additions and 25 deletions

View File

@ -62,6 +62,8 @@ export class QemuVmTemplateDetailsComponent implements OnInit {
this.getConfiguration();
this.qemuService.getTemplate(this.server, template_id).subscribe((qemuTemplate: QemuTemplate) => {
this.qemuTemplate = qemuTemplate;
this.adapters.push(adapter);
});
this.qemuService.getBinaries(server).subscribe((qemuBinaries: QemuBinary[]) => {
this.binaries = qemuBinaries;
@ -114,7 +116,23 @@ export class QemuVmTemplateDetailsComponent implements OnInit {
configureCustomAdapters(){
this.isConfiguratorOpened = !this.isConfiguratorOpened;
this.qemuTemplate.custom_adapters = this.adapters;
this.saveCustomAdapters();
}
saveCustomAdapters() {
let copyOfAdapters = this.adapters;
this.adapters = [];
for(let i=0; i<this.qemuTemplate.adapters; i++){
if (copyOfAdapters[i]) {
this.adapters.push(copyOfAdapters[i]);
} else {
this.adapters.push({
adapter_number: i,
adapter_type: 'e1000'
});
}
}
}
goBack() {
@ -128,6 +146,8 @@ export class QemuVmTemplateDetailsComponent implements OnInit {
if (!this.activateCpuThrottling){
this.qemuTemplate.cpu_throttling = 0;
}
this.saveCustomAdapters();
this.qemuTemplate.custom_adapters = this.adapters;
this.qemuService.saveTemplate(this.server, this.qemuTemplate).subscribe((savedTemplate: QemuTemplate) => {
this.toasterService.success("Changes saved");

View File

@ -65,17 +65,9 @@ export class VirtualBoxTemplateDetailsComponent implements OnInit {
this.virtualBoxService.getTemplate(this.server, template_id).subscribe((virtualBoxTemplate: VirtualBoxTemplate) => {
this.virtualBoxTemplate = virtualBoxTemplate;
for(let i=0; i<this.virtualBoxTemplate.adapters; i++){
let adapter = this.virtualBoxTemplate.custom_adapters.find(elem => elem.adapter_number === i);
if (adapter) {
this.adapters.push(adapter);
} else {
this.adapters.push({
adapter_number: i,
adapter_type: this.virtualBoxTemplate.adapter_type
});
}
}
this.virtualBoxTemplate.custom_adapters.forEach((adapter: CustomAdapter) => {
this.adapters.push(adapter);
});
});
});
}
@ -89,7 +81,23 @@ export class VirtualBoxTemplateDetailsComponent implements OnInit {
configureCustomAdapters(){
this.isConfiguratorOpened = !this.isConfiguratorOpened;
this.virtualBoxTemplate.custom_adapters = this.adapters;
this.saveCustomAdapters();
}
saveCustomAdapters() {
let copyOfAdapters = this.adapters;
this.adapters = [];
for(let i=0; i<this.virtualBoxTemplate.adapters; i++){
if (copyOfAdapters[i]) {
this.adapters.push(copyOfAdapters[i]);
} else {
this.adapters.push({
adapter_number: i,
adapter_type: 'e1000'
});
}
}
}
cancelConfigureCustomAdapters(){
@ -101,6 +109,9 @@ export class VirtualBoxTemplateDetailsComponent implements OnInit {
}
onSave() {
this.saveCustomAdapters();
this.virtualBoxTemplate.custom_adapters = this.adapters;
this.virtualBoxService.saveTemplate(this.server, this.virtualBoxTemplate).subscribe((virtualBoxTemplate: VirtualBoxTemplate) => {
this.toasterService.success("Changes saved");
});

View File

@ -55,6 +55,10 @@ export class VmwareTemplateDetailsComponent implements OnInit {
this.getConfiguration();
this.vmwareService.getTemplate(this.server, template_id).subscribe((vmwareTemplate: VmwareTemplate) => {
this.vmwareTemplate = vmwareTemplate;
this.vmwareTemplate.custom_adapters.forEach((adapter: CustomAdapter) => {
this.adapters.push(adapter);
});
});
});
}
@ -74,6 +78,9 @@ export class VmwareTemplateDetailsComponent implements OnInit {
if (this.generalSettingsForm.invalid) {
this.toasterService.error(`Fill all required fields`);
} else {
this.saveCustomAdapters();
this.vmwareTemplate.custom_adapters = this.adapters;
this.vmwareService.saveTemplate(this.server, this.vmwareTemplate).subscribe((vmwareTemplate: VmwareTemplate) => {
this.toasterService.success("Changes saved");
});
@ -84,27 +91,25 @@ export class VmwareTemplateDetailsComponent implements OnInit {
this.isConfiguratorOpened = !this.isConfiguratorOpened;
}
configureCustomAdapters() {
configureCustomAdapters(){
this.isConfiguratorOpened = !this.isConfiguratorOpened;
this.saveCustomAdapters();
}
saveCustomAdapters() {
let copyOfAdapters = this.adapters;
this.adapters = [];
let adapters: CustomAdapter[] = [];
for (let i=0; i<this.vmwareTemplate.adapters; i++){
if (this.vmwareTemplate.custom_adapters[i]) {
adapters.push(this.vmwareTemplate.custom_adapters[i]);
for(let i=0; i<this.vmwareTemplate.adapters; i++){
if (copyOfAdapters[i]) {
this.adapters.push(copyOfAdapters[i]);
} else {
adapters.push({
this.adapters.push({
adapter_number: i,
adapter_type: 'e1000'
});
}
}
this.adapters = adapters;
}
saveCustomAdapters() {
this.isConfiguratorOpened = !this.isConfiguratorOpened;
this.vmwareTemplate.custom_adapters = this.adapters;
}
chooseSymbol() {