diff --git a/code/frontend/src/app/settings/download-cleaner/download-cleaner-settings.component.html b/code/frontend/src/app/settings/download-cleaner/download-cleaner-settings.component.html index 3304e0e1..942c6260 100644 --- a/code/frontend/src/app/settings/download-cleaner/download-cleaner-settings.component.html +++ b/code/frontend/src/app/settings/download-cleaner/download-cleaner-settings.component.html @@ -248,6 +248,7 @@ > + At least one category is required when unlinked download handling is enabled Categories to check for unlinked downloads diff --git a/code/frontend/src/app/settings/download-cleaner/download-cleaner-settings.component.ts b/code/frontend/src/app/settings/download-cleaner/download-cleaner-settings.component.ts index 88f55959..79e06032 100644 --- a/code/frontend/src/app/settings/download-cleaner/download-cleaner-settings.component.ts +++ b/code/frontend/src/app/settings/download-cleaner/download-cleaner-settings.component.ts @@ -139,7 +139,7 @@ export class DownloadCleanerSettingsComponent implements OnDestroy, CanComponent unlinkedUseTag: [{ value: false, disabled: true }], unlinkedIgnoredRootDir: [{ value: '', disabled: true }], unlinkedCategories: [{ value: [], disabled: true }] - }); + }, { validators: this.validateUnlinkedCategories }); // Load the current configuration effect(() => { @@ -199,6 +199,20 @@ export class DownloadCleanerSettingsComponent implements OnDestroy, CanComponent return null; } + /** + * Custom validator for unlinked categories - requires categories when unlinked handling is enabled + */ + private validateUnlinkedCategories(group: FormGroup): ValidationErrors | null { + const unlinkedEnabled = group.get('unlinkedEnabled')?.value; + const unlinkedCategories = group.get('unlinkedCategories')?.value; + + if (unlinkedEnabled && (!unlinkedCategories || unlinkedCategories.length === 0)) { + return { unlinkedCategoriesRequired: true }; + } + + return null; + } + /** * Helper method to get a category control as FormGroup for the template */ @@ -592,6 +606,13 @@ export class DownloadCleanerSettingsComponent implements OnDestroy, CanComponent return control ? control.touched && control.hasError(errorName) : false; } + /** + * Check if the form has the unlinked categories validation error + */ + hasUnlinkedCategoriesError(): boolean { + return this.downloadCleanerForm.touched && this.downloadCleanerForm.hasError('unlinkedCategoriesRequired'); + } + /** * Get schedule value options based on the current schedule unit type */