From 84519ef81c74b9e0d4fe9c16f494da441ad8e0ab Mon Sep 17 00:00:00 2001 From: Florian Eisenmenger Date: Tue, 26 Mar 2024 15:47:55 +0100 Subject: [PATCH] new task partners fixed --- .../tasks/new-task/new-task.component.html | 14 ++++------ .../app/tasks/new-task/new-task.component.ts | 26 ++++++++++++++++--- 2 files changed, 27 insertions(+), 13 deletions(-) diff --git a/matsen-tool/src/app/tasks/new-task/new-task.component.html b/matsen-tool/src/app/tasks/new-task/new-task.component.html index c7fffb8..abbb485 100644 --- a/matsen-tool/src/app/tasks/new-task/new-task.component.html +++ b/matsen-tool/src/app/tasks/new-task/new-task.component.html @@ -18,20 +18,16 @@ -
+
- -
- {{ 'form.partner' | translate }} {{ 'form.mandatory' | translate }}. -
+ +
-
diff --git a/matsen-tool/src/app/tasks/new-task/new-task.component.ts b/matsen-tool/src/app/tasks/new-task/new-task.component.ts index 44a111f..28d6880 100644 --- a/matsen-tool/src/app/tasks/new-task/new-task.component.ts +++ b/matsen-tool/src/app/tasks/new-task/new-task.component.ts @@ -1,5 +1,5 @@ import {Component, EventEmitter, Input, OnInit, Output} from '@angular/core'; -import {TaskJsonld, TaskService, UserJsonld, UserService} from "@app/core/api/v1"; +import {PartnerService, TaskJsonld, TaskService, UserJsonld, UserService} from "@app/core/api/v1"; import {ModalStatus} from "@app/_helpers/modal.states"; import {FormGroupInitializer} from "@app/_helpers/formgroup.initializer"; import {FormGroup} from "@angular/forms"; @@ -23,7 +23,7 @@ export class NewTaskComponent implements OnInit { protected formatter = (apiData: any) => apiData.name; - protected search: OperatorFunction = (text$: Observable) => + protected searchUsers: OperatorFunction = (text$: Observable) => text$.pipe( debounceTime(200), distinctUntilChanged(), @@ -32,9 +32,19 @@ export class NewTaskComponent implements OnInit { map((users) => users.slice(0, 10)), ); + protected searchPartners: OperatorFunction = (text$: Observable) => + text$.pipe( + debounceTime(200), + distinctUntilChanged(), + filter((term) => term.length >= 2), + switchMap((term) => this.fetchPartners(term)), + map((partners) => partners.slice(0, 10)), + ); + constructor( private taskService: TaskService, - private userService: UserService + private userService: UserService, + private partnerService: PartnerService ) { this.taskForm = taskForm; this.taskSub = new Subscription(); @@ -42,7 +52,6 @@ export class NewTaskComponent implements OnInit { } ngOnInit(): void { - console.log(this.dueAtValue); this.taskForm = FormGroupInitializer.initFormGroup(this.taskForm, this.task); } @@ -52,6 +61,15 @@ export class NewTaskComponent implements OnInit { ); } + protected fetchPartners(term: string): Observable<{ id: any; name: any }[]> { + return this.partnerService.partnersGetCollection(1, 50, undefined, undefined, term).pipe( + map((response) => response['hydra:member'].map(partner => ({ id: partner.id, name: partner.name }))), + ); + } + + protected onPartnerSelect(selectedItem: any): void { + this.taskForm.get('partner')?.setValue(selectedItem.item.id); + } protected onAssignedToSelect(selectedItem: any): void { this.taskForm.get('assignedTo')?.setValue(selectedItem.item.id);