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
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
Use op-autocompleter in filter component
Oliver Güntherffb350e479b0
diff --git a/frontend/src/app/features/work-packages/components/filters/filter-searchable-multiselect-value/filter-searchable-multiselect-value.component.html b/frontend/src/app/features/work-packages/components/filters/filter-searchable-multiselect-value/filter-searchable-multiselect-value.component.htmlindex 6900bb55735..c676fab244b 100644--- a/frontend/src/app/features/work-packages/components/filters/filter-searchable-multiselect-value/filter-searchable-multiselect-value.component.html+++ b/frontend/src/app/features/work-packages/components/filters/filter-searchable-multiselect-value/filter-searchable-multiselect-value.component.html@@ -1,30 +1,18 @@<div class="inline-label ng-select-container"id="div-values-{{filter.id}}">- <ng-select #ngSelectInstance- [ngModel]="filter.values"- (change)="setValues($event)"- (add)="repositionDropdown()"- (remove)="repositionDropdown()"- (open)="repositionDropdown()"- [compareWith]="compareByHrefOrString"- [clearSearchOnAdd]="true"- [placeholder]="text.placeholder"- [ngClass]="{'-required-highlighting' : isEmpty}"- class="advanced-filters--ng-select -multi-select"- [id]="'values-' + filter.id"- [items]="availableOptions"- [multiple]="true"- [closeOnSelect]="false"- [hideSelected]="true"- appendTo="body"- bindLabel="name"- [typeahead]="requests.input$"- [virtualScroll]="true">- <ng-template ng-footer-tmp *ngIf="total > count">- <div class="ng-footer-text">- <span [textContent]="moreItemsText(count, total)"></span>- </div>- </ng-template>- </ng-select>+ <op-autocompleter+ appendTo="body"+ class="advanced-filters--ng-select -multi-select"+ [getOptionsFn]="autocompleterFn"+ [classes]="{'-required-highlighting' : isEmpty}"+ [virtualScroll]+ [closeOnSelect]="false"+ [placeholder]="text.placeholder"+ [hideSelected]="true"+ [multiple]="true"+ [fetchDataDirectly]="true"+ [focusDirectly]="shouldFocus"+ (change)="setValues($event)"+ ></op-autocompleter></div>diff --git a/frontend/src/app/features/work-packages/components/filters/filter-searchable-multiselect-value/filter-searchable-multiselect-value.component.ts b/frontend/src/app/features/work-packages/components/filters/filter-searchable-multiselect-value/filter-searchable-multiselect-value.component.tsindex 1d3d2e265e6..2a8ce7cac20 100644--- a/frontend/src/app/features/work-packages/components/filters/filter-searchable-multiselect-value/filter-searchable-multiselect-value.component.ts+++ b/frontend/src/app/features/work-packages/components/filters/filter-searchable-multiselect-value/filter-searchable-multiselect-value.component.ts@@ -7,7 +7,10 @@ import {import { Observable } from 'rxjs';import { CurrentProjectService } from 'core-app/core/current-project/current-project.service';import { ApiV3FilterBuilder } from 'core-app/shared/helpers/api-v3/api-v3-filter-builder';-import { map, tap } from 'rxjs/operators';+import {+ map,+ tap,+} from 'rxjs/operators';import { ApiV3ResourceCollection } from 'core-app/core/apiv3/paths/apiv3-resource';import { UntilDestroyedMixin } from 'core-app/shared/helpers/angular/until-destroyed.mixin';import { ApiV3Resource } from 'core-app/core/apiv3/cache/cachable-apiv3-resource';@@ -16,11 +19,15 @@ import { HalResourceService } from 'core-app/features/hal/services/hal-resource.import { HalResourceSortingService } from 'core-app/features/hal/services/hal-resource-sorting.service';import { HalResourceNotificationService } from 'core-app/features/hal/services/hal-resource-notification.service';import {- AfterViewInit, ChangeDetectionStrategy,+ ChangeDetectionStrategy,ChangeDetectorRef,- Component, EventEmitter, Input, NgZone, OnInit, Output, ViewChild,+ Component,+ EventEmitter,+ Input,+ NgZone,+ Output,+ ViewChild,} from '@angular/core';-import { compareByHrefOrString } from 'core-app/shared/helpers/angular/tracking-functions';import { HalResource } from 'core-app/features/hal/resources/hal-resource';import { I18nService } from 'core-app/core/i18n/i18n.service';@@ -29,7 +36,7 @@ import { I18nService } from 'core-app/core/i18n/i18n.service';changeDetection: ChangeDetectionStrategy.OnPush,templateUrl: './filter-searchable-multiselect-value.component.html',})-export class FilterSearchableMultiselectValueComponent extends UntilDestroyedMixin implements OnInit, AfterViewInit {+export class FilterSearchableMultiselectValueComponent extends UntilDestroyedMixin {@Input() public filter:QueryFilterInstanceResource;@Input() public shouldFocus = false;@@ -38,21 +45,7 @@ export class FilterSearchableMultiselectValueComponent extends UntilDestroyedMixprivate _isEmpty:boolean;- public _availableOptions:HalResource[] = [];-- public compareByHrefOrString = compareByHrefOrString;-- public active:Set<string>;-- public count = 0;-- public total = 0;-- public requests = new DebouncedRequestSwitchmap<string, HalResource>(- (searchTerm:string) => this.loadAvailable(searchTerm),- errorNotificationHandler(this.halNotification),- true,- );+ autocompleterFn = (searchTerm:string):Observable<HalResource[]> => this.loadAvailable(searchTerm);readonly text = {placeholder: this.I18n.t('js.placeholders.selection'),@@ -62,14 +55,6 @@ export class FilterSearchableMultiselectValueComponent extends UntilDestroyedMixreturn this.filter.values;}- public get availableOptions() {- return this._availableOptions;- }-- public set availableOptions(val:HalResource[]) {- this._availableOptions = this.halSorting.sort(val);- }-public get isEmpty():boolean {return this._isEmpty = this.value.length === 0;}@@ -87,37 +72,6 @@ export class FilterSearchableMultiselectValueComponent extends UntilDestroyedMixsuper();}- ngOnInit() {- this.initialization();- // Request an empty value to load warning early on- this.requests.input$.next('');- }-- ngAfterViewInit():void {- if (this.ngSelectInstance && this.shouldFocus) {- this.ngSelectInstance.focus();- }- }-- initialization() {- this- .requests- .output$.pipe(- this.untilDestroyed(),- )- .subscribe((values:HalResource[]) => {- this.availableOptions = values;- this.cdRef.detectChanges();- });- }-- public moreItemsText(count:number, total:number) {- return this.I18n.t(- 'js.filter.more_values_not_shown',- { total: total - count },- );- }-public loadAvailable(matching:string):Observable<HalResource[]> {const filters:ApiV3FilterBuilder = this.createFilters(matching);const { href } = this.filter.currentSchema!.values!.allowedValues as any;@@ -127,10 +81,6 @@ export class FilterSearchableMultiselectValueComponent extends UntilDestroyedMix.filtered(filters, { pageSize: '-1' }).get().pipe(- tap((collection) => {- this.count = collection.count;- this.total = collection.total;- }),map((collection) => collection.elements),);@@ -150,21 +100,6 @@ export class FilterSearchableMultiselectValueComponent extends UntilDestroyedMixpublic setValues(val:any) {this.filter.values = val.length > 0 ? (Array.isArray(val) ? val : [val]) : [] as HalResource[];this.filterChanged.emit(this.filter);- this.requests.input$.next('');this.cdRef.detectChanges();}-- public repositionDropdown() {- if (this.ngSelectInstance) {- const component = (this.ngSelectInstance) as any;- if (component && component.dropdownPanel) {- this.ngZone.runOutsideAngular(() => {- setTimeout(() => {- component.dropdownPanel._updatePosition();- }, 25);- });- }- }- }-}diff --git a/frontend/src/app/features/work-packages/components/filters/filter-toggled-multiselect-value/filter-toggled-multiselect-value.component.html b/frontend/src/app/features/work-packages/components/filters/filter-toggled-multiselect-value/filter-toggled-multiselect-value.component.htmlindex 5cb6073d070..c4ebf7c1e47 100644--- a/frontend/src/app/features/work-packages/components/filters/filter-toggled-multiselect-value/filter-toggled-multiselect-value.component.html+++ b/frontend/src/app/features/work-packages/components/filters/filter-toggled-multiselect-value/filter-toggled-multiselect-value.component.html@@ -11,8 +11,5 @@[placeholder]="text.placeholder"[hideSelected]="true"(change)="setValues($event)"- (add)="repositionDropdown()"- (remove)="repositionDropdown()"- (open)="repositionDropdown()"></op-autocompleter></div>diff --git a/frontend/src/app/features/work-packages/components/filters/filter-toggled-multiselect-value/filter-toggled-multiselect-value.component.ts b/frontend/src/app/features/work-packages/components/filters/filter-toggled-multiselect-value/filter-toggled-multiselect-value.component.tsindex acbdab82fe9..e6ed1f4ce94 100644--- a/frontend/src/app/features/work-packages/components/filters/filter-toggled-multiselect-value/filter-toggled-multiselect-value.component.ts+++ b/frontend/src/app/features/work-packages/components/filters/filter-toggled-multiselect-value/filter-toggled-multiselect-value.component.ts@@ -39,7 +39,6 @@ import {ViewChild,} from '@angular/core';import { I18nService } from 'core-app/core/i18n/i18n.service';-import { compareByHrefOrString } from 'core-app/shared/helpers/angular/tracking-functions';import { HalResourceSortingService } from 'core-app/features/hal/services/hal-resource-sorting.service';import { PathHelperService } from 'core-app/core/path-helper/path-helper.service';import { NgSelectComponent } from '@ng-select/ng-select';@@ -103,17 +102,4 @@ export class FilterToggledMultiselectValueComponent implements OnInit, AfterViewpublic get isEmpty():boolean {return this._isEmpty = this.value.length === 0;}-- public repositionDropdown():void {- if (this.ngSelectInstance) {- setTimeout(() => {- const component = this.ngSelectInstance;- if (component && component.dropdownPanel) {- // _updatePosition is private, but necessary for workaround- /* eslint-disable-next-line @typescript-eslint/no-explicit-any,@typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access */- (component.dropdownPanel as any)._updatePosition();- }- }, 25);- }- }}diff --git a/frontend/src/app/shared/components/autocompleter/op-autocompleter/op-autocompleter.component.ts b/frontend/src/app/shared/components/autocompleter/op-autocompleter/op-autocompleter.component.tsindex a8d9ff5b6e6..c1eb179c21d 100644--- a/frontend/src/app/shared/components/autocompleter/op-autocompleter/op-autocompleter.component.ts+++ b/frontend/src/app/shared/components/autocompleter/op-autocompleter/op-autocompleter.component.ts@@ -273,7 +273,6 @@ export class OpAutocompleterComponent extends UntilDestroyedMixin implements Aft} else if (this.focusDirectly) {this.ngSelectInstance.focus();}-}, 25);});}