#8: Add URL check
All checks were successful
Jenkins Production Deployment

This commit is contained in:
Patrick Müller 2022-12-28 16:25:23 +01:00
parent 754408dfa3
commit a1c46c2648
Signed by: Paddy
GPG Key ID: 37ABC11275CAABCE
2 changed files with 32 additions and 2 deletions

View File

@ -22,10 +22,10 @@
<td> <td>
<input type="text" [(ngModel)]="event!.location"> <input type="text" [(ngModel)]="event!.location">
</td> </td>
<td class="{{showDateError || requiredFieldsMissing? 'has-error' : ''}}"> <td class="{{requiredFieldsMissing? 'has-error' : ''}}">
{{event?.createdBy}} {{event?.createdBy}}
</td> </td>
<td> <td class="{{invalidUrlError? 'has-error' : ''}}">
<input type="text" [(ngModel)]="event!.url"> <input type="text" [(ngModel)]="event!.url">
</td> </td>
<td> <td>
@ -33,6 +33,7 @@
<p class="has-error" *ngIf="showDateError">Start Date must not be after end date!</p> <p class="has-error" *ngIf="showDateError">Start Date must not be after end date!</p>
<p class="has-error" *ngIf="requiredFieldsMissing">Required fields are missing!</p> <p class="has-error" *ngIf="requiredFieldsMissing">Required fields are missing!</p>
<p class="has-error" *ngIf="showCreateError">Error creating event. Please try again.</p> <p class="has-error" *ngIf="showCreateError">Error creating event. Please try again.</p>
<p class="has-error" *ngIf="invalidUrlError">Invalid URL, please only provide valid ones!</p>
</td> </td>
<td> <td>
<button (click)="triggerDelete()">Delete</button> <button (click)="triggerDelete()">Delete</button>

View File

@ -16,6 +16,7 @@ export class EventComponent implements OnInit {
newEndDate: string | undefined; newEndDate: string | undefined;
newEndTime: string | undefined; newEndTime: string | undefined;
showDateError: boolean = false; showDateError: boolean = false;
invalidUrlError: boolean = false;
requiredFieldsMissing: boolean = false; requiredFieldsMissing: boolean = false;
showCreateError: boolean = false; showCreateError: boolean = false;
@Output() deleteEvent = new EventEmitter<number>(); @Output() deleteEvent = new EventEmitter<number>();
@ -53,6 +54,11 @@ export class EventComponent implements OnInit {
return; return;
} }
if(!this.checkEventValidUrl()) {
this.invalidUrlError = true;
return;
}
if(this.event.eventId === undefined) { if(this.event.eventId === undefined) {
this.api.createEvent(this.event).subscribe((res: any) => { this.api.createEvent(this.event).subscribe((res: any) => {
console.log(res); console.log(res);
@ -148,4 +154,27 @@ export class EventComponent implements OnInit {
}); });
} }
} }
checkEventValidUrl(): boolean {
if(this.isNullOrBlank(this.event!.url)) {
return true;
}
const urlRegex = /^(https?:\/\/)?((www\.)?([a-z0-9äöü]*\.)+[a-z]{2,10}.*)$/i;
let validUrl = urlRegex.test(this.event!.url);
if(validUrl){
let match = this.event!.url.match(urlRegex);
if(match) {
console.log(match);
let url = 'https://' + match[2];
this.event!.url = url;
} else {
validUrl = false;
}
}
return validUrl;
}
} }