Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

Extract searchFunction used for both autocompleters

Aaron Contrerase1ab64c29b08
diff --git a/frontend/src/app/features/work-packages/components/filters/query-filters/query-filters.component.ts b/frontend/src/app/features/work-packages/components/filters/query-filters/query-filters.component.ts
index aac57a3d257..6a72bbc5901 100644
--- a/frontend/src/app/features/work-packages/components/filters/query-filters/query-filters.component.ts
+++ b/frontend/src/app/features/work-packages/components/filters/query-filters/query-filters.component.ts
@@ -49,6 +49,7 @@ import { QueryFilterResource } from 'core-app/features/hal/resources/query-filte
import { WorkPackageViewBaselineService } from 'core-app/features/work-packages/routing/wp-view-base/view-services/wp-view-baseline.service';
import { combineLatestWith } from 'rxjs';
import { repositionDropdownBugfix } from 'core-app/shared/components/autocompleter/op-autocompleter/autocompleter.helper';
+import { AlternativeSearchService } from 'core-app/shared/components/work-packages/alternative-search.service';
const ADD_FILTER_SELECT_INDEX = -1;
@@ -89,20 +90,12 @@ export class QueryFiltersComponent extends UntilDestroyedMixin implements OnInit
baseline_warning: this.I18n.t('js.work_packages.filters.baseline_warning'),
};
- public specialSearchStrings = {
- done_ratio: this.I18n.t('js.work_packages.properties.done_ratio'),
- done_ratio_alternative: this.I18n.t('js.work_packages.properties.done_ratio_alternative'),
- work: this.I18n.t('js.work_packages.properties.work'),
- work_alternative: this.I18n.t('js.work_packages.properties.work_alternative'),
- remaining_work: this.I18n.t('js.work_packages.properties.remaining_work'),
- remaining_work_alternative: this.I18n.t('js.work_packages.properties.remaining_work_alternative'),
- };
-
constructor(
readonly wpTableFilters:WorkPackageViewFiltersService,
readonly wpTableBaseline:WorkPackageViewBaselineService,
readonly wpFiltersService:WorkPackageFiltersService,
readonly I18n:I18nService,
+ readonly alternativeSearchService:AlternativeSearchService,
readonly cdRef:ChangeDetectorRef,
) {
super();
@@ -198,25 +191,6 @@ export class QueryFiltersComponent extends UntilDestroyedMixin implements OnInit
}
searchFunction = (term:string, currentItem:QueryFilterResource):boolean => {
- const alternativeNames:{ [index:string]:string } = {
- [this.specialSearchStrings.done_ratio_alternative]: this.specialSearchStrings.done_ratio,
- [this.specialSearchStrings.work_alternative]: this.specialSearchStrings.work,
- [this.specialSearchStrings.remaining_work_alternative]: this.specialSearchStrings.remaining_work,
- };
-
- const lowercaseSearchTerm = term.toLowerCase();
- const lowercaseCurrentItemName = currentItem.name.toLowerCase();
-
- const alternativeMatch = Object
- .keys(alternativeNames)
- .some((alternativeName) => {
- return alternativeName.toLowerCase().indexOf(lowercaseSearchTerm) > -1
- && currentItem.name === alternativeNames[alternativeName];
- });
-
- return (
- lowercaseCurrentItemName.indexOf(lowercaseSearchTerm) > -1
- || alternativeMatch
- );
+ return this.alternativeSearchService.searchFunction(term, currentItem);
};
}
diff --git a/frontend/src/app/shared/components/autocompleter/draggable-autocomplete/draggable-autocomplete.component.ts b/frontend/src/app/shared/components/autocompleter/draggable-autocomplete/draggable-autocomplete.component.ts
index 359dc4b4ca3..b6566fd4309 100644
--- a/frontend/src/app/shared/components/autocompleter/draggable-autocomplete/draggable-autocomplete.component.ts
+++ b/frontend/src/app/shared/components/autocompleter/draggable-autocomplete/draggable-autocomplete.component.ts
@@ -17,6 +17,7 @@ import { merge } from 'rxjs';
import { setBodyCursor } from 'core-app/shared/helpers/dom/set-window-cursor.helper';
import { repositionDropdownBugfix } from 'core-app/shared/components/autocompleter/op-autocompleter/autocompleter.helper';
import { QueryFilterResource } from 'core-app/features/hal/resources/query-filter-resource';
+import { AlternativeSearchService } from 'core-app/shared/components/work-packages/alternative-search.service';
export interface DraggableOption {
name:string;
@@ -55,8 +56,11 @@ export class DraggableAutocompleteComponent extends UntilDestroyedMixin implemen
placeholder: this.I18n.t('js.label_add_columns'),
};
- constructor(readonly I18n:I18nService,
- readonly dragula:DragulaService) {
+ constructor(
+ readonly I18n:I18nService,
+ readonly dragula:DragulaService,
+ readonly alternativeSearchService:AlternativeSearchService,
+ ) {
super();
}
@@ -138,36 +142,8 @@ export class DraggableAutocompleteComponent extends UntilDestroyedMixin implemen
repositionDropdownBugfix(this.ngSelectComponent);
}
- public specialSearchStrings = {
- done_ratio: this.I18n.t('js.work_packages.properties.done_ratio'),
- done_ratio_alternative: this.I18n.t('js.work_packages.properties.done_ratio_alternative'),
- work: this.I18n.t('js.work_packages.properties.work'),
- work_alternative: this.I18n.t('js.work_packages.properties.work_alternative'),
- remaining_work: this.I18n.t('js.work_packages.properties.remaining_work'),
- remaining_work_alternative: this.I18n.t('js.work_packages.properties.remaining_work_alternative'),
- };
-
searchFunction = (term:string, currentItem:QueryFilterResource):boolean => {
- const alternativeNames:{ [index:string]:string } = {
- [this.specialSearchStrings.done_ratio_alternative]: this.specialSearchStrings.done_ratio,
- [this.specialSearchStrings.work_alternative]: this.specialSearchStrings.work,
- [this.specialSearchStrings.remaining_work_alternative]: this.specialSearchStrings.remaining_work,
- };
-
- const lowercaseSearchTerm = term.toLowerCase();
- const lowercaseCurrentItemName = currentItem.name.toLowerCase();
-
- const alternativeMatch = Object
- .keys(alternativeNames)
- .some((alternativeName) => {
- return alternativeName.toLowerCase().indexOf(lowercaseSearchTerm) > -1
- && currentItem.name === alternativeNames[alternativeName];
- });
-
- return (
- lowercaseCurrentItemName.indexOf(lowercaseSearchTerm) > -1
- || alternativeMatch
- );
+ return this.alternativeSearchService.searchFunction(term, currentItem);
};
private updateAvailableOptions() {
diff --git a/frontend/src/app/shared/components/work-packages/alternative-search.service.ts b/frontend/src/app/shared/components/work-packages/alternative-search.service.ts
new file mode 100644
index 00000000000..34d4d07b8a4
--- /dev/null
+++ b/frontend/src/app/shared/components/work-packages/alternative-search.service.ts
@@ -0,0 +1,43 @@
+import { Injectable } from '@angular/core';
+import { I18nService } from 'core-app/core/i18n/i18n.service';
+import { QueryFilterResource } from 'core-app/features/hal/resources/query-filter-resource';
+
+@Injectable({ providedIn: 'root' })
+
+export class AlternativeSearchService {
+ constructor(
+ readonly I18n:I18nService,
+ ) { }
+
+ public specialSearchStrings = {
+ done_ratio: this.I18n.t('js.work_packages.properties.done_ratio'),
+ done_ratio_alternative: this.I18n.t('js.work_packages.properties.done_ratio_alternative'),
+ work: this.I18n.t('js.work_packages.properties.work'),
+ work_alternative: this.I18n.t('js.work_packages.properties.work_alternative'),
+ remaining_work: this.I18n.t('js.work_packages.properties.remaining_work'),
+ remaining_work_alternative: this.I18n.t('js.work_packages.properties.remaining_work_alternative'),
+ };
+
+ public searchFunction = (term:string, currentItem:QueryFilterResource):boolean => {
+ const alternativeNames:{ [index:string]:string } = {
+ [this.specialSearchStrings.done_ratio_alternative]: this.specialSearchStrings.done_ratio,
+ [this.specialSearchStrings.work_alternative]: this.specialSearchStrings.work,
+ [this.specialSearchStrings.remaining_work_alternative]: this.specialSearchStrings.remaining_work,
+ };
+
+ const lowercaseSearchTerm = term.toLowerCase();
+ const lowercaseCurrentItemName = currentItem.name.toLowerCase();
+
+ const alternativeMatch = Object
+ .keys(alternativeNames)
+ .some((alternativeName) => {
+ return alternativeName.toLowerCase().indexOf(lowercaseSearchTerm) > -1
+ && currentItem.name === alternativeNames[alternativeName];
+ });
+
+ return (
+ lowercaseCurrentItemName.indexOf(lowercaseSearchTerm) > -1
+ || alternativeMatch
+ );
+ };
+}