Skip to content

Commit

Permalink
Merge pull request #6280 from deNBI/fix/application_names
Browse files Browse the repository at this point in the history
Fix/application names
  • Loading branch information
dweinholz authored Dec 12, 2024
2 parents ed936b2 + a26e198 commit 2ff97d8
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 3 deletions.
8 changes: 8 additions & 0 deletions src/app/api-connector/applications.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -336,4 +336,12 @@ export class ApplicationsService {
withCredentials: true
})
}

checkForTakenShortname(shortname: string): Observable<any> {
return this.http.get(`${ApiSettings.getApiBaseURL()}project_applications/shortname/`, {
params: { shortname: shortname },
withCredentials: true
});

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,11 @@ <h5 class="col-md-6 form-control-label">General Information</h5>
<font color="red">Umlauts and special characters are prohibited in the shortname.</font>
</strong>
</div>
<div *ngIf="shortNameTaken">
<strong>
<font color="red">Please choose another shortname</font>
</strong>
</div>
<input
required
type="text"
Expand All @@ -160,17 +165,19 @@ <h5 class="col-md-6 form-control-label">General Information</h5>
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),
}"
/>

<span class="help-block">Enter a short name (between 5 and 15 characters).</span>

</div>
</div>

Expand Down Expand Up @@ -1792,6 +1799,7 @@ <h6><strong>Platforms</strong></h6>
data-test-id="submit_application_btn"
[disabled]="
submitting ||
shortNameTaken ||
form.invalid ||
(!unknownPiAffiliationsConfirmation &&
!valid_pi_affiliations &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -87,6 +90,9 @@ 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<string>();
shortnameChecking: boolean = false;
shortNameTaken: boolean = false;

MAX_LIFETIME_DEFAULT: number = 6
max_lifetime: number = this.MAX_LIFETIME_DEFAULT
Expand Down Expand Up @@ -119,6 +125,7 @@ export class ApplicationFormularComponent extends ApplicationBaseClassComponent
this.getListOfFlavors()
this.getListOfTypes()
this.is_vo_admin = is_vo
this.nameCheckPipe.pipe(debounceTime(600), distinctUntilChanged()).subscribe(value => {this.checkIfNameIsTaken(value)});

if (this.openstack_project) {
this.simple_vm_min_vm = true
Expand All @@ -138,6 +145,16 @@ export class ApplicationFormularComponent extends ApplicationBaseClassComponent
}
}

checkIfNameIsTaken(shortname: string): void {
this.shortnameChecking = true;
this.applicationsService.checkForTakenShortname(shortname).subscribe((result: boolean): void => {
let nameExists: boolean = result['exists'];
this.shortnameChecking = false;
this.shortNameTaken = nameExists;
});

}

checkValidityComment(): boolean {
if (this.extraResourceCommentRequired) {
if (this.application.project_application_comment?.length < 50) {
Expand Down Expand Up @@ -238,6 +255,11 @@ export class ApplicationFormularComponent extends ApplicationBaseClassComponent
*/
public checkShortname(shortname: string): void {
this.invalid_shortname = !/^[a-zA-Z0-9\s]*$/.test(shortname)
if (!this.invalid_shortname) {
this.shortnameChecking = true;
this.nameCheckPipe.next(shortname);
}

}

public checkLongname(longname: string): void {
Expand Down

0 comments on commit 2ff97d8

Please sign in to comment.