From 418f37917d8d98d5c406353c5ca63b7d9bc2d2cf Mon Sep 17 00:00:00 2001 From: Tristan Eisermann <19949441+Tristan2357@users.noreply.github.com> Date: Tue, 28 Jul 2020 16:12:53 +0200 Subject: [PATCH] TSK-1338: List now does not refresh after selection of a task --- .../task-list-toolbar.component.ts | 5 ++- .../task-list/task-list.component.ts | 1 - .../task-master/task-master.component.ts | 44 ++++++++---------- .../components/task/task.component.ts | 1 + .../app/workplace/services/task.service.ts | 45 +++++++------------ 5 files changed, 38 insertions(+), 58 deletions(-) diff --git a/web/src/app/workplace/components/task-list-toolbar/task-list-toolbar.component.ts b/web/src/app/workplace/components/task-list-toolbar/task-list-toolbar.component.ts index f8ca074f2..bb1b8b261 100644 --- a/web/src/app/workplace/components/task-list-toolbar/task-list-toolbar.component.ts +++ b/web/src/app/workplace/components/task-list-toolbar/task-list-toolbar.component.ts @@ -7,7 +7,7 @@ import { Sorting } from 'app/shared/models/sorting'; import { Filter } from 'app/shared/models/filter'; import { TaskanaType } from 'app/shared/models/taskana-type'; import { expandDown } from 'theme/animations/expand.animation'; -import { ActivatedRoute, Router, NavigationExtras } from '@angular/router'; +import { ActivatedRoute, NavigationExtras, Router } from '@angular/router'; import { WorkplaceService } from 'app/workplace/services/workplace.service'; import { ObjectReference } from 'app/workplace/models/object-reference'; @@ -15,6 +15,7 @@ export enum Search { byWorkbasket = 'workbasket', byTypeAndValue = 'type-and-value' } + @Component({ selector: 'taskana-task-list-toolbar', animations: [expandDown], @@ -94,7 +95,6 @@ export class TaskListToolbarComponent implements OnInit { this.workplaceService.selectObjectReference(objectReference); this.searched = true; } else { - this.workplaceService.selectObjectReference(); if (this.workbaskets) { this.workbaskets.forEach((workbasket) => { if (workbasket.name === this.resultName) { @@ -141,5 +141,6 @@ export class TaskListToolbarComponent implements OnInit { }; this.router.navigate([''], navigationExtras); + this.searchBasket(); } } diff --git a/web/src/app/workplace/components/task-list/task-list.component.ts b/web/src/app/workplace/components/task-list/task-list.component.ts index 4906e9fd3..2cdfe010b 100644 --- a/web/src/app/workplace/components/task-list/task-list.component.ts +++ b/web/src/app/workplace/components/task-list/task-list.component.ts @@ -23,7 +23,6 @@ export class TaskListComponent implements OnInit { ngOnInit() {} selectTask(taskId: string) { - this.workplaceService.selectObjectReference(); this.selectedId = taskId; this.selectedIdChange.emit(taskId); this.router.navigate([{ outlets: { detail: `taskdetail/${this.selectedId}` } }], { relativeTo: this.route }); diff --git a/web/src/app/workplace/components/task-master/task-master.component.ts b/web/src/app/workplace/components/task-master/task-master.component.ts index 5fc13bbcc..75396d58f 100644 --- a/web/src/app/workplace/components/task-master/task-master.component.ts +++ b/web/src/app/workplace/components/task-master/task-master.component.ts @@ -39,7 +39,6 @@ export class TaskMasterComponent implements OnInit, OnDestroy { }); requestInProgress = false; - objectReference: ObjectReference; selectedSearchType: Search = Search.byWorkbasket; destroy$ = new Subject(); @@ -55,19 +54,18 @@ export class TaskMasterComponent implements OnInit, OnDestroy { ) {} ngOnInit() { - this.taskService - .getSelectedTask() - .pipe(takeUntil(this.destroy$)) - .subscribe((task: Task) => { - if (!this.currentBasket) { - this.selectedId = task.taskId; - this.currentBasket = task.workbasketSummary; - this.getTasks(); - } - if (!task) { - this.selectedId = ''; - } - }); + this.taskService.taskSelectedStream.pipe(takeUntil(this.destroy$)).subscribe((task: Task) => { + this.selectedId = task ? task.taskId : ''; + if (!this.tasks) { + this.currentBasket = task.workbasketSummary; + this.getTasks(); + } + }); + + this.taskService.taskChangedStream.pipe(takeUntil(this.destroy$)).subscribe((task) => { + this.currentBasket = task.workbasketSummary; + this.getTasks(); + }); this.orientationService .getOrientation() @@ -76,11 +74,6 @@ export class TaskMasterComponent implements OnInit, OnDestroy { this.refreshWorkbasketList(); }); - this.taskService.taskChangedStream.pipe(takeUntil(this.destroy$)).subscribe((task) => { - this.getTasks(); - this.selectedId = task ? task.taskId : ''; - }); - this.workplaceService.workbasketSelectedStream.pipe(takeUntil(this.destroy$)).subscribe((workbasket) => { this.currentBasket = workbasket; if (this.selectedSearchType === Search.byWorkbasket) { @@ -89,10 +82,9 @@ export class TaskMasterComponent implements OnInit, OnDestroy { }); this.workplaceService.objectReferenceSelectedStream.pipe(takeUntil(this.destroy$)).subscribe((objectReference) => { - this.objectReference = objectReference; - delete this.currentBasket; if (objectReference) { - this.getTasks(); + delete this.currentBasket; + this.getTasks(objectReference); } }); } @@ -134,9 +126,9 @@ export class TaskMasterComponent implements OnInit, OnDestroy { } } - private getTasks(): void { + private getTasks(objectReference?: ObjectReference): void { this.requestInProgress = true; - if (!this.currentBasket && !this.objectReference) { + if (!this.currentBasket && !objectReference) { this.requestInProgress = false; this.tasks = []; } else { @@ -150,8 +142,8 @@ export class TaskMasterComponent implements OnInit, OnDestroy { this.filterBy.filterParams.owner, this.filterBy.filterParams.priority, this.filterBy.filterParams.state, - this.objectReference ? this.objectReference.type : '', - this.objectReference ? this.objectReference.value : '' + objectReference ? objectReference.type : '', + objectReference ? objectReference.value : '' ) .pipe(takeUntil(this.destroy$)) .subscribe((taskResource) => { diff --git a/web/src/app/workplace/components/task/task.component.ts b/web/src/app/workplace/components/task/task.component.ts index a7af6b6df..309b7f95b 100644 --- a/web/src/app/workplace/components/task/task.component.ts +++ b/web/src/app/workplace/components/task/task.component.ts @@ -43,6 +43,7 @@ export class TaskComponent implements OnInit, OnDestroy { async getTask(id: string) { this.requestInProgress = true; this.task = await this.taskService.getTask(id).toPromise(); + this.taskService.selectTask(this.task); const classification = await this.classificationService .getClassification(this.task.classificationSummary.classificationId) .toPromise(); diff --git a/web/src/app/workplace/services/task.service.ts b/web/src/app/workplace/services/task.service.ts index 499c92c38..e2424c810 100644 --- a/web/src/app/workplace/services/task.service.ts +++ b/web/src/app/workplace/services/task.service.ts @@ -6,22 +6,20 @@ import { environment } from 'environments/environment'; import { TaskResource } from 'app/workplace/models/task-resource'; import { Direction } from 'app/shared/models/sorting'; import { TaskanaQueryParameters } from 'app/shared/util/query-parameters'; -import { TaskanaDate } from 'app/shared/util/taskana.date'; -import { map } from 'rxjs/operators'; import { QueryParameters } from 'app/shared/models/query-parameters'; @Injectable() export class TaskService { url = `${environment.taskanaRestUrl}/v1/tasks`; - taskChangedSource = new Subject(); + private taskChangedSource = new Subject(); taskChangedStream = this.taskChangedSource.asObservable(); - taskSelectedSource = new Subject(); + private taskSelectedSource = new Subject(); taskSelectedStream = this.taskSelectedSource.asObservable(); constructor(private httpClient: HttpClient) {} - publishUpdatedTask(task: Task = new Task('empty')) { + publishUpdatedTask(task?: Task) { this.taskChangedSource.next(task); } @@ -46,7 +44,7 @@ export class TaskService { allPages: boolean = false ): Observable { const url = `${this.url}${TaskanaQueryParameters.getQueryParameters( - this.accessIdsParameters( + TaskService.accessIdsParameters( basketId, sortBy, sortDirection, @@ -70,16 +68,17 @@ export class TaskService { return this.httpClient.post(`${this.url}/${id}/complete`, ''); } - claimTask(id: string): Observable { + // currently unused + /* claimTask(id: string): Observable { return this.httpClient.post(`${this.url}/${id}/claim`, 'test'); - } + } */ transferTask(taskId: string, workbasketId: string): Observable { return this.httpClient.post(`${this.url}/${taskId}/transfer/${workbasketId}`, ''); } updateTask(task: Task): Observable { - const taskConv = this.convertTasksDatesToGMT(task); + const taskConv = TaskService.convertTasksDatesToGMT(task); return this.httpClient.put(`${this.url}/${task.taskId}`, taskConv); } @@ -91,29 +90,17 @@ export class TaskService { return this.httpClient.post(this.url, task); } - private convertTasksDatesToGMT(task: Task): Task { - if (task.created) { - task.created = new Date(task.created).toISOString(); - } - if (task.claimed) { - task.claimed = new Date(task.claimed).toISOString(); - } - if (task.completed) { - task.completed = new Date(task.completed).toISOString(); - } - if (task.modified) { - task.modified = new Date(task.modified).toISOString(); - } - if (task.planned) { - task.planned = new Date(task.planned).toISOString(); - } - if (task.due) { - task.due = new Date(task.due).toISOString(); - } + private static convertTasksDatesToGMT(task: Task): Task { + const timeAttributes = ['created', 'claimed', 'completed', 'modified', 'planned', 'due']; + timeAttributes.forEach((attributeName) => { + if (task[attributeName]) { + task[attributeName] = new Date(task[attributeName]).toISOString(); + } + }); return task; } - private accessIdsParameters( + private static accessIdsParameters( basketId: string, sortBy = 'priority', sortDirection: string = Direction.ASC,