From 77a1e98aff3e5f1681ba8d0c6341021f46b90e3f Mon Sep 17 00:00:00 2001 From: vktrrdk Date: Tue, 10 Dec 2024 12:26:54 +0000 Subject: [PATCH] fix(Projects): Shortname checking --- .../application-formular.component.html | 14 +++++++++++--- .../application-formular.component.ts | 14 ++++++++++---- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/src/app/applications/application-formular/application-formular.component.html b/src/app/applications/application-formular/application-formular.component.html index 14e60fcaa6..c67609c38a 100644 --- a/src/app/applications/application-formular/application-formular.component.html +++ b/src/app/applications/application-formular/application-formular.component.html @@ -145,6 +145,11 @@
General Information
Umlauts and special characters are prohibited in the shortname. +
+ + Please choose another shortname + +
General Information pattern="[a-zA-Z0-9]+" [ngClass]="{ 'is-invalid': - form.controls.project_application_shortname?.invalid && + (form.controls.project_application_shortname?.invalid || shortNameTaken) && (form.controls.project_application_shortname?.dirty || - form.controls.project_application_shortname?.touched), + form.controls.project_application_shortname?.touched) + , 'is-valid': - form.controls.project_application_shortname?.valid && + form.controls.project_application_shortname?.valid && !shortNameTaken && (form.controls.project_application_shortname?.dirty || form.controls.project_application_shortname?.touched), }" /> Enter a short name (between 5 and 15 characters). + @@ -1792,6 +1799,7 @@
Platforms
data-test-id="submit_application_btn" [disabled]=" submitting || + shortNameTaken || form.invalid || (!unknownPiAffiliationsConfirmation && !valid_pi_affiliations && diff --git a/src/app/applications/application-formular/application-formular.component.ts b/src/app/applications/application-formular/application-formular.component.ts index 3fa2f4ee65..a1f2ae3525 100644 --- a/src/app/applications/application-formular/application-formular.component.ts +++ b/src/app/applications/application-formular/application-formular.component.ts @@ -92,6 +92,7 @@ export class ApplicationFormularComponent extends ApplicationBaseClassComponent survey_link_visible: boolean = false private nameCheckPipe = new Subject(); shortnameChecking: boolean = false; + shortNameTaken: boolean = false; MAX_LIFETIME_DEFAULT: number = 6 max_lifetime: number = this.MAX_LIFETIME_DEFAULT @@ -124,7 +125,7 @@ export class ApplicationFormularComponent extends ApplicationBaseClassComponent this.getListOfFlavors() this.getListOfTypes() this.is_vo_admin = is_vo - this.nameCheckPipe.pipe(debounceTime(300), distinctUntilChanged()).subscribe(value => {this.checkIfNameIsTaken(value)}); + this.nameCheckPipe.pipe(debounceTime(600), distinctUntilChanged()).subscribe(value => {this.checkIfNameIsTaken(value)}); if (this.openstack_project) { this.simple_vm_min_vm = true @@ -147,7 +148,9 @@ export class ApplicationFormularComponent extends ApplicationBaseClassComponent checkIfNameIsTaken(shortname: string): void { this.shortnameChecking = true; this.applicationsService.checkForTakenShortname(shortname).subscribe((result: boolean): void => { - console.log(result); + let nameExists: boolean = result['exists']; + this.shortnameChecking = false; + this.shortNameTaken = nameExists; }); } @@ -252,8 +255,11 @@ export class ApplicationFormularComponent extends ApplicationBaseClassComponent */ public checkShortname(shortname: string): void { this.invalid_shortname = !/^[a-zA-Z0-9\s]*$/.test(shortname) - this.shortnameChecking = true; - this.nameCheckPipe.next(shortname) + if (!this.invalid_shortname) { + this.shortnameChecking = true; + this.nameCheckPipe.next(shortname); + } + } public checkLongname(longname: string): void {