From ec18c6a2455ead8206f2d57474ca4060dac9836d Mon Sep 17 00:00:00 2001 From: vktrrdk Date: Tue, 10 Dec 2024 10:40:07 +0000 Subject: [PATCH 1/2] working on name checkign --- src/app/api-connector/applications.service.ts | 8 ++++++++ .../application-formular.component.ts | 16 ++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/src/app/api-connector/applications.service.ts b/src/app/api-connector/applications.service.ts index c004fca888..876e3fed58 100644 --- a/src/app/api-connector/applications.service.ts +++ b/src/app/api-connector/applications.service.ts @@ -336,4 +336,12 @@ export class ApplicationsService { withCredentials: true }) } + + checkForTakenShortname(shortname: string): Observable { + return this.http.get(`${ApiSettings.getApiBaseURL()}project_applications/shortname/`, { + params: { shortname: shortname }, + withCredentials: true + }); + + } } diff --git a/src/app/applications/application-formular/application-formular.component.ts b/src/app/applications/application-formular/application-formular.component.ts index 8beeb64cd6..3fa2f4ee65 100644 --- a/src/app/applications/application-formular/application-formular.component.ts +++ b/src/app/applications/application-formular/application-formular.component.ts @@ -33,6 +33,9 @@ import { UserService } from '../../api-connector/user.service' import { Userinfo } from '../../userinfo/userinfo.model' import { User } from '../application.model/user.model' import { NotificationModalComponent } from '../../shared/modal/notification-modal' +import { Subject, Subscription } from 'rxjs'; +import { debounceTime, distinctUntilChanged } from 'rxjs/operators'; +import { thresholdScott } from 'd3' /** * Application formular component. @@ -87,6 +90,8 @@ export class ApplicationFormularComponent extends ApplicationBaseClassComponent WIKI_BACKUP_LINK: string = WIKI_BACKUP_LINK GDPR_LINK: string = GDPR_LINK survey_link_visible: boolean = false + private nameCheckPipe = new Subject(); + shortnameChecking: boolean = false; MAX_LIFETIME_DEFAULT: number = 6 max_lifetime: number = this.MAX_LIFETIME_DEFAULT @@ -119,6 +124,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)}); if (this.openstack_project) { this.simple_vm_min_vm = true @@ -138,6 +144,14 @@ export class ApplicationFormularComponent extends ApplicationBaseClassComponent } } + checkIfNameIsTaken(shortname: string): void { + this.shortnameChecking = true; + this.applicationsService.checkForTakenShortname(shortname).subscribe((result: boolean): void => { + console.log(result); + }); + + } + checkValidityComment(): boolean { if (this.extraResourceCommentRequired) { if (this.application.project_application_comment?.length < 50) { @@ -238,6 +252,8 @@ 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) } public checkLongname(longname: string): void { From 77a1e98aff3e5f1681ba8d0c6341021f46b90e3f Mon Sep 17 00:00:00 2001 From: vktrrdk Date: Tue, 10 Dec 2024 12:26:54 +0000 Subject: [PATCH 2/2] 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 {