Skip to content

Commit

Permalink
feat: validate storage url inside storage config (advanced settings) (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
MartaOB authored Jan 30, 2025
1 parent eb30b31 commit 93cf42d
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,18 @@ <h4>
<mat-hint *ngIf="_showHelp">{{
_defaultFormValues.rclone_url.description
}}</mat-hint>
<mat-error
*ngIf="
storageConfFormGroup
.get('storageUrlInput')
?.hasError('invalidURL')
"
>
{{
'MODULES.MODULE-TRAIN.DATA-CONF-FORM.STORAGE-URL-ERROR'
| translate
}}
</mat-error>
</mat-form-field>

<mat-form-field>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@ import {
ViewChild,
} from '@angular/core';
import {
AbstractControl,
FormBuilder,
FormControl,
FormGroup,
FormGroupDirective,
ValidationErrors,
ValidatorFn,
Validators,
} from '@angular/forms';
import {
Expand Down Expand Up @@ -44,6 +47,19 @@ const mockedConfObjectStringBoolean: confObjectStringBoolean = {
description: '',
};

export function urlValidator(): ValidatorFn {
return (control: AbstractControl): ValidationErrors | null => {
const urlPattern =
/^(https?:\/\/)?([\da-z.-]+)\.([a-z.]{2,6})([/\w.-]*)*\/?$/i;
const value = control.value;
let validURL = true;
if (value.trim().length > 0) {
validURL = urlPattern.test(value);
}
return validURL ? null : { invalidURL: true };
};
}

@Component({
selector: 'app-storage-conf-form',
templateUrl: './storage-conf-form.component.html',
Expand Down Expand Up @@ -118,7 +134,7 @@ export class StorageConfFormComponent implements OnInit {
disabled: true,
}),
rcloneConfInput: [''],
storageUrlInput: [''],
storageUrlInput: ['', [urlValidator()]],
rcloneVendorSelect: [''],
rcloneUserInput: [''],
rclonePasswordInput: [''],
Expand Down
1 change: 1 addition & 0 deletions src/assets/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,7 @@
"DATASET-LIST": "Datasets list",
"NO-DATASETS": "No datasets added yet",
"STORAGE-URL": "Storage URL",
"STORAGE-URL-ERROR": "Invalid URL format",
"STORAGE-SERVICE": "Storage service",
"STORAGE-SERVICE-HINT": "You can select which storage service to use. Make sure your account is already linked in your",
"PROFILE-SECTION": "profile section",
Expand Down

0 comments on commit 93cf42d

Please sign in to comment.