From 6c5fa37258d6b3df7bafba5538655f64f5f3c5e9 Mon Sep 17 00:00:00 2001 From: saffaalvi Date: Wed, 16 Dec 2020 13:18:55 -0500 Subject: [PATCH] fix: set max cpu/ram values for 1 gpu + translation --- .../form-gpus/form-gpus.component.html | 1 + .../form-gpus/form-gpus.component.ts | 9 ++++- .../form-specs/form-specs.component.html | 2 + .../form-specs/form-specs.component.ts | 37 ++++++------------- .../resource-form.component.html | 6 ++- .../resource-form/resource-form.component.ts | 13 +++++++ frontend/src/assets/i18n/en.json | 3 +- frontend/src/assets/i18n/fr.json | 8 ++-- 8 files changed, 47 insertions(+), 32 deletions(-) diff --git a/frontend/src/app/resource-form/form-gpus/form-gpus.component.html b/frontend/src/app/resource-form/form-gpus/form-gpus.component.html index f683c090..e9ee20ec 100644 --- a/frontend/src/app/resource-form/form-gpus/form-gpus.component.html +++ b/frontend/src/app/resource-form/form-gpus/form-gpus.component.html @@ -18,6 +18,7 @@

{{ v }} + {{ message }} diff --git a/frontend/src/app/resource-form/form-gpus/form-gpus.component.ts b/frontend/src/app/resource-form/form-gpus/form-gpus.component.ts index 898ca7a2..c60b6244 100644 --- a/frontend/src/app/resource-form/form-gpus/form-gpus.component.ts +++ b/frontend/src/app/resource-form/form-gpus/form-gpus.component.ts @@ -1,4 +1,4 @@ -import { Component, OnInit, Input } from '@angular/core'; +import { Component, OnInit, Input, Output, EventEmitter } from '@angular/core'; import { FormGroup, ValidatorFn, AbstractControl } from '@angular/forms'; import { Subscription } from 'rxjs'; import { GPUVendor } from 'src/app/utils/types'; @@ -12,12 +12,16 @@ import { TranslateService } from '@ngx-translate/core'; export class FormGpusComponent implements OnInit { @Input() parentForm: FormGroup; @Input() vendors: GPUVendor[]; + @Output() gpuValueEvent = new EventEmitter(); + private gpuCtrl: FormGroup; subscriptions = new Subscription(); maxGPUs = 16; gpusCount = ['1']; + message: string; + constructor(private translate: TranslateService) {} ngOnInit() { @@ -32,10 +36,13 @@ export class FormGpusComponent implements OnInit { this.subscriptions.add( this.gpuCtrl.get('num').valueChanges.subscribe((n: string) => { if (n === 'none') { + this.message = ""; this.gpuCtrl.get('vendor').disable(); } else { + this.message = this.translate.instant('formGpus.specsWarningMessage') this.gpuCtrl.get('vendor').enable(); } + this.gpuValueEvent.emit(n) }), ); } diff --git a/frontend/src/app/resource-form/form-specs/form-specs.component.html b/frontend/src/app/resource-form/form-specs/form-specs.component.html index 2ba3621f..154b84bc 100644 --- a/frontend/src/app/resource-form/form-specs/form-specs.component.html +++ b/frontend/src/app/resource-form/form-specs/form-specs.component.html @@ -12,6 +12,7 @@

{{ "formSpecs.lblCpu" | translate }} {{ "formSpecs.lblMemory" | translate }} max.cpu) { - errors["maxCpu"] = {max: max.cpu, gpu}; - } - if (ram > max.ram) { - errors["maxRam"] = {max: max.ram, gpu}; + if (gpu == 0) { + if (cpu > max.cpu) { + errors["maxCpu"] = {max: max.cpu, gpu}; + } + if (ram > max.ram) { + errors["maxRam"] = {max: max.ram, gpu}; + } } - return Object.entries(errors).length > 0 ? errors : null; }; } @@ -47,8 +47,10 @@ export class FormSpecsComponent implements OnInit { @Input() parentForm: FormGroup; @Input() readonlyCPU: boolean; @Input() readonlyMemory: boolean; + @Input() readonlySpecs: boolean; constructor(private translate: TranslateService) {} + ngOnInit() { this.parentForm .get("cpu") @@ -85,7 +87,6 @@ export class FormSpecsComponent implements OnInit { cpuErrorMessage(): string { let e: any; const errs = this.parentForm.get("cpu").errors || {}; - if (errs.required) return this.translate.instant("formSpecs.errorCpuRequired"); if (errs.pattern) return this.translate.instant("formSpecs.errorCpuNumber"); @@ -93,36 +94,20 @@ export class FormSpecsComponent implements OnInit { return this.translate.instant("formSpecs.errorCpuMin", {min: `${e.min}`}); if (this.parentForm.hasError("maxCpu")) { e = this.parentForm.errors.maxCpu; - return ( - this.translate.instant("formSpecs.errorCpuMax", {max: `${e.max}`}) + - (e.gpu > 0 - ? this.translate.instant("formSpecs.errorCpuMaxLimit", { - gpu: `${e.gpu}` - }) - : "") - ); + return this.translate.instant("formSpecs.errorCpuMax", {max: `${e.max}`}); } } memoryErrorMessage(): string { let e: any; const errs = this.parentForm.get("memory").errors || {}; - if (errs.required || errs.pattern) return this.translate.instant("formSpecs.errorRamRequired"); if ((e = errs.min)) return this.translate.instant("formSpecs.errorRamMin", {min: `${e.min}`}); - if (this.parentForm.hasError("maxRam")) { e = this.parentForm.errors.maxRam; - return ( - this.translate.instant("formSpecs.errorRamMax", {max: `${e.max}`}) + - (e.gpu > 0 - ? this.translate.instant("formSpecs.errorRamMaxLimit", { - gpu: `${e.gpu}` - }) - : "") - ); + return this.translate.instant("formSpecs.errorRamMax", {max: `${e.max}`}); } } } diff --git a/frontend/src/app/resource-form/resource-form.component.html b/frontend/src/app/resource-form/resource-form.component.html index 3f3c17ae..52f58e2b 100644 --- a/frontend/src/app/resource-form/resource-form.component.html +++ b/frontend/src/app/resource-form/resource-form.component.html @@ -12,7 +12,10 @@ [hideVersion]="config?.image?.hideVersion" > - +