]> git.ipfire.org Git - thirdparty/paperless-ngx.git/commitdiff
limit the frontend algo select too
authorshamoon <4887959+shamoon@users.noreply.github.com>
Fri, 21 Mar 2025 06:17:38 +0000 (23:17 -0700)
committershamoon <4887959+shamoon@users.noreply.github.com>
Fri, 21 Mar 2025 06:17:44 +0000 (23:17 -0700)
src-ui/src/app/components/common/edit-dialog/custom-field-edit-dialog/custom-field-edit-dialog.component.ts

index fada6c53e0e099c2d7e91a43d6e68ec3ab409de8..ace0db2e3a17c22f7282868c63e4c7561043add3 100644 (file)
@@ -21,7 +21,7 @@ import {
   CustomFieldDataType,
   DATA_TYPE_LABELS,
 } from 'src/app/data/custom-field'
-import { MATCH_NONE } from 'src/app/data/matching-model'
+import { MATCH_NONE, MATCHING_ALGORITHMS } from 'src/app/data/matching-model'
 import { CustomFieldsService } from 'src/app/services/rest/custom-fields.service'
 import { UserService } from 'src/app/services/rest/user.service'
 import { SettingsService } from 'src/app/services/settings.service'
@@ -29,6 +29,27 @@ import { SelectComponent } from '../../input/select/select.component'
 import { TextComponent } from '../../input/text/text.component'
 import { EditDialogComponent, EditDialogMode } from '../edit-dialog.component'
 
+const FIELDS_WITH_DISCRETE_MATCHING = [
+  CustomFieldDataType.Boolean,
+  CustomFieldDataType.Select,
+]
+
+const MATCHING_ALGORITHMS_FOR_ALL_FIELDS = [
+  // MATCH_NONE
+  MATCHING_ALGORITHMS[6],
+  // MATCH_REGEX
+  MATCHING_ALGORITHMS[4],
+]
+
+const MATCHING_ALGORITHMS_FOR_DISCRETE_FIELDS = [
+  // MATCH_NONE
+  MATCHING_ALGORITHMS[6],
+  // MATCH_AUTO
+  MATCHING_ALGORITHMS[0],
+  // MATCH_REGEX
+  MATCHING_ALGORITHMS[4],
+]
+
 @Component({
   selector: 'pngx-custom-field-edit-dialog',
   templateUrl: './custom-field-edit-dialog.component.html',
@@ -131,4 +152,15 @@ export class CustomFieldEditDialogComponent
   public removeSelectOption(index: number) {
     this.selectOptions.removeAt(index)
   }
+
+  public getMatchingAlgorithms() {
+    if (
+      FIELDS_WITH_DISCRETE_MATCHING.includes(this.getForm().value.data_type) ||
+      FIELDS_WITH_DISCRETE_MATCHING.includes(this.object?.data_type)
+    ) {
+      return MATCHING_ALGORITHMS_FOR_DISCRETE_FIELDS
+    } else {
+      return MATCHING_ALGORITHMS_FOR_ALL_FIELDS
+    }
+  }
 }