TRIX-28 creating machine with same specs no longer works

This commit is contained in:
Dragos 2021-06-03 16:59:53 +03:00
parent bffce99fb0
commit 4fa77a0932
5 changed files with 31 additions and 26 deletions

View File

@ -47,7 +47,7 @@ export class PackagesComponent implements OnInit, OnDestroy, OnChanges
{ {
this._selectedPackage = value; this._selectedPackage = value;
this.select.next(value); this.select.emit(value);
} }
get selectedPackage(): CatalogPackage get selectedPackage(): CatalogPackage
{ {
@ -72,8 +72,10 @@ export class PackagesComponent implements OnInit, OnDestroy, OnChanges
} }
// ---------------------------------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------------------------------
private setPackagesByImageType() private setPackagesByImageType(raiseEvent = false)
{ {
if (!this.imageType) return;
this._selectedPackage = null; this._selectedPackage = null;
this.packages = this._packages.filter(x => this.packages = this._packages.filter(x =>
@ -100,11 +102,16 @@ export class PackagesComponent implements OnInit, OnDestroy, OnChanges
}); });
if (this._selectedPackage) if (this._selectedPackage)
{
if (raiseEvent)
this.select.emit(this._selectedPackage);
setTimeout(() => setTimeout(() =>
{ {
this.elementRef.nativeElement.querySelector(`#package-${this._selectedPackage.id}`) this.elementRef.nativeElement.querySelector(`#package-${this._selectedPackage.id}`)
.scrollIntoView({behavior:'auto', block: 'center'}); .scrollIntoView({behavior:'auto', block: 'center'});
}, 0); }, 0);
}
} }
// ---------------------------------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------------------------------
@ -114,7 +121,7 @@ export class PackagesComponent implements OnInit, OnDestroy, OnChanges
.subscribe((changes: SimpleChanges) => .subscribe((changes: SimpleChanges) =>
{ {
if (changes.image?.currentValue && changes.imageType?.currentValue) if (changes.image?.currentValue && changes.imageType?.currentValue)
this.setPackagesByImageType(); this.setPackagesByImageType(true);
}); });
} }

View File

@ -83,7 +83,7 @@
<div *ngIf="currentStep === 2" class="d-flex flex-column h-100"> <div *ngIf="currentStep === 2" class="d-flex flex-column h-100">
<h5 class="px-3 mb-3 mt-1">Choose the <b>package</b> that matches the technical specifications this machine will have</h5> <h5 class="px-3 mb-3 mt-1">Choose the <b>package</b> that matches the technical specifications this machine will have</h5>
<app-packages [image]="editorForm.get('image').value" [imageType]="editorForm.get('imageType').value" [package]="preselectedPackage" <app-packages [image]="editorForm.get('image').value" [imageType]="imageType" [package]="preselectedPackage"
(select)="setPackage($event)"> (select)="setPackage($event)">
</app-packages> </app-packages>
</div> </div>

View File

@ -35,10 +35,6 @@ export class MachineWizardComponent implements OnInit, OnDestroy
imageList: any[]; imageList: any[];
operatingSystems: any[]; operatingSystems: any[];
private packages: {};
packageList: any[];
packageGroups: any[];
machines: Machine[]; machines: Machine[];
dataCenters: any[]; dataCenters: any[];
@ -163,11 +159,11 @@ export class MachineWizardComponent implements OnInit, OnDestroy
.pipe(takeUntil(this.destroy$)) .pipe(takeUntil(this.destroy$))
.subscribe(value => .subscribe(value =>
{ {
const imageType = value | 0; this.imageType = value | 0;
const imageList = []; const imageList = [];
const operatingSystems = {}; const operatingSystems = {};
if (imageType === CatalogImageType.InfrastructureContainer) if (this.imageType === CatalogImageType.InfrastructureContainer)
{ {
for (const image of this.images) for (const image of this.images)
if (['lx-dataset', 'zone-dataset'].includes(image.type) && image.owner !== this.userId) if (['lx-dataset', 'zone-dataset'].includes(image.type) && image.owner !== this.userId)
@ -176,7 +172,7 @@ export class MachineWizardComponent implements OnInit, OnDestroy
imageList.push(image); imageList.push(image);
} }
} }
else if (imageType === CatalogImageType.VirtualMachine) else if (this.imageType === CatalogImageType.VirtualMachine)
{ {
for (const image of this.images) for (const image of this.images)
if (['zvol'].includes(image.type) && image.owner !== this.userId) if (['zvol'].includes(image.type) && image.owner !== this.userId)
@ -185,7 +181,7 @@ export class MachineWizardComponent implements OnInit, OnDestroy
imageList.push(image); imageList.push(image);
} }
} }
else if (imageType === CatalogImageType.Custom) else if (this.imageType === CatalogImageType.Custom)
{ {
for (const image of this.images) for (const image of this.images)
if (image.owner === this.userId) if (image.owner === this.userId)
@ -213,11 +209,10 @@ export class MachineWizardComponent implements OnInit, OnDestroy
.pipe(takeUntil(this.destroy$), distinctUntilChanged()) .pipe(takeUntil(this.destroy$), distinctUntilChanged())
.subscribe(imageOs => .subscribe(imageOs =>
{ {
const imageType = this.editorForm.get('imageType').value | 0;
const imageList = []; const imageList = [];
const operatingSystems = {}; const operatingSystems = {};
if (imageType === CatalogImageType.InfrastructureContainer) if (this.imageType === CatalogImageType.InfrastructureContainer)
{ {
for (const image of this.images) for (const image of this.images)
if (['lx-dataset', 'zone-dataset'].includes(image.type) && (!imageOs || imageOs === image.os) && image.owner !== this.userId) if (['lx-dataset', 'zone-dataset'].includes(image.type) && (!imageOs || imageOs === image.os) && image.owner !== this.userId)
@ -226,7 +221,7 @@ export class MachineWizardComponent implements OnInit, OnDestroy
imageList.push(image); imageList.push(image);
} }
} }
else if (imageType === CatalogImageType.VirtualMachine) else if (this.imageType === CatalogImageType.VirtualMachine)
{ {
for (const image of this.images) for (const image of this.images)
if (['zvol'].includes(image.type) && (!imageOs || imageOs === image.os) && image.owner !== this.userId) if (['zvol'].includes(image.type) && (!imageOs || imageOs === image.os) && image.owner !== this.userId)
@ -235,7 +230,7 @@ export class MachineWizardComponent implements OnInit, OnDestroy
imageList.push(image); imageList.push(image);
} }
} }
else if (imageType === CatalogImageType.Custom) else if (this.imageType === CatalogImageType.Custom)
{ {
for (const image of this.images) for (const image of this.images)
if (image.owner === this.userId) if (image.owner === this.userId)
@ -390,7 +385,7 @@ export class MachineWizardComponent implements OnInit, OnDestroy
if (this.currentStep < this.steps.length) return; if (this.currentStep < this.steps.length) return;
this.readyText = this.translateService.instant('machines.wizard.ready', { this.readyText = this.translateService.instant('machines.wizard.ready', {
imageType: this.editorForm.get('imageType').value == 1 imageType: this.imageType == 1
? this.translateService.instant('machines.wizard.readyImageTypeContainer') ? this.translateService.instant('machines.wizard.readyImageTypeContainer')
: this.translateService.instant('machines.wizard.readyImageTypeVm'), : this.translateService.instant('machines.wizard.readyImageTypeVm'),
packageDescription: this.editorForm.get('package').value.description || packageDescription: this.editorForm.get('package').value.description ||
@ -410,9 +405,6 @@ export class MachineWizardComponent implements OnInit, OnDestroy
this.steps[1].complete = true; this.steps[1].complete = true;
this.editorForm.get('package').setValue(selection); this.editorForm.get('package').setValue(selection);
if (this.machine)
this.nextStep();
} }
// ---------------------------------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------------------------------
@ -606,13 +598,15 @@ export class MachineWizardComponent implements OnInit, OnDestroy
if (this.machine) if (this.machine)
{ {
if (this.machine.type === 'smartmachine') if (this.machine.type === 'smartmachine')
this.imageType = 1; this.imageType = CatalogImageType.InfrastructureContainer;
else if (this.machine.type === 'virtualmachine') else if (this.machine.type === 'virtualmachine')
this.imageType = 2; this.imageType = CatalogImageType.VirtualMachine;
this.preselectedPackage = this.machine.package; this.preselectedPackage = this.machine.package;
this.nextStep(); this.currentStep = 2;
setTimeout(() => this.currentStep = 3, 300);
} }
if (this.imageType <= 2) if (this.imageType <= 2)

View File

@ -660,6 +660,9 @@ export class MachinesComponent implements OnInit, OnDestroy
// ---------------------------------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------------------------------
createMachine(machine?: Machine) createMachine(machine?: Machine)
{ {
if (machine)
machine.contextMenu = false;
const modalConfig = { const modalConfig = {
ignoreBackdropClick: true, ignoreBackdropClick: true,
keyboard: false, keyboard: false,

View File

@ -5,6 +5,7 @@ import { NavigationStart, Router } from '@angular/router';
import { Subject } from 'rxjs'; import { Subject } from 'rxjs';
import { filter, takeUntil } from 'rxjs/operators'; import { filter, takeUntil } from 'rxjs/operators';
import { CatalogPackage } from '../../catalog/models/package'; import { CatalogPackage } from '../../catalog/models/package';
import { CatalogImageType } from 'src/app/catalog/models/image';
@Component({ @Component({
selector: 'app-package-selector', selector: 'app-package-selector',
@ -70,11 +71,11 @@ export class PackageSelectorComponent implements OnInit
switch (this.machine.type) switch (this.machine.type)
{ {
case 'virtualmachine': case 'virtualmachine':
this.imageType = 1; this.imageType = CatalogImageType.VirtualMachine;
break; break;
case 'smartmachine': case 'smartmachine':
this.imageType = 2; this.imageType = CatalogImageType.InfrastructureContainer;
break; break;
} }