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
Switch to op-autocomplete for the time-entry wp autocompleter (#9434)
Benjamin Bädorfcd80bd4047bb
diff --git a/frontend/src/app/core/global_search/input/global-search-input.component.html b/frontend/src/app/core/global_search/input/global-search-input.component.htmlindex bef38ad8a1c..bc1abbd0eef 100644--- a/frontend/src/app/core/global_search/input/global-search-input.component.html+++ b/frontend/src/app/core/global_search/input/global-search-input.component.html@@ -11,7 +11,7 @@<op-autocompleter#select- [defaulData]="false"+ [defaultData]="false"[name]="'global-search-input'"[id]="'global-search-input'"class="global-search"@@ -61,11 +61,11 @@<span class="global-search--wp-subject">{{item.subject}}</span><div class="global-search--wp-content">- <span [textContent]="item.project" class="global-search--wp-project"></span>+ <span [textContent]="item.project.name" class="global-search--wp-project"></span>#{{item.id}}<span- [textContent]="item.status"- [ngClass]="statusHighlighting(item.statusId)"+ [textContent]="item.status.name"+ [ngClass]="statusHighlighting(item.status.id)"class="global-search--wp-status"></span></div>diff --git a/frontend/src/app/core/global_search/input/global-search-input.component.ts b/frontend/src/app/core/global_search/input/global-search-input.component.tsindex 61b636dffa9..ecf80e4dc8c 100644--- a/frontend/src/app/core/global_search/input/global-search-input.component.ts+++ b/frontend/src/app/core/global_search/input/global-search-input.component.ts@@ -112,9 +112,9 @@ export class GlobalSearchInputComponent implements AfterViewInit, OnDestroy {/** Remember the item that best matches the query.* That way, it will be highlighted (as we manually mark the selected item) and we can handle enter.* */- public selectedItem:SearchResultItem|SearchOptionItem|null;+ public selectedItem:WorkPackageResource|SearchOptionItem|null;- private unregisterGlobalListener:Function|undefined;+ private unregisterGlobalListener:(() => unknown)|undefined;public text:{ [key:string]:string } = {all_projects: this.I18n.t('js.global_search.all_projects'),@@ -239,13 +239,13 @@ export class GlobalSearchInputComponent implements AfterViewInit, OnDestroy {return this.selectedItem && this.selectedItem.hasOwnProperty('id');}- public followItem(item:SearchResultItem|SearchOptionItem) {- if (item.hasOwnProperty('id')) {- window.location.href = this.wpPath((item as SearchResultItem).id);+ public followItem(item:WorkPackageResource|SearchOptionItem) {+ if (item instanceof HalResource) {+ window.location.href = this.wpPath(item.id!);} else {// update embedded table and title when new search is submittedthis.globalSearchService.searchTerm = this.currentValue;- this.searchInScope((item as SearchOptionItem).projectScope);+ this.searchInScope(item.projectScope);}}@@ -260,7 +260,7 @@ export class GlobalSearchInputComponent implements AfterViewInit, OnDestroy {return item.id === undefined || item.subject.toLowerCase().indexOf(term.toLowerCase()) !== -1;}- private autocompleteWorkPackages(query:string):Observable<(SearchResultItem|SearchOptionItem)[]> {+ private autocompleteWorkPackages(query:string):Observable<(WorkPackageResource|SearchOptionItem)[]> {if (!query) {return of([]);}@@ -302,32 +302,14 @@ export class GlobalSearchInputComponent implements AfterViewInit, OnDestroy {}private searchResultsToOptions(results:WorkPackageResource[], query:string) {- const searchItems = results.map((wp) => {- const item = {- id: wp.id!,- subject: wp.subject,- status: wp.status.name,- statusId: wp.status.idFromLink,- href: wp.href,- project: wp.project.name,- author: wp.author,- type: wp.type,- } as SearchResultItem;- // If we have a direct hit, we choose it to be the selected element.- if (query === wp.id!.toString()) {- this.selectedItem = item;- }-- return item;- });-const searchOptions = this.detailedSearchOptions();+ // If we have a direct hit, we choose it to be the selected element.+ this.selectedItem = results.find((wp) => wp.id?.toString() === query) || searchOptions[0];- if (!this.selectedItem) {- this.selectedItem = searchOptions[0];- }-- return (searchOptions as (SearchResultItem|SearchOptionItem)[]).concat(searchItems);+ return [+ ...searchOptions,+ ...results,+ ];}// set the possible 'search in scope' options for the current project pathdiff --git a/frontend/src/app/features/boards/board/add-list-modal/add-list-modal.html b/frontend/src/app/features/boards/board/add-list-modal/add-list-modal.htmlindex 4da6dd3fa7e..ba668fca625 100644--- a/frontend/src/app/features/boards/board/add-list-modal/add-list-modal.html+++ b/frontend/src/app/features/boards/board/add-list-modal/add-list-modal.html@@ -16,26 +16,28 @@<div class="form--field-container"><div class="form--select-container"><label class="form--label" [textContent]="actionService.label"></label>- <op-autocompleter #select- classes="new-list--action-select"- appendTo="body"- [resource]="autocompleterOptions.resource"- [openDirectly]="true"- [fetchDataDirectly]="true"- [getOptionsFn]=autocompleterOptions.getOptionsFn- (change)="onModelChange($event)">- <ng-template op-autocompleter-footer-tmp *ngIf="autocompleterOptions.resource=='version'" let-search>- <button- class="op-select-footer--label"- type="button"- (click)="onNewActionCreated()">- <span class="icon-context">- <op-icon icon-classes="icon-plus icon-context"></op-icon>- {{text.button_create}} {{ngSelectComponent.ngSelectInstance.searchTerm}}- </span>- </button>+ <op-autocompleter+ #select+ classes="new-list--action-select"+ appendTo="body"+ [resource]="autocompleterOptions.resource"+ [openDirectly]="true"+ [fetchDataDirectly]="true"+ [getOptionsFn]=autocompleterOptions.getOptionsFn+ (change)="onModelChange($event)"+ >+ <ng-template op-autocompleter-footer-tmp *ngIf="autocompleterOptions.resource=='version'" let-search>+ <button+ class="op-select-footer--label"+ type="button"+ (click)="onNewActionCreated()">+ <span class="icon-context">+ <op-icon icon-classes="icon-plus icon-context"></op-icon>+ {{text.button_create}} {{ngSelectComponent.ngSelectInstance.searchTerm}}+ </span>+ </button>- </ng-template>+ </ng-template></op-autocompleter></div></div>diff --git a/frontend/src/app/features/boards/board/inline-add/board-inline-add-autocompleter.html b/frontend/src/app/features/boards/board/inline-add/board-inline-add-autocompleter.htmlindex f5cd656fb5b..25b4775a661 100644--- a/frontend/src/app/features/boards/board/inline-add/board-inline-add-autocompleter.html+++ b/frontend/src/app/features/boards/board/inline-add/board-inline-add-autocompleter.html@@ -1,11 +1,11 @@<op-autocompleter-[appendTo]="appendToContainer"-classes="wp-inline-create--reference-autocompleter"-[closeOnSelect]="false"-[placeholder]="text.placeholder"-[loading]="isLoading"-[resource]="autocompleterOptions.resource"-[getOptionsFn]="autocompleterOptions.getOptionsFn"-(close)="cancel()"-(change)="addWorkPackageToQuery($event)">-</op-autocompleter>\ No newline at end of file+ [appendTo]="appendToContainer"+ classes="wp-inline-create--reference-autocompleter"+ [closeOnSelect]="false"+ [placeholder]="text.placeholder"+ [loading]="isLoading"+ [resource]="autocompleterOptions.resource"+ [getOptionsFn]="autocompleterOptions.getOptionsFn"+ (close)="cancel()"+ (change)="addWorkPackageToQuery($event)"+></op-autocompleter>\ No newline at end of filediff --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 0b0cb8ece02..679ae1224f8 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@@ -1,7 +1,6 @@import { NgSelectComponent } from '@ng-select/ng-select';import { APIV3Service } from 'core-app/core/apiv3/api-v3.service';import { DebouncedRequestSwitchmap, errorNotificationHandler } from 'core-app/shared/helpers/rxjs/debounced-input-switchmap';-import { ValueOption } from 'core-app/shared/components/fields/edit/field-types/select-edit-field/select-edit-field.component';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';@@ -42,7 +41,7 @@ export class FilterSearchableMultiselectValueComponent extends UntilDestroyedMixpublic active:Set<string>;- public requests = new DebouncedRequestSwitchmap<string, ValueOption>(+ public requests = new DebouncedRequestSwitchmap<string, HalResource>((searchTerm:string) => this.loadAvailable(searchTerm),errorNotificationHandler(this.halNotification),true,diff --git a/frontend/src/app/features/work-packages/components/wp-relations/wp-relations-create/wp-relations-autocomplete/wp-relations-autocomplete.html b/frontend/src/app/features/work-packages/components/wp-relations/wp-relations-create/wp-relations-autocomplete/wp-relations-autocomplete.htmlindex 0a0586312d7..1bf4eb30115 100644--- a/frontend/src/app/features/work-packages/components/wp-relations/wp-relations-create/wp-relations-autocomplete/wp-relations-autocomplete.html+++ b/frontend/src/app/features/work-packages/components/wp-relations/wp-relations-create/wp-relations-autocomplete/wp-relations-autocomplete.html@@ -1,17 +1,17 @@<div class="wp-relations--autocomplete"><op-autocompleter- classes="wp-inline-create--reference-autocompleter"- [appendTo]="appendToContainer"- [placeholder]="inputPlaceholder"- [typeToSearchText]="inputPlaceholder"- [loading]="isLoading"- [resource]="autocompleterOptions.resource"- [defaulData]="false"- (open)="onOpen()"- (change)="onWorkPackageSelected($event)"- [getOptionsFn]=autocompleterOptions.getOptionsFn>- </op-autocompleter>+ classes="wp-inline-create--reference-autocompleter"+ [appendTo]="appendToContainer"+ [placeholder]="inputPlaceholder"+ [typeToSearchText]="inputPlaceholder"+ [loading]="isLoading"+ [resource]="autocompleterOptions.resource"+ [defaultData]="false"+ (open)="onOpen()"+ (change)="onWorkPackageSelected($event)"+ [getOptionsFn]=autocompleterOptions.getOptionsFn+ ></op-autocompleter></div>diff --git a/frontend/src/app/shared/components/autocompleter/op-autocompleter/op-autocompleter.component.html b/frontend/src/app/shared/components/autocompleter/op-autocompleter/op-autocompleter.component.htmlindex 32c42fb4d9f..b339a304616 100644--- a/frontend/src/app/shared/components/autocompleter/op-autocompleter/op-autocompleter.component.html+++ b/frontend/src/app/shared/components/autocompleter/op-autocompleter/op-autocompleter.component.html@@ -4,7 +4,7 @@[(ngModel)]="model"[items]="results$ | async"[ngClass]="classes"- [typeahead]="searchInput$"+ [typeahead]="typeahead"[clearOnBackspace]="clearOnBackspace"[clearSearchOnAdd]="clearSearchOnAdd"[hideSelected]="hideSelected"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 862812e04b1..6e6a077b1b7 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@@ -1,5 +1,6 @@import {AfterViewInit,+ OnChanges,ChangeDetectionStrategy,ChangeDetectorRef,Component,@@ -10,16 +11,20 @@ import {Output,TemplateRef,ViewChild,+ SimpleChanges,} from '@angular/core';import { DropdownPosition, NgSelectComponent } from '@ng-select/ng-select';-import { Observable, of, Subject } from 'rxjs';+import { Observable, NEVER, of, Subject, combineLatest, merge } from 'rxjs';import { debounceTime, distinctUntilChanged, switchMap } from 'rxjs/operators';import { GroupValueFn } from '@ng-select/ng-select/lib/ng-select.component';++import { HalResource } from 'core-app/features/hal/resources/hal-resource';import { Highlighting } from 'core-app/features/work-packages/components/wp-fast-table/builders/highlighting/highlighting.functions';import { UntilDestroyedMixin } from 'core-app/shared/helpers/angular/until-destroyed.mixin';import { I18nService } from 'core-app/core/i18n/i18n.service';import { AngularTrackingHelpers } from 'core-app/shared/helpers/angular/tracking-functions';import { OpAutocompleterFooterTemplateDirective } from 'core-app/shared/components/autocompleter/autocompleter-footer-template/op-autocompleter-footer-template.directive';+import { OpAutocompleterService } from './services/op-autocompleter.service';import { OpAutocompleterHeaderTemplateDirective } from './directives/op-autocompleter-header-template.directive';import { OpAutocompleterLabelTemplateDirective } from './directives/op-autocompleter-label-template.directive';@@ -36,7 +41,7 @@ import { OpAutocompleterOptionTemplateDirective } from './directives/op-autocomp// it has all inputs and outputs of ng-select// in order to use it, you only need to pass the data type and its filters// you also can change the value of ng-select default options by changing @inputs and @outputs-export class OpAutocompleterComponent extends UntilDestroyedMixin implements AfterViewInit {+export class OpAutocompleterComponent extends UntilDestroyedMixin implements AfterViewInit, OnChanges {@Input() public filters?:IAPIFilter[] = [];@Input() public resource:resource;@@ -45,7 +50,7 @@ export class OpAutocompleterComponent extends UntilDestroyedMixin implements Aft@Input() public searchKey?:string = '';- @Input() public defaulData?:boolean = false;+ @Input() public defaultData?:boolean = false;@Input() public focusDirectly?:boolean = true;@@ -67,7 +72,8 @@ export class OpAutocompleterComponent extends UntilDestroyedMixin implements Aft@Input() public id?:string;- @Input() public configOptions?:IOPAutocompleterOptions[];+ @Input() public items?:IOPAutocompleterOption[]|HalResource[];+ private items$ = new Subject();@Input() public clearSearchOnAdd?:boolean = true;@@ -147,7 +153,7 @@ export class OpAutocompleterComponent extends UntilDestroyedMixin implements Aft@Input() public keyDownFn ? = (_:KeyboardEvent) => true;- @Input() public typeahead?:Subject<string>;+ @Input() public typeahead:Subject<string> = new Subject();// a function for setting the options of ng-select@Input() public getOptionsFn:(searchTerm:string) => any;@@ -180,8 +186,6 @@ export class OpAutocompleterComponent extends UntilDestroyedMixin implements Aftpublic active:Set<string>;- public searchInput$ = new Subject<string>();-public results$:any;public isLoading = false;@@ -209,6 +213,12 @@ export class OpAutocompleterComponent extends UntilDestroyedMixin implements Aftsuper();}+ ngOnChanges(changes:SimpleChanges) {+ if (changes.items) {+ this.items$.next(changes.items.currentValue);+ }+ }+ngAfterViewInit():void {if (!this.ngSelectInstance) {return;@@ -216,21 +226,22 @@ export class OpAutocompleterComponent extends UntilDestroyedMixin implements Aftthis.ngZone.runOutsideAngular(() => {setTimeout(() => {- this.results$ = this.configOptions ? (this.searchInput$.pipe(- debounceTime(250),- distinctUntilChanged(),- switchMap((queryString) => this.getOptionsItems(queryString)),- )) : this.defaulData ? (this.searchInput$.pipe(- debounceTime(250),- distinctUntilChanged(),- switchMap((queryString) => this.opAutocompleterService.loadData(queryString, this.resource, this.filters, this.searchKey)),- )) : (this.searchInput$.pipe(- debounceTime(250),- distinctUntilChanged(),- switchMap((queryString) => this.getOptionsFn(queryString)),- ));+ this.results$ = merge(+ (this.items$ || new Subject()),+ this.typeahead.pipe(+ distinctUntilChanged(),+ debounceTime(250),+ (this.defaultData+ ? switchMap((queryString) => this.opAutocompleterService.loadData(queryString, this.resource, this.filters, this.searchKey))+ : this.getOptionsFn+ ? switchMap((queryString) => this.getOptionsFn(queryString))+ : switchMap(() => NEVER)+ ),+ ),+ );+if (this.fetchDataDirectly) {- this.results$ = this.defaulData+ this.results$ = this.defaultData? (this.opAutocompleterService.loadData('', this.resource, this.filters, this.searchKey)): (this.getOptionsFn(''));}@@ -256,9 +267,9 @@ export class OpAutocompleterComponent extends UntilDestroyedMixin implements Aft}}- public opened(val:any) {+ public opened(val: any) {if (this.openDirectly) {- this.results$ = this.defaulData+ this.results$ = this.defaultData? (this.opAutocompleterService.loadData('', this.resource, this.filters, this.searchKey)): (this.getOptionsFn(''));}@@ -267,7 +278,7 @@ export class OpAutocompleterComponent extends UntilDestroyedMixin implements Aft}public getOptionsItems(searchKey:string):Observable<any> {- return of(this.configOptions?.filter((element) => element.name.includes(searchKey)));+ return of((this.items as IOPAutocompleterOption[])?.filter((element) => element.name.includes(searchKey)));}public closeSelect() {diff --git a/frontend/src/app/shared/components/autocompleter/op-autocompleter/op-autocompleter.spec.ts b/frontend/src/app/shared/components/autocompleter/op-autocompleter/op-autocompleter.spec.tsindex ac98c0ead54..3ed38376db8 100644--- a/frontend/src/app/shared/components/autocompleter/op-autocompleter/op-autocompleter.spec.ts+++ b/frontend/src/app/shared/components/autocompleter/op-autocompleter/op-autocompleter.spec.ts@@ -8,19 +8,6 @@ import { By } from '@angular/platform-browser';import { OpAutocompleterService } from './services/op-autocompleter.service';import { OpAutocompleterComponent } from './op-autocompleter.component';-function triggerKeyDownEvent(element:DebugElement, which:number, key = ''):void {- element.triggerEventHandler('keydown', {- which,- key,- preventDefault: () => {- },- });-}--function getNgSelectElement(fixture:ComponentFixture<any>):DebugElement {- return fixture.debugElement.query(By.css('ng-select'));-}-describe('autocompleter', () => {let fixture:ComponentFixture<OpAutocompleterComponent>;let opAutocompleterServiceSpy:jasmine.SpyObj<OpAutocompleterService>;@@ -91,7 +78,7 @@ describe('autocompleter', () => {fixture.componentInstance.closeOnSelect = true;fixture.componentInstance.virtualScroll = true;fixture.componentInstance.classes = 'wp-inline-create--reference-autocompleter';- fixture.componentInstance.defaulData = true;+ fixture.componentInstance.defaultData = true;// @ts-ignoreopAutocompleterServiceSpy.loadData.and.returnValue(of(workPackagesStub));diff --git a/frontend/src/app/shared/components/autocompleter/op-autocompleter/services/op-autocompleter.service.ts b/frontend/src/app/shared/components/autocompleter/op-autocompleter/services/op-autocompleter.service.tsindex c5eb9253aa5..eeaca13eaa5 100644--- a/frontend/src/app/shared/components/autocompleter/op-autocompleter/services/op-autocompleter.service.ts+++ b/frontend/src/app/shared/components/autocompleter/op-autocompleter/services/op-autocompleter.service.ts@@ -53,7 +53,6 @@ export class OpAutocompleterService extends UntilDestroyedMixin {// in this case we can add more functions for fetching usual resourcesdefault: {return this.loadAvailable(matching, resource, filters, searchKey);- break;}}}diff --git a/frontend/src/app/shared/components/autocompleter/op-autocompleter/typings.d.ts b/frontend/src/app/shared/components/autocompleter/op-autocompleter/typings.d.tsindex 7e7e6283f06..72d3fc950a9 100644--- a/frontend/src/app/shared/components/autocompleter/op-autocompleter/typings.d.ts+++ b/frontend/src/app/shared/components/autocompleter/op-autocompleter/typings.d.ts@@ -4,7 +4,7 @@ interface IAPIFilter {values:ApiV3FilterValueType[];}-interface IOPAutocompleterOptions {+interface IOPAutocompleterOption {id:number;name:string;}diff --git a/frontend/src/app/shared/components/autocompleter/te-work-package-autocompleter/te-work-package-autocompleter.component.html b/frontend/src/app/shared/components/autocompleter/te-work-package-autocompleter/te-work-package-autocompleter.component.htmlindex 4dcc2b618ce..26a20361cd5 100644--- a/frontend/src/app/shared/components/autocompleter/te-work-package-autocompleter/te-work-package-autocompleter.component.html+++ b/frontend/src/app/shared/components/autocompleter/te-work-package-autocompleter/te-work-package-autocompleter.component.html@@ -1,26 +1,27 @@-<ng-select- #ngSelectComponent- [(ngModel)]="model"- [items]="availableValues"- [ngClass]="classes"- [addTag]="createAllowed"- [virtualScroll]="true"- [required]="required"- [clearable]="!required"- [disabled]="disabled"- [typeahead]="typeahead"- [clearOnBackspace]="false"- [appendTo]="appendTo"- [hideSelected]="hideSelected"- [loading]="finishedLoading | async"- [id]="id"- (change)="changeModel($event)"- (open)="opened()"- (close)="closed()"- (keydown)="keyPressed($event)"- bindLabel="name"+<op-autocompleter+ #ngSelectComponent+ [model]="model"+ [items]="availableValues"+ [ngClass]="classes"+ [addTag]="createAllowed"+ [virtualScroll]="true"+ [required]="required"+ [clearable]="!required"+ [disabled]="disabled"+ [clearOnBackspace]="false"+ [typeahead]="typeahead"+ [appendTo]="appendTo"+ [hideSelected]="hideSelected"+ [loading]="finishedLoading | async"+ [id]="id"+ (change)="changeModel($event)"+ (open)="opened()"+ (close)="closed()"+ (keydown)="keyPressed($event)"+ bindLabel="name"+ resource="work_packages">- <ng-template ng-header-tmp>+ <ng-template op-autocompleter-header-tmp><div class="scrollable-tabs"><div class="op-scrollable-tabs--tab-container"><ul class="op-tab-row">@@ -38,12 +39,12 @@</li><liclass="op-tab-row--tab"- [ngClass]="{'selected': mode === 'recent'}"(click)="setMode('recent')"><a- class="op-tab-row--link"href="#"+ class="op-tab-row--link"+ [class.op-tab-row--link_selected]="mode === 'recent'"[textContent]="text.recent"></a>@@ -52,10 +53,7 @@</div></div></ng-template>- <ng-template ng-tag-tmp let-search="searchTerm">+ <ng-template op-autocompleter-tag-tmp let-search="searchTerm"><b [textContent]="text.add_new_action"></b>: {{search}}</ng-template>- <ng-template ng-option-tmp let-item="item" let-search="searchTerm">- <div [ngOptionHighlight]="search" class="ng-option-label ellipsis">{{ item.name }}</div>- </ng-template>-</ng-select>+</op-autocompleter>diff --git a/frontend/src/app/shared/components/autocompleter/te-work-package-autocompleter/te-work-package-autocompleter.component.ts b/frontend/src/app/shared/components/autocompleter/te-work-package-autocompleter/te-work-package-autocompleter.component.tsindex eff42c55715..c243581238a 100644--- a/frontend/src/app/shared/components/autocompleter/te-work-package-autocompleter/te-work-package-autocompleter.component.ts+++ b/frontend/src/app/shared/components/autocompleter/te-work-package-autocompleter/te-work-package-autocompleter.component.ts@@ -29,13 +29,17 @@import {AfterViewInit, Component, EventEmitter, Injector, Output, ViewEncapsulation,} from '@angular/core';+import { of } from 'rxjs';+import { HalResource } from 'core-app/features/hal/resources/hal-resource';import { WorkPackageAutocompleterComponent } from 'core-app/shared/components/autocompleter/work-package-autocompleter/wp-autocompleter.component';export type TimeEntryWorkPackageAutocompleterMode = 'all'|'recent';@Component({templateUrl: './te-work-package-autocompleter.component.html',- styleUrls: ['./te-work-package-autocompleter.component.sass'],+ styleUrls: [+ './te-work-package-autocompleter.component.sass',+ ],selector: 'te-work-package-autocompleter',encapsulation: ViewEncapsulation.None,})diff --git a/frontend/src/app/shared/components/fields/edit/field-types/multi-select-edit-field.component.html b/frontend/src/app/shared/components/fields/edit/field-types/multi-select-edit-field.component.htmlindex 61f598c7197..ebe070a6c28 100644--- a/frontend/src/app/shared/components/fields/edit/field-types/multi-select-edit-field.component.html+++ b/frontend/src/app/shared/components/fields/edit/field-types/multi-select-edit-field.component.html@@ -4,7 +4,7 @@[clearable]="!required"[disabled]="inFlight"[id]="handler.htmlId"- [items]="valueOptions"+ [items]="availableOptions"bindLabel="name"[virtualScroll]="true"[clearSearchOnAdd]="true"diff --git a/frontend/src/app/shared/components/fields/edit/field-types/multi-select-edit-field.component.ts b/frontend/src/app/shared/components/fields/edit/field-types/multi-select-edit-field.component.tsindex 43c33f317d8..8bb6a7016cb 100644--- a/frontend/src/app/shared/components/fields/edit/field-types/multi-select-edit-field.component.ts+++ b/frontend/src/app/shared/components/fields/edit/field-types/multi-select-edit-field.component.ts@@ -45,8 +45,6 @@ export class MultiSelectEditFieldComponent extends EditFieldComponent implementspublic availableOptions:any[] = [];- public valueOptions:ValueOption[];-public text = {requiredPlaceholder: this.I18n.t('js.placeholders.selection'),placeholder: this.I18n.t('js.placeholders.default'),@@ -160,7 +158,7 @@ export class MultiSelectEditFieldComponent extends EditFieldComponent implementslet result;if (option) {- result = _.find(this.valueOptions, (valueOption) => valueOption.href === option.href)!;+ result = _.find(this.availableOptions, (valueOption) => valueOption.href === option.href)!;}return result || this.nullOption;@@ -176,7 +174,6 @@ export class MultiSelectEditFieldComponent extends EditFieldComponent implements}this.availableOptions = availableValues || [];- this.valueOptions = this.availableOptions.map((el) => ({ name: el.name, href: el.href }));this._selectedOption = this.buildSelectedOption();this.checkCurrentValueValidity();diff --git a/frontend/src/app/shared/components/fields/edit/field-types/select-edit-field/select-edit-field.component.html b/frontend/src/app/shared/components/fields/edit/field-types/select-edit-field/select-edit-field.component.htmlindex be0288841e7..5d6b41c9a29 100644--- a/frontend/src/app/shared/components/fields/edit/field-types/select-edit-field/select-edit-field.component.html+++ b/frontend/src/app/shared/components/fields/edit/field-types/select-edit-field/select-edit-field.component.html@@ -1,5 +1,5 @@<ndc-dynamic [ndcDynamicComponent]="autocompleterComponent()"- [ndcDynamicInputs]="{ availableValues: valueOptions,+ [ndcDynamicInputs]="{ availableValues: availableOptions,appendTo: appendTo,resource: this.resource,model: selectedOption ? selectedOption : '',diff --git a/frontend/src/app/shared/components/fields/edit/field-types/select-edit-field/select-edit-field.component.ts b/frontend/src/app/shared/components/fields/edit/field-types/select-edit-field/select-edit-field.component.tsindex a7c5b6bdcd0..818cef90510 100644--- a/frontend/src/app/shared/components/fields/edit/field-types/select-edit-field/select-edit-field.component.ts+++ b/frontend/src/app/shared/components/fields/edit/field-types/select-edit-field/select-edit-field.component.ts@@ -61,8 +61,6 @@ export class SelectEditFieldComponent extends EditFieldComponent implements OnInpublic availableOptions:any[];- public valueOptions:ValueOption[];-public text:{ [key:string]:string };public appendTo:any = null;@@ -78,7 +76,7 @@ export class SelectEditFieldComponent extends EditFieldComponent implements OnInpublic get selectedOption() {const href = this.value ? this.value.href : null;- return _.find(this.valueOptions, (o) => o.href === href)!;+ return _.find(this.availableOptions, (o) => o.href === href)!;}public set selectedOption(val:ValueOption|HalResource) {@@ -160,7 +158,6 @@ export class SelectEditFieldComponent extends EditFieldComponent implements OnInprivate setValues(availableValues:HalResource[]) {this.availableOptions = this.sortValues(availableValues);this.addEmptyOption();- this.valueOptions = this.availableOptions.map((el) => this.mapAllowedValue(el));}protected loadValues(query?:string) {@@ -175,20 +172,13 @@ export class SelectEditFieldComponent extends EditFieldComponent implements OnInthis.setValues([]);}- return from(Promise.resolve(this.valueOptions));+ return from(Promise.resolve(this.availableOptions));}protected loadValuesFromBackend(query?:string) {return from(this.loadAllowedValues(query),).pipe(- tap((collection) => {- // if it is an unpaginated collection or if we get all possible entries when fetching with a blank- // query, we do not need to load the values again;- if (collection.count === undefined || collection.total === undefined || (!query && collection.total === collection.count)) {- this.valuesLoaded = true;- }- }),map((collection) => {if (collection.count === undefined || collection.total === undefined || (!query && collection.total === collection.count) || !this.value) {return collection.elements;@@ -196,7 +186,7 @@ export class SelectEditFieldComponent extends EditFieldComponent implements OnInreturn collection.elements.concat([this.value]);}),tap((elements) => this.setValues(elements)),- map(() => this.valueOptions),+ map(() => this.availableOptions),);}@@ -216,7 +206,6 @@ export class SelectEditFieldComponent extends EditFieldComponent implements OnInprivate addValue(val:HalResource) {this.availableOptions.push(val);- this.valueOptions.push({ name: val.name, href: val.href });}public get currentValueInvalid():boolean {@@ -282,17 +271,13 @@ export class SelectEditFieldComponent extends EditFieldComponent implements OnInreturn this.halSorting.sort(availableValues);}- protected mapAllowedValue(value:HalResource):ValueOption {- return { name: value.name, href: value.href };- }-// Subclasses shall be able to override the filters with which the// allowed values are reduced in the backend.protected allowedValuesFilter(query?:string) {return {};}- private getEmptyOption():ValueOption|undefined {+ private getEmptyOption():undefined {return _.find(this.availableOptions, (el) => el.name === this.text.placeholder);}diff --git a/frontend/src/app/shared/components/fields/edit/field-types/work-package-edit-field.component.ts b/frontend/src/app/shared/components/fields/edit/field-types/work-package-edit-field.component.tsindex f60cda65335..67868398a87 100644--- a/frontend/src/app/shared/components/fields/edit/field-types/work-package-edit-field.component.ts+++ b/frontend/src/app/shared/components/fields/edit/field-types/work-package-edit-field.component.ts@@ -27,21 +27,21 @@//++import { Component } from '@angular/core';-import { WorkPackageResource } from 'core-app/features/hal/resources/work-package-resource';+import { HalResource } from 'core-app/features/hal/resources/hal-resource';import {DebouncedRequestSwitchmap,errorNotificationHandler,} from 'core-app/shared/helpers/rxjs/debounced-input-switchmap';import { take } from 'rxjs/operators';import { ApiV3FilterBuilder } from 'core-app/shared/helpers/api-v3/api-v3-filter-builder';-import { SelectEditFieldComponent, ValueOption } from './select-edit-field/select-edit-field.component';+import { SelectEditFieldComponent } from './select-edit-field/select-edit-field.component';@Component({templateUrl: './work-package-edit-field.component.html',})export class WorkPackageEditFieldComponent extends SelectEditFieldComponent {/** Keep a switchmap for search term and loading state */- public requests = new DebouncedRequestSwitchmap<string, ValueOption>(+ public requests = new DebouncedRequestSwitchmap<string, HalResource>((searchTerm:string) => this.loadValues(searchTerm),errorNotificationHandler(this.halNotification),);@@ -51,7 +51,7 @@ export class WorkPackageEditFieldComponent extends SelectEditFieldComponent {// Using this hack with the empty value to have the values loaded initially// while avoiding loading it multiple times.- return new Promise<ValueOption[]>((resolve) => {+ return new Promise<HalResource[]>((resolve) => {this.requests.output$.pipe(take(1)).subscribe((options) => {resolve(options);});@@ -61,9 +61,6 @@ export class WorkPackageEditFieldComponent extends SelectEditFieldComponent {}public get typeahead() {- if (this.valuesLoaded) {- return false;- }return this.requests.input$;}@@ -80,17 +77,4 @@ export class WorkPackageEditFieldComponent extends SelectEditFieldComponent {return filterParams;}-- protected mapAllowedValue(value:WorkPackageResource|ValueOption):ValueOption {- if ((value as WorkPackageResource).id) {- const prefix = (value as WorkPackageResource).type ? `${(value as WorkPackageResource).type.name} ` : '';- const suffix = (value as WorkPackageResource).subject || value.name;-- return {- name: `${prefix}#${(value as WorkPackageResource).id} ${suffix}`,- href: value.href,- };- }- return value;- }}