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
Fix loading me value
Oliver Günther0003590e33d1
diff --git a/frontend/src/app/core/apiv3/paths/apiv3-resource.ts b/frontend/src/app/core/apiv3/paths/apiv3-resource.tsindex 24f91429cba..a808f555a8d 100644--- a/frontend/src/app/core/apiv3/paths/apiv3-resource.ts+++ b/frontend/src/app/core/apiv3/paths/apiv3-resource.ts@@ -116,7 +116,7 @@ export class ApiV3ResourceCollection<V, T extends ApiV3GettableResource<V>> exteurl.searchParams.set(key, params[key]);});- const cls = resourceClass || APIv3GettableResource;+ const cls = resourceClass || ApiV3GettableResource;// eslint-disable-next-line new-capreturn new cls(this.apiRoot, url.pathname, url.search, this) as R;}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 503de7d5d1d..56ebc06e90e 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@@ -6,7 +6,7 @@class="advanced-filters--ng-select -multi-select"[id]="'values-' + filter.id"[getOptionsFn]="autocompleterFn"- [classes]="{'-required-highlighting' : isEmpty}"+ [classes]="{'-required-highlighting' : value.length === 0}"[virtualScroll][closeOnSelect]="false"[placeholder]="text.placeholder"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 2a8ce7cac20..6d9697f4a91 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,15 +1,15 @@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 { Observable } from 'rxjs';+ Observable,+ of,+} 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,+ switchMap,+ withLatestFrom,} from 'rxjs/operators';import { ApiV3ResourceCollection } from 'core-app/core/apiv3/paths/apiv3-resource';import { UntilDestroyedMixin } from 'core-app/shared/helpers/angular/until-destroyed.mixin';@@ -30,6 +30,8 @@ import {} from '@angular/core';import { HalResource } from 'core-app/features/hal/resources/hal-resource';import { I18nService } from 'core-app/core/i18n/i18n.service';+import { CurrentUserService } from 'core-app/core/current-user/current-user.service';+import { take } from 'rxjs/internal/operators/take';@Component({selector: 'filter-searchable-multiselect-value',@@ -43,7 +45,16 @@ export class FilterSearchableMultiselectValueComponent extends UntilDestroyedMix@Output() public filterChanged = new EventEmitter<QueryFilterInstanceResource>();- private _isEmpty:boolean;+ private meValue = this.halResourceService.createHalResource(+ {+ _links: {+ self: {+ href: this.apiV3Service.users.me.path,+ title: this.I18n.t('js.label_me'),+ },+ },+ }, true,+ );autocompleterFn = (searchTerm:string):Observable<HalResource[]> => this.loadAvailable(searchTerm);@@ -51,14 +62,10 @@ export class FilterSearchableMultiselectValueComponent extends UntilDestroyedMixplaceholder: this.I18n.t('js.placeholders.selection'),};- public get value() {+ public get value():string[]|HalResource[] {return this.filter.values;}- public get isEmpty():boolean {- return this._isEmpty = this.value.length === 0;- }-@ViewChild('ngSelectInstance', { static: true }) ngSelectInstance:NgSelectComponent;constructor(readonly halResourceService:HalResourceService,@@ -67,6 +74,7 @@ export class FilterSearchableMultiselectValueComponent extends UntilDestroyedMixreadonly cdRef:ChangeDetectorRef,readonly I18n:I18nService,protected currentProject:CurrentProjectService,+ protected currentUser:CurrentUserService,readonly halNotification:HalResourceNotificationService,readonly ngZone:NgZone) {super();@@ -74,14 +82,14 @@ export class FilterSearchableMultiselectValueComponent extends UntilDestroyedMixpublic loadAvailable(matching:string):Observable<HalResource[]> {const filters:ApiV3FilterBuilder = this.createFilters(matching);- const { href } = this.filter.currentSchema!.values!.allowedValues as any;+ const { href } = this.filter.currentSchema!.values!.allowedValues as { href:string };const filteredData = (this.apiV3Service.collectionFromString(href) asApiV3ResourceCollection<HalResource, ApiV3Resource>).filtered(filters, { pageSize: '-1' }).get().pipe(- map((collection) => collection.elements),+ switchMap((collection) => this.withMeValue(collection.elements)),);return filteredData;@@ -102,4 +110,30 @@ export class FilterSearchableMultiselectValueComponent extends UntilDestroyedMixthis.filterChanged.emit(this.filter);this.cdRef.detectChanges();}++ private withMeValue(elements:HalResource[]):Observable<HalResource[]> {+ if (!this.isUserResource) {+ return of(elements);+ }++ return this+ .currentUser+ .isLoggedIn$+ .pipe(+ take(1),+ withLatestFrom(this.currentUser.user$),+ map(([logged, user]) => {+ if (logged && user) {+ return [this.meValue].concat(elements);+ }++ return elements;+ }),+ );+ }++ private get isUserResource() {+ const type = _.get(this.filter.currentSchema, 'values.type', null) as string;+ return type && type.indexOf('User') > 0;+ }}diff --git a/spec/features/work_packages/table/queries/me_filter_spec.rb b/spec/features/work_packages/table/queries/me_filter_spec.rbindex 2d331b038cd..649df15714e 100644--- a/spec/features/work_packages/table/queries/me_filter_spec.rb+++ b/spec/features/work_packages/table/queries/me_filter_spec.rb@@ -114,6 +114,10 @@ describe 'filter me value', js: true do# Expect new work packages receive assigneesplit_screen = wp_table.create_wp_by_button wp_user.type++ # Wait a bit for the page to load+ sleep 2+subject = split_screen.edit_field :subjectsubject.set_value 'foobar'subject.submit_by_enter