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
Load projects via signalling in project-autocompleter
Benjamin Bädorf1a3597889a5f
diff --git a/frontend/src/app/features/invite-user-modal/project-selection/project-selection.component.html b/frontend/src/app/features/invite-user-modal/project-selection/project-selection.component.htmlindex 365c2511d10..1fcc4fb8e2c 100644--- a/frontend/src/app/features/invite-user-modal/project-selection/project-selection.component.html+++ b/frontend/src/app/features/invite-user-modal/project-selection/project-selection.component.html@@ -12,6 +12,8 @@<op-project-autocompleter[opFormBinding]="projectControl"slot="input"+ [APIFilters]="APIFiltersForProjects"+ [resultsFilterFn]="projectFilterFn"></op-project-autocompleter><divdiff --git a/frontend/src/app/features/invite-user-modal/project-selection/project-selection.component.ts b/frontend/src/app/features/invite-user-modal/project-selection/project-selection.component.tsindex 9d04faa4b24..e5e820a4a4d 100644--- a/frontend/src/app/features/invite-user-modal/project-selection/project-selection.component.ts+++ b/frontend/src/app/features/invite-user-modal/project-selection/project-selection.component.ts@@ -18,6 +18,7 @@ import { IOpOptionListOption } from 'core-app/shared/components/option-list/optiimport { ProjectResource } from 'core-app/features/hal/resources/project-resource';import { PrincipalType } from '../invite-user.component';import { ProjectAllowedValidator } from './project-allowed.validator';+import { IProject } from 'core-app/core/state/projects/project.model';@Component({selector: 'op-ium-project-selection',@@ -121,4 +122,11 @@ export class ProjectSelectionComponent implements OnInit {type: this.typeControl?.value,});}++ APIFiltersForProjects = [['active', '=', true]];++ projectFilterFn(projects:IProject[]) {+ console.log('filtering!', projects);+ return projects;+ }}diff --git a/frontend/src/app/shared/components/autocompleter/project-autocompleter/project-autocompleter.component.html b/frontend/src/app/shared/components/autocompleter/project-autocompleter/project-autocompleter.component.htmlindex f412af23f49..10dff73cf60 100644--- a/frontend/src/app/shared/components/autocompleter/project-autocompleter/project-autocompleter.component.html+++ b/frontend/src/app/shared/components/autocompleter/project-autocompleter/project-autocompleter.component.html@@ -12,13 +12,14 @@[appendTo]="appendTo"[multiple]="multiple">- <ng-template ng-option-tmp let-item="item" let-index="index">- <op-principal- *ngIf="item && item.href"- [principal]="item"- [hideName]="true"- size="mini"- ></op-principal>- {{ item.name }}+ <ng-template+ ng-option-tmp+ let-item="item"+ let-index="index"+ >+ <div [ngStyle]="{ 'padding-left.px': item.numberOfAncestors * 20 }">+ {{ item.name }}+ {{ item.numberOfAncestors }}+ </div></ng-template></ng-select>diff --git a/frontend/src/app/shared/components/autocompleter/project-autocompleter/project-autocompleter.component.ts b/frontend/src/app/shared/components/autocompleter/project-autocompleter/project-autocompleter.component.tsindex 1f9a7377258..c53db4fdf09 100644--- a/frontend/src/app/shared/components/autocompleter/project-autocompleter/project-autocompleter.component.ts+++ b/frontend/src/app/shared/components/autocompleter/project-autocompleter/project-autocompleter.component.ts@@ -42,22 +42,43 @@ import { HalResourceNotificationService } from 'core-app/features/hal/services/himport { NgSelectComponent } from '@ng-select/ng-select';import { ProjectResource } from 'core-app/features/hal/resources/project-resource';import { ApiV3Service } from 'core-app/core/apiv3/api-v3.service';-import { ApiV3FilterBuilder, FilterOperator } from 'core-app/shared/helpers/api-v3/api-v3-filter-builder';import { DatasetInputs } from 'core-app/shared/components/dataset-inputs.decorator';+import { ApiV3ListFilter, listParamsString } from 'core-app/core/apiv3/paths/apiv3-list-resource.interface';+import { getPaginatedResults } from 'core-app/core/apiv3/helpers/get-paginated-results';+import { IHALCollection } from 'core-app/core/apiv3/types/hal-collection.type';+import { IProject } from 'core-app/core/state/projects/project.model';+import { HttpClient } from '@angular/common/http';++import { insertInList } from '../../project-include/insert-in-list';+import { recursiveSort } from '../../project-include/recursive-sort';+import { IProjectData } from '../../project-include/project-data';+import { ID } from '@datorama/akita';export const projectsAutocompleterSelector = 'op-project-autocompleter';export interface IProjectAutocompleteItem {name:string;- id:string|null;+ id:ID;href:string|null;- avatar:string|null;+ numberOfAncestors:number;+ disabled?:boolean;+ disabledReason?:string;}-export interface IProjectAutocompleterFilters {- selector:string;- operator:FilterOperator;- values:string[];+const flattenProjectTree = (projectTree:IProjectData, depth = 0):IProjectAutocompleteItem[] => {+ let projectList = [+ {+ name: projectTree.name,+ id: projectTree.id,+ href: projectTree.href,+ numberOfAncestors: depth,+ }+ ];++ return projectTree.children.reduce((list, child) => [+ ...list,+ ...flattenProjectTree(child, depth + 1),+ ], projectList);};@DatasetInputs@@ -85,34 +106,25 @@ export class ProjectAutocompleterComponent implements OnInit {@Input() public initialSelection:number|null = null;- private _additionalFilters:IProjectAutocompleterFilters[] = [];- @Input()- public set additionalFilters(newFilters:IProjectAutocompleterFilters[]) {- this._additionalFilters = newFilters;- this.inputFilters = new ApiV3FilterBuilder();- this.additionalFilters.forEach((filter) => this.inputFilters.add(filter.selector, filter.operator, filter.values));- }- public get additionalFilters() {- return this._additionalFilters;- }+ @Input() public APIFilters:ApiV3ListFilter[] = [];- public inputFilters:ApiV3FilterBuilder = new ApiV3FilterBuilder();+ @Input() public resultsFilterFn:(projects:IProject[]) => IProject[] = (projects) => projects;// Update an input field after changing, used when externally loadedprivate updateInputField:HTMLInputElement|undefined;/** Keep a switchmap for search term and loading state */public requests = new DebouncedRequestSwitchmap<string, IProjectAutocompleteItem>(- (searchTerm:string) => this.getAvailableProjects(this.url, searchTerm),+ (searchTerm:string) => this.getAvailableProjects(searchTerm),errorNotificationHandler(this.halNotification),);-constructor(public elementRef:ElementRef,protected halResourceService:HalResourceService,protected I18n:I18nService,protected halNotification:HalResourceNotificationService,+ readonly http:HttpClient,readonly pathHelper:PathHelperService,readonly apiV3Service:ApiV3Service,readonly injector:Injector,@@ -145,29 +157,46 @@ export class ProjectAutocompleterComponent implements OnInit {}}- protected getAvailableProjects(url:string, searchTerm:any):Observable<IProjectAutocompleteItem[]> {- // Need to clone the filters to not add additional filters on every- // search term being processed.- const searchFilters = this.inputFilters.clone();-- if (searchTerm && searchTerm.length) {- searchFilters.add('name', '~', [searchTerm]);- }-- return this.halResourceService- .get(url, { filters: searchFilters.toJson() })+ protected getAvailableProjects(searchTerm:string):Observable<IProjectAutocompleteItem[]> {+ return getPaginatedResults<IProject>(+ (params) => {+ const filters:ApiV3ListFilter[] = [ ...this.APIFilters ];+ const fullParams = {+ filters,+ select: [+ 'elements/id',+ 'elements/name',+ 'elements/identifier',+ 'elements/self',+ 'elements/ancestors',+ 'total',+ 'count',+ 'pageSize',+ ],+ ...params,+ };+ const collectionURL = listParamsString(fullParams);+ return this.http.get<IHALCollection<IProject>>(this.url + collectionURL);+ },+ ).pipe(- map((res) => {- const options = res.elements.map((el:any) => ({- name: el.name, id: el.id, href: el.href, avatar: el.avatar,- }));-- if (this.allowEmpty) {- options.unshift({ name: this.I18n.t('js.timelines.filter.noneSelection'), href: null, id: null });- }-- return options;- }),+ map(this.resultsFilterFn),+ map((projects) => projects+ .sort((a, b) => a._links.ancestors.length - b._links.ancestors.length)+ .reduce(+ (list, project) => {+ const { ancestors } = project._links;++ return insertInList(projects, project, list, ancestors);+ },+ [] as IProjectData[],+ )+ ),+ map((projects) => recursiveSort(projects)),+ map((projectTreeItems) => projectTreeItems+ .map(item => flattenProjectTree(item))+ .reduce((total, list) => [...total, ...list], []),+ ));}diff --git a/frontend/src/app/shared/helpers/rxjs/debounced-input-switchmap.ts b/frontend/src/app/shared/helpers/rxjs/debounced-input-switchmap.tsindex 211f3852203..10cea3f243a 100644--- a/frontend/src/app/shared/helpers/rxjs/debounced-input-switchmap.ts+++ b/frontend/src/app/shared/helpers/rxjs/debounced-input-switchmap.ts@@ -43,10 +43,12 @@ export class DebouncedRequestSwitchmap<T, R = HalResource> {* @param preFilterNull {boolean} Whether to exclude null and undefined searches* @param emptyValue {R} The empty fall back value before first response or on errors*/- constructor(readonly requestHandler:RequestSwitchmapHandler<T, R[]>,+ constructor(+ readonly requestHandler:RequestSwitchmapHandler<T, R[]>,readonly errorHandler:RequestErrorHandler,readonly preFilterNull:boolean = false,- readonly debounceMs = 250) {+ readonly debounceMs = 250,+ ) {/** Output switchmap observable */this.output$ = concat(of([]),